diff --git a/uc-people.js b/uc-people.js index fe4951c..1ceb6e6 100644 --- a/uc-people.js +++ b/uc-people.js @@ -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"); diff --git a/uc-people.php b/uc-people.php index 1f6fc01..e0171ea 100644 --- a/uc-people.php +++ b/uc-people.php @@ -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(){ @@ -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);