The most reliable way was via text messaging and the mass action function menu in appgini is perfect for a quick implementation!
We wanted to use our own devices rather than a third party text message service for sending the SMS.
I thought the following simple scripts may be useful to others in the appgini community.
jquery is more compact, but to make it readable for those not used to using the framework I've used JavaScript.
First, add a menu item to your '*TableName*.php' file in the hooks folder (remember to replace *TableName* with yours!):
find this function: function *TableName*_batch_actions(&$args)
In the return array inside this function, make it look like this if you haven't added any other batch functions:
Code: Select all
return array(array(
'title' => 'Text Contacts',
'function' => 'text-contacts',
'icon' => 'th-list'
)
);
Code: Select all
function text_contacts(table_name, ids){
// get parameters to send
var url = 'text-contacts.php?table=' + table_name;
for(var i = 0; i < ids.length; i++){
url = url + '&'
+ encodeURI('ids[]') + '='
+ encodeURIComponent(ids[i]);
}
// Ajax call
var phonenumbers = ''; // response text
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() { // Ajax call back function
if(xhr.readyState == 4 && xhr.status ==200) {
phonenumbers = xhr.responseText;
url = "sms://open?addresses=" + phonenumbers + "&body="; //works in safari on mac & ios. change for android or get fancy and handle both!
location.href = url; // open messages app
}
}
xhr.open("GET", url ,true);
xhr.send();
};
Code: Select all
<?php
/*
Including the following files allows us to use many shortcut
functions provided by AppGini. Here, we'll be using the
following functions:
makeSafe()
protect against malicious SQL injection attacks
sql()
connect to the database and execute a SQL query
db_fetch_assoc()
same as PHP built-in mysqli_fetch_assoc() function
*/
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");
/* receive calling parameters */
$table = $_REQUEST['table'];
$ids = $_REQUEST['ids']; /* this is an array of IDs */
/* a comma-separated list of IDs to use in the query */
$cs_ids = '';
foreach($ids as $id){
$cs_ids .= "'" . makeSafe($id) . "',";
}
$cs_ids = substr($cs_ids, 0, -1); /* remove last comma */
$phone = sql( "SELECT Lastname, Firstname, mobile from Contacts " . //Replace 'Contacts' with your table name and 'mobile' with your field name!
"WHERE Contacts.id in ({$cs_ids}) " . // LastName and FirstName are not necessary unless you want to compile records without mobile numbers.
"ORDER by LastName", $eo);
$phonelist = ''; //numbers to be returned from Ajax query
$nonumberlist = ''; // names selected without phone numbers
while($row = db_fetch_assoc($phone)){
if($row['mobile'] != '') {
$phonelist .= $row['mobile'].',';
}
else {
$nonumberlist .= $row['Firstname'].' '.$row['Lastname'].',';
}
}
$phonelist = substr($phonelist, 0, -1); /* remove last comma */
$nonumberlist = substr($nonumberlist, 0, -1); /* remove last comma */
echo $phonelist; // send those numbers back. Use json if you want to add the $nonumberlist
We didn't have to check in the script for the user agent and adjust for android devices. Also a list of names without numbers is generated that can be returned if needed to alert the user, perhaps using json encode.