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

Commit

Permalink
NetID LDAP Lookup
Browse files Browse the repository at this point in the history
Fills following fields; first/last name, email address, phone number
  • Loading branch information
Salman Z Kaleem committed Jul 15, 2015
1 parent ae0739a commit 6386530
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 9 deletions.
190 changes: 190 additions & 0 deletions acf-export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?php
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_person',
'title' => 'Person',
'fields' => array (
array (
'key' => 'field_55a6595eba964',
'label' => 'First Name',
'name' => 'first_name',
'type' => 'text',
'required' => 1,
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a6596c4a44d',
'label' => 'Middle Name',
'name' => 'middle_name',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a65973063d2',
'label' => 'Last Name',
'name' => 'last_name',
'type' => 'text',
'required' => 1,
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a65979063d3',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a659a4063d4',
'label' => 'About',
'name' => 'about',
'type' => 'wysiwyg',
'default_value' => '',
'toolbar' => 'full',
'media_upload' => 'yes',
),
array (
'key' => 'field_55a659aa063d5',
'label' => 'File',
'name' => 'file',
'type' => 'file',
'save_format' => 'object',
'library' => 'all',
),
array (
'key' => 'field_55a659b1063d6',
'label' => 'Email',
'name' => 'email',
'type' => 'email',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
array (
'key' => 'field_55a659c4063d7',
'label' => 'Phone',
'name' => 'phone',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a659ca063d8',
'label' => 'Phone (alternate)',
'name' => 'phone_(alternate)',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a659d2063d9',
'label' => 'Fax',
'name' => 'fax',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a659de063da',
'label' => 'Mailing Address',
'name' => 'mailing_address',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a659ee063db',
'label' => 'Office Location',
'name' => 'office_location',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a659f7063dc',
'label' => 'Office Hours',
'name' => 'office_hours',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
array (
'key' => 'field_55a659ff063dd',
'label' => 'Courses',
'name' => 'courses',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'person',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
?>
40 changes: 31 additions & 9 deletions uc-people.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
jQuery(document).ready(function($){
if( $('#acf-field-netid_lookup').length ){
$('#acf-field-netid_lookup').keyup(function(e){
if( e.target.value.length == 8 ){
var netidQuery = e.target.value;
console.log( netidQuery );
/**
* Ajax lookup with netidQuery
*/
if( $('#uc_people_netid_lookup').length ){
$('#uc_people_netid_search').click(function(ev){
ev.preventDefault();

var query = $('#uc_people_netid_lookup').val();
if( query.length == 8 && query.match(/[a-z]{3}[0-9]{5}/) ){
$.ajax({
url: ajax_object.ajax_url,
data: { 'action': 'uc_netid_lookup', 'netid': query },
success: function(response){
if( !isEmpty(response) ){
var fields = ['first_name', 'last_name', 'phone', 'email'];
fields.forEach(function(el,i,a){
if( response.hasOwnProperty(el) ){
$('#acf-field-'+el).val( response[el] );
}
});
}
},
dataType: 'json'
});
}
});
}
});
});

function isEmpty( object ){
for( var key in object ){
if( Object.prototype.hasOwnProperty.call(object,key) ){
return false;
}
}
return true;
}
24 changes: 24 additions & 0 deletions uc-people.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
die;
}
include 'acf-export.php';
require_once(WP_CONTENT_DIR . '/ldap.php');

function create_custom_custom_post_type(){
$labels = array(
Expand Down Expand Up @@ -181,9 +182,32 @@ function uc_people_settings_page(){
<?php
}

function uc_people_netid_metabox(){
add_meta_box( 'uc_netid_lookup', 'NetID Lookup', 'uc_people_netid_metabox_callback', 'person', 'side', 'core' );
}
add_action( 'add_meta_boxes', 'uc_people_netid_metabox' );
function uc_people_netid_metabox_callback(){
echo '<div id="uc_people_netid_metabox">';
echo '<input type="text" id="uc_people_netid_lookup" class="form-input-tip" size="16">';
echo '<input type="button" id="uc_people_netid_search" class="button" value="Search">';
echo '</div>';
}

function uc_acf_admin_enqueue_scripts(){
wp_enqueue_script( 'ucpeoplejs', plugin_dir_url(__FILE__).'/uc-people.js', array('jquery'), '1.0' );
}

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

add_action( 'wp_ajax_uc_netid_lookup', 'uc_netid_lookup_callback' );
function uc_netid_lookup_callback(){
$query = $_GET['netid'];

$userInfo = netid_lookup($query);

echo wp_json_encode($userInfo);

wp_die();
}

?>

0 comments on commit 6386530

Please sign in to comment.