view.html.php
137 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 group management view. |
| 16 | * |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class VikAppointmentsViewmanagegroup 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 | $ids = $input->getUint('cid', array()); |
| 33 | $type = $ids ? 'edit' : 'new'; |
| 34 | |
| 35 | $pagetype = $input->get('type', 1, 'uint'); |
| 36 | |
| 37 | // set the toolbar |
| 38 | $this->addToolBar($type, $pagetype); |
| 39 | |
| 40 | $group = null; |
| 41 | |
| 42 | if ($type == 'edit') |
| 43 | { |
| 44 | $q = $dbo->getQuery(true); |
| 45 | |
| 46 | $q->select('*'); |
| 47 | |
| 48 | if ($pagetype == 1) |
| 49 | { |
| 50 | $q->from($dbo->qn('#__vikappointments_group')); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | $q->from($dbo->qn('#__vikappointments_employee_group')); |
| 55 | } |
| 56 | |
| 57 | $q->where($dbo->qn('id') . ' = ' . $ids[0]); |
| 58 | |
| 59 | $dbo->setQuery($q, 0, 1); |
| 60 | $group = $dbo->loadObject(); |
| 61 | } |
| 62 | |
| 63 | if (empty($group)) |
| 64 | { |
| 65 | $group = (object) $this->getBlankItem(); |
| 66 | } |
| 67 | |
| 68 | // use group data stored in user state |
| 69 | $this->injectUserStateData($group, 'vap.group.data'); |
| 70 | |
| 71 | $this->group = $group; |
| 72 | $this->pageType = $pagetype; |
| 73 | |
| 74 | // Display the template |
| 75 | parent::display($tpl); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Setting the toolbar. |
| 80 | * |
| 81 | * @param string $type The request type (new or edit). |
| 82 | * @param integer $pageType The type of group (1 for services, 2 for employees). |
| 83 | * |
| 84 | * @return void |
| 85 | */ |
| 86 | protected function addToolBar($type, $pageType) |
| 87 | { |
| 88 | // add menu title and some buttons to the page |
| 89 | if ($type == 'edit') |
| 90 | { |
| 91 | $title = $pageType == 1 ? 'VAPMAINTITLEEDITGROUP' : 'VAPMAINTITLEEDITEMPGROUP'; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | $title = $pageType == 1 ? 'VAPMAINTITLENEWGROUP' : 'VAPMAINTITLENEWEMPGROUP'; |
| 96 | } |
| 97 | |
| 98 | JToolBarHelper::title(JText::translate($title), 'vikappointments'); |
| 99 | |
| 100 | $user = JFactory::getUser(); |
| 101 | |
| 102 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 103 | || $user->authorise('core.create', 'com_vikappointments')) |
| 104 | { |
| 105 | JToolbarHelper::apply('group.save', JText::translate('VAPSAVE')); |
| 106 | JToolbarHelper::save('group.saveclose', JText::translate('VAPSAVEANDCLOSE')); |
| 107 | } |
| 108 | |
| 109 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 110 | && $user->authorise('core.create', 'com_vikappointments')) |
| 111 | { |
| 112 | JToolbarHelper::save2new('group.savenew', JText::translate('VAPSAVEANDNEW')); |
| 113 | } |
| 114 | |
| 115 | if ($type == 'edit' && $user->authorise('core.create', 'com_vikappointments')) |
| 116 | { |
| 117 | JToolbarHelper::save2copy('group.savecopy', JText::translate('VAPSAVEASCOPY')); |
| 118 | } |
| 119 | |
| 120 | JToolbarHelper::cancel('group.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL'); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Returns a blank item. |
| 125 | * |
| 126 | * @return array A blank item for new requests. |
| 127 | */ |
| 128 | protected function getBlankItem() |
| 129 | { |
| 130 | return array( |
| 131 | 'id' => 0, |
| 132 | 'name' => '', |
| 133 | 'description' => '', |
| 134 | ); |
| 135 | } |
| 136 | } |
| 137 |