| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage com_vikbooking |
| 5 |
* @author Alessio Gaggii - e4j - Extensionsforjoomla.com |
| 6 |
* @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved. |
| 7 |
* @license GNU General Public License version 2 or later; see LICENSE |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 12 |
|
| 13 |
// import Joomla view library |
| 14 |
jimport('joomla.application.component.view'); |
| 15 |
|
| 16 |
class VikBookingViewRooms extends JViewVikBooking |
| 17 |
{ |
| 18 |
public function display($tpl = null) |
| 19 |
{ |
| 20 |
// Set the toolbar |
| 21 |
$this->addToolBar(); |
| 22 |
|
| 23 |
if (!JFactory::getUser()->authorise('core.vbo.rooms', 'com_vikbooking')) { |
| 24 |
VBOHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 25 |
} |
| 26 |
|
| 27 |
$rows = ""; |
| 28 |
$navbut = ""; |
| 29 |
$mainframe = JFactory::getApplication(); |
| 30 |
$pmodtar = VikRequest::getString('modtar', '', 'request'); |
| 31 |
//to fix js issues |
| 32 |
$ptarmod = VikRequest::getString('tarmod', '', 'request'); |
| 33 |
// |
| 34 |
$proomid = VikRequest::getString('roomid', '', 'request'); |
| 35 |
$dbo = JFactory::getDBO(); |
| 36 |
if ((!empty($pmodtar) || !empty($ptarmod)) && !empty($proomid)) { |
| 37 |
$q = "SELECT * FROM `#__vikbooking_dispcost` WHERE `idroom`=".$dbo->quote($proomid).";"; |
| 38 |
$dbo->setQuery($q); |
| 39 |
$dbo->execute(); |
| 40 |
if ($dbo->getNumRows() > 0) { |
| 41 |
$tars = $dbo->loadAssocList(); |
| 42 |
foreach ($tars as $tt) { |
| 43 |
$tmpcost = VikRequest::getString('cost'.$tt['id'], '', 'request'); |
| 44 |
$tmpattr = VikRequest::getString('attr'.$tt['id'], '', 'request'); |
| 45 |
if (strlen($tmpcost)) { |
| 46 |
$q = "UPDATE `#__vikbooking_dispcost` SET `cost`='".$tmpcost."'".(strlen($tmpattr) ? ", `attrdata`=".$dbo->quote($tmpattr)."" : "")." WHERE `id`='".$tt['id']."';"; |
| 47 |
$dbo->setQuery($q); |
| 48 |
$dbo->execute(); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
$lim0 = VikRequest::getVar('limitstart', 0, '', 'int'); |
| 53 |
$mainframe->redirect("index.php?option=com_vikbooking&task=tariffs&cid[]=".$proomid."&limitstart=".$lim0); |
| 54 |
exit; |
| 55 |
} |
| 56 |
$lim = $mainframe->getUserStateFromRequest("com_vikbooking.limit", 'limit', $mainframe->get('list_limit'), 'int'); |
| 57 |
$lim0 = VikRequest::getVar('limitstart', 0, '', 'int'); |
| 58 |
$session = JFactory::getSession(); |
| 59 |
$pvborderby = VikRequest::getString('vborderby', '', 'request'); |
| 60 |
$pvbordersort = VikRequest::getString('vbordersort', '', 'request'); |
| 61 |
$validorderby = array('name', 'toadult', 'tochild', 'totpeople', 'units', 'avail'); |
| 62 |
$orderby = $session->get('vbViewRoomsOrderby', 'name'); |
| 63 |
$ordersort = $session->get('vbViewRoomsOrdersort', 'ASC'); |
| 64 |
if (!empty($pvborderby) && in_array($pvborderby, $validorderby)) { |
| 65 |
$orderby = $pvborderby; |
| 66 |
$session->set('vbViewRoomsOrderby', $orderby); |
| 67 |
if (!empty($pvbordersort) && in_array($pvbordersort, array('ASC', 'DESC'))) { |
| 68 |
$ordersort = $pvbordersort; |
| 69 |
$session->set('vbViewRoomsOrdersort', $ordersort); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
// filters |
| 74 |
$prname = $mainframe->getUserStateFromRequest("vbo.rooms.rname", 'rname', '', 'string'); |
| 75 |
$pidcat = $mainframe->getUserStateFromRequest("vbo.rooms.idcat", 'idcat', 0, 'int'); |
| 76 |
$q = "SELECT `id`, `name` FROM `#__vikbooking_categories` ORDER BY `name` ASC;"; |
| 77 |
$dbo->setQuery($q); |
| 78 |
$dbo->execute(); |
| 79 |
$allcats = $dbo->getNumRows() ? $dbo->loadAssocList() : array(); |
| 80 |
$clauses = array(); |
| 81 |
if (!empty($prname)) { |
| 82 |
array_push($clauses, "`r`.`name` LIKE " . $dbo->quote("%{$prname}%")); |
| 83 |
} |
| 84 |
if (!empty($pidcat)) { |
| 85 |
array_push($clauses, "(`r`.`idcat`='" . $pidcat . ";' OR `r`.`idcat` LIKE '" . $pidcat . ";%' OR `r`.`idcat` LIKE '%;" . $pidcat . ";%' OR `r`.`idcat` LIKE '%;" . $pidcat . ";')"); |
| 86 |
} |
| 87 |
// |
| 88 |
|
| 89 |
$q = "SELECT SQL_CALC_FOUND_ROWS `r`.*, (SELECT 1 FROM `#__vikbooking_calendars_xref` AS `x` WHERE `x`.`mainroom`=`r`.`id` OR `x`.`childroom`=`r`.`id` LIMIT 1) AS `sharedcals` FROM `#__vikbooking_rooms` AS `r`" . (count($clauses) ? ' WHERE ' . implode(' AND ', $clauses) : '') . " ORDER BY `r`.`".$orderby."` ".$ordersort; |
| 90 |
$dbo->setQuery($q, $lim0, $lim); |
| 91 |
$dbo->execute(); |
| 92 |
|
| 93 |
/** |
| 94 |
* Call assertListQuery() from the View class to make sure the filters set |
| 95 |
* do not produce an empty result. This would reset the page in this case. |
| 96 |
* |
| 97 |
* @since 1.13.0 (J) - 1.3.0 (WP) |
| 98 |
*/ |
| 99 |
$this->assertListQuery($lim0, $lim); |
| 100 |
// |
| 101 |
|
| 102 |
if ($dbo->getNumRows() > 0) { |
| 103 |
$rows = $dbo->loadAssocList(); |
| 104 |
$dbo->setQuery('SELECT FOUND_ROWS();'); |
| 105 |
jimport('joomla.html.pagination'); |
| 106 |
$pageNav = new JPagination( $dbo->loadResult(), $lim0, $lim ); |
| 107 |
$navbut = "<table align=\"center\"><tr><td>".$pageNav->getListFooter()."</td></tr></table>"; |
| 108 |
} |
| 109 |
|
| 110 |
$this->rows = $rows; |
| 111 |
$this->lim0 = $lim0; |
| 112 |
$this->navbut = $navbut; |
| 113 |
$this->orderby = $orderby; |
| 114 |
$this->ordersort = $ordersort; |
| 115 |
$this->allcats = $allcats; |
| 116 |
|
| 117 |
// Display the template |
| 118 |
parent::display($tpl); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Sets the toolbar |
| 123 |
*/ |
| 124 |
protected function addToolBar() |
| 125 |
{ |
| 126 |
JToolBarHelper::title(JText::translate('VBMAINDEAFULTTITLE'), 'vikbooking'); |
| 127 |
if (JFactory::getUser()->authorise('core.create', 'com_vikbooking')) { |
| 128 |
JToolBarHelper::addNew('newroom', JText::translate('VBMAINDEFAULTNEW')); |
| 129 |
JToolBarHelper::spacer(); |
| 130 |
} |
| 131 |
if (JFactory::getUser()->authorise('core.edit', 'com_vikbooking')) { |
| 132 |
JToolBarHelper::editList('editroom', JText::translate('VBMAINDEFAULTEDITC')); |
| 133 |
JToolBarHelper::spacer(); |
| 134 |
JToolBarHelper::editList('tariffs', JText::translate('VBMAINDEFAULTEDITT')); |
| 135 |
JToolBarHelper::spacer(); |
| 136 |
JToolBarHelper::custom( 'calendar', 'calendar', 'calendar', JText::translate('VBMAINDEFAULTCAL'), true, false); |
| 137 |
JToolBarHelper::spacer(); |
| 138 |
} |
| 139 |
if (JFactory::getUser()->authorise('core.delete', 'com_vikbooking')) { |
| 140 |
JToolBarHelper::deleteList(JText::translate('VBDELCONFIRM'), 'removeroom', JText::translate('VBMAINDEFAULTDEL')); |
| 141 |
JToolBarHelper::spacer(); |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|