/**
 * Smarty modifier to format datetimes in a more Human Readable form 
 * (like tomorow, 4 days from now, 6 hours ago)
 *
 * Example
 * <!--[$futuredate|dateformatHuman:'%x':'2']-->
 *
 * @author   Erik Spaan
 * @since    05/03/09
 * @param    string   $string   input datetime string
 * @param    string   $format   The format of the regular date output (default %x)
 * @param    string   $niceval  [1|2|3|4] Choose the nice value of the output (default 2)
 *                                    1 = full human readable
 *                                    2 = past date > 1 day with dateformat, otherwise human readable
 *                                    3 = within 1 day human readable, otherwise dateformat
 *                                    4 = only use the specified format
 * @return   string   the modified output
 */
function smarty_modifier_dateformatHuman($string, $format = '%x', $niceval = 2)
{
    $dom = ZLanguage::getModuleDomain('News');
    if (empty($format)) {
        $format = '%x';
    }
    // store the current datetime in a variable
    $now = DateUtil::getDatetime();
    if (empty($string)) {
        return DateUtil::formatDatetime($now, $format);
    }
    if (empty($niceval)) {
        $niceval = 2;
    }
    // now format the date with respect to the current datetime
    $res = '';
    $diff = DateUtil::getDatetimeDiff($now, $string);
    if ($diff['d'] < 0) {
        if ($niceval == 1) {
            $res = _fn('%s day ago', '%s days ago', abs($diff['d']), abs($diff['d']), $dom);
        } elseif ($niceval < 4 && $diff['d'] == -1) {
            $res = __('yesterday', $dom);
        } else {
            $res = DateUtil::formatDatetime($string, $format);
        }
    } elseif ($diff['d'] > 0) {
        if ($niceval > 2) {
            $res = DateUtil::formatDatetime($string, $format);
        } elseif ($diff['d'] == 1) {
            $res = __('tomorrow', $dom);
        } else {
            $res = _fn('%s day from now', '%s days from now', $diff['d'], $diff['d'], $dom);
        }
    } else {
        // no day difference
        if ($diff['h'] < 0) {
            $res = _fn('%s hour ago', '%s hours ago', abs($diff['h']), abs($diff['h']), $dom);
        } elseif ($diff['h'] > 0) {
            $res = _fn('%s hour from now', '%s hours from now', $diff['h'], $diff['h'], $dom);
        } else {
            // no hour difference
            if ($diff['m'] < 0) {
                $res = _fn('%s minute ago', '%s minutes ago', abs($diff['m']), abs($diff['m']), $dom);
            } elseif ($diff['m'] > 0) {
                $res = _fn('%s minute from now', '%s minutes from now', $diff['m'], $diff['m'], $dom);
            } else {
                // no min difference
                if ($diff['s'] < 0) {
                    $res = _fn('%s second ago', '%s seconds ago', abs($diff['s']), abs($diff['s']), $dom);
                } else {
                    $res = _fn('%s second from now', '%s seconds from now', $diff['s'], $diff['s'], $dom);
                }
            }
        }
    }
    return $res;
}
예제 #2
0
 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     if ($obj['endDate'] == $obj['startDate']) {
         $out->insert(strtotime($obj['startDate']), $obj);
     } else {
         $diff = DateUtil::getDatetimeDiff($obj['startDate'], $obj['endDate']);
         $timestamp = strtotime($obj['startDate']);
         $timestamp = mktime(0, 0, 0, date('n', $timestamp), date('j', $timestamp), date('Y', $timestamp));
         // add days
         for ($i = 0; $i <= $diff['d']; $i++) {
             $out->insert($timestamp, $obj);
             // next day
             $timestamp += 86400;
         }
     }
 }
