Esempio n. 1
0
 /**
  * Convert the date to a more useful format.
  *
  * @param string $date Date string.
  *
  * @return string Converted date
  */
 protected function dateConvert($date)
 {
     if (strptime($date, "%d.%m.%Y %H:%M:%S") !== false) {
         $arr = strptime($date, "%d.%m.%Y %H:%M:%S");
         $time = \DateUtil::buildDatetime($arr['tm_year'], $arr['tm_mon'], $arr['tm_monday'], $arr['tm_hour'], $arr['tm_min'], $arr['tm_sec']);
     } elseif (is_numeric($date)) {
         $time = \DateUtil::getDatetime($date);
     } else {
         $time = str_replace('_', ' ', $date);
     }
     return $time;
 }
Esempio n. 2
0
    public function update_hour($args) {
        // Security check
        if (!SecurityUtil::checkPermission('IWtimeframes::', "::", ACCESS_EDIT)) {
            throw new Zikula_Exception_Forbidden();
        }
        $hid = FormUtil::getPassedValue('hid', isset($args['hid']) ? $args['hid'] : null, 'POST');
        $mdid = FormUtil::getPassedValue('mdid', isset($args['mdid']) ? $args['mdid'] : null, 'POST');
        $hora_i = FormUtil::getPassedValue('hora_i', isset($args['hora_i']) ? $args['hora_i'] : null, 'POST');
        $hora_f = FormUtil::getPassedValue('hora_f', isset($args['hora_f']) ? $args['hora_f'] : null, 'POST');
        $minut_i = FormUtil::getPassedValue('minut_i', isset($args['minut_i']) ? $args['minut_i'] : null, 'POST');
        $minut_f = FormUtil::getPassedValue('minut_f', isset($args['minut_f']) ? $args['minut_f'] : null, 'POST');
        $descriu = FormUtil::getPassedValue('descriu', isset($args['descriu']) ? $args['descriu'] : null, 'POST');

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

        $year = '0000'; //DateUtil::getDatetime_Field($now, 1);
        $month =  '00'; //DateUtil::getDatetime_Field($now, 2);
        $day =  '00'; //DateUtil::getDatetime_Field($now, 3);

        $date_i = DateUtil::buildDatetime($year, $month, $day, $hora_i, $minut_i);
        $date_f = DateUtil::buildDatetime($year, $month, $day, $hora_f, $minut_f);
        //Construim la franja horï¿œria i comprovem que l'hora inicial sigui mï¿œs petita que la hora final
        $start = $hora_i . ':' . $minut_i;
        $end = $hora_f . ':' . $minut_f;

        if ($start >= $end) {
            LogUtil::registerError($this->__('The time allocated is not correct.'));
            return System::redirect(ModUtil::url('IWtimeframes', 'admin', 'timetable',
                            array('mdid' => $mdid)));
        }

        // Check for overlaping time periods
        $overlap = ModUtil::apiFunc('IWtimeframes', 'admin', 'overlap',
                        array('mdid' => $mdid,
                            'start' => $date_i,
                            'end' => $date_f,
                            'hid' => $hid));
        if ($overlap) {
            LogUtil::registerError($this->__('Warning! The new time is overlaps with some of the existing ones.'));
        }

        //Insert new time into DB
        $lid = ModUtil::apiFunc('IWtimeframes', 'admin', 'update_hour',
                        array('mdid' => $mdid,
                            'start' => $date_i,
                            'end' => $date_f,
                            'descriu' => $descriu,
                            'hid' => $hid));

        if (!empty($lid)) {
            //S'ha creat una nova hora dins del marc horari
            SessionUtil::setVar('statusmsg', $this->__('Has changed the time.'));
        }
        $horari = ModUtil::apiFunc('IWtimeframes', 'user', 'getall_horari',
                        array('mdid' => $mdid));

        return System::redirect(ModUtil::url('IWtimeframes', 'admin', 'timetable',
                        array('mdid' => $mdid)));
    }
