view.html.php
126 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 status code management view. |
| 16 | * |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class VikAppointmentsViewmanagestatuscode extends JViewVAP |
| 20 | { |
| 21 | /** |
| 22 | * VikAppointments view display method. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | function display($tpl = null) |
| 27 | { |
| 28 | $dbo = JFactory::getDbo(); |
| 29 | $app = JFactory::getApplication(); |
| 30 | $input = $app->input; |
| 31 | |
| 32 | $ids = $input->getUint('cid', array()); |
| 33 | $type = $ids ? 'edit' : 'new'; |
| 34 | |
| 35 | // set the toolbar |
| 36 | $this->addToolBar($type); |
| 37 | |
| 38 | $status = null; |
| 39 | |
| 40 | if ($type == 'edit') |
| 41 | { |
| 42 | $q = $dbo->getQuery(true) |
| 43 | ->select('*') |
| 44 | ->from($dbo->qn('#__vikappointments_status_code')) |
| 45 | ->where($dbo->qn('id') . ' = ' . $ids[0]); |
| 46 | |
| 47 | $dbo->setQuery($q, 0, 1); |
| 48 | $status = $dbo->loadObject(); |
| 49 | } |
| 50 | |
| 51 | if (empty($status)) |
| 52 | { |
| 53 | $status = (object) $this->getBlankItem(); |
| 54 | } |
| 55 | |
| 56 | // use status code data stored in user state |
| 57 | $this->injectUserStateData($status, 'vap.statuscode.data'); |
| 58 | |
| 59 | $this->status = $status; |
| 60 | |
| 61 | // display the template |
| 62 | parent::display($tpl); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Setting the toolbar. |
| 67 | * |
| 68 | * @param string $type The request type (new or edit). |
| 69 | * |
| 70 | * @return void |
| 71 | */ |
| 72 | protected function addToolBar($type) |
| 73 | { |
| 74 | // add menu title and some buttons to the page |
| 75 | if ($type == 'edit') |
| 76 | { |
| 77 | JToolBarHelper::title(JText::translate('VAPMAINTITLEEDITSTATUSCODE'), 'vikappointments'); |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | JToolBarHelper::title(JText::translate('VAPMAINTITLENEWSTATUSCODE'), 'vikappointments'); |
| 82 | } |
| 83 | |
| 84 | $user = JFactory::getUser(); |
| 85 | |
| 86 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 87 | || $user->authorise('core.create', 'com_vikappointments')) |
| 88 | { |
| 89 | JToolbarHelper::apply('statuscode.save', JText::translate('VAPSAVE')); |
| 90 | JToolbarHelper::save('statuscode.saveclose', JText::translate('VAPSAVEANDCLOSE')); |
| 91 | } |
| 92 | |
| 93 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 94 | && $user->authorise('core.create', 'com_vikappointments')) |
| 95 | { |
| 96 | JToolbarHelper::save2new('statuscode.savenew', JText::translate('VAPSAVEANDNEW')); |
| 97 | } |
| 98 | |
| 99 | JToolBarHelper::cancel('statuscode.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL'); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns a blank item. |
| 104 | * |
| 105 | * @return array A blank item for new requests. |
| 106 | */ |
| 107 | protected function getBlankItem() |
| 108 | { |
| 109 | return array( |
| 110 | 'id' => 0, |
| 111 | 'name' => '', |
| 112 | 'description' => '', |
| 113 | 'code' => '', |
| 114 | 'color' => ltrim(JHtml::fetch('vaphtml.color.preset'), '#'), |
| 115 | 'appointments' => 1, |
| 116 | 'packages' => 0, |
| 117 | 'subscriptions' => 0, |
| 118 | 'approved' => 0, |
| 119 | 'reserved' => 0, |
| 120 | 'expired' => 0, |
| 121 | 'cancelled' => 0, |
| 122 | 'paid' => 0, |
| 123 | ); |
| 124 | } |
| 125 | } |
| 126 |