예제 #3
0
 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     $time = $start;
     $diff = DateUtil::getDatetimeDiff($obj['startDate'], $time);
     // weekly?
     if ($obj['repeatSpec'] == "week") {
         $weeks = (int) date('W', strtotime($start)) - (int) date('W', strtotime($obj['startDate']));
         $weeks = (int) floor($weeks / $obj['repeatFrec']);
         if ($weeks < 0) {
             $weeks = 0;
         }
         $date = DateUtil::getDatetime(strtotime('+' . $weeks * $obj['repeatFrec'] . ' week', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
         while ($date <= $end && $date <= $obj['endDate']) {
             // in requested range?
             if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                 $temp = getDate(strtotime($date));
                 $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $temp['year']);
                 $out->insert($temp, $obj);
             }
             // next occurence
             $weeks++;
             $date = DateUtil::getDatetime(strtotime('+' . $weeks * $obj['repeatFrec'] . ' week', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
         }
         // monthly?
     } else {
         if ($obj['repeatSpec'] == "month") {
             // calc start
             $years = (int) date('Y', strtotime($end)) - (int) date('Y', strtotime($obj['startDate']));
             $months = $years * 12;
             $monthsTemp = (int) date('n', strtotime($start)) - (int) date('n', strtotime($obj['startDate']));
             $months = $months + $monthsTemp;
             $months = (int) floor($months / $obj['repeatFrec']);
             $date = DateUtil::getDatetime(strtotime('+' . $months * $obj['repeatFrec'] . ' month', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
             //print_r($monthsTemp);exit();
             while ($date <= $end && $date <= $obj['endDate']) {
                 // in requested range?
                 if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                     $temp = getDate(strtotime($date));
                     $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $temp['year']);
                     $out->insert($temp, $obj);
                 }
                 // next occurence
                 $months++;
                 $date = DateUtil::getDatetime(strtotime('+' . $months * $obj['repeatFrec'] . ' month', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
             }
             // yearly
         } else {
             if ($obj['repeatSpec'] == "year") {
                 $years_start = (int) date('Y', strtotime($obj['startDate']));
                 $years_ende = (int) date('Y', strtotime($obj['endDate']));
                 for ($year = $years_start; $year <= $years_ende; $year += $obj['repeatFrec']) {
                     // calc timestamp
                     $temp = getDate(strtotime($obj['startDate']));
                     $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $year);
                     $date = DateUtil::getDatetime($temp, DATEONLYFORMAT_FIXED);
                     // in requested range?
                     if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                         $out->insert($temp, $obj);
                     }
                 }
                 // daily
             } else {
                 $repeats = (int) floor($diff['d'] / $obj['repeatFrec']);
                 $repeats--;
                 if ($repeats < 0) {
                     $daysToLastUnusedRepeat = (int) -$obj['repeatFrec'];
                     /* } else if($repeats == 0)
                        {
                                $daysToLastUnusedRepeat = 0 - $obj['repeatFrec'];*/
                 } else {
                     $daysToLastUnusedRepeat = $repeats * $obj['repeatFrec'];
                 }
                 $timestamp = strtotime($obj['startDate']);
                 $timestampEnd = strtotime($end);
                 $counter = $obj['repeatFrec'];
                 while (true) {
                     $temp = mktime(0, 0, 0, date('n', $timestamp), date('j', $timestamp) + $daysToLastUnusedRepeat + $counter, date('Y', $timestamp));
                     $counter += $obj['repeatFrec'];
                     // end reached?
                     if ($temp > strtotime($obj['endDate']) || $temp > $timestampEnd) {
                         break;
                     }
                     $out->insert($temp, $obj);
                 }
             }
         }
     }
 }
예제 #4
0
파일: View.php 프로젝트: rmaiwald/MUBoard
 /**
  * This method checks if user must edit this posting - creater of the issue
  */
 public static function getStateOfEditOfIssue($postingid)
 {
     $dom = ZLanguage::getModuleDomain('MUBoard');
     //get repository for Postings
     $repository = MUBoard_Util_Model::getPostingRepository();
     // get posting
     $posting = $repository->selectById($postingid);
     // check if issue or anser
     $parent = $posting->getParent();
     // get forum of posting
     $forum = $posting->getForum();
     $forumid = $forum->getId();
     // get userid of user created this posting
     $createdUserId = $posting->getCreatedUserId();
     // get created Date
     $createdDate = $posting->getCreatedDate();
     $createdDate = $createdDate->getTimestamp();
     // get the actual time
     $actualTime = DateUtil::getDatetime();
     // get modvar editTime
     $editTime = ModUtil::getVar('MUBoard', 'editTime');
     $diffTime = DateUtil::getDatetimeDiff($createdDate, $actualTime);
     $diffTimeHours = $diffTime['d'] * 24 + $diffTime['h'];
     if (UserUtil::isLoggedIn() == true) {
         $userid = UserUtil::getVar('uid');
     } else {
         $out = '';
     }
     if ($createdUserId == $userid && ($diffTimeHours < $editTime || $parent == NULL)) {
         $serviceManager = ServiceUtil::getManager();
         // generate an auth key to use in urls
         //$csrftoken = SecurityUtil::generateCsrfToken($serviceManager, true); we do not use token at the moment TODO, 'token' => $csrftoken
         $url = ModUtil::url('MUBoard', 'user', 'edit', array('ot' => 'posting', 'id' => $postingid, 'forum' => $forumid));
         $title = __('You have permissions to edit this posting!', $dom);
         $out = "<a title='{$title}' id='muboard-user-posting-header-infos-edit-creater' href='{$url}'>\n            <img src='/images/icons/extrasmall/xedit.png' />\n            </a>";
     } else {
         $out = '';
     }
     return $out;
 }
예제 #5
0
파일: User.php 프로젝트: projectesIF/Sirius
    /**
     * Generates the main page for book, cancel and consult bookings
     * @author	Albert Pérez Monfort (aperezm@xtec.cat)
     * @author	Josep Ferràndiz Farré (jferran6@xtec.cat)
     * @return	the page
     */
    public function assigna($args) {
        // Security check
        if (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_READ)) {
            throw new Zikula_Exception_Forbidden();
        }

        $sid = FormUtil::getPassedValue('sid', isset($args['sid']) ? $args['sid'] : null, 'REQUEST');
        $dow = FormUtil::getPassedValue('dow', isset($args['dow']) ? $args['dow'] : 0, 'GET');
        $showontop = FormUtil::getPassedValue('sot', isset($args['sot']) ? $args['sot'] : 0, 'GET');
        $date = FormUtil::getPassedValue('d', isset($args['d']) ? $args['d'] : null, 'GET'); //User selects a cell in the booking table
        $mensual = FormUtil::getPassedValue('mensual', isset($args['mensual']) ? $args['mensual'] : null, 'REQUEST');
        $inc = FormUtil::getPassedValue('m', isset($args['m']) ? $args['m'] : null, 'GET');

        $currentDate = FormUtil::getPassedValue('date', isset($args['date']) ? $args['date'] : null, 'POST'); //User selects a date in the calendar
        $month = FormUtil::getPassedValue('month', isset($args['month']) ? $args['month'] : null, 'REQUEST');
        $year = FormUtil::getPassedValue('year', isset($args['year']) ? $args['year'] : null, 'REQUEST');

        $calendari = '';
        $formulari = '';

        // Si l'usuari selecciona una data de la taula
        if (empty($currentDate) and (!empty($date))) {
            $dateParts = explode('-', $date);
            $currentDate = DateUtil::buildDatetime($dateParts[2], $dateParts[1], $dateParts[0], 0, 0, 0, '%Y-%m-%d');
        }

        if ($sid <> -1) {
            $nom = ModUtil::apiFunc('IWbookings', 'user', 'get', array('sid' => $sid));
            $marc = $nom['mdid'];
            if ($marc != 0) {
                $n = ModUtil::apiFunc('IWbookings', 'user', 'checktimeframe', $marc);
                if ((ModUtil::apiFunc('IWbookings', 'user', 'checktimeframe', $marc) < 2)) {
                    LogUtil::registerError($this->__('No hi ha franges'));
                }
            }

            //Per si falla la c�rrega de les dades
            if ($nom == false) {
                LogUtil::registerError($this->__('The room or equipment was not found'));
                return System::redirect(ModUtil::url('IWbookings', 'user', 'main'));
            }
        } else {
            $nom['space_name'] = $this->__('All rooms and equipments');
        }

        // Get date difference in days to limit backtracking
        $diff = DateUtil::getDatetimeDiff($currentDate, DateUtil::getDatetime());

        // Weeks before actual week are not allowed
        if ($diff['d'] > 0) {
            $currentDate = DateUtil::getDatetime();
        }

        if (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_ADMIN)) {
            // Weeks beyond num. weeks limit are not allowed
            $weekslimit = ModUtil::getVar('IWbookings', 'weeks');
            if (($weekslimit > 0 ) and ($diff['d'] < -7 * $weekslimit)) {
                $currentDate = DateUtil::getDatetime(DateUtil::makeTimestamp() + $weekslimit * 7 * 24 * 60 * 60, '%Y-%m-%d');
                LogUtil::registerError($this->__('Bookings can only be made for the following ') . $weekslimit . $this->__(' week(s). Booking date is not valid'));
            }
        }
        $canbook = SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_ADD);

        if ($mensual) {
            $taula = ModUtil::func('IWbookings', 'user', 'monthlyview', array('sid' => $sid,
                        'mensual' => $mensual,
                        'm' => $inc,
                        'month' => $month,
                        'year' => $year));
        } else {
            $week = ModUtil::apiFunc('IWbookings', 'user', 'getWeek', array('date' => $currentDate,
                        'format' => 'dmy'));

            $jumpDates = ModUtil::apiFunc('IWbookings', 'user', 'getJumpDates', array('date' => $currentDate));
            if ($canbook) {
                //Creem el formulari per fer reserves temporals
                $formulari = ModUtil::func('IWbookings', 'user', 'formulari_assigna', array('sid' => $sid,
                            'dow' => $dow,
                            'cdate' => $currentDate,
                            'sot' => $showontop));
            } else {
                $formulari = '.';
            }
            //Creem la taula de l'estat de les reserves
            $taula = ModUtil::func('IWbookings', 'user', 'taula', array('sid' => $sid,
                        'currentDate' => $currentDate,
                        'bookingDate' => $date,
                        'mensual' => $mensual,
                        'canbook' => $canbook));
            // Creem el formulari per seleccionar la data
            $calendari = ModUtil::func('IWbookings', 'user', 'selectDate', array('sid' => $sid,
                        'date' => $currentDate,
                        'start' => $week['start'],
                        'end' => $week['end'],
                        'prevWeek' => $jumpDates['prevweek'],
                        'nextWeek' => $jumpDates['nextweek'],
                        'prevMonth' => $jumpDates['prevmonth'],
                        'nextMonth' => $jumpDates['nextmonth'],
                        'mensual' => $mensual,
                        'showontop' => $showontop));


            // anteriorment: (empty($taula) || empty($formulari))
            /*   if ($taula == '' || empty($formulari)) {
              LogUtil::registerError($this->__('An error has occurred when loading the table or the form'));
              return System::redirect(ModUtil::url('IWbookings', 'user', 'main'));
              } */
        }
        $space = ModUtil::apiFunc('IWbookings', 'user', 'get', array('sid' => $sid));
        // Not show in tabular format
        $ntf = !(($space['mdid']) and ($space['vertical']));

        return $this->view->assign('space_name', $nom['space_name'])
                        ->assign('taula', $taula)
                        ->assign('sid', $sid)
                        ->assign('showontop', $showontop)
                        ->assign('calendari', $calendari)
                        ->assign('formulari', $formulari)
                        ->assign('noTable', $ntf)
                        ->assign('dow', $dow) //day of week
                        ->assign('menu', ModUtil::func('IWbookings', 'user', 'menu', array('mensual' => $mensual,
                                    'sid' => $sid)))
                        ->fetch('IWbookings_user_assigna.htm');
    }