Exemple #1
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 . '&task=add_book_fe&Itemid=' . $Itemid);
         $pathway_name = _BOOKLIBRARY_LABEL_TITLE_ADD_BOOK;
     } else {
         $pathway = sefRelToAbs('index.php?option=' . $option . '&task=edit_book&Itemid=' . $Itemid . '&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);
 }