Ejemplo n.º 1
0
/**
 * Saves the record on an edit form submit
 * @param database A database connector object
 */
function saveBook($option, $task)
{
    echo __FILE__ . ":  " . __LINE__ . "<br />";
    echo "qwerty11<pre>";
    print_r($_REQUEST);
    echo "<br>";
    echo "qwerty11111111</pre>";
    //exit;
    global $langlist, $database, $my, $mosConfig_absolute_path, $mosConfig_live_site, $booklibrary_configuration;
    //check how the other info should be provided
    $book = new mosBookLibrary($database);
    if (!is_numeric($_POST['bookid']) && $booklibrary_configuration['bookid']['auto-increment']['boolean'] == 1) {
        echo "<script> alert('You set no numeric BookID. Please set option " . _BOOKLIBRARY_ADMIN_CONFIG_BOOKID_AUTO_INCREMENT . " to \\'No\\' or change BookID to numeric '); window.history.go(-1); </script>\n";
        exit;
    }
    if (!$book->bind($_POST)) {
        echo "<script> alert('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n";
        exit;
    }
    $book->catid = mosGetParam($_POST, 'catid', '');
    //fetch all information from the webservices if necessary
    $book = mosBooklibraryWS::fetchInfos($book);
    $database->setQuery("SELECT owneremail, owner_id FROM #__booklibrary WHERE id = '" . $_POST['owneremail'] . "'");
    $own = $database->loadObjectList();
    if ($own == "" || $own == NUll) {
        $book->owner_id = $my->id;
    }
    if (is_string($book)) {
        //there was an error while fetching!
        echo "<script> alert('" . addslashes($book) . "'); window.history.go(-1); </script>\n";
        exit;
    }
    if ($booklibrary_configuration['publish_on_add']['show']) {
        $book->published = 1;
    } else {
        $book->published = 0;
    }
    $file = $_FILES['picture_file'];
    //-------------------
    if (intval($file['error']) != 4) {
        $ext = pathinfo($_FILES['picture_file']['name'], PATHINFO_EXTENSION);
        $allowed_exts = explode(",", $booklibrary_configuration['allowed_exts_img']);
        $ext = strtolower($ext);
        if (!in_array($ext, $allowed_exts)) {
            echo "<script> alert(' File ext. not allowed to upload! - " . $file['name'] . "'); window.history.go(-1); </script>\n";
            exit;
        }
    }
    //-------------------
    //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('" . addslashes($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('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n";
        exit;
    }
    if (!$book->store()) {
        echo "<script> alert('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n";
        exit;
    }
    storeEbook($book);
    $query = "delete from #__booklibrary_categories where bookid='" . (int) $book->id . "'";
    $database->setQuery($query);
    $database->query();
    foreach ($book->catid as $catitem) {
        $query = "insert into #__booklibrary_categories (bookid, catid) VALUES ('" . (int) $book->id . "','" . (int) $catitem . "')";
        $database->setQuery($query);
        $database->query();
    }
    $book->checkin();
    deleteFiles($book->id);
    //mosRedirect("index.php?option=$option");
    //print_r($book);exit;
    switch ($task) {
        case 'apply':
            //$_POST['bid'] = $book->id;
            // 	$_REQUEST['task'] = 'edit';
            mosRedirect("index.php?option=" . $option . "&task=edit&bid[]=" . $book->id);
            break;
        case 'save':
            mosRedirect("index.php?option=" . $option);
            break;
    }
}
 static function importBooksXML($files_name_pars, $catid)
 {
     $files_name_pars = file($files_name_pars);
     $files_name_pars = implode('', $files_name_pars);
     //echo $files_name_pars;
     global $database;
     $retVal = array();
     $new_categories = array();
     $k = 0;
     $dom = new domDocument('1.0', 'utf-8');
     $dom->loadXML($files_name_pars);
     $version = $dom->getElementsByTagName('version');
     if ($version->item(0) != NULL) {
         $numversion = explode(' ', $version->item(0)->nodeValue);
         if (intval($numversion[0]) >= 2) {
             $categories_xml = $dom->getElementsByTagName('category');
             if ($categories_xml->item(0) != NULL) {
                 //�µÑ��»�¸ �² XML �µÑ�Ñ‚ÑŒ Ñ��¿�¸Ñ��¾�º �º�°Ñ‚�µÑ€�¾�³�¸�¹ �´�»Ñ� �¸�¼�¿�¾Ñ€Ñ‚�°
                 mosBooklibraryImportExport::remove_info();
                 //ч�¸Ñ�Ñ‚�¸�¼ �±�°�·Ñƒ �´�°�½�½Ñ‹Ñ…
                 if ($catid === null) {
                     //�µÑ��»�¸ �º�°Ñ‚�µ�³�¾Ñ€�¸Ñ� �´�»Ñ� �¸�¼�¿�¾Ñ€Ñ‚�° �½�µ �²Ñ‹�±Ñ€�°�½�°
                     for ($i = 0; $i < $categories_xml->length; $i++) {
                         $category = $categories_xml->item($i);
                         $new_category = new stdClass();
                         $new_category->old_id = mosBooklibraryImportExport::getXMLItemValue($category, 'id');
                         $new_category->old_parent_id = mosBooklibraryImportExport::getXMLItemValue($category, 'parent_id');
                         $new_category->name = mosBooklibraryImportExport::getXMLItemValue($category, 'name');
                         $new_category->title = mosBooklibraryImportExport::getXMLItemValue($category, 'title');
                         $new_category->alias = mosBooklibraryImportExport::getXMLItemValue($category, 'alias');
                         $new_category->published = mosBooklibraryImportExport::getXMLItemValue($category, 'published');
                         $new_category->ordering = mosBooklibraryImportExport::getXMLItemValue($category, 'ordering');
                         $new_category->access = mosBooklibraryImportExport::getXMLItemValue($category, 'access');
                         $new_category->description = mosBooklibraryImportExport::getXMLItemValue($category, 'description');
                         $new_category->params = mosBooklibraryImportExport::getXMLItemValue($category, 'params');
                         $new_category->params2 = mosBooklibraryImportExport::getXMLItemValue($category, 'params2');
                         $new_category = mosBooklibraryImportExport::findCategory($new_categories, $new_category);
                     }
                 }
                 mosBooklibraryImportExport::refreshCategoryParentId($new_categories);
             }
             //end if exist categories
             //exit;
             $books_xml = $dom->getElementsByTagName('book');
             foreach ($books_xml as $i => $book_xml) {
                 //echo mosBooklibraryImportExport::getXMLItemValue($book_xml,'bookid');
                 $book = new mosBooklibrary($database);
                 //get BookID
                 $book->bookid = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'bookid');
                 //get ISBN
                 $book->isbn = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'isbn');
                 //get Title(book)
                 $book->title = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'title');
                 //get Authors
                 $book->authors = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'authors');
                 //get Manufacturer
                 $book->manufacturer = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'manufacturer');
                 //get releasedate
                 $book->release_Date = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'releaseDate');
                 //get language
                 $book->language = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'language');
                 $book->langshow = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'langshow');
                 if ($book->langshow == "") {
                     $book->langshow = "*";
                 }
                 //get hits
                 $book->hits = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'hits');
                 $book->user_name = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'user_name');
                 //get featured_clicks
                 $book->featured_clicks = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'featured_clicks');
                 //get featured_shows
                 $book->featured_shows = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'featured_shows');
                 //get rating
                 $book->rating = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'rating');
                 //get price
                 $book->price = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'price');
                 //get priceunit
                 $book->priceunit = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'priceunit');
                 //get URL
                 $book->URL = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'url');
                 //get imageURL
                 $book->imageURL = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'imageURL');
                 //get edition
                 $book->edition = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'edition');
                 //get ebookURL
                 $book->ebookURL = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'ebookURL');
                 //get informationFrom
                 $book->informationFrom = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'informationFrom');
                 //get date
                 $book->date = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'date');
                 //get published
                 $book->published = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'published');
                 //get comment
                 $book->comment = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'comment');
                 //get numberOfPages
                 $book->numberOfPages = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'numberOfPages');
                 $book->comment = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'comment');
                 //get email owner book
                 $book->owneremail = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'owneremail');
                 //get email owner book
                 $book->owner_id = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'owner_id');
                 //get email owner book
                 $book->vm_id_product = mosBooklibraryImportExport::getXMLItemValue($book_xml, 'vm_id_product');
                 //get Categorie
                 if ($catid != "0" && $catid != "") {
                     //�µÑ��»�¸ �²Ñ‹�±Ñ€�°�½ �¸�¼�¿�¾Ñ€Ñ‚ �² �º�°Ñ‚�µ�³�¾Ñ€�¸ÑŽ
                     $book->categs = array($catid);
                 } else {
                     $categ = $book_xml->getElementsByTagName('categ');
                     //var_dump($categ);
                     $arrcatid = array();
                     foreach ($categ as $cattemp) {
                         //Ñ��¿�¸Ñ��¾�º �º�°Ñ‚�µ�³�¾Ñ€�¸�¹ �º�½�¸�³ �¸�· XML
                         $category_book_old_id = $cattemp->nodeValue;
                         //n-�°Ñ� �º�°Ñ‚�µ�³�¾Ñ€�¸Ñ� �º�½�¸�³�¸ �¸�· XML
                         foreach ($new_categories as $new_category) {
                             //�¸Ñ‰�µ�¼ �² Ñ��¿�¸Ñ��º�µ Ñ��¾�·�´�°�½�½Ñ‹Ñ… �º�°Ñ‚�µ�³�¾Ñ€�¸�¹
                             if ($new_category->old_id == $category_book_old_id) {
                                 $arrcatid[] = $new_category->id;
                             }
                         }
                     }
                     $book->categs = $arrcatid;
                 }
                 $tmp[] = $i;
                 $tmp[] = $book->bookid;
                 $tmp[] = $book->isbn;
                 $tmp[] = $book->title;
                 $tmp[] = $book->authors;
                 $tmp[] = $book->manufacturer;
                 if (!$book->check()) {
                     $tmp[] = $book->getError();
                     $retVal[$i] = $tmp;
                     unset($tmp);
                     continue;
                 }
                 if (!$book->store()) {
                     $tmp[] = $book->getError();
                     $retVal[$i] = $tmp;
                     unset($tmp);
                     continue;
                 } else {
                     $book->saveCategs();
                     $tmp[] = "OK";
                     //save categ
                     //get Reviews
                     if (mosBooklibraryImportExport::getXMLItemValue($book_xml, 'reviews') != "") {
                         $review_list = $book_xml->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();*/
                             $fk_bookid = $book->id;
                             //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 #__booklibrary_review
                             if (version_compare(JVERSION, "3.3.0", "ge")) {
                                 $database->setQuery("INSERT INTO #__booklibrary_review" . "\n (fk_bookid, fk_userid, date, rating, title, comment)" . "\n VALUES " . "\n (" . $database->Quote($fk_bookid) . ",\n                                                    " . $database->Quote($review_fk_userid) . ",\n                                                    " . $database->Quote($review_date) . ",\n                                                    " . $database->Quote($review_rating) . ",\n                                                    " . $database->Quote($review_title) . ",\n                                                    " . $database->Quote($review_comment) . ");");
                             } else {
                                 $database->setQuery("INSERT INTO #__booklibrary_review" . "\n (fk_bookid, fk_userid, date, rating, title, comment)" . "\n VALUES " . "\n (" . $fk_bookid . ",\n                                                        " . $review_fk_userid . ",\n                                                        '" . $review_date . "',\n                                                        " . $review_rating . ",\n                                                        '" . $review_title . "',\n                                                        '" . $review_comment . "');");
                             }
                             $database->query();
                         }
                         //end for(...) - REVIEW
                     }
                     //end if(...) - REVIEW
                     //***********************************************efiles **************************************************
                     if (mosBooklibraryImportExport::getXMLItemValue($book_xml, 'ebook') != "") {
                         $ebook_list = $book_xml->getElementsByTagName('ebook');
                         for ($j = 0; $j < $ebook_list->length; $j++) {
                             $efile = $ebook_list->item($j);
                             $fk_bookid = $book->id;
                             $efileLoc = mosBooklibraryImportExport::getXMLItemValue($efile, 'location');
                             $efileDesc = mosBooklibraryImportExport::getXMLItemValue($efile, 'description');
                             //insert data in table #__booklibrary_files
                             $database->setQuery("INSERT INTO #__booklibrary_files" . "\n (fk_book_id, location, description)" . "\n VALUES " . "\n (" . $fk_bookid . ",\n                                                    '" . $efileLoc . "',\n                                                    '" . $efileDesc . "');");
                             $database->query();
                         }
                         //end for(...) - EFILES
                     }
                     //end if(...) - EFILES
                     //************************************************end efiles***********************************************
                     $book->checkin();
                     //$book->updateOrder( "catid='$book->catid'" );
                     $retVal[$i] = $tmp;
                 }
                 //echo $i,':';var_dump($tmp); echo '<br/>';
                 unset($tmp);
                 continue;
             }
             //end foreach books */
         }
         // end if version >2.0
     } else {
         // ----- OLD VERSION------
         //exit;
         $st = $bookid = "";
         $begin = $end = $kol = 0;
         $book_list = $dom->getElementsByTagName('book');
         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 = 1 + $book_class->getMaxBookid();
             //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 hits
             $book_class->hits = mosBooklibraryImportExport::getXMLItemValue($book, 'hits');
             $book_class->user_name = mosBooklibraryImportExport::getXMLItemValue($book, 'user_name');
             //get rating
             $book_class->rating = mosBooklibraryImportExport::getXMLItemValue($book, 'rating');
             //get featured_clicks
             $book_class->featured_clicks = mosBooklibraryImportExport::getXMLItemValue($book, 'featured_clicks');
             //get featured_shows
             $book_class->featured_shows = mosBooklibraryImportExport::getXMLItemValue($book, 'featured_shows');
             //get price
             $book_class->price = mosBooklibraryImportExport::getXMLItemValue($book, 'price');
             if (substr($book_class->price, 0, 1) == "\$") {
                 $book_class->price = substr($book_class->price, 1);
                 $book_class->priceunit = 'USD';
             }
             //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->categs = array($catid);
             //get Language
             $book_class->language = mosBooklibraryImportExport::getXMLItemValue($book, 'language');
             $book_class->langshow = mosBooklibraryImportExport::getXMLItemValue($book, 'langshow');
             if ($book_class->langshow == "") {
                 $book_class->langshow = "*";
             }
             //get Comment for book (item Book Description)
             $book_class->comment = mosBooklibraryImportExport::getXMLItemValue($book, 'comment');
             //get vm_id_product
             $book_class->vm_id_product = mosBooklibraryImportExport::getXMLItemValue($book, 'vm_id_product');
             //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();
                 $retVal[$i] = $tmp;
                 continue;
             }
             if (!$book_class->store()) {
                 $tmp[6] = $book_class->getError();
                 $retVal[$i] = $tmp;
                 continue;
             } else {
                 $tmp[6] = "OK";
                 $book_class->saveCategs();
             }
             //***********************************************efiles **************************************************
             if (mosBooklibraryImportExport::getXMLItemValue($book_xml, 'ebook') != "") {
                 $ebook_list = $book_xml->getElementsByTagName('ebook');
                 for ($j = 0; $j < $ebook_list->length; $j++) {
                     $efile = $ebook_list->item($j);
                     $fk_bookid = $book->id;
                     $efileLoc = mosBooklibraryImportExport::getXMLItemValue($efile, 'location');
                     $efileDesc = mosBooklibraryImportExport::getXMLItemValue($efile, 'description');
                     //insert data in table #__booklibrary_files
                     $database->setQuery("INSERT INTO #__booklibrary_files" . "\n (fk_book_id, location, description)" . "\n VALUES " . "\n (" . $fk_bookid . ",\n                                                    '" . $efileLoc . "',\n                                                    '" . $efileDesc . "');");
                     $database->query();
                 }
                 //end for(...) - EFILES
             }
             //end if(...) - EFILES
             //************************************************end efiles***********************************************
             $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();*/
                     $fk_bookid = $book_class->id;
                     //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 #__booklibrary_review
                     if (version_compare(JVERSION, "3.3.0", "ge")) {
                         $database->setQuery("INSERT INTO #__booklibrary_review" . "\n (fk_bookid, fk_userid, date, rating, title, comment)" . "\n VALUES " . "\n (" . $database->Quote($fk_bookid) . ",\n                                                    " . $database->Quote($review_fk_userid) . ",\n                                                    " . $database->Quote($review_date) . ",\n                                                    " . $database->Quote($review_rating) . ",\n                                                    " . $database->Quote($review_title) . ",\n                                                    " . $database->Quote($review_comment) . ");");
                     } else {
                         $database->setQuery("INSERT INTO #__booklibrary_review" . "\n (fk_bookid, fk_userid, date, rating, title, comment)" . "\n VALUES " . "\n (" . $fk_bookid . ",\n                                                        " . $review_fk_userid . ",\n                                                        '" . $review_date . "',\n                                                        " . $review_rating . ",\n                                                        '" . $review_title . "',\n                                                        '" . $review_comment . "');");
                     }
                     $database->query();
                 }
                 //end for(...) - REVIEW
             }
         }
         //end for(...) - BOOK
     }
     //var_dump($retVal);    exit;
     return $retVal;
 }
