Schedule (EMAIL PLUGIN)

I have a scheduled function with the email plugin but seem to be having a problem with my sql query in the condition box. It continues to send the same emails regardless of what I have put in the condition box.

This is what I have put there please correct me if I am wrong.

PHP:
mysql_query("SELECT studentstatus FROM course_students WHERE studentstatus = '3'
AND notification = '0'");

This query works in phpmyadmin
 
So what if I tried something like this

PHP:
$query = $db->getQuery(true);
 
$query
    ->select(array('studentstatus', 'notification'))
    ->from('tablename')
    ->where('studentstatus = '3'')
    ->and ('notification = '0\");
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
 
$status=$db->loadResult();
return (bool)$status;
I have tried this and it does not work.....

However when I run this query in phpmyadmin. I get the proper result (1 row returns) But when placed into the condition I get 10 emails and non of the 10 are the correct result.

PHP:
SELECT studentstatus, notification
FROM course_students
WHERE studentstatus = '3'
AND notification = '0'
 
->and (notification = 0");
should be
->and ("notification = '0'"); (or escaped as in studentstatus)

loadResult will give you only one value (first selected field in first row found), so it will always be '3' because you are selecting
studentstatus ...WHERE studentstatus = '3'

and (bool)'3' is true.

I don't know what you need to select; is the condition something like
"don't send email if notification of the current row is 0"?
Then try
return (bool)$row->notification_raw;
 
That is the sum of it....

I am trying to send email if notification = '0' and studentstatus ='3'.

If those conditions are met than I need the email to go through.

It is also set up to change the notifications field to '1' if the notification is sent.

I am pretty sure I am 100% lost here..... I now tried this and don't get any results either.

PHP:
// Get a db connection.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
 
$query
    ->select(array('studentstatus', 'notification'))
    ->from('tablename')
    ->where('studentstatus = '3'')
    ->and ("notification = '0'");
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
 
$status=$db->loadResult();
return (bool)$row->notification_raw;
 
In this case you don't need to select anything from the database.

Try with only

$send = ($row->notification_raw=='0' && $row->studentstatus_raw=='3');
return $send;

What are your cron settings?
 
I believe you are asking how often this is susposed to run.....

Here is the settings:

Run
Every: 1
Unit: hour
Log
Log Events: No
Options
to:josh.blevins@sciototech.com
Subject: Student Completion Notice
Message:
HTML:
Please be informed that
<br></br>
{course_students___userid} has completed the {course_students___courseid} course.
<br></br>
Please see the following information below.
<br></br>
Students Current Course Status: {course_students___studentstatus}
<br></br>
Student Final Exam Status: {course_students___finalexam}
Students NREMT Practical Status {course_students___practicals}
<br></br>
If the above results show that the student has completed the course, passed the final exam and passed the NREMT practical skills you should visit www.nremt.org and clear the student for testing of the National Registry Exam.
<br></br>
To view a detailed view of the students course work you may visit: http://ems-complete.com/my-institution/courses-offered/course-students/details/7/{course_students___id}

Eval: No

Condition:
PHP:
$send = ($row->notification_raw=='0' && $row->studentstatus_raw=='3');
return $send;

Update
Field: Completion Notification
Value: 1
Eval: No

I tried the last bit of code you recommended and it did not appear to work.
 
Are you running a recent GitHub version?

There must be a group "Connection" between "log" and "Options" where you select the table all is running on.

For debugging you can do
$send = ($row->notification_raw=='0' && $row->studentstatus_raw=='3');
var_dump($row,$send);exit;
return
$send;


which should give you a blank page with the debugging output.
 
So did you select course_students in "Connections"?
Try the debug to see what you get.
 
Nothing jumped out at me in the dbug
PHP:
if (typeof(Dsc) === 'undefined') {
	var Dsc = {};
}

/**
 * Simple function to refresh a page.
 */
Dsc.update = function()
{
    location.reload(true);
}
    
/**
 * Resets the filters in a form.
 * 
 * @param form
 * @return
 */
Dsc.resetFormFilters = function(form)
{
    // loop through form elements
    var str = new Array();
    for(i=0; i<form.elements.length; i++)
    {
        var string = form.elements[i].name;
        if (string.substring(0,6) == 'filter')
        {
            form.elements[i].value = '';
        }
    }
    form.submit();
}
    
/**
 * 
 * @param order
 * @param dir
 * @param form
 */
Dsc.gridOrdering = function( order, dir, form ) 
{
	if (!form) {
		form = document.adminForm;
	}
     
	form.filter_order.value     = order;
	form.filter_direction.value	= dir;

	form.submit();
}
	
/**
 * 
 * @param id
 * @param change
 * @return
 */
Dsc.gridOrder = function(id, change, form) 
{
	if (!form) {
		form = document.adminForm;
	}
	
	form.id.value= id;
	form.order_change.value	= change;
	form.task.value = 'order';
	
	form.submit();
}

/**
 * Sends form values to server for validation and outputs message returned.
 * Submits form if error flag is not set in response
 * @param url
 * @param container
 * @param task
 * @param form
 * @param doModal
 * @param msg
 * @param onCompleteFunction
 */
Dsc.formValidation = function( url, container, task, form, doModal, msg, onCompleteFunction ) 
{
	if (doModal != false) { Dsc.newModal(msg); }
	
    // loop through form elements and prepare an array of objects for passing to server
    var str = new Array();
    for(i=0; i<form.elements.length; i++)
    {
        if (form.elements[i].name) {
            postvar = {
                    name : form.elements[i].name,
                    value : form.elements[i].value,
                    checked : form.elements[i].checked,
                    id : form.elements[i].id
                };
            str[i] = postvar;
        }
    }
    
    // execute request to server
    var a = new Request({
        url: url,
        method:"post",
        data:{"elements":JSON.encode(str)},
        onSuccess: function(response){
            var resp = JSON.decode(response, false);
            if (resp.error != '1')
            {
                if (typeof onCompleteFunction == 'function') {
                    onCompleteFunction();
                }
                form.task.value = task;
                form.submit();
            } else {
                if (document.id(container)) { document.id(container).set( 'html', resp.msg); }
            }
            if (doModal != false) { (function() { document.body.removeChild( document.getElementById('dscModal') ); }).delay(500); }
        }
    }).send();

}

/**
 * Submits form using onsubmit if present
 * @param task
 * @return
 */
Dsc.submitForm = function(task, form)
{
	if (!form) {
		form = document.adminForm;
	}

    form.task.value = task;

    if (typeof form.onsubmit == "function") 
    {
        form.onsubmit();
    }
        else
    {
        form.submit();
    }
}

/**
 * 
 * @param {Object} divname
 * @param {Object} spanname
 * @param {Object} showtext
 * @param {Object} hidetext
 */
Dsc.displayDiv = function(divname, spanname, showtext, hidetext) { 
	var div = document.getElementById(divname);
	var span = document.getElementById(spanname);

	if (div.style.display == "none")	{
		div.style.display = "";
		span.innerHTML = hidetext;
	} else {
		div.style.display = "none";
		span.innerHTML = showtext;
	}
}

/**
 * 
 * @param {Object} prefix
 * @param {Object} newSuffix
 */
Dsc.switchDisplayDiv = function( prefix, newSuffix )
{
	var newName = prefix + newSuffix;
	var currentSuffixDiv = document.getElementById('currentSuffix');
	var currentSuffix = currentSuffixDiv.innerHTML;	
	var oldName = prefix + currentSuffix;
	var newDiv = document.getElementById(newName);
	var oldDiv = document.getElementById(oldName);

	currentSuffixDiv.innerHTML = newSuffix;
	newDiv.style.display = "";
	oldDiv.style.display = "none";
}

/**
 * 
 * @param divname
 */
Dsc.showHideDiv = function(divname)
{
	var divObject = document.getElementById(divname);
	if (divObject == null){return;}
	if (divObject.style.display == "none"){
		divObject.style.display = "";
	}
	else{
		divObject.style.display = "none";
	}
}

/**
 * 
 * @param {String} url to query
 * @param {String} document element to update after execution
 * @param {String} form name (optional)
 * @param {String} msg message for the modal div (optional)
 */
Dsc.doTask = function( url, container, form, msg, doModal, onCompleteFunction ) 
{
	if (doModal != false) { Dsc.newModal(msg); }
	
	
	// if url is present, do validation
	if (url && form) 
	{	
		// loop through form elements and prepare an array of objects for passing to server
		var str = new Array();
		for(i=0; i<form.elements.length; i++)
		{
			postvar = {
				name : form.elements[i].name,
				value : form.elements[i].value,
				checked : form.elements[i].checked,
				id : form.elements[i].id
			};
			str[i] = postvar;
		}
		
        var a = new Request({
            url: url,
            method:"post",
            data:{"elements":JSON.encode(str)},
            onSuccess: function(response){
                var resp = JSON.decode(response, false);
                if (document.id(container)) { document.id(container).set( 'html', resp.msg); }
                if (doModal != false) { (function() { document.body.removeChild( document.getElementById('dscModal') ); }).delay(500); }
                if (typeof onCompleteFunction == 'function') {
                    onCompleteFunction();
                }
                return true;
            }
        }).send();
        
	}
		else if (url && !form) 
	{
	        var a = new Request({
	            url: url,
	            method:"post",
	            onSuccess: function(response){
	                var resp = JSON.decode(response, false);
	                if (document.id(container)) { document.id(container).set( 'html', resp.msg); }
	                if (doModal != false) { (function() { document.body.removeChild( document.getElementById('dscModal') ); }).delay(500); }
	                if (typeof onCompleteFunction == 'function') {
	                    onCompleteFunction();
	                }
	                return true;
	            }
	        }).send();
	}
	return a;
}

/**
 * 
 * @param {String} msg message for the modal div (optional)
 */
Dsc.newModal = function(msg)
{
    if (typeof window.innerWidth != 'undefined') {
        var h = window.innerHeight;
        var w = window.innerWidth;
    } else {
        var h = document.documentElement.clientHeight;
        var w = document.documentElement.clientWidth;
    }
    var t = (h / 2) - 15;
    var l = (w / 2) - 15;
	var i = document.createElement('img');
	var s = window.location.toString();
	var src = Dsc.jbase + 'media/dioscouri/images/ajax-loader.gif';
	i.src = src;
	i.style.position = 'absolute';
	i.style.top = t + 'px';
	i.style.left = l + 'px';
	i.style.backgroundColor = '#000000';
	i.style.zIndex = '100001';
	var d = document.createElement('div');
	d.id = 'dscModal';
	d.style.position = 'fixed';
	d.style.top = '0px';
	d.style.left = '0px';
	d.style.width = w + 'px';
	d.style.height = h + 'px';
	d.style.backgroundColor = '#000000';
	d.style.opacity = 0.5;
	d.style.filter = 'alpha(opacity=50)';
	d.style.zIndex = '100000';
	d.appendChild(i);
    if (msg != '' && msg != null) {
	    var m = document.createElement('div');
	    m.style.position = 'absolute';
	    m.style.width = '200px';
	    m.style.top = t + 50 + 'px';
	    m.style.left = (w / 2) - 100 + 'px';
	    m.style.textAlign = 'center';
	    m.style.zIndex = '100002';
	    m.style.fontSize = '1.2em';
	    m.style.color = '#ffffff';
	    m.innerHTML = msg;
	    d.appendChild(m);
	}
	document.body.appendChild(d);
}

/**
 * Submits form after clicking boolean item in lists,
 * such as a tick mark or a red x un an enabled/disabled column
 *
 * @param id
 * @param task
 * @return
 */
Dsc.listItemTask = function (id, task, form) {
    if (!form) {
        var f = document.adminForm;
    } else {
        var f = form;
    }
    
    var cb = f[id];
    if (cb) {
        for (var i = 0; true; i++) {
            var cbx = f['cb'+i];
            if (!cbx)
                break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.boxchecked.value = 1;
        Dsc.submitbutton(task);
    }
    return false;
}

/**
 * Overriding core submitbutton task to perform onsubmit function
 * without submitting form afterwards
 * 
 * @param task
 * @return
 */
Dsc.submitbutton = function(task, form) 
{
    if (typeof(form) === 'undefined') {
        form = document.getElementById('adminForm');
        /**
         * Added to ensure Joomla 1.5 compatibility
         */
        if(!form){
            form = document.adminForm;
        }
    }
    
    if (typeof(task) !== 'undefined' && '' !== task) {
        form.task.value = task;
    }

    if (typeof form.onsubmit == "function") 
    {
        form.onsubmit();
    }
        else
    {
        if (typeof form.onsubmit == "function") {
            form.onsubmit();
        }
        if (typeof form.fireEvent == "function") {
            form.fireEvent('submit');
        }
        form.submit();
    }
}

/*
 * Method to get value from all form inputs and put it in an array which will be passed via AJAX request
 *
 * @param form		Form with inputs
 *
 * @return Array with all data from all inputs on the form
 */
Dsc.getFormInputData = function(form) {
	var str = new Array();
	for ( i = 0; i < form.elements.length; i++) {
		postvar = {
			name : form.elements[i].name,
			value : form.elements[i].value,
			checked : form.elements[i].checked,
			id : form.elements[i].id
		};
		str[i] = postvar;
	}
	return str;
}

/**
 * Overriding core submitbutton task to perform onsubmit function
 * without submitting form afterwards
 * 
 * @param task
 * @return
 */
function submitbutton(task) 
{
    Dsc.submitbutton(task);
}
 
:confused:Where is this coming from?
If you put the
var_dump...;exit;
into your condition code and then run your task manually you should see something like
object(stdClass)#404 (14) { ["dummy___id"]=> string(181) "1" ["dummy___id_raw"]=> string(1) "1" ["dummy___date_time"]=> string(199) "Saturday 2012-06-30" ["dummy___date_time_raw"]=> string(19) "2012-06-30 21:43:00" .....

course_student instead of dummy in your case.
 
after github update this is my debug

PHP:
if (typeof(Dsc) === 'undefined') {
 var Dsc = {};
}
/**
 * Simple function to refresh a page.
 */
Dsc.update = function()
{
    location.reload(true);
}
    
/**
 * Resets the filters in a form.
 * 
 * @param form
 * @return
 */
Dsc.resetFormFilters = function(form)
{
    // loop through form elements
    var str = new Array();
    for(i=0; i<form.elements.length; i++)
    {
        var string = form.elements[i].name;
        if (string.substring(0,6) == 'filter')
        {
            form.elements[i].value = '';
        }
    }
    form.submit();
}
    
/**
 * 
 * @param order
 * @param dir
 * @param form
 */
Dsc.gridOrdering = function( order, dir, form ) 
{
 if (!form) {
  form = document.adminForm;
 }
     
 form.filter_order.value     = order;
 form.filter_direction.value = dir;
 form.submit();
}
 
/**
 * 
 * @param id
 * @param change
 * @return
 */
Dsc.gridOrder = function(id, change, form) 
{
 if (!form) {
  form = document.adminForm;
 }
 
 form.id.value= id;
 form.order_change.value = change;
 form.task.value = 'order';
 
 form.submit();
}
/**
 * Sends form values to server for validation and outputs message returned.
 * Submits form if error flag is not set in response
 * @param url
 * @param container
 * @param task
 * @param form
 * @param doModal
 * @param msg
 * @param onCompleteFunction
 */
Dsc.formValidation = function( url, container, task, form, doModal, msg, onCompleteFunction ) 
{
 if (doModal != false) { Dsc.newModal(msg); }
 
    // loop through form elements and prepare an array of objects for passing to server
    var str = new Array();
    for(i=0; i<form.elements.length; i++)
    {
        if (form.elements[i].name) {
            postvar = {
                    name : form.elements[i].name,
                    value : form.elements[i].value,
                    checked : form.elements[i].checked,
                    id : form.elements[i].id
                };
            str[i] = postvar;
        }
    }
    
    // execute request to server
    var a = new Request({
        url: url,
        method:"post",
        data:{"elements":JSON.encode(str)},
        onSuccess: function(response){
            var resp = JSON.decode(response, false);
            if (resp.error != '1')
            {
                if (typeof onCompleteFunction == 'function') {
                    onCompleteFunction();
                }
                form.task.value = task;
                form.submit();
            } else {
                if (document.id(container)) { document.id(container).set( 'html', resp.msg); }
            }
            if (doModal != false) { (function() { document.body.removeChild( document.getElementById('dscModal') ); }).delay(500); }
        }
    }).send();
}
/**
 * Submits form using onsubmit if present
 * @param task
 * @return
 */
Dsc.submitForm = function(task, form)
{
 if (!form) {
  form = document.adminForm;
 }
    form.task.value = task;
    if (typeof form.onsubmit == "function") 
    {
        form.onsubmit();
    }
        else
    {
        form.submit();
    }
}
/**
 * 
 * @param {Object} divname
 * @param {Object} spanname
 * @param {Object} showtext
 * @param {Object} hidetext
 */
Dsc.displayDiv = function(divname, spanname, showtext, hidetext) { 
 var div = document.getElementById(divname);
 var span = document.getElementById(spanname);
 if (div.style.display == "none") {
  div.style.display = "";
  span.innerHTML = hidetext;
 } else {
  div.style.display = "none";
  span.innerHTML = showtext;
 }
}
/**
 * 
 * @param {Object} prefix
 * @param {Object} newSuffix
 */
Dsc.switchDisplayDiv = function( prefix, newSuffix )
{
 var newName = prefix + newSuffix;
 var currentSuffixDiv = document.getElementById('currentSuffix');
 var currentSuffix = currentSuffixDiv.innerHTML; 
 var oldName = prefix + currentSuffix;
 var newDiv = document.getElementById(newName);
 var oldDiv = document.getElementById(oldName);
 currentSuffixDiv.innerHTML = newSuffix;
 newDiv.style.display = "";
 oldDiv.style.display = "none";
}
/**
 * 
 * @param divname
 */
Dsc.showHideDiv = function(divname)
{
 var divObject = document.getElementById(divname);
 if (divObject == null){return;}
 if (divObject.style.display == "none"){
  divObject.style.display = "";
 }
 else{
  divObject.style.display = "none";
 }
}
/**
 * 
 * @param {String} url to query
 * @param {String} document element to update after execution
 * @param {String} form name (optional)
 * @param {String} msg message for the modal div (optional)
 */
Dsc.doTask = function( url, container, form, msg, doModal, onCompleteFunction ) 
{
 if (doModal != false) { Dsc.newModal(msg); }
 
 
 // if url is present, do validation
 if (url && form) 
 { 
  // loop through form elements and prepare an array of objects for passing to server
  var str = new Array();
  for(i=0; i<form.elements.length; i++)
  {
   postvar = {
    name : form.elements[i].name,
    value : form.elements[i].value,
    checked : form.elements[i].checked,
    id : form.elements[i].id
   };
   str[i] = postvar;
  }
  
        var a = new Request({
            url: url,
            method:"post",
            data:{"elements":JSON.encode(str)},
            onSuccess: function(response){
                var resp = JSON.decode(response, false);
                if (document.id(container)) { document.id(container).set( 'html', resp.msg); }
                if (doModal != false) { (function() { document.body.removeChild( document.getElementById('dscModal') ); }).delay(500); }
                if (typeof onCompleteFunction == 'function') {
                    onCompleteFunction();
                }
                return true;
            }
        }).send();
        
 }
  else if (url && !form) 
 {
         var a = new Request({
             url: url,
             method:"post",
             onSuccess: function(response){
                 var resp = JSON.decode(response, false);
                 if (document.id(container)) { document.id(container).set( 'html', resp.msg); }
                 if (doModal != false) { (function() { document.body.removeChild( document.getElementById('dscModal') ); }).delay(500); }
                 if (typeof onCompleteFunction == 'function') {
                     onCompleteFunction();
                 }
                 return true;
             }
         }).send();
 }
 return a;
}
/**
 * 
 * @param {String} msg message for the modal div (optional)
 */
Dsc.newModal = function(msg)
{
    if (typeof window.innerWidth != 'undefined') {
        var h = window.innerHeight;
        var w = window.innerWidth;
    } else {
        var h = document.documentElement.clientHeight;
        var w = document.documentElement.clientWidth;
    }
    var t = (h / 2) - 15;
    var l = (w / 2) - 15;
 var i = document.createElement('img');
 var s = window.location.toString();
 var src = Dsc.jbase + 'media/dioscouri/images/ajax-loader.gif';
 i.src = src;
 i.style.position = 'absolute';
 i.style.top = t + 'px';
 i.style.left = l + 'px';
 i.style.backgroundColor = '#000000';
 i.style.zIndex = '100001';
 var d = document.createElement('div');
 d.id = 'dscModal';
 d.style.position = 'fixed';
 d.style.top = '0px';
 d.style.left = '0px';
 d.style.width = w + 'px';
 d.style.height = h + 'px';
 d.style.backgroundColor = '#000000';
 d.style.opacity = 0.5;
 d.style.filter = 'alpha(opacity=50)';
 d.style.zIndex = '100000';
 d.appendChild(i);
    if (msg != '' && msg != null) {
     var m = document.createElement('div');
     m.style.position = 'absolute';
     m.style.width = '200px';
     m.style.top = t + 50 + 'px';
     m.style.left = (w / 2) - 100 + 'px';
     m.style.textAlign = 'center';
     m.style.zIndex = '100002';
     m.style.fontSize = '1.2em';
     m.style.color = '#ffffff';
     m.innerHTML = msg;
     d.appendChild(m);
 }
 document.body.appendChild(d);
}
/**
 * Submits form after clicking boolean item in lists,
 * such as a tick mark or a red x un an enabled/disabled column
 *
 * @param id
 * @param task
 * @return
 */
Dsc.listItemTask = function (id, task, form) {
    if (!form) {
        var f = document.adminForm;
    } else {
        var f = form;
    }
    
    var cb = f[id];
    if (cb) {
        for (var i = 0; true; i++) {
            var cbx = f['cb'+i];
            if (!cbx)
                break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.boxchecked.value = 1;
        Dsc.submitbutton(task);
    }
    return false;
}
/**
 * Overriding core submitbutton task to perform onsubmit function
 * without submitting form afterwards
 * 
 * @param task
 * @return
 */
Dsc.submitbutton = function(task, form) 
{
    if (typeof(form) === 'undefined') {
        form = document.getElementById('adminForm');
        /**
         * Added to ensure Joomla 1.5 compatibility
         */
        if(!form){
            form = document.adminForm;
        }
    }
    
    if (typeof(task) !== 'undefined' && '' !== task) {
        form.task.value = task;
    }
    if (typeof form.onsubmit == "function") 
    {
        form.onsubmit();
    }
        else
    {
        if (typeof form.onsubmit == "function") {
            form.onsubmit();
        }
        if (typeof form.fireEvent == "function") {
            form.fireEvent('submit');
        }
        form.submit();
    }
}
/*
 * Method to get value from all form inputs and put it in an array which will be passed via AJAX request
 *
 * @param form  Form with inputs
 *
 * @return Array with all data from all inputs on the form
 */
Dsc.getFormInputData = function(form) {
 var str = new Array();
 for ( i = 0; i < form.elements.length; i++) {
  postvar = {
   name : form.elements[i].name,
   value : form.elements[i].value,
   checked : form.elements[i].checked,
   id : form.elements[i].id
  };
  str[i] = postvar;
 }
 return str;
}
/**
 * Overriding core submitbutton task to perform onsubmit function
 * without submitting form afterwards
 * 
 * @param task
 * @return
 */
function submitbutton(task) 
{
    Dsc.submitbutton(task);
}
 
ok Im confuseddddddd :D
All that looks like front end javascript code, custom written to do something with Fabrik. Are you sure you don't know where its coming from?
 
How did you start the task?

In backend, checking the select box in front of the task + clicking the "Run" icon?
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top