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 Code:
<?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:389/') 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['mail'])) {
$curMail=$_REQUEST['mail'];
$curMail = strtolower($curMail);
$curMail.='*';
$filter="(&(mail=$curMail)(objectCategory=person))";
}
elseif (!empty($_REQUEST['name'])) {
$curName=$_REQUEST['name'];
$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['maxEntries'])
{
$max=$_REQUEST['maxEntries'];
}
else
{
$max=count($user_info);
}
for ( $i=1; $i<$max; $i+=1)
{
if (!empty($_REQUEST['mail'])) {
$arr[]= "{\"id\": \"".$i."\", \"value\": \"".$user_info[$i-1]['mail'][0]."\", \"info\": \"".$user_info[$i-1]['displayname'][0]."\"}";
}
elseif (!empty($_REQUEST['name'])) {
$arr[]= "{\"id\": \"".$i."\", \"value\": \"".$user_info[$i-1]['displayname'][0]."\", \"info\": \"".$user_info[$i-1]['mail'][0]."\"}";
}
}
echo implode (", ", $arr);
echo "]}";
}
//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/client/header.inc.php.
FIND ~10
PHP Code:
<link rel="stylesheet" href="./styles/main.css" media="screen">
<link rel="stylesheet" href="./styles/colors.css" media="screen">
REPLACE BY
PHP Code:
<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/client/open.inc.php.
FIND ~37
PHP Code:
<input type="text" name="email" size="25" value="<?=$info['email']?>">
REPLACE BY
PHP Code:
<!-- START MOD06 Change to auto populate name and email address from AD -->
<input type="text" id="email" name="email" size="25" value="<?=$info['email']?>">
<!-- END MOD06 -->
FIND ~119
REPLACE BY
PHP Code:
</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/staff/newticket.inc.php.
FIND ~163
PHP Code:
</table>
<script type="text/javascript">
var options = {
script:"ajax.php?api=tickets&f=searchbyemail&limit=10&",
varname:"input",
json: true,
shownoresults:false,
maxresults:10,
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
PHP Code:
</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>