Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.when(
- $.ajax({
- type: "GET",
- headers: {
- "accept": "application/json;odata=verbose"
- },
- url: "https://yourSPsitecollectionhere/_api/SP.UserProfiles.PeopleManager/GetMyProperties"
- })
- ).done(function(myProps) {
- var jsonDatabase = {};
- jsonDatabase["users"] = {};
- jsonDatabase.users[myProps.d.DisplayName] = {};
- jsonDatabase.users[myProps.d.DisplayName]["pLine1"] = myProps.title;
- jsonDatabase.users[myProps.d.DisplayName]["eMail"] = myProps.email;
- jsonDatabase.users[myProps.d.DisplayName]["mName"] = "";
- jsonDatabase.users[myProps.d.DisplayName]["pLine2"] = "";
- jsonDatabase.users[myProps.d.DisplayName]["location"] = "1";
- jsonDatabase["locations"] = { "1" };
- jsonDatabase.locations["1"]["desc"] = "Your Location Goes Here";
- jsonDatabase.locations["1"]["address1"] = "Your Location's 1st Address Line";
- jsonDatabase.locations["1"]["address2"] = "Your Locationa's 2nd Address Line";
- for (var i = 0; i < myProps.d.DisplayName.UserProfileProperties.results.length; i++) {
- switch (myProps.d.DisplayName.UserProfileProperties.results[i].Key) {
- case "FirstName":
- jsonDatabase.users[myProps.d.DisplayName]["fName"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
- break;
- case "LastName":
- jsonDatabase.users[myProps.d.DisplayName]["lName"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
- break;
- case "WorkPhone":
- jsonDatabase.users[myProps.d.DisplayName]["phone"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
- break;
- case "CellPhone":
- jsonDatabase.users[myProps.d.DisplayName]["mobile"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
- break;
- case "Department":
- jsonDatabase.users[myProps.d.DisplayName]["department"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
- break;
- case "Fax":
- jsonDatabase.users[myProps.d.DisplayName]["fax"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
- break;
- }
- }
- $.when(
- $.ajax({
- url: "https://yourPHPsitehere/index.php?target=ajax",
- type: "POST",
- data: jsonDatabase,
- dataType: "json"
- })
- ).done(function() {
- $("yourIMGtagselectorhere").attr("src", "https://yourPHPsitehere/index.php?target=display&user=" + myProps.d.DisplayName + "&refresh=" + new Date()).getTime();
- }).fail(function() {
- alert("Unable to send the current user's properties to the PHP page.");
- });
- }).fail(function() {
- alert("Unable to get the current user's properties.");
- });
Advertisement
Add Comment
Please, Sign In to add comment