Beispiel #1
0
/**
 * 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 $mosConfig_absolute_path;
    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 = array();
    if (empty($book->bookid) && $booklibrary_configuration['bookid']['auto-increment']['boolean'] == 1) {
        $database->setQuery("select bookid from #__booklibrary order by bookid");
        $bookids = $database->loadObjectList();
        foreach ($bookids as $bookid) {
            if (!is_numeric($bookid->bookid)) {
                echo "<script> alert('You have no numeric BookId. Please set option  " . _BOOKLIBRARY_ADMIN_CONFIG_BOOKID_AUTO_INCREMENT . " to \\'No\\' or change all BookID to numeric '); window.history.go(-1); </script>\n";
                exit;
            }
            $numeric_bookids[] = intval($bookid->bookid);
        }
        if (count($bookids) > 0) {
            sort($numeric_bookids);
            $book->bookid = $numeric_bookids[count($numeric_bookids) - 1] + 1;
        } else {
            $book->bookid = 1;
        }
    }
    // get list of categories
    $categories[] = mosHTML::makeOption('0', _BOOKLIBRARY_LABEL_SELECT_CATEGORIES);
    $query = "SELECT  id ,name, parent_id as parent" . "\n FROM #__booklibrary_main_categories" . "\n WHERE section='com_booklibrary'" . "\n AND published > 0" . "\n ORDER BY parent_id, ordering";
    $database->setQuery($query);
    $rows = $database->loadObjectList();
    // 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);
    foreach ($list as $i => $item) {
        $item->text = $item->treename;
        $item->value = $item->id;
        $list[$i] = $item;
    }
    $categories = array_merge($categories, $list);
    if (count($categories) <= 1) {
        mosRedirect("index.php?option=com_booklibrary&section=categories", _BOOKLIBRARY_ADMIN_IMPEXP_ADD);
    }
    $query = "select catid from #__booklibrary_categories where bookid='" . $book->id . "'";
    $database->setQuery($query);
    //$cat_idlist = $database->loadResultArray();
    if (version_compare(JVERSION, '3.0', 'lt')) {
        $cat_idlist = $database->loadResultArray();
    } else {
        $cat_idlist = $database->loadColumn();
    }
    if (empty($cat_idlist)) {
        $cat_idlist[0] = '0';
    }
    $clist = mosHTML::selectList($categories, 'catid[]', 'class="inputbox"', 'value', 'text', $cat_idlist);
    // 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', intval($booklibrary_configuration['editbook']['default']['host']));
    } 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']);
        $langlistshow = mosHTML::selectList($lang, 'langshow', 'class="inputbox" size="1"', 'value', 'text', '1');
    } else {
        $langlist = mosHTML::selectList($lang, 'language', 'class="inputbox" size="1"', 'value', 'text', $book->language);
        $langlistshow = mosHTML::selectList($lang, 'langshow', 'class="inputbox" size="1"', 'value', 'text', $book->langshow);
    }
    //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);
    if (!empty($book->id)) {
        //check ebook file
        $db = JFactory::getDBO();
        $db->setQuery("SELECT * FROM #__booklibrary_files WHERE fk_book_id=" . $book->id);
        $files = $db->loadObjectList();
    } else {
        $files = array();
    }
    if ($book->checked_out && $book->checked_out != $my->id) {
        mosRedirect("index.php?option={$option}", _BOOKLIBRARY_IS_EDITED);
    }
    // fail if checked out not by 'me'
    if ($book->checked_out && $book->checked_out != $my->id) {
        mosRedirect("index.php?option={$option}", _BOOKLIBRARY_IS_EDITED);
    }
    if ($bid) {
        $book->checkout($my->id);
    } else {
        // initialise new record
        $book->published = 0;
        $book->approved = 0;
    }
    if ($book->owneremail == '' || $bid == 0) {
        $book->owneremail = $my->email;
    }
    $database->setQuery("SELECT username AS owner FROM #__users" . "\nWHERE email='{$book->owneremail}'");
    $book->owner = $database->loadResult();
    //*****************************   begin for reviews **************************/
    $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 as 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, $langlistshow, $ratinglist, $delete_ebook, $reviews, $files);
}
Beispiel #2
0
 static function add_book_fe($option, $bid)
 {
     global $database, $my, $mosConfig_live_site, $booklibrary_configuration, $Itemid, $mainframe;
     PHP_booklibrary::addTitleAndMetaTags();
     $book = new mosBookLibrary($database);
     $book->load(intval($bid));
     if ($bid != 0 && $my->email != $book->owneremail) {
         mosRedirect('index.php?option=com_booklibrary&Itemid=$Itemid');
         exit;
     }
     if ($bid == 0) {
         $pathway = sefRelToAbs('index.php?option=' . $option . '&amp;task=add_book_fe&amp;Itemid=' . $Itemid);
         $pathway_name = _BOOKLIBRARY_LABEL_TITLE_ADD_BOOK;
     } else {
         $pathway = sefRelToAbs('index.php?option=' . $option . '&amp;task=edit_book&amp;Itemid=' . $Itemid . '&amp;id=' . $bid);
         $pathway_name = _BOOKLIBRARY_LABEL_TITLE_EDIT_BOOK;
     }
     $path_way = $mainframe->getPathway();
     $path_way->addItem($pathway_name, $pathway);
     $tpl_list = array();
     if (array_key_exists('catid', $_POST)) {
         $catid = intval($_POST['catid']);
     } else {
         $catid = '';
     }
     $auto_bookID = '';
     if ($booklibrary_configuration['bookid']['auto-increment']['boolean'] == 1) {
         $database->setQuery("select bookid from #__booklibrary ORDER by bookid");
         $bookids = $database->loadObjectList();
         foreach ($bookids as $bookid) {
             if (!is_numeric($bookid->bookid)) {
                 echo "<script> alert('You have no numeric BookId. Please set option  " . _BOOKLIBRARY_ADMIN_CONFIG_BOOKID_AUTO_INCREMENT . " to \\'No\\' or change all BookID to numeric '); window.history.go(-1); </script>\n";
                 exit;
             }
             if ((int) $auto_bookID < $bookid->bookid) {
                 $auto_bookID = $bookid->bookid;
             }
         }
         if ($auto_bookID != '') {
             ++$auto_bookID;
         } else {
             $auto_bookID = 1;
         }
     }
     $categories[] = mosHTML::makeOption('0', _BOOKLIBRARY_LABEL_SELECT_CATEGORIES);
     $query = "SELECT  id ,name, parent_id as parent" . "\n FROM #__booklibrary_main_categories" . "\n WHERE section='com_booklibrary'" . "\n AND published > 0" . "\n ORDER BY parent_id, ordering";
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     // 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 = PHP_booklibrary::bookLibraryTreeRecurse(0, '', array(), $children);
     foreach ($list as $i => $item) {
         $item->text = $item->treename;
         $item->value = $item->id;
         $list[$i] = $item;
     }
     $categories = array_merge($categories, $list);
     $allow_categories = explode(',', $booklibrary_configuration['addbook_button']['allow']['categories']);
     if (count($categories) <= 1) {
         mosRedirect("index.php?option=com_booklibrary&section=categories", _BOOKLIBRARY_ADMIN_IMPEXP_ADD);
     }
     $query = "select catid from #__booklibrary_categories where bookid='" . $book->id . "'";
     $database->setQuery($query);
     if (version_compare(JVERSION, '3.0', 'lt')) {
         $cat_idlist = $database->loadResultArray();
     } else {
         $cat_idlist = $database->loadColumn();
     }
     if (empty($cat_idlist)) {
         $cat_idlist[0] = '0';
     }
     if (in_array("-2", $allow_categories)) {
         $clist = mosHTML::selectList($categories, 'catid[]', 'class="inputbox" multiple', 'value', 'text', $cat_idlist);
     } else {
         $categories_n = array();
         for ($i = 1; $i < count($categories); $i++) {
             if (in_array($categories[$i]->id, $allow_categories)) {
                 $categories_n[] = $categories[$i];
             }
         }
         $clist = mosHTML::selectList($categories_n, 'catid[]', 'class="inputbox" multiple', 'value', 'text', $cat_idlist);
     }
     $tpl_list['clist'] = $clist;
     $tpl_list['ncid'] = $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]);
     }
     $tpl_list['wlist'] = mosHTML::selectList($ws, 'informationFrom', 'class="inputbox" size="1"', 'value', 'text', intval($booklibrary_configuration['editbook']['default']['host']));
     //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]);
     }
     $tpl_list['langlist'] = mosHTML::selectList($lang, 'language', 'class="inputbox" size="1"', 'value', 'text', $booklibrary_configuration['editbook']['default']['lang']);
     $tpl_list['auto_bookID'] = $auto_bookID;
     //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);
     HTML_booklibrary::showAddBook($tpl_list, $option, $Itemid, $ratinglist, $book);
 }