Esempio n. 3
0
    /**
     * Get booking info from the booking form, verify validity and call a function who records the book
     * @author	Albert Pérez Monfort (aperezm@xtec.cat)
     * @author	Josep Ferràndiz Farré (jferran6@xtec.cat)
     * @return
     */
    public function reserva($args) {
        if (!SecurityUtil::checkPermission('IWbookings::', '::', ACCESS_ADD)) {
            LogUtil::registerError($this->__('You are not allowed to administrate the bookings'));
            System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid)));
            return false;
        }

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

        $bookingDate = FormUtil::getPassedValue('bookingDate', isset($args['bookingDate']) ? $args['bookingDate'] : null, 'POST');
        $date = FormUtil::getPassedValue('date', isset($args['date']) ? $args['date'] : null, 'POST');
        $dow = FormUtil::getPassedValue('dow', isset($args['dow']) ? $args['dow'] : 0, 'POST');
        $fh = FormUtil::getPassedValue('fh', isset($args['fh']) ? $args['fh'] : 0, 'POST');
        $sid = FormUtil::getPassedValue('sid', isset($args['sid']) ? $args['sid'] : null, 'POST');
        $nsessions = FormUtil::getPassedValue('nsessions', isset($args['nsessions']) ? $args['nsessions'] : null, 'POST');
        $group = FormUtil::getPassedValue('group', isset($args['group']) ? $args['group'] : null, 'POST');
        $reason = FormUtil::getPassedValue('reason', isset($args['reason']) ? $args['reason'] : null, 'POST');
        $inici_h = FormUtil::getPassedValue('inici_h', isset($args['inici_h']) ? $args['inici_h'] : null, 'POST');
        $inici_m = FormUtil::getPassedValue('inici_m', isset($args['inici_m']) ? $args['inici_m'] : null, 'POST');
        $final_h = FormUtil::getPassedValue('final_h', isset($args['final_h']) ? $args['final_h'] : null, 'POST');
        $final_m = FormUtil::getPassedValue('final_m', isset($args['final_m']) ? $args['final_m'] : null, 'POST');
        $user = FormUtil::getPassedValue('user', isset($args['user']) ? $args['user'] : null, 'POST');
        $book_end = FormUtil::getPassedValue('book_end', isset($args['book_end']) ? $args['book_end'] : null, 'POST');
        $finish_date = FormUtil::getPassedValue('date_input', isset($args['date_input']) ? $args['date_input'] : null, 'POST');
        $hora = FormUtil::getPassedValue('hora', isset($args['hora']) ? $args['hora'] : null, 'POST');

        if (is_null($user))
            $user = UserUtil::getVar('uid');

        // Arrange dates and times
        $horaris = array();
        $d = explode('-', $bookingDate);
        $cdate = DateUtil::buildDatetime($d[2], $d[1], $d[0], 0, 0, 0, '%Y-%m-%d');

        if ($hora) { // Space has got timeFrame
            $mdid = ModUtil::apiFunc('IWbookings', 'user', 'get', array('sid' => $sid));
            $mdid = $mdid['mdid'];

            $frames = ModUtil::apiFunc('IWtimeframes', 'user', 'getall_horari', array('mdid' => $mdid));
            $t = explode(' - ', $hora);
            $t_inici = explode(':', $t[0]);
            $t_final = explode(':', $t[1]);

            foreach ($frames as $frame) {
                $f = explode(' - ', $frame['hora']);
                $f_inici = explode(':', $f[0]);
                $f_final = explode(':', $f[1]);

                if (($t_inici[0] . $t_inici[1] <= $f_inici[0] . $f_inici[1]) && ($t_final[0] . $t_final[1] >= $f_final[0] . $f_final[1])) {
                    $horaris[] = array('t_inici' => $f_inici,
                        't_final' => $f_final);
                }
            }
            $horari = $hora;
        } else { // Space has no timeframe
            $t_inici[0] = $inici_h;
            $t_inici[1] = $inici_m;
            $t_final[0] = $final_h;
            $t_final[1] = $final_m;
            $horaris[] = array('t_inici' => $t_inici, 't_final' => $t_final);
            $horari = $t_inici[0] . ":" . $t_inici[1] . " - " . $t_final[0] . ":" . $t_final[1];
        }

        $startBooking = DateUtil::buildDatetime($d[2], $d[1], $d[0], $t_inici[0], $t_inici[1], 0, '%Y-%m-%d %H:%M:%S');
        $endBooking = DateUtil::buildDatetime($d[2], $d[1], $d[0], $t_final[0], $t_final[1], 0, '%Y-%m-%d %H:%M:%S');

        $sb = DateUtil::makeTimeStamp($startBooking);
        $eb = DateUtil::makeTimeStamp($endBooking);

        if (empty($group)) {
            LogUtil::registerError($this->__('You must specify a group'));
            System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid,
                        'fh' => $fh,
                        'dow' => $dow,
                        'd' => $bookingDate)));
            return true;
        }

        //Check if start date < end date
        if ($sb > $eb) {
            LogUtil::registerError($this->__('Finish time is minnor than start time'));
            System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid,
                        'fh' => $fh,
                        'dow' => $dow,
                        'd' => $bookingDate)));
            return true;
        }

        if ($book_end == 'date') {
            if (empty($finish_date)) {
                LogUtil::registerError($this->__('You must specify a finish date'));
                System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid)));
                return true;
            } else {
                $finish_date = strtotime($finish_date);
                if ($finish_date < strtotime('today')) {
                    LogUtil::registerError($this->__('Finish date is minnor than actual date'));
                    System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid)));
                    return true;
                }
            }
        }


        // get nsessions from finish_date
        if ($book_end == 'date') {
            $nsessions = 0;
            $tmp_date = strtotime(date('Y-m-d', $eb));
            while ($tmp_date <= $finish_date) {
                $nsessions++;
                $tmp_date = strtotime(date('Y-m-d', $tmp_date) . ' + 1 week');
            }
        }

        $admin = true;
        if (!SecurityUtil::checkPermission('IWbookings::', '::', ACCESS_ADMIN)) {
            $admin = false;
            // Check if num sessions exceeds num weeks limit from actual date
            $maxWeeks = ModUtil::getVar('IWbookings', 'weeks');
            if ($maxWeeks != 0) {
                $factor = $nsessions - 1;
                $last = strtotime(date('Y-m-d', $eb) . ' + ' . $factor . ' weeks');
                $limit = strtotime('today + ' . $maxWeeks . ' weeks');
                $alert = false;

                while ($last > $limit) {
                    $last = strtotime(date('Y-m-d', $last) . ' -1 week');
                    $nsessions--;
                    $alert = true;
                }
                if ($alert)
                    $msg = $this->__('Bookings can only be made for the following ') . $maxWeeks . $this->__(' week(s). Haven\'t made all the requested bookings.');
            }
        }

        $bookingDates = array();
        // Generate all booking dates
        for ($i = 0; $i < $nsessions; ++$i) {
            foreach ($horaris as $h) {
                // Calculate next week
                $next = DateUtil::getDatetime_NextWeek($i, "%Y-%m-%d", $d[2], $d[1], $d[0], 12, 0, 0);
                // Per evitar canvis d'hora produits per l'horari d'estiu
                $bookingDates[] = array('s' => $next . " " . $h[t_inici][0] . ":" . $h[t_inici][1] . ":00",
                    'e' => $next . " " . $h[t_final][0] . ":" . $h[t_final][1] . ":00");
            }
        }



        // Check if the requested bookings is possible
        $reserved = array();
        foreach ($bookingDates as $bd) {
            $bookings = ModUtil::apiFunc('IWbookings', 'user', 'reservat', array('sid' => $sid,
                        'start' => $bd[s],
                        'end' => $bd[e]));
            if (count($bookings) != 0)
                $reserved[] = $bookings;
        }

        if (!count($reserved)) {
            // If all bookings are possible do it
            foreach ($bookingDates as $bd) {
                $success = ModUtil::apiFunc('IWbookings', 'user', 'reserva', array('sid' => $sid,
                            'start' => $bd[s],
                            'end' => $bd[e],
                            'user' => $user,
                            'usrgroup' => $group,
                            'reason' => $reason,
                            'nsessions' => $nsessions,
                            'nbooking' => $success,
                            'admin' => $admin));
                if (!$success) {
                    LogUtil::registerError($this->__('An error has occurred when loading the table or the form'));
                    return System::redirect(ModUtil::url('IWbookings', 'user', 'assigna', array('sid' => $sid,
                                        'date' => $cdate)));
                }
            }
            // Book receipt
            LogUtil::registerStatus("<b>[ " . $this->__('Booking receipt') . " ]</b><br />" . $this->__('Booking day: ') . ": <b> " . $bookingDate . "</b><br/>" . $this->__('Time: ') . ": <b>" . $horari
                    . "</b><br />" . $this->__('Group: ') . ": <b>" . $group . "</b><br />" . $this->__('Reason for booking') . ": <b>" . $reason . "</b><br />"
                    . $this->__('Repeat next weeks') . ": <b>" . $nsessions . "<br /><br /><b>" . $msg);
        } else {
            // Launch error message with reserved frames
            $message = $this->__('Booking failed! The following times are reserved:') . '<ul>';
            foreach ($reserved as $r) {
                $message .= '<li><b>' . date('d-m-Y', strtotime($r['0']['start'])) . $this->__('</b> from ') . date('H:i', strtotime($r['0']['start'])) . $this->__(' to ') . date('H:i', strtotime($r['0']['end'])) . '</li>';
            }
            $message .= '</ul>';
            LogUtil::registerError($message);
        }

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