Ajax Event Calendar Support Product Page

Conflict in schedule

Asked 04 Mar 2011 07:06:48
1
has this question
04 Mar 2011 07:06:48 Nelson Therrien posted:
Hi,

Is there a way to look for/prevent conflicts in the calendar?

I suppose it is more an "insert" topic, but I uses the calendar database, so I was wondering...

Replies

Replied 08 Mar 2011 13:30:53
08 Mar 2011 13:30:53 Miroslav Zografski replied:
Hello Nelson,

It is indeed Insert Server Behavior topic. Would advice to have a recordset on the insert page in order to check if similar event is appointed.

Regards,
Replied 08 Mar 2011 16:21:34
08 Mar 2011 16:21:34 Nelson Therrien replied:
Yeah, that's what I thought... But man, I have a hard time figuring what the SELECT instuction can be...

If you have any clue, you're welcome to share it []
Replied 09 Mar 2011 11:13:06
09 Mar 2011 11:13:06 Miroslav Zografski replied:
Hello Nelson,

You can have something like :

// does value exist? 
$myVar= mysql_real_escape_string($myVar); 
$query = "SELECT * FROM events WHERE startDate='$myVar'"; 
$res = mysql_query($query); 
if (mysql_num_rows($res) > 0) { 
  //do something if there is event with same startDate
} else 
  //do something if there isn't
} 


You can add more than one value to check against by adding :

AND anotherColumn = '$mySecondVar'


in the $query.

And you can have this check in separate php file and use Ajax to do the check on field change event.
Here is a sample jQuery function to do this:
<script type="text/javascript">
 function checkValue(myvalue){
   $.ajax({
	method: "get",url: "path/filename.php",data: "myValue="+myvalue,
	beforeSend: function(){
           //if you like to show loading}
        complete: function(){//stop showing loading},  
	success: function(html){ 
          //handle the retrieved html, for instance - set it inside a specifyed container:
	$(".container").html(html);}
  }
</script>


and here is a sample php file to handle the ajax request:

<?php
require_once('Connections/alablala.php');
// retrieve the passed variable
$myVar = $_GET['myvalue'];
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
} 
// does value exist? 
$myVar= mysql_real_escape_string($myVar);
mysql_select_db($database_alabala, $alabala); 
$query = "SELECT * FROM events WHERE startDate='$myVar'"; 
$res = mysql_query($query); 
if (mysql_num_rows($res) > 0) { 
  echo "<span class='notOkay'>There is such event</span>";
} else 
  echo "<span class='okay'><img src='okay.png'/></span>";
}
mysql_free_result($query);
?>


so the result will be either of bot spans.

Regards,
Replied 09 Mar 2011 15:09:30
09 Mar 2011 15:09:30 Nelson Therrien replied:
Thanks a lot!

I need to check not only the date, but the hours... that's where the query gets harder...

But anyway, you pointed me in a good direction and I like the jQuery/AJAX way... I'll look into that deeper.

Reply to this topic