示例#1
0
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('" . addslashes($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();
        $id = array_pop($bid);
        while ($id != null) {
            $book = new mosBookLibrary($database);
            $book->load($id);
            $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();
            }
            $id = array_pop($bid);
        }
        $infos = array_reverse($infos);
        HTML_booklibrary::showInfoRefetchBooks($option, $infos, $wslist);
    }
}