Ejemplo n.º 1
0
function checkCategoryLimits($eventdata)
{
    extract($eventdata);
    //print_r($eventdata);
    //print "$event_starttimeh:$event_starttimem";
    $limits =& pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategoryLimits');
    //print_r($limits);
    foreach ($limits as $limit) {
        if ($limit['catid'] == $event_category) {
            //print_r($limit);
            $sdate = $event_startmonth . '/' . $event_startday . '/' . $event_startyear;
            $edate = $sdate;
            $stime = date("H:i:00", strtotime($limit['startTime']));
            $etime = date("H:i:00", strtotime($limit['endTime']));
            if ($is_update) {
                $searchText = "a.pc_eid != '{$pc_event_id}' AND ";
            }
            //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate<br />";
            $a = array('s_category' => " a.pc_catid = {$event_category}", 'start' => $edate, 'end' => $sdate, 'stime' => $stime, 'etime' => $etime, 'providerID' => $event_userid, 's_keywords' => $searchText . "a.pc_starttime >= '{$stime}' AND a.pc_endtime <= '{$etime}'");
            $eventsByDate =& postcalendar_userapi_pcGetEvents($a);
            //print_r($eventsByDate);
            $ret = null;
            foreach ($eventsByDate as $day) {
                //if event time falls within limit time check
                //hour from forms is 12 not 24 format, convert here
                if ($event_startampm == 2 && $event_starttimeh != 12) {
                    $event_starttimeh += 12;
                } elseif ($event_startampm == 1 && $event_starttimeh == 12) {
                    $event_starttimeh -= 12;
                }
                $event_starttime = date("H:i:00", strtotime($event_starttimeh . ":" . $event_starttimem . ":" . "00"));
                $event_endtime = date("H:i:00", strtotime($event_endtimeh . ":" . $event_endtimem . ":" . "00"));
                if ($event_starttime >= $limit['startTime']) {
                    $numToday = count($day);
                    if ($numToday >= $limit['limit']) {
                        //reached limit
                        $ret = array("start" => $limit['startTime'], "end" => $limit['endTime'], "limit" => $limit['limit']);
                        return $ret;
                    }
                }
                //if in limit time span
            }
        }
    }
    return null;
}
Ejemplo n.º 2
0
/**
 *  checkEventCollision
 *  Returns an array containing any events that collide with the specified event
 *  @params array(key=>value)
 *  @return array $events[][]
 */
function checkEventCollision($edata)
{
    extract($edata);
    $sdate = $event_startmonth . '/' . $event_startday . '/' . $event_startyear;
    $edate = $sdate;
    //hour from forms is 12 not 24 format, convert here
    if ($event_startampm == 2 && $event_starttimeh != 12) {
        $event_starttimeh += 12;
    } elseif ($event_startampm == 1 && $event_starttimeh == 12) {
        $event_starttimeh -= 12;
    }
    $stime = date("H:i:00", strtotime($event_starttimeh . ':' . $event_starttimem . ':00'));
    $etime = date("H:i:00", $event_duration + strtotime($stime));
    //echo "stime is: $stime, etime is: $etime sdate is: $sdate edate is: $edate<br />";
    $a = array('collideFlag' => true, 'start' => $edate, 'end' => $sdate, 'provider_id' => $event_userid, 'stime' => $stime, 'etime' => $etime);
    $eventsByDate =& postcalendar_userapi_pcGetEvents($a);
    //print_r($eventsByDate);
    $collisions = array();
    foreach ($eventsByDate as $day) {
        foreach ($day as $event) {
            if ($event['duration'] == 0 && $event['alldayevent'] == 0) {
                continue;
            } elseif ($event['alldayevent'] == 1) {
                $collisions[] = $event;
            }
            $festart = strtotime($event['startTime']);
            $feend = strtotime($event['startTime'] + $event['duration']);
            $estart = strtotime($stime);
            $eend = strtotime($etime);
            //echo "festart = $festart feend = $feend estart = $estart eend = $eend<br />";
            if ($festart < $eend && $feend > $estart) {
                $collisions[] = $event;
            } elseif ($festart <= $estart && $feend <= $eend && $feend >= $estart) {
                $collisions[] = $event;
            } elseif ($festart >= $estart && $festart < $eend) {
                $collisions[] = $event;
            }
        }
    }
    //foreach ($collisions as $collide) {
    //	echo "collided: " . $collide['title'] . "<br />";
    //}
    return $collisions;
}