Hope jpastin doesn't bother that I remake the step-by-step tutorial with the line numbering (referring to the original file) and some steps reworked.
ALL CREDITS TO jpastin
FIRST STEP
First create a file userfind.php with the following content:
<?php
// START MOD06 AD lookup of Name and Email
// Jpastin http://osticket.com/forums/showthread.php?p=13780#post13780
// START EDIT
// Replace this with your AD Domain Controller
$ds=ldap_connect('ldap://servername.domain.local/') or die("Couldn't connect to AD!");
//Replace this with a username that has read permissions on your AD
$connect_u = "DOMAIN\AdminUser";
//Replace this with the password of the user
$conect_p="PPAASSWWOORRDD";
//Replace this with the DN of the base OU you want to search
$search_user_dn = "OU=Users,DC=domain,DC=local";
// STOP EDIT
$inforequired = array("displayName","mail");
if (!ldap_bind( $ds, $connect_u, $conect_p) ) {
$error_msg = "Could not bind AD connection<br>";
}
else
{
if (!empty($_REQUEST)) {
$curMail=$_REQUEST;
$curMail = strtolower($curMail);
$curMail.='*';
$filter="(&(mail=$curMail)(objectCategory=person))";
}
elseif (!empty($_REQUEST)) {
$curName=$_REQUEST;
$curName = strtolower($curName);
$curName.='*';
$filter="(&(displayName=$curName)(objectCategory=person))";
}
$user_result = ldap_search($ds,$search_user_dn,$filter,$inforequired);
$user_info = ldap_get_entries($ds,$user_result);
header("Content-Type: application/json");
echo"{\"results\": [";
$arr=Array();
if (count($user_info) > $_REQUEST)
{
$max=$_REQUEST;
}
else
{
$max=count($user_info);
}
for ( $i=1; $i<$max; $i+=1)
{
if (!empty($_REQUEST)) {
$arr= "{\"id\": \"".$i."\", \"value\": \"".$user_info."\", \"info\": \"".$user_info."\"}";
}
elseif (!empty($_REQUEST)) {
$arr= "{\"id\": \"".$i."\", \"value\": \"".$user_info."\", \"info\": \"".$user_info}";
}
//END MOD06
?>
WARNING: Search the "START EDIT" and modify the fields according with your Active Directory connect settings.
Copy the userfind.php to following path: osTicketRootFolder/scp
SECOND STEP
make the following modifications:
File: include/clientheader.inc.php.
FIND ~10
<link rel="stylesheet" href="./styles/main.css" media="screen">
<link rel="stylesheet" href="./styles/colors.css" media="screen">
REPLACE BY
<link rel="stylesheet" href="./styles/main.css" media="screen">
<link rel="stylesheet" href="./styles/colors.css" media="screen">
START MOD06 Change to add auto lookup of name and email
<script type="text/javascript" src="./scp/js/bsn.AutoSuggest_2.1.3.js" charset="utf-8"></script>
<link rel="stylesheet" href="./scp/css/autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />
END MOD06
THIRD STEP
File: include/clientopen.inc.php.
FIND ~37
<input type="text" name="email" size="25" value="<?=$info?>">
REPLACE BY
START MOD06 Change to auto populate name and email address from AD
<input type="text" id="email" name="email" size="25" value="<?=$info?>">
END MOD06
FIND ~119
</form>
REPLACE BY
</form>
<script type="text/javascript">
// START - MOD06 Active directory look up
var name_options = {
script: "./scp/userfind.php?maxEntries=10&",
varname: "name",
json: true,
delay: 100,
cache: false,
callback: function (obj) {document.getElementById('email').value=obj.info;}
};
var email_options = {
script: "./scp/userfind.php?maxEntries=10&",
varname: "mail",
json: true,
cache: false,
callback: function (obj) {document.getElementById('name').value=obj.info;}
};
var email_as=new bsn.AutoSuggest('email', email_options);
var name_as=new bsn.AutoSuggest('name', name_options);
// END - MOD06 Active directory look up
</script>
FOURTH STEP
File: include/staffnewticket.inc.php.
FIND ~163
</table>
<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; document.getElementById('name').value = obj.info; return false;}
};
var autosug = new bsn.AutoSuggest('email', options);
</script>
REPLACE BY
</table>
<script type="text/javascript">
// START - MOD06 Active directory look up
var name_options = {
script: "userfind.php?maxEntries=10&",
varname: "name",
json: true,
delay: 100,
cache: false,
callback: function (obj) {document.getElementById('email').value=obj.info;}
};
var email_options = {
script: "userfind.php?maxEntries=10&",
varname: "mail",
json: true,
cache: false,
callback: function (obj) {document.getElementById('name').value=obj.info;}
};
var email_as=new bsn.AutoSuggest('email', email_options);
var name_as=new bsn.AutoSuggest('name', name_options);
// END MOD06 - Active directory look up
</script>
