Example #1
0
 static function showMyBooks($option)
 {
     global $database, $Itemid, $mainframe, $booklibrary_configuration, $my;
     PHP_booklibrary::addTitleAndMetaTags();
     //print_r($_REQUEST);
     //$menu = new JTableMenu($database);
     //   $menu = new mosMenu($database);
     //   $menu_name = set_header_name_bl($menu, $Itemid);
     //   $menu->load( $Itemid );
     //   $params = new mosParameters( $menu->params );
     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);
     }
     $menu_name = set_header_name_bl($menu, $Itemid);
     $database->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_booklibrary'");
     if ($database->loadResult() != $Itemid) {
         $params->def('wrongitemid', '1');
     }
     $user = mosGetParam($_REQUEST, 'name');
     if (!isset($user)) {
         $params = $mainframe->getParams();
         $user = $params->get('ownerslists');
     }
     $limit = $booklibrary_configuration['page']['items'];
     $limitstart = mosGetParam($_REQUEST, 'limitstart', 0);
     if (!$params->get('wrongitemid')) {
         $pathway = sefRelToAbs('index.php?option=' . $option . '&task=show_my_books&Itemid=' . $Itemid);
         $params->def('title', _BOOKLIBRARY_LABEL_TITLE_USER_BOOKS);
         $params->def('header', $menu_name);
         $params->def('show_rating', 1);
         $params->def('hits', 1);
         $params->def('back_button', $mainframe->getCfg('back_button'));
         //check user
         if ($my->email == null) {
             mosRedirect("index.php?", "Please login");
             exit;
         }
         //publish books
         if (isset($_REQUEST['submitbutton'])) {
             $do = mosGetParam($_REQUEST, 'submitbutton');
             $bid = mosGetParam($_REQUEST, 'bid');
             if ($do == 'addbook') {
                 if ($option == 'com_comprofiler') {
                     $redirect = "index.php?option={$option}&task=show_add&is_show_data=1&tab=getmybooksTab&Itemid={$Itemid}";
                 } else {
                     $redirect = "index.php?option={$option}&task=show_add&Itemid={$Itemid}";
                 }
                 mosRedirect($redirect);
                 exit;
             }
             //print_r($do);exit;
             //get real user books id
             if (count($bid)) {
                 $database->setQuery("SELECT id FROM #__booklibrary\n                            \nWHERE owner_id='{$my->id}' AND id IN (" . implode(', ', $bid) . ")");
                 if (version_compare(JVERSION, '3.0', 'lt')) {
                     $bid = $database->loadResultArray();
                 } else {
                     $bid = $database->loadColumn();
                 }
                 //$bid=$database->loadResultArray();
                 if (count($bid)) {
                     $bids = implode(',', $bid);
                     switch ($do) {
                         case 'publish':
                             $database->setQuery("UPDATE #__booklibrary SET published = 1\n                      \n WHERE owneremail='{$my->email}' AND id IN (" . $bids . ");");
                             $database->query();
                             break;
                         case 'unpublish':
                             $database->setQuery("UPDATE #__booklibrary SET published = 0\n                      \n WHERE owneremail='{$my->email}' AND id IN (" . $bids . ");");
                             $database->query();
                             break;
                         case 'delete':
                             $database->setQuery("DELETE FROM #__booklibrary_review WHERE fk_bookid IN ({$bids})");
                             if (!$database->query()) {
                                 echo "<script> alert('" . addslashes($database->getErrorMsg()) . "'); window.history.go(-1); </script>\n";
                             }
                             $database->setQuery("DELETE FROM #__booklibrary_categories WHERE bookid IN ({$bids})");
                             if (!$database->query()) {
                                 echo "<script> alert('" . addslashes($database->getErrorMsg()) . "'); window.history.go(-1); </script>\n";
                             }
                             $database->setQuery("DELETE FROM #__booklibrary WHERE id IN ({$bids})");
                             if (!$database->query()) {
                                 echo "<script> alert('" . addslashes($database->getErrorMsg()) . "'); window.history.go(-1); </script>\n";
                             }
                             break;
                     }
                 }
             }
         }
         $database->setQuery("SELECT COUNT(id) FROM #__booklibrary\n                            \nWHERE owneremail='{$my->email}'");
         $total = $database->loadResult();
         $pageNav = new JPagination($total, $limitstart, $limit);
         // for J 1.6
         //getting my cars
         $selectstring = "SELECT a.*, GROUP_CONCAT(cc.title SEPARATOR ', ') AS category,\n                l.id as lendid, l.lend_from as lend_from, l.lend_return as\n                lend_return,\n                l.lend_until as lend_until, u.name AS editor,\n                l.user_name as user_name, l.user_email as user_email, l.user_mailing as user_mailing\n                FROM #__booklibrary AS a " . "\nLEFT JOIN #__booklibrary_categories AS vc ON vc.bookid = a.id " . "\nLEFT JOIN #__booklibrary_main_categories AS cc ON cc.id = vc.catid " . "  LEFT JOIN #__booklibrary_lend AS l ON a.fk_lendid = l.id\n                LEFT JOIN #__users AS u ON u.id = a.checked_out                 \n                 WHERE owneremail='{$my->email}' " . "\nGROUP BY a.id" . "\nORDER BY a.title " . "\nLIMIT {$pageNav->limitstart},{$pageNav->limit};";
         $database->setQuery($selectstring);
         $books = $database->loadObjectList();
         //print_r($books);exit;
         $database->setQuery("SELECT id,bookid FROM #__booklibrary\n                            \nWHERE owneremail='{$my->email}'\n                            \nLIMIT {$pageNav->limitstart},{$pageNav->limit};");
         //$results=$database->loadResultArray();
         if (version_compare(JVERSION, '3.0', 'lt')) {
             $results = $database->loadResultArray();
         } else {
             $results = $database->loadColumn();
         }
         $params->def('my01', "{loadposition com_booklibrary_my_book_01}");
         $params->def('my02', "{loadposition com_booklibrary_my_book_02}");
         $params->def('my03', "{loadposition com_booklibrary_my_book_03}");
         $params->def('my04', "{loadposition com_booklibrary_my_book_04}");
         $params->def('my05', "{loadposition com_booklibrary_my_book_05}");
         $tab = JRequest::getVar('tab', '', 'get');
         /*       if($tab === 'showmybooks') {
                      $currentcat = new stdClass();
                      $currentcat->header = $params->get('header');
                      $currentcat->img = null;
                      for($i = 0;$i < count($books); $i++) {
                          $books[$i]->rating2 = 0;
                      }
                      $pageNav = null;
                      $layout = $booklibrary_configuration['view_type'];
                      HTML_booklibrary::displayBooks($books, $currentcat, $params, 0, 0, null, false, array('field' =>'id'),array(),$pageNav,$layout);
                  }  
                  else */
         HTML_booklibrary::showMyBooks($books, $params, $pageNav);
     }
 }