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); } }
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.'); }