AnsweredAssumed Answered

Sugar 7 bwc overriding Save button to add ajax

Question asked by Gaelle Fernandez on Jul 8, 2014
Latest reply on Jul 10, 2014 by Gaelle Fernandez
MERGED
This conversation has been merged. Please reference the main conversation:
Hello everybody,

I'm encountering a problem and i would like some help on it.

First of all, if anyone has some tips or tutorials to help me overriding save button in editview (for module Meeting, so in Backward Compatibility), i would be glad to read it. (and by overriding, i mean ajax overriding)

I've already read this :
http://phpbugs.wordpress.com/2010/01/22/sugarcrm-adding-javascript-validation-on-form-submit/
and this :
http://developer.sugarcrm.com/2013/04/04/sugarcrm-create-a-custom-javascript-validation-before-savin...

And tried to apply it to my specific case.

What i want?
When saving a meeting,  i want sugar to go search if the status is on "Planned", does the assigned user already have other meetings at the date_start time. If he does, Sugar must throw an alert and interrupt the saving action.
If the assigned user does not have any meetings, Sugar saves the meeting.

What i did :
custom/modules/Meetings/views/view.edit.php

require_once('include/MVC/View/views/view.edit.php');
class CustomMeetingsViewEdit extends ViewEdit {
    /**
    * @see SugarView::display()
    */
    protected function _displayJavascript() {
        // Call the parent handler
        parent::_displayJavascript();
    }
    /**
    * @see SugarView::display()
    */
    public function preDisplay() {
        // Call parent
        parent::preDisplay();
echo '<script type="text/javascript">
function customJavascriptValidation() {
console.log("first view.edit.php");
// Insert code here
if($("#status").val()=="Planned"){
var user_id = $("#assigned_user_id").val();
var user_name = $("#assigned_user_name").val();
var duration_h = $("#duration_hours").val();
var duration_m = $("#duration_minutes").val();
var date_start = $("#date_start_date").val()+" "+$("#date_start_hours").val()+":"+$("#date_start_minutes").val();
var href = $(".moduleTitle").find("h2 a").attr("href");//trouver le lien du record
if (href != undefined){
var idx = href.indexOf("record");
var bean_id = href.substr(idx+7);
}else{
var bean_id = "";
}
//before modification, it was only this ajax function
$.ajax({
url: "http://<SUGARBASE>/index.php?entryPoint=validateAvailability";,
type: "POST",
data: { userid : user_id, beanid : bean_id, date : date_start, h : duration_h, m : duration_m},
success: function(data){
console.log(data);
if (data === "false"){
//console.log("nok");
alert("L
                                                                                                                                                                                                                                            
As you can see, i've made an entry point to access my function in another file, which lies under custom/modules/Meetings/phpfunctions/validateAvailability.php. (THIS entrypoint WORKS, i've tested it)

<?php//GFE 24/06/2014
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $sugar_config, $dbhost, $db_user_name, $db_password, $db_name, $dbport; 
global $db; 
//this one is for validate user's availability
$user_id = $_POST['userid'];
$date_start = $_POST['date'];
$duration_h = $_POST['h'];
$duration_m = $_POST['m'];
$bean_id = $_POST['beanid'];
require_once("custom/modules/Meetings/Meetings.php");
$isavailable = CustomMeeting::checkUserIsAvailable($user_id,$bean_id,$date_start,$duration_h,$duration_m);
/*if ($isavailable== false){
echo "false";
}else{
echo "true";
}*/
?>
                                    

And this one calls the checkUserIsAvailable, wich is under custom/module/Meetings/Meetings.php and contain this :

public static function checkUserIsAvailable($user_id, $bean_id = null, $date_start, $duration_hours, $duration_minutes) {
global $db, $timedate;
//attention : on a enlevé la timezone. trouver comment la remettre ensuite.
// Dissociate date and time
$dateStartArr = explode(" ", trim($date_start));
$dateStartDArr = explode("/",$dateStartArr[0]);
$dateStartHArr = explode(":",$dateStartArr[1]);
// Calculate date end
$dateStartTimestamp = mktime($dateStartHArr[0], $dateStartHArr[1], 0, $dateStartDArr[1], $dateStartDArr[0], $dateStartDArr[2]);
$dateEndTimestamp = $dateStartTimestamp + ($duration_hours * 3600) + ($duration_minutes * 60);
// Create Date ISO from timestamp
$dateEnd = date('Y-m-d H:i:00', $dateEndTimestamp);
$dateStartFormat = $dateStartDArr[2].'-'.$dateStartDArr[1].'-'.$dateStartDArr[0].' '.$dateStartHArr[0].':'.$dateStartHArr[1].':00';
//Go query check duplicates meeting for user
$query  = "";
$query .= "SELECT DISTINCT id ";
$query .= "FROM meetings AS m ";
$query .= "INNER JOIN meetings_cstm AS mc ON (m.id = mc.id_c) ";
$query .= "WHERE m.deleted = 0 ";
if (!empty($bean_id))
{ // Exclude current Meeting from search
$query .= "AND m.id <> '{$bean_id}' ";
}
$query .= "  AND m.status IN ('Planned', 'Held', 'HeldNoNext') ";
$query .= "  AND ( m.assigned_user_id = '{$user_id}' OR (mc.withdr_c = 1 AND m.assigned_user_id IN (SELECT u.id FROM users AS u WHERE reports_to_id = '{$user_id}')) ) ";
$query .= "  AND ( ";
$query .= "   ( m.date_start < '{$dateStartFormat}' AND '{$dateStartFormat}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start < '{$dateEnd}' AND '{$dateEnd}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start > '{$dateStartFormat}' AND m.date_start < '{$dateEnd}' ) ";
$query .= "   OR ( DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) > '{$dateStartFormat}' AND DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) < '{$dateEnd}' )";
$query .= "   OR m.date_start = '{$dateStartFormat}' ";
$query .= "   OR DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) = '{$dateEnd}' ";
$query .= "   ); ";
//var_dump($query);exit();die();
//var_dump($query);exit();die();
$result = $db->query($query);
$return = "true";
if ($db->getRowCount($result) > 0)
{ // User already has a meeting
$return = "false";
}
//echo $query;
echo $return;
}
                                                                                                   
I've tested the query, it WORKS.

Now, i think i need some help on my ajax links, because everytime i click on save button, i got a console.log saying "SQL Failure", which is the sign of error for my ajax function.

So, sugar enters the ajax call, but can't find the files?
How can i make the ajax simpler? by adding the php functions to the "view.edit.php"? but this way, how do i call my functions?

What do you think, and do you have any idea on how to perform ajax calls on click for the save button?

Thanks a lot, this is really urgent.
Have a nice evening
Gaëlle







utilisateur a déjà d                                                                                                                                                                                                                                            
As you can see, i've made an entry point to access my function in another file, which lies under custom/modules/Meetings/phpfunctions/validateAvailability.php. (THIS entrypoint WORKS, i've tested it)

<?php//GFE 24/06/2014
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $sugar_config, $dbhost, $db_user_name, $db_password, $db_name, $dbport; 
global $db; 
//this one is for validate user's availability
$user_id = $_POST['userid'];
$date_start = $_POST['date'];
$duration_h = $_POST['h'];
$duration_m = $_POST['m'];
$bean_id = $_POST['beanid'];
require_once("custom/modules/Meetings/Meetings.php");
$isavailable = CustomMeeting::checkUserIsAvailable($user_id,$bean_id,$date_start,$duration_h,$duration_m);
/*if ($isavailable== false){
echo "false";
}else{
echo "true";
}*/
?>
                                    

And this one calls the checkUserIsAvailable, wich is under custom/module/Meetings/Meetings.php and contain this :

public static function checkUserIsAvailable($user_id, $bean_id = null, $date_start, $duration_hours, $duration_minutes) {
global $db, $timedate;
//attention : on a enlevé la timezone. trouver comment la remettre ensuite.
// Dissociate date and time
$dateStartArr = explode(" ", trim($date_start));
$dateStartDArr = explode("/",$dateStartArr[0]);
$dateStartHArr = explode(":",$dateStartArr[1]);
// Calculate date end
$dateStartTimestamp = mktime($dateStartHArr[0], $dateStartHArr[1], 0, $dateStartDArr[1], $dateStartDArr[0], $dateStartDArr[2]);
$dateEndTimestamp = $dateStartTimestamp + ($duration_hours * 3600) + ($duration_minutes * 60);
// Create Date ISO from timestamp
$dateEnd = date('Y-m-d H:i:00', $dateEndTimestamp);
$dateStartFormat = $dateStartDArr[2].'-'.$dateStartDArr[1].'-'.$dateStartDArr[0].' '.$dateStartHArr[0].':'.$dateStartHArr[1].':00';
//Go query check duplicates meeting for user
$query  = "";
$query .= "SELECT DISTINCT id ";
$query .= "FROM meetings AS m ";
$query .= "INNER JOIN meetings_cstm AS mc ON (m.id = mc.id_c) ";
$query .= "WHERE m.deleted = 0 ";
if (!empty($bean_id))
{ // Exclude current Meeting from search
$query .= "AND m.id <> '{$bean_id}' ";
}
$query .= "  AND m.status IN ('Planned', 'Held', 'HeldNoNext') ";
$query .= "  AND ( m.assigned_user_id = '{$user_id}' OR (mc.withdr_c = 1 AND m.assigned_user_id IN (SELECT u.id FROM users AS u WHERE reports_to_id = '{$user_id}')) ) ";
$query .= "  AND ( ";
$query .= "   ( m.date_start < '{$dateStartFormat}' AND '{$dateStartFormat}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start < '{$dateEnd}' AND '{$dateEnd}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start > '{$dateStartFormat}' AND m.date_start < '{$dateEnd}' ) ";
$query .= "   OR ( DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) > '{$dateStartFormat}' AND DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) < '{$dateEnd}' )";
$query .= "   OR m.date_start = '{$dateStartFormat}' ";
$query .= "   OR DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) = '{$dateEnd}' ";
$query .= "   ); ";
//var_dump($query);exit();die();
//var_dump($query);exit();die();
$result = $db->query($query);
$return = "true";
if ($db->getRowCount($result) > 0)
{ // User already has a meeting
$return = "false";
}
//echo $query;
echo $return;
}
                                                                                                   
I've tested the query, it WORKS.

Now, i think i need some help on my ajax links, because everytime i click on save button, i got a console.log saying "SQL Failure", which is the sign of error for my ajax function.

So, sugar enters the ajax call, but can't find the files?
How can i make the ajax simpler? by adding the php functions to the "view.edit.php"? but this way, how do i call my functions?

What do you think, and do you have any idea on how to perform ajax calls on click for the save button?

Thanks a lot, this is really urgent.
Have a nice evening
Gaëlle







autres rendez-vous de prévus sur cette plage horaire!");
//on ne peut pas sauvegarder
return false;
}
if (data === "true"){
//on peut sauvegarder
return check_form(                                                                                                                                                                                                                                            
As you can see, i've made an entry point to access my function in another file, which lies under custom/modules/Meetings/phpfunctions/validateAvailability.php. (THIS entrypoint WORKS, i've tested it)

<?php//GFE 24/06/2014
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $sugar_config, $dbhost, $db_user_name, $db_password, $db_name, $dbport; 
global $db; 
//this one is for validate user's availability
$user_id = $_POST['userid'];
$date_start = $_POST['date'];
$duration_h = $_POST['h'];
$duration_m = $_POST['m'];
$bean_id = $_POST['beanid'];
require_once("custom/modules/Meetings/Meetings.php");
$isavailable = CustomMeeting::checkUserIsAvailable($user_id,$bean_id,$date_start,$duration_h,$duration_m);
/*if ($isavailable== false){
echo "false";
}else{
echo "true";
}*/
?>
                                    

And this one calls the checkUserIsAvailable, wich is under custom/module/Meetings/Meetings.php and contain this :

public static function checkUserIsAvailable($user_id, $bean_id = null, $date_start, $duration_hours, $duration_minutes) {
global $db, $timedate;
//attention : on a enlevé la timezone. trouver comment la remettre ensuite.
// Dissociate date and time
$dateStartArr = explode(" ", trim($date_start));
$dateStartDArr = explode("/",$dateStartArr[0]);
$dateStartHArr = explode(":",$dateStartArr[1]);
// Calculate date end
$dateStartTimestamp = mktime($dateStartHArr[0], $dateStartHArr[1], 0, $dateStartDArr[1], $dateStartDArr[0], $dateStartDArr[2]);
$dateEndTimestamp = $dateStartTimestamp + ($duration_hours * 3600) + ($duration_minutes * 60);
// Create Date ISO from timestamp
$dateEnd = date('Y-m-d H:i:00', $dateEndTimestamp);
$dateStartFormat = $dateStartDArr[2].'-'.$dateStartDArr[1].'-'.$dateStartDArr[0].' '.$dateStartHArr[0].':'.$dateStartHArr[1].':00';
//Go query check duplicates meeting for user
$query  = "";
$query .= "SELECT DISTINCT id ";
$query .= "FROM meetings AS m ";
$query .= "INNER JOIN meetings_cstm AS mc ON (m.id = mc.id_c) ";
$query .= "WHERE m.deleted = 0 ";
if (!empty($bean_id))
{ // Exclude current Meeting from search
$query .= "AND m.id <> '{$bean_id}' ";
}
$query .= "  AND m.status IN ('Planned', 'Held', 'HeldNoNext') ";
$query .= "  AND ( m.assigned_user_id = '{$user_id}' OR (mc.withdr_c = 1 AND m.assigned_user_id IN (SELECT u.id FROM users AS u WHERE reports_to_id = '{$user_id}')) ) ";
$query .= "  AND ( ";
$query .= "   ( m.date_start < '{$dateStartFormat}' AND '{$dateStartFormat}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start < '{$dateEnd}' AND '{$dateEnd}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start > '{$dateStartFormat}' AND m.date_start < '{$dateEnd}' ) ";
$query .= "   OR ( DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) > '{$dateStartFormat}' AND DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) < '{$dateEnd}' )";
$query .= "   OR m.date_start = '{$dateStartFormat}' ";
$query .= "   OR DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) = '{$dateEnd}' ";
$query .= "   ); ";
//var_dump($query);exit();die();
//var_dump($query);exit();die();
$result = $db->query($query);
$return = "true";
if ($db->getRowCount($result) > 0)
{ // User already has a meeting
$return = "false";
}
//echo $query;
echo $return;
}
                                                                                                   
I've tested the query, it WORKS.

Now, i think i need some help on my ajax links, because everytime i click on save button, i got a console.log saying "SQL Failure", which is the sign of error for my ajax function.

So, sugar enters the ajax call, but can't find the files?
How can i make the ajax simpler? by adding the php functions to the "view.edit.php"? but this way, how do i call my functions?

What do you think, and do you have any idea on how to perform ajax calls on click for the save button?

Thanks a lot, this is really urgent.
Have a nice evening
Gaëlle







EditView                                                                                                                                                                                                                                            
As you can see, i've made an entry point to access my function in another file, which lies under custom/modules/Meetings/phpfunctions/validateAvailability.php. (THIS entrypoint WORKS, i've tested it)

<?php//GFE 24/06/2014
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $sugar_config, $dbhost, $db_user_name, $db_password, $db_name, $dbport; 
global $db; 
//this one is for validate user's availability
$user_id = $_POST['userid'];
$date_start = $_POST['date'];
$duration_h = $_POST['h'];
$duration_m = $_POST['m'];
$bean_id = $_POST['beanid'];
require_once("custom/modules/Meetings/Meetings.php");
$isavailable = CustomMeeting::checkUserIsAvailable($user_id,$bean_id,$date_start,$duration_h,$duration_m);
/*if ($isavailable== false){
echo "false";
}else{
echo "true";
}*/
?>
                                    

And this one calls the checkUserIsAvailable, wich is under custom/module/Meetings/Meetings.php and contain this :

public static function checkUserIsAvailable($user_id, $bean_id = null, $date_start, $duration_hours, $duration_minutes) {
global $db, $timedate;
//attention : on a enlevé la timezone. trouver comment la remettre ensuite.
// Dissociate date and time
$dateStartArr = explode(" ", trim($date_start));
$dateStartDArr = explode("/",$dateStartArr[0]);
$dateStartHArr = explode(":",$dateStartArr[1]);
// Calculate date end
$dateStartTimestamp = mktime($dateStartHArr[0], $dateStartHArr[1], 0, $dateStartDArr[1], $dateStartDArr[0], $dateStartDArr[2]);
$dateEndTimestamp = $dateStartTimestamp + ($duration_hours * 3600) + ($duration_minutes * 60);
// Create Date ISO from timestamp
$dateEnd = date('Y-m-d H:i:00', $dateEndTimestamp);
$dateStartFormat = $dateStartDArr[2].'-'.$dateStartDArr[1].'-'.$dateStartDArr[0].' '.$dateStartHArr[0].':'.$dateStartHArr[1].':00';
//Go query check duplicates meeting for user
$query  = "";
$query .= "SELECT DISTINCT id ";
$query .= "FROM meetings AS m ";
$query .= "INNER JOIN meetings_cstm AS mc ON (m.id = mc.id_c) ";
$query .= "WHERE m.deleted = 0 ";
if (!empty($bean_id))
{ // Exclude current Meeting from search
$query .= "AND m.id <> '{$bean_id}' ";
}
$query .= "  AND m.status IN ('Planned', 'Held', 'HeldNoNext') ";
$query .= "  AND ( m.assigned_user_id = '{$user_id}' OR (mc.withdr_c = 1 AND m.assigned_user_id IN (SELECT u.id FROM users AS u WHERE reports_to_id = '{$user_id}')) ) ";
$query .= "  AND ( ";
$query .= "   ( m.date_start < '{$dateStartFormat}' AND '{$dateStartFormat}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start < '{$dateEnd}' AND '{$dateEnd}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start > '{$dateStartFormat}' AND m.date_start < '{$dateEnd}' ) ";
$query .= "   OR ( DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) > '{$dateStartFormat}' AND DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) < '{$dateEnd}' )";
$query .= "   OR m.date_start = '{$dateStartFormat}' ";
$query .= "   OR DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) = '{$dateEnd}' ";
$query .= "   ); ";
//var_dump($query);exit();die();
//var_dump($query);exit();die();
$result = $db->query($query);
$return = "true";
if ($db->getRowCount($result) > 0)
{ // User already has a meeting
$return = "false";
}
//echo $query;
echo $return;
}
                                                                                                   
I've tested the query, it WORKS.

Now, i think i need some help on my ajax links, because everytime i click on save button, i got a console.log saying "SQL Failure", which is the sign of error for my ajax function.

So, sugar enters the ajax call, but can't find the files?
How can i make the ajax simpler? by adding the php functions to the "view.edit.php"? but this way, how do i call my functions?

What do you think, and do you have any idea on how to perform ajax calls on click for the save button?

Thanks a lot, this is really urgent.
Have a nice evening
Gaëlle







);
//on ne fait rien 
//console.log(                                                                                                                                                                                                                                            
As you can see, i've made an entry point to access my function in another file, which lies under custom/modules/Meetings/phpfunctions/validateAvailability.php. (THIS entrypoint WORKS, i've tested it)

<?php//GFE 24/06/2014
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $sugar_config, $dbhost, $db_user_name, $db_password, $db_name, $dbport; 
global $db; 
//this one is for validate user's availability
$user_id = $_POST['userid'];
$date_start = $_POST['date'];
$duration_h = $_POST['h'];
$duration_m = $_POST['m'];
$bean_id = $_POST['beanid'];
require_once("custom/modules/Meetings/Meetings.php");
$isavailable = CustomMeeting::checkUserIsAvailable($user_id,$bean_id,$date_start,$duration_h,$duration_m);
/*if ($isavailable== false){
echo "false";
}else{
echo "true";
}*/
?>
                                    

And this one calls the checkUserIsAvailable, wich is under custom/module/Meetings/Meetings.php and contain this :

public static function checkUserIsAvailable($user_id, $bean_id = null, $date_start, $duration_hours, $duration_minutes) {
global $db, $timedate;
//attention : on a enlevé la timezone. trouver comment la remettre ensuite.
// Dissociate date and time
$dateStartArr = explode(" ", trim($date_start));
$dateStartDArr = explode("/",$dateStartArr[0]);
$dateStartHArr = explode(":",$dateStartArr[1]);
// Calculate date end
$dateStartTimestamp = mktime($dateStartHArr[0], $dateStartHArr[1], 0, $dateStartDArr[1], $dateStartDArr[0], $dateStartDArr[2]);
$dateEndTimestamp = $dateStartTimestamp + ($duration_hours * 3600) + ($duration_minutes * 60);
// Create Date ISO from timestamp
$dateEnd = date('Y-m-d H:i:00', $dateEndTimestamp);
$dateStartFormat = $dateStartDArr[2].'-'.$dateStartDArr[1].'-'.$dateStartDArr[0].' '.$dateStartHArr[0].':'.$dateStartHArr[1].':00';
//Go query check duplicates meeting for user
$query  = "";
$query .= "SELECT DISTINCT id ";
$query .= "FROM meetings AS m ";
$query .= "INNER JOIN meetings_cstm AS mc ON (m.id = mc.id_c) ";
$query .= "WHERE m.deleted = 0 ";
if (!empty($bean_id))
{ // Exclude current Meeting from search
$query .= "AND m.id <> '{$bean_id}' ";
}
$query .= "  AND m.status IN ('Planned', 'Held', 'HeldNoNext') ";
$query .= "  AND ( m.assigned_user_id = '{$user_id}' OR (mc.withdr_c = 1 AND m.assigned_user_id IN (SELECT u.id FROM users AS u WHERE reports_to_id = '{$user_id}')) ) ";
$query .= "  AND ( ";
$query .= "   ( m.date_start < '{$dateStartFormat}' AND '{$dateStartFormat}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start < '{$dateEnd}' AND '{$dateEnd}' < DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) ) ";
$query .= "   OR ( m.date_start > '{$dateStartFormat}' AND m.date_start < '{$dateEnd}' ) ";
$query .= "   OR ( DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) > '{$dateStartFormat}' AND DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) < '{$dateEnd}' )";
$query .= "   OR m.date_start = '{$dateStartFormat}' ";
$query .= "   OR DATE_ADD(m.date_start, INTERVAL(m.duration_hours * 60) + m.duration_minutes MINUTE) = '{$dateEnd}' ";
$query .= "   ); ";
//var_dump($query);exit();die();
//var_dump($query);exit();die();
$result = $db->query($query);
$return = "true";
if ($db->getRowCount($result) > 0)
{ // User already has a meeting
$return = "false";
}
//echo $query;
echo $return;
}
                                                                                                   
I've tested the query, it WORKS.

Now, i think i need some help on my ajax links, because everytime i click on save button, i got a console.log saying "SQL Failure", which is the sign of error for my ajax function.

So, sugar enters the ajax call, but can't find the files?
How can i make the ajax simpler? by adding the php functions to the "view.edit.php"? but this way, how do i call my functions?

What do you think, and do you have any idea on how to perform ajax calls on click for the save button?

Thanks a lot, this is really urgent.
Have a nice evening
Gaëlle







ok                                                                                                                                                                                                                                            
As you can see, i've made an entry point to access my function in another file, which lies under custom/modules/Meetings/phpfunctions/validateAvailability.php. (THIS entrypoint WORKS, i've tested it)

<?php//GFE 24/06/2014
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $sugar_config, $dbhost, $db_user_name, $db_password, $db_name, $dbport; 
global $db; 
//this one is for validate user's availability
$user_id = $_POST['userid'];
$date_start = $_POST['date'];
$duration_h = $_POST['h'];
$duration_m = $_POST['m'];
$bean_id = $_POST['beanid'];
require_once("custom/modules/Meetings/Meetings.php");
$isavailable = CustomMeeting::checkUserIsAvailable($user_id,$bean_id,$date_start,$duration_h,$duration_m);
/*if ($isavailable== false){
echo "false";
}else{
echo "true";
}*/
?>
                                    

And this one calls the checkUserIsAvailable, wich is under custom/module/Meetings/Meetings.php and contain this :

public static function checkUserIsAvailable($user_id, $bean_id = null, $date_start, $duration_hours, $duration_minutes) {
global $db, $timedate;
//attention : on a enlevé la timezone. trouver comment la remettre ensuite.
// Dissociate date and time
$dateStartArr = explode(" ", trim($date_start));
$dateStartDArr = explode("/",$dateStartArr[0]);
$dateStartHArr = explode(":",$dateStartArr[1]);
// Calculate date end
$dateStartTimestamp = mktime($dateStartHArr[0], $dateStartHArr[1], 0, $dateStartDArr[1], $dateStartDArr[0], $dateStartDArr[2]);
$dateEndTimestamp = $dateStartTimestamp + ($duration_hours * 3600) + ($duration_minutes * 60);
// Create Date ISO from timestamp
$dateEnd = date('Y-m-d H:i:00', $dateEndTimestamp);
$dateStartFormat = $dateStartDArr[2].'-'.$dateStartDArr[1]

Outcomes