view.html.php
146 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 payment management view. |
| 16 | * |
| 17 | * @since 1.0 |
| 18 | */ |
| 19 | class VikAppointmentsViewmanagepayment 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 | $payment = null; |
| 39 | |
| 40 | if ($type == 'edit') |
| 41 | { |
| 42 | $q = $dbo->getQuery(true) |
| 43 | ->select('*') |
| 44 | ->from($dbo->qn('#__vikappointments_gpayments')) |
| 45 | ->where($dbo->qn('id') . ' = ' . $ids[0]); |
| 46 | |
| 47 | $dbo->setQuery($q, 0, 1); |
| 48 | $payment = $dbo->loadObject(); |
| 49 | } |
| 50 | |
| 51 | if (empty($payment)) |
| 52 | { |
| 53 | $payment = (object) $this->getBlankItem(); |
| 54 | } |
| 55 | |
| 56 | // use payment data stored in user state |
| 57 | $this->injectUserStateData($payment, 'vap.payment.data'); |
| 58 | |
| 59 | // get rid of file extension to properly select the correct driver |
| 60 | $payment->file = preg_replace("/\.php$/", '', $payment->file); |
| 61 | |
| 62 | if ($payment->selfconfirm) |
| 63 | { |
| 64 | // always turn on auto-confirm in case of self-confirmation |
| 65 | $payment->setconfirmed = 1; |
| 66 | } |
| 67 | |
| 68 | // check if the current user is the owner of the payment: |
| 69 | // global payment OR new payment OR current user equals to payment author |
| 70 | $owner = $payment->id_employee == 0 || $payment->id <= 0 || $payment->createdby == JFactory::getUser()->id; |
| 71 | |
| 72 | $this->payment = $payment; |
| 73 | $this->isOwner = $owner; |
| 74 | |
| 75 | // display the template (default.php) |
| 76 | parent::display($tpl); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Setting the toolbar. |
| 81 | * |
| 82 | * @return void |
| 83 | */ |
| 84 | protected function addToolBar($type) |
| 85 | { |
| 86 | // add menu title and some buttons to the page |
| 87 | if ($type == 'edit') |
| 88 | { |
| 89 | JToolBarHelper::title(JText::translate('VAPMAINTITLEEDITPAYMENT'), 'vikappointments'); |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | JToolBarHelper::title(JText::translate('VAPMAINTITLENEWPAYMENT'), 'vikappointments'); |
| 94 | } |
| 95 | |
| 96 | $user = JFactory::getUser(); |
| 97 | |
| 98 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 99 | || $user->authorise('core.create', 'com_vikappointments')) |
| 100 | { |
| 101 | JToolbarHelper::apply('payment.save', JText::translate('VAPSAVE')); |
| 102 | JToolbarHelper::save('payment.saveclose', JText::translate('VAPSAVEANDCLOSE')); |
| 103 | } |
| 104 | |
| 105 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 106 | && $user->authorise('core.create', 'com_vikappointments')) |
| 107 | { |
| 108 | JToolbarHelper::save2new('payment.savenew', JText::translate('VAPSAVEANDNEW')); |
| 109 | } |
| 110 | |
| 111 | JToolBarHelper::cancel('payment.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL'); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Returns a blank item. |
| 116 | * |
| 117 | * @param integer $id_emp The ID of the employee. |
| 118 | * |
| 119 | * @return array A blank item for new requests. |
| 120 | */ |
| 121 | protected function getBlankItem() |
| 122 | { |
| 123 | return array( |
| 124 | 'id' => 0, |
| 125 | 'name' => '', |
| 126 | 'file' => '', |
| 127 | 'published' => 0, |
| 128 | 'prenote' => '', |
| 129 | 'note' => '', |
| 130 | 'charge' => 0, |
| 131 | 'id_tax' => 0, |
| 132 | 'icontype' => 0, |
| 133 | 'icon' => '', |
| 134 | 'setconfirmed' => 0, |
| 135 | 'selfconfirm' => 0, |
| 136 | 'appointments' => 1, |
| 137 | 'subscr' => 0, |
| 138 | 'position' => '', |
| 139 | 'level' => 1, |
| 140 | 'trust' => 0, |
| 141 | 'id_employee' => 0, |
| 142 | 'createdby' => 0, |
| 143 | ); |
| 144 | } |
| 145 | } |
| 146 |