view.html.php
114 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * VikAppointments API bans view. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | class VikAppointmentsViewapibans extends JViewVAP |
| 20 | { |
| 21 | /** |
| 22 | * VikAppointments view display method. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | function display($tpl = null) |
| 27 | { |
| 28 | $app = JFactory::getApplication(); |
| 29 | $input = $app->input; |
| 30 | $dbo = JFactory::getDbo(); |
| 31 | |
| 32 | // set the toolbar |
| 33 | $this->addToolBar(); |
| 34 | |
| 35 | $filters = array(); |
| 36 | $filters['keysearch'] = $app->getUserStateFromRequest($this->getPoolName() . '.keysearch', 'keysearch', '', 'string'); |
| 37 | $filters['type'] = $app->getUserStateFromRequest($this->getPoolName() . '.type', 'type', 1, 'uint'); |
| 38 | |
| 39 | $this->filters = $filters; |
| 40 | |
| 41 | $this->ordering = $app->getUserStateFromRequest($this->getPoolName() . '.ordering', 'filter_order', 'b.id', 'string'); |
| 42 | $this->orderDir = $app->getUserStateFromRequest($this->getPoolName() . '.orderdir', 'filter_order_Dir', 'ASC', 'string'); |
| 43 | |
| 44 | $lim = $app->getUserStateFromRequest('com_vikappointments.limit', 'limit', $app->get('list_limit'), 'int'); |
| 45 | $lim0 = $this->getListLimitStart($filters); |
| 46 | $navbut = ''; |
| 47 | |
| 48 | $rows = array(); |
| 49 | |
| 50 | $q = $dbo->getQuery(true) |
| 51 | ->select('SQL_CALC_FOUND_ROWS b.*') |
| 52 | ->from($dbo->qn('#__vikappointments_api_ban', 'b')) |
| 53 | ->order($dbo->qn($this->ordering) . ' ' . $this->orderDir); |
| 54 | |
| 55 | if ($filters['keysearch']) |
| 56 | { |
| 57 | $q->where($dbo->qn('b.ip') . ' LIKE ' . $dbo->q("%{$filters['keysearch']}%")); |
| 58 | } |
| 59 | |
| 60 | if ($filters['type'] == 1) |
| 61 | { |
| 62 | $q->where($dbo->qn('b.fail_count') . ' >= ' . VAPFactory::getConfig()->getUint('apimaxfail')); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Add support for manipulating query through the plugins. |
| 67 | * |
| 68 | * @see /site/helpers/libraries/mvc/view.php @ JViewVAP::onBeforeListQuery() |
| 69 | * |
| 70 | * @since 1.7 |
| 71 | */ |
| 72 | $this->onBeforeListQuery($q); |
| 73 | |
| 74 | $dbo->setQuery($q, $lim0, $lim); |
| 75 | $dbo->execute(); |
| 76 | |
| 77 | // assert limit used for list query |
| 78 | $this->assertListQuery($lim0, $lim); |
| 79 | |
| 80 | if ($dbo->getNumRows()) |
| 81 | { |
| 82 | $rows = $dbo->loadAssocList(); |
| 83 | $dbo->setQuery('SELECT FOUND_ROWS();'); |
| 84 | jimport('joomla.html.pagination'); |
| 85 | $pageNav = new JPagination($dbo->loadResult(), $lim0, $lim); |
| 86 | $navbut = JLayoutHelper::render('blocks.pagination', ['pageNav' => $pageNav]); |
| 87 | } |
| 88 | |
| 89 | $this->rows = $rows; |
| 90 | $this->navbut = $navbut; |
| 91 | |
| 92 | // display the template (default.php) |
| 93 | parent::display($tpl); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Setting the toolbar. |
| 98 | * |
| 99 | * @return void |
| 100 | */ |
| 101 | private function addToolBar() |
| 102 | { |
| 103 | // add menu title and some buttons to the page |
| 104 | JToolbarHelper::title(JText::translate('VAPMAINTITLEVIEWAPIBANS'), 'vikappointments'); |
| 105 | |
| 106 | JToolBarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_vikappointments&view=apiusers'); |
| 107 | |
| 108 | if (JFactory::getUser()->authorise('core.delete', 'com_vikappointments')) |
| 109 | { |
| 110 | JToolbarHelper::deleteList(VikAppointments::getConfirmSystemMessage(), 'apiban.delete'); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 |