PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | admin/views/backups/view.html.php +144 -0 1.6.3 → 1.8.16 View file →
@@ -1,0 +1,144 @@
1 +<?php
2 +/**
3 + * @package VikBooking
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 + * VikBooking backups view.
16 + *
17 + * @since 1.5
18 + */
19 +class VikBookingViewBackups extends JViewVikBooking
20 +{
21 + /**
22 + * VikBooking view display method.
23 + *
24 + * @return void
25 + */
26 + function display($tpl = null)
27 + {
28 + $app = JFactory::getApplication();
29 + $dbo = JFactory::getDbo();
30 +
31 + $model = new VBOModelBackup();
32 +
33 + // set the toolbar
34 + $this->addToolBar();
35 +
36 + $this->ordering = $app->getUserStateFromRequest('com_vikbooking.backups.ordering', 'filter_order', 'createdon', 'string');
37 + $this->orderDir = $app->getUserStateFromRequest('com_vikbooking.backups.orderdir', 'filter_order_Dir', 'DESC', 'string');
38 +
39 + // db object
40 + $lim = $app->getUserStateFromRequest('com_vikbooking.limit', 'limit', $app->get('list_limit'), 'uint');
41 + $lim0 = $app->input->getUint('limitstart', 0);
42 + $navbut = '';
43 +
44 + // load all the export types
45 + $this->exportTypes = $model->getExportTypes();
46 +
47 + $rows = array();
48 +
49 + // fetch folder in which the backup are stored
50 + $folder = VBOFactory::getConfig()->get('backupfolder');
51 +
52 + if (!$folder)
53 + {
54 + // use temporary folder if not specified
55 + $folder = JFactory::getApplication()->get('tmp_path');
56 + }
57 +
58 + if ($folder && JFolder::exists($folder))
59 + {
60 + // load all backup archives
61 + $rows = JFolder::files($folder, 'backup_', $recurse = false, $fullpath = true);
62 + }
63 +
64 + // fetch backup details
65 + $rows = array_map(function($file) use ($model)
66 + {
67 + return $model->getItem($file);
68 + }, $rows);
69 +
70 + $ordering = $this->ordering;
71 + $direction = $this->orderDir;
72 +
73 + // fetch the type of ordering
74 + usort($rows, function($a, $b) use ($ordering, $direction)
75 + {
76 + switch ($ordering)
77 + {
78 + case 'filesize':
79 + // sort by file size
80 + $factor = $a->size - $b->size;
81 + break;
82 +
83 + default:
84 + // sort by creation date
85 + $factor = $a->timestamp - $b->timestamp;
86 + }
87 +
88 + // in case of descending direction, reverse the ordering factor
89 + if (preg_match("/desc/i", $direction))
90 + {
91 + $factor *= -1;
92 + }
93 +
94 + return $factor;
95 + });
96 +
97 + $tot_count = count($rows);
98 +
99 + if ($tot_count > $lim)
100 + {
101 + if ($lim0 >= $tot_count)
102 + {
103 + // We exceeded the pagination, probably because we deleted all the records of the last page.
104 + // For this reason, we need to go back to the previous one.
105 + $lim0 = max(array(0, $lim0 - $lim));
106 + }
107 +
108 + $rows = array_slice($rows, $lim0, $lim);
109 +
110 + jimport('joomla.html.pagination');
111 + $pageNav = new JPagination($tot_count, $lim0, $lim);
112 + $navbut = "<table align=\"center\"><tr><td>" . $pageNav->getListFooter() . "</td></tr></table>";
113 + }
114 +
115 + $this->rows = $rows;
116 + $this->navbut = $navbut;
117 +
118 + // Display the template
119 + parent::display($tpl);
120 + }
121 +
122 + /**
123 + * Setting the toolbar.
124 + *
125 + * @return void
126 + */
127 + protected function addToolBar()
128 + {
129 + // add menu title and some buttons to the page
130 + JToolBarHelper::title(JText::translate('VBMAINBACKUPSTITLE'), 'vikbooking');
131 +
132 + $user = JFactory::getUser();
133 +
134 + if ($user->authorise('core.create', 'com_vikbooking'))
135 + {
136 + JToolBarHelper::addNew('backup.add');
137 + }
138 +
139 + if ($user->authorise('core.delete', 'com_vikbooking'))
140 + {
141 + JToolBarHelper::deleteList(JText::translate('VBDELCONFIRM'), 'backup.delete');
142 + }
143 + }
144 +}