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

Commit

Permalink
Fixing conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmbacon committed Aug 5, 2015
1 parent a1d8f0b commit e74a255
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
41 changes: 41 additions & 0 deletions uc-people.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
jQuery(document).ready(function($){
if( $('#uc_people_lookup').length ){
$('#uc_people_lookup_search').click(function(ev){
ev.preventDefault();

var query = $('#uc_people_lookup').val();
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 },
success: function(response){
if( !isEmpty(response) ){
$('#uc_people_lookup_metabox p.howto').text("Person found");
var fields = ['first_name', 'last_name', 'phone', 'email'];
fields.forEach(function(el,i,a){
$('#acf-field-'+el).val("");
if( response.hasOwnProperty(el) ){
$('#acf-field-'+el).val( response[el] );
}
});
} else {
$('#uc_people_lookup_metabox p.howto').text("Person not found");
}
},
dataType: 'json'
});
} else {
$('#uc_people_lookup_metabox p.howto').text("Invalid e-mail address or NetID entered");
}
});
}
});

function isEmpty( object ){
for( var key in object ){
if( Object.prototype.hasOwnProperty.call(object,key) ){
return false;
}
}
return true;
}
42 changes: 39 additions & 3 deletions uc-people.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
if ( ! defined( 'WPINC' ) ) {
die;
}
require 'acf-export.php';
require_once(WP_CONTENT_DIR . '/ldap.php');


function create_custom_custom_post_type(){
$labels = array(
Expand Down Expand Up @@ -128,7 +131,7 @@ function importFile(){
$title = $v['First Name'].' '.$v['Last Name'];
$args = array(
'post_title' => $title,
'post_name' => 'testing-contact',
'post_name' => strtolower($v['First Name']).'-'.strtolower($v['Last Name']),
'post_status' => 'publish',
'post_type' => 'person',
'menu_order' => ( !empty($v['Order']) ? $v['Order'] : 0 ),
Expand Down Expand Up @@ -178,6 +181,39 @@ function uc_people_settings_page(){

</div>
<?php
}
include 'acf-export.php';
}

function uc_people_lookup_metabox(){
add_meta_box( 'uc_lookup', 'UConn Lookup', 'uc_people_lookup_metabox_callback', 'person', 'side', 'core' );
}
add_action( 'add_meta_boxes', 'uc_people_lookup_metabox' );
function uc_people_lookup_metabox_callback(){
echo '<div id="uc_people_lookup_metabox">';
echo '<p><input type="text" id="uc_people_lookup" class="form-input-tip" size="16">';
echo '<input type="button" id="uc_people_lookup_search" class="button" value="Search"></p>';
echo '<p class="howto"></p>';
echo '</div>';
}


function uc_acf_admin_enqueue_scripts(){
wp_enqueue_script( 'ucpeoplejs', plugin_dir_url(__FILE__).'/uc-people.js', array('jquery'), '1.0' );
wp_localize_script( 'ucpeoplejs', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}

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

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

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

echo wp_json_encode($userInfo);

wp_die();
}

?>

0 comments on commit e74a255

Please sign in to comment.