Home arrow Forums
Home
FAQ
Documentation
Forums
License Key
  FAQFAQ    SearchSearch  RegisterRegister   Log inLog in 
Auto-disallow conflicting entries

 
Post new topic   Reply to topic     Forum Index -> Hacking Thyme
View previous topic :: View next topic  
Author Message
nick



Joined: 07 Sep 2006
Posts: 13

PostPosted: Fri Sep 22, 2006 9:48 am    Post subject: Auto-disallow conflicting entries Reply with quote

Hi

We're using the calendar to allow users to book a meeting room but don't want to rely on them remembering to use the 'conflict checking' option (because they won't remember to).

Where would I need to edit in order to prevent entries being entered that overlap with existing ones? I'd like to be able to bounce the user back with a basic "You can't do that" message.

Thanks,

Nick
Back to top
View user's profile Send private message
esoft_ian



Joined: 12 Sep 2005
Posts: 5511

PostPosted: Fri Sep 22, 2006 1:59 pm    Post subject: Reply with quote

Hi,

In include/events.php around line:626, before if(!$_cal_event->save()) you can check for a conflicting event:

global $cal;

require_once(_CAL_BASE_PATH_."include/classes/class.calendar.php");

$cal or $cal = new calendar();
$cal->set("calendar", $_cal_event->calendar);
$cal->set("filter", "id != ". intval($_cal_event->id));

list($events) = $cal->get_event_list("day", $_cal_event->starttime);

foreach($events as $e) {

if(($e->starttime < $_cal_event->endtime) && ($e->endtime > $_cal_event->starttime)) {

echo("You can't do that!");
return;
}
}

Something like that should do it or at least be a starting point. Let me know if you have any questions / trouble.
Back to top
View user's profile Send private message Visit poster's website
nick



Joined: 07 Sep 2006
Posts: 13

PostPosted: Fri Sep 22, 2006 2:45 pm    Post subject: Reply with quote

Hello again Ian!

Thanks for the code. As it is, it is causing the script to die just after writing the "bounding_table" , returning the following error message:

Fatal error: Call to undefined function: set() in D:\Webs\intranet\calendar\include\events.php on line 631

Any thoughts?

Cheers,

Nick
Back to top
View user's profile Send private message
esoft_ian



Joined: 12 Sep 2005
Posts: 5511

PostPosted: Fri Sep 22, 2006 2:50 pm    Post subject: Reply with quote

Ah.. in all the code I entered, replace $cal with $eventcal
Back to top
View user's profile Send private message Visit poster's website
nick



Joined: 07 Sep 2006
Posts: 13

PostPosted: Fri Sep 22, 2006 2:57 pm    Post subject: Reply with quote

Hmmm - no joy. No error messages, but it allows conflicting entries to be added. Just to make sure I've got it right, these are my lines 625 - 644:

Code:
      ###########
global $eventcal;

require_once(_CAL_BASE_PATH_."include/classes/class.calendar.php");

$eventcal or $eventcal = new calendar();
$eventcal->set("calendar", $_cal_event->calendar);
$eventcal->set("filter", "id != ". intval($_cal_event->id));

list($events) = $eventcal->get_event_list("day", $_cal_event->starttime);

foreach($events as $e) {

if(($e->starttime < $_cal_event->endtime) && ($e->endtime > $_cal_event->starttime)) {

echo("You can't do that!");
return;
}
}
      if(!$_cal_event->save()) {
Back to top
View user's profile Send private message
esoft_ian



Joined: 12 Sep 2005
Posts: 5511

PostPosted: Fri Sep 22, 2006 3:17 pm    Post subject: Reply with quote

Le'ts try that again:

Code:

##################
#
### CHECK FOR CONFLICTS
#
###########################
global $eventcal;

if(!$_cal_event->allday) {
   list($hr,$mn,$sc) = explode(":", $_cal_event->duration);
   $_cal_event->ends_at = $_cal_event->starttime + ($hr * 3600) + ($mn * 60);
}

require_once(_CAL_BASE_PATH_."include/classes/class.calendar.php");
require_once(_CAL_BASE_PATH_."include/classes/class.event_minimal.php");

$eventcal or $eventcal = new calendar();
$eventcal->set("calendar", $_cal_event->calendar);
$eventcal->set("filter", "id != ". intval($_cal_event->id));

list($events) = $eventcal->get_event_list("day", $_cal_event->starttime);

foreach($events as $e) {

   $e = new _cal_event_minimal($e);

   if(($_cal_event->allday || $e->allday) ||
        (($e->starttime < $_cal_event->ends_at) && ($e->ends_at > $_cal_event->starttime))) {

   echo("You can't do that!");
   require_once(_CAL_BASE_PATH_."include/templates/event_edit_tpl.php");
   return;
   }
}
Back to top
View user's profile Send private message Visit poster's website
nick



Joined: 07 Sep 2006
Posts: 13

PostPosted: Fri Sep 22, 2006 4:04 pm    Post subject: Bingo! Reply with quote

Works like a charm!

Thanks again, Ian. I owe you a cyberbeer.

Cheers,

Nick
Back to top
View user's profile Send private message
harpistic



Joined: 06 Feb 2008
Posts: 5

PostPosted: Fri Feb 15, 2008 1:34 pm    Post subject: Reply with quote

Hi,

how would I amend this to check to see if there's a conflict in category as well? (As we're using the categories as individual meeting rooms).

I've tried the below (and variations on) but the 'type' (and 'etype') parameters are being overlooked:

foreach($events as $e) {

$e = new _cal_event_minimal($e);

if(($_cal_event->allday || $e->allday) ||
(($e->starttime < $_cal_event->ends_at) && ($e->ends_at > $_cal_event->starttime) && ($e_type == $_cal_event->type))) {

echo('Sorry, this slot has already been taken. Please try again later');
Back to top
View user's profile Send private message
esoft_ian



Joined: 12 Sep 2005
Posts: 5511

PostPosted: Sat Feb 16, 2008 3:47 pm    Post subject: Reply with quote

Hi,

You should be able to add this:

$eventcal->set("event_types", intval($_cal_event->type));

after this:

$eventcal->set("filter", "id != ". intval($_cal_event->id));

Leaving the rest of the code the same.

Let me know if this isn't what you are looking for.
Back to top
View user's profile Send private message Visit poster's website
machold



Joined: 10 Mar 2009
Posts: 2

PostPosted: Wed Apr 15, 2009 7:20 pm    Post subject: Reply with quote

Hi,

If I were wanting to disallow conflicting events but only for certain calendars, is there a way to name them such that I can put this block of code into an if statement?

Thanks,

Dan
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Hacking Thyme All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum