Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Use LDAP lookup in wp-content dir
Browse files Browse the repository at this point in the history
Also renames phone # array key to match UC-People's phone # label
  • Loading branch information
Salman Z Kaleem committed Jul 16, 2015
1 parent 8664240 commit 823596f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 69 deletions.
11 changes: 2 additions & 9 deletions uc-people.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ jQuery(document).ready(function($){
ev.preventDefault();

var query = $('#uc_people_lookup').val();
var type = null;
if( query.length == 8 && query.match(/[a-z]{3}[0-9]{5}/) ){
var type = 'netid';
} else if( query.match(/uconn.edu/) ){
var type = 'email';
}

if( type != null ){
if( (query.length == 8 && query.match(/[a-z]{3}[0-9]{5}/)) || query.match(/uconn.edu/) ){
$.ajax({
url: ajax_object.ajax_url,
data: { 'action': 'uc_people_lookup', 'query': query, 'type': type },
data: { 'action': 'uc_people_lookup', 'query': query },
success: function(response){
if( !isEmpty(response) ){
$('#uc_people_lookup_metabox p.howto').text("Person found");
Expand Down
64 changes: 4 additions & 60 deletions uc-people.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
die;
}
require 'acf-export.php';
//require_once(WP_CONTENT_DIR . '/ldap.php');
require_once(WP_CONTENT_DIR . '/ldap.php');


function create_custom_custom_post_type(){
Expand Down Expand Up @@ -203,69 +203,13 @@ function uc_acf_admin_enqueue_scripts(){

add_action('acf/input/admin_enqueue_scripts', 'uc_acf_admin_enqueue_scripts');

if( !function_exists('uc_people_lookup') ){
function uc_people_lookup( $query, $type ){
if( is_null($query) || is_null($type) ){
return false;
}
//LDAP Config
$ldapdn = 'uid=web-aurora,ou=accounts,ou=ldap,dc=uconn,dc=edu';
$ldappass = 'nyZqY6evmFBft2oS5fJDReeIa1W36CXViEPZCXpTRyD5IuiM2GCdeiDOlNJQOiu0';

$ldaphost = 'ldaps://ldap.uconn.edu:636';
$ldapconn = ldap_connect($ldaphost) or die('Can\'t contact LDAP');

if($ldapconn){
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapbind = ldap_bind($ldapconn, $ldapdn, $ldappass) or die('Can\'t bind LDAP');

$search = '';
if( $type == 'netid' ){
$field = 'uid';
} else if( $type == 'email' ){
$field = 'mail';
}
$search = '('.$field.'='.$query.')';

$ldap_fields = array('uid', 'title','cn', 'telephoneNumber', 'postalAddress', 'givenName', 'sn','mail','uconnpersonaffiliation','l','ou');
$results = ldap_search($ldapconn, 'dc=uconn,dc=edu', $search, $ldap_fields);
if($results == false){
return;
}

$var = ldap_get_entries($ldapconn, $results);
$ldap_keys = array('title' ,'cn', 'telephonenumber', 'postaladdress', 'givenname', 'sn','mail','uconnpersonaffiliation','l','ou');
$meta_keys = array('title', 'name', 'phone', 'address', 'first_name', 'last_name','email','affiliation','campus','department');
$fields = array_combine($ldap_keys, $meta_keys);
$user_data = array();
foreach( $var as $k=>$result ){
if( is_int($k) ){
foreach ($fields as $ldap_key=>$meta_key){
if( isset($result) && isset($result[$ldap_key]) && isset($result[$ldap_key][0]) ){
$count = $result[$ldap_key]['count'] - 1;
if( $count > 0 ){
for ($i=0; $i <= $count; $i++) {
$user_data[$meta_key][$i] = $result[$ldap_key][$i];
}
} else if( $count == 0 ) {
$user_data[$meta_key] = $result[$ldap_key][0];
}
}
}
}
}
return $user_data;
}
ldap_close($ldapconn);
}
}

add_action( 'wp_ajax_uc_people_lookup', 'uc_people_lookup_callback' );
function uc_people_lookup_callback(){
$query = $_GET['query'];
$type = $_GET['type'];

$userInfo = uc_people_lookup($query, $type);
$userInfo = ldap_lookup($query);
$userInfo['phone'] = $userInfo['uup-phone1'];
unset($userInfo['uup-phone1']);

echo wp_json_encode($userInfo);

Expand Down

0 comments on commit 823596f

Please sign in to comment.