コード例 #1
0
ファイル: User.php プロジェクト: projectesIF/Sirius
    /**
     * Delete a booking o grouped bookings
     * @author	Albert Pérez Monfort (aperezm@xtec.cat)
     * @author	Josep Ferràndiz Farré (jferran6@xtec.cat)
     * @return	The form
     */
    public function anulla($arg) {
        $sid = FormUtil::getPassedValue('sid', isset($args['sid']) ? $args['sid'] : null, 'REQUEST');
        $bid = FormUtil::getPassedValue('bid', isset($args['bid']) ? $args['bid'] : null, 'REQUEST');
        $mensual = FormUtil::getPassedValue('mensual', isset($args['mensual']) ? $args['mensual'] : null, 'REQUEST');
        $cdate = FormUtil::getPassedValue('d', isset($args['d']) ? $args['d'] : null, 'REQUEST');

        $confirm = FormUtil::getPassedValue('confirmation', isset($args['confirmation']) ? $args['confirmation'] : null, 'POST');
        $eraseAll = FormUtil::getPassedValue('eraseAll', isset($args['eraseAll']) ? $args['eraseAll'] : 0, 'POST');

        // Security check
        if (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_READ)) {
            throw new Zikula_Exception_Forbidden();
        }

        //Mirem les caracter�stiques de la reserva que volem anul�lar per verificar
        //si l'usuari que est� fent l'eliminaci� �s qui t� l'espai o equip reservat
        // Check if user can delete this book
        $bookingInfo = ModUtil::apiFunc('IWbookings', 'user', 'get_bookingInfo', array('bid' => $bid));

        if (empty($bookingInfo)) {
            //Error a l'intentar anul�lar la reserva
            // Delete book error
            return LogUtil::registerError($this->__('An error has ocurred while cancelling the booking. Please, try it again. If the problem persists, please, contact webmaster. Additionally, check you are not cancelling a book on past dates'));
        }

        if (($bookingInfo['user'] != UserUtil::getVar('uid')) and (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_ADMIN))) {
            //Un usuari est� intentant anul�lar la reserva d'un altre
            // User is triying to delete a book from another user
            LogUtil::registerError($this->__('You are not allowed to cancel bookings from other people'));
            System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid,
                        'mensual' => $mensual,
                        'd' => $cdate)));
            return true;
        }


        if (empty($confirm)) {
            $room = ModUtil::apiFunc('IWbookings', 'user', 'get', array('sid' => $sid));
            if ($bookingInfo['count'] > 0) {
                LogUtil::registerError($this->__('This booking belongs to a set of simultaneous bookings'));
            }
            if ($bookingInfo['temp'] == 1) {
                LogUtil::registerError($this->__('Warning, this is a preferential booking.'));
            }

            return $this->view->assign('menu', ModUtil::func('IWbookings', 'user', 'menu'))
                            ->assign('name', $room['space_name'])
                            ->assign('d', $cdate)
                            ->assign('sid', $sid)
                            ->assign('multiple', $bookingInfo['count'])
                            ->assign('bookingDate', date('d-m-Y', strtotime($bookingInfo['start'])))
                            ->assign('start', date('H:i', strtotime($bookingInfo['start'])))
                            ->assign('end', date('H:i', strtotime($bookingInfo['end'])))
                            ->assign('user', ModUtil::func('IWmain', 'user', 'getUserInfo', array('uid' => $bookingInfo['user'],
                                        'sv' => ModUtil::func('IWmain', 'user', 'genSecurityValue'),
                                        'info' => 'ncc')))
                            ->assign('group', $bookingInfo['usrgroup'])
                            ->assign('bid', $bid)
                            ->assign('mensual', $mensual)
                            ->assign('d', $cdate)
                            ->fetch('IWbookings_user_delete_bookings.htm');
        }

        // Confirm authorisation code
        $this->checkCsrfToken();


        $anulla = ModUtil::apiFunc('IWbookings', 'user', 'anulla', array('bid' => $bid,
                    'eraseAll' => $eraseAll,
                    'bookingKey' => $bookingInfo['bkey']));
        if (!$anulla) {
            LogUtil::registerError($this->__('An error has ocurred while cancelling the booking. Please, try it again. If the problem persists, please, contact webmaster. Additionally, check you are not cancelling a book on past dates'));
        } else {
            LogUtil::registerstatus($this->__('Thanks for freeing the room or equipment. Possibly somebody will be grateful'));
        }

        System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid,
                    'mensual' => $mensual,
                    'd' => $cdate)));
        return true;
    }