I wanted the ability to auto input the phone number and extension when creating a new ticket. I could be wrong, but the json for the AutoSuggest is limited to a certain structure, i.e. id: x, value: y, info: z. So I added the phone and phone_ext to the info variable along side the name and I just do a simple var.split() in javascript to parse out the data on the other end.
Files: ajax.tickets.php, newticket.inc.php
Mods:
ajax.tickets.php
Change this line:
$sql='SELECT DISTINCT email,name FROM '.TICKET_TABLE.' WHERE email LIKE \''.$input.'%\' ORDER BY created LIMIT '.$limit;
To this:
$sql='SELECT email,name,MAX(phone) AS phone,MAX(phone_ext) AS phone_ext FROM '.TICKET_TABLE.' WHERE email LIKE \''.$input.'%\' GROUP BY email,name ORDER BY created LIMIT '.$limit;
Find "if($resp && db_num_rows($resp)){
Replace the entire if block with this:
if($resp && db_num_rows($resp)){
while(list($email,$name,$phone,$phone_ext)=db_fetch_row($resp)) {
$name=(strpos($name,'@')===false)?$name:'';
$items ='{"id": "'.$email.'", "value": "'.$email.'", "info": "'.$name.' - '.$phone.' - '.$phone_ext.'"}';
}
}
newticket.inc.php
Change the "var options..." javascript to this:
<script type="text/javascript">
var options = {
script:"ajax.php?api=tickets&f=searchbyemail&limit=10&",
varname:"input",
json: true,
shownoresults,
maxresults,
callback: function (obj) {
document.getElementById('email').value = obj.id;
var sc_info = obj.info.split(" - ");
document.getElementById('name').value = sc_info;
document.getElementById('phone').value = sc_info;
document.getElementById('phone_ext').value = sc_info;
return false;}
};
var autosug = new bsn.AutoSuggest('email', options);
</script>