Ejemplo n.º 3
0
    function save_book_fe($option)
    {
        PHP_booklibrary::addTitleAndMetaTags();
        global $database, $my, $mosConfig_absolute_path, $mosConfig_live_site, $acl, $booklibrary_configuration, $mosConfig_mailfrom, $Itemid;
        if (array_key_exists('Itemid', $_POST)) {
            $Itemid = intval($_POST['Itemid']);
        }
        $err_msg = '';
        //check how the other info should be provided
        $book = new mosBookLibrary($database);
        if (!is_numeric($_POST['bookid']) && $booklibrary_configuration['bookid']['auto-increment']['boolean'] == 1) {
            $err_msg .= "You set no numeric BookID. Please set option " . _BOOKLIBRARY_ADMIN_CONFIG_BOOKID_AUTO_INCREMENT . " to 'No' or change BookID to numeric <br />";
        }
        if (!$book->bind($_POST)) {
            $err_msg .= "Catchable error: " . $book->getError() . '<br />';
        }
        if (strlen($book->owneremail) > 0 && $book->owner_id == 0) {
            $book->owner_id = $my->id;
        }
        /* if ($id != 0 && $my->id != $book->owner_id)
           {
           mosRedirect('index.php?option=com_booklibrary&Itemid=' . $Itemid);
           exit;
           }
           print_r($book);exit; */
        //fetch all information from the webservices if necessary
        if ($_POST['informationFrom'] != 0) {
            $book = mosBooklibraryWS::fetchInfos($book);
        }
        if (is_string($book)) {
            $err_msg = "Error fetching info";
            mosRedirect("index.php?option={$option}&Itemid={$Itemid}", $err_msg);
        }
        if ($_POST['ebook_Url'] != '') {
            $book->ebookURL = $_POST['ebook_Url'];
        }
        //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;
        } elseif ($booklibrary_configuration['ebooks']['allow'] && intval($file['error']) != 4) {
            /* $file_new = $mosConfig_absolute_path . $booklibrary_configuration['ebooks']['location'] .
               $file['name'];
               echo $file_new; */
            //---------------------
            $uploaddir = $mosConfig_absolute_path . $booklibrary_configuration['ebooks']['location'];
            $file_new = $uploaddir . $_FILES['ebook_file']['name'];
            echo $file_new;
            $ext = pathinfo($_FILES['ebook_file']['name'], PATHINFO_EXTENSION);
            $allowed_exts = explode(",", $booklibrary_configuration['allowed_exts']);
            if (!in_array($ext, $allowed_exts)) {
                echo "<script> alert(' File ext. not allowed to upload! - " . $edfile['name'] . "'); window.history.go(-1); </script>\n";
                exit;
            }
            $db = JFactory::getDbo();
            $db->setQuery("SELECT mime_type FROM #__booklibrary_mime_types WHERE `mime_ext` = " . $db->quote($ext));
            $file_db_mime = $db->loadResult();
            $file['type'] = $_FILES['ebook_file']['type'];
            if ($file_db_mime != $file['type']) {
                echo "<script> alert(' File mime type not match file ext. - " . $edfile['name'] . "'); window.history.go(-1); </script>\n";
                exit;
            }
            //----------------------
            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'];
            }
        }
        if ($booklibrary_configuration['publish_on_add']['show']) {
            if (checkAccessBL($booklibrary_configuration['publish_on_add']['registrationlevel'], 'RECURSE', userGID_BL($my->id), $acl)) {
                $book->published = 1;
            } else {
                $book->published = 0;
            }
        } else {
            $book->published = 0;
        }
        $file = $_FILES['picture_file'];
        //-------------------
        if (intval($file['error']) != 4) {
            $ext = pathinfo($_FILES['picture_file']['name'], PATHINFO_EXTENSION);
            $allowed_exts = explode(",", $booklibrary_configuration['allowed_exts_img']);
            if (!in_array($ext, $allowed_exts)) {
                echo "<script> alert(' File ext. not allowed to upload! - " . $file['name'] . "'); window.history.go(-1); </script>\n";
                exit;
            }
        }
        //-------------------
        //check if fileupload is correct
        if ($file['size'] != 0 && ($file['error'] != 0 || strpos($file['type'], 'image') === false || strpos($file['type'], 'image') === "")) {
            $err_msg .= _BOOKLIBRARY_LABEL_PICTURE_URL_UPLOAD_ERROR . '<br />';
        }
        //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) {
                $err_msg .= $retVal . "<br />";
            }
        }
        if ($file['size'] == 0) {
            $file = null;
        }
        //ERR OUT
        if ($err_msg != '') {
            mosRedirect("index.php?option={$option}&Itemid={$Itemid}", $err_msg);
        }
        //END ERR OUT
        $book->date = date("Y-m-d H:i:s");
        if (!$book->check()) {
            echo "<script> alert('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n";
            exit;
        }
        if (!$book->store()) {
            echo "<script> alert('" . addslashes($book->getError()) . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $catid = mosGetParam($_POST, 'catid', '');
        if (empty($catid)) {
            ?>
            <script>alert("<?php 
            echo _BOOKLIBRARY_ADMIN_INFOTEXT_JS_EDIT_CATEGORY;
            ?>
");
                window.history.go(-1);</script>
            <?php 
            exit;
        }
        $query = "SELECT id FROM #__booklibrary_categories WHERE bookid='" . $book->id . "'";
        $database->setQuery($query);
        $categ_id = $database->loadResult();
        if (isset($categ_id) || $categ_id != 0) {
            $stroka = "Update #__booklibrary_categories SET bookid='" . $book->id . "', catid='" . $catid[0] . "' WHERE id='" . $categ_id . "'";
        } else {
            $catid_tmp = array();
            for ($i = 0; $i < count($catid); $i++) {
                $catid_tmp[] = $catid[$i];
                $stroka = "INSERT INTO #__booklibrary_categories (bookid, catid)" . "\n VALUES" . "\n ('" . $book->id . "', '" . $catid_tmp[$i] . "');";
                $database->setQuery($stroka);
                $database->query();
            }
        }
        $book->checkin();
        // Parameters
        if (version_compare(JVERSION, '3.0', 'ge')) {
            $menu = new JTableMenu($database);
            $menu->load($Itemid);
            $params = new JRegistry();
            $params->loadString($menu->params);
        } else {
            $menu = new mosMenu($database);
            $menu->load($Itemid);
            $params = new mosParameters($menu->params);
        }
        if ($booklibrary_configuration['addbook_email']['show']) {
            if (checkAccessBL($booklibrary_configuration['addbook_email']['registrationlevel'], 'RECURSE', userGID_BL($my->id), $acl)) {
                $params->def('show_input_email', 1);
            }
        }
        if ($params->get('show_input_email')) {
            $mail_to = explode(",", $booklibrary_configuration['lendrequest_email']['address']);
            $userid = $my->id;
            $zapros = "SELECT name, email FROM #__users WHERE id=" . $userid . ";";
            $database->setQuery($zapros);
            $item_user = $database->loadObjectList();
            $query = "SELECT * FROM #__booklibrary_main_categories WHERE id='" . $catid[0] . "'";
            $database->setQuery($query);
            $cat_name = $database->loadAssoc();
            $mes_title = "Add Book";
            if ($_POST['owneremail'] != "") {
                $email = $_POST['owneremail'];
            } else {
                $email = "anonymous";
            }
            $message = _BOOKLIBRARY_EMAIL_NOTIFICATION_ADD_BOOK;
            $message = str_replace("{title}", $mes_title, $message);
            $message = str_replace("{id}", $_POST['bookid'], $message);
            $message = str_replace("{username}", $email, $message);
            $message = str_replace("{date}", date("r"), $message);
            $message = str_replace("{category}", $cat_name['title'], $message);
            mosMail($mosConfig_mailfrom, $item_user[0]->name, $mail_to, $mes_title, $message, true);
        }
        mosRedirect("index.php?option={$option}&Itemid={$Itemid}", 'Book successfuly added. You can see it after administrator approval.');
    }