Star-crossed

SP User Email Signature Generator

Jun 18th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.when(
  2.     $.ajax({
  3.         type: "GET",
  4.         headers: {
  5.             "accept": "application/json;odata=verbose"
  6.         },
  7.         url: "https://yourSPsitecollectionhere/_api/SP.UserProfiles.PeopleManager/GetMyProperties"
  8.     })
  9. ).done(function(myProps) {
  10.     var jsonDatabase = {};
  11.     jsonDatabase["users"] = {};
  12.     jsonDatabase.users[myProps.d.DisplayName] = {};
  13.     jsonDatabase.users[myProps.d.DisplayName]["pLine1"] = myProps.title;
  14.     jsonDatabase.users[myProps.d.DisplayName]["eMail"] = myProps.email;
  15.     jsonDatabase.users[myProps.d.DisplayName]["mName"] = "";
  16.     jsonDatabase.users[myProps.d.DisplayName]["pLine2"] = "";
  17.     jsonDatabase.users[myProps.d.DisplayName]["location"] = "1";
  18.     jsonDatabase["locations"] = { "1" };
  19.     jsonDatabase.locations["1"]["desc"] = "Your Location Goes Here";
  20.     jsonDatabase.locations["1"]["address1"] = "Your Location's 1st Address Line";
  21.     jsonDatabase.locations["1"]["address2"] = "Your Locationa's 2nd Address Line";
  22.     for (var i = 0; i < myProps.d.DisplayName.UserProfileProperties.results.length; i++) {
  23.         switch (myProps.d.DisplayName.UserProfileProperties.results[i].Key) {
  24.             case "FirstName":
  25.                 jsonDatabase.users[myProps.d.DisplayName]["fName"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
  26.                 break;
  27.             case "LastName":
  28.                 jsonDatabase.users[myProps.d.DisplayName]["lName"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
  29.                 break;
  30.             case "WorkPhone":
  31.                 jsonDatabase.users[myProps.d.DisplayName]["phone"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
  32.                 break;
  33.             case "CellPhone":
  34.                 jsonDatabase.users[myProps.d.DisplayName]["mobile"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
  35.                 break;
  36.             case "Department":
  37.                 jsonDatabase.users[myProps.d.DisplayName]["department"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
  38.                 break;
  39.             case "Fax":
  40.                 jsonDatabase.users[myProps.d.DisplayName]["fax"] = myProps.d.DisplayName.UserProfileProperties.results[i].Value;
  41.                 break;
  42.         }
  43.     }
  44.  
  45.     $.when(
  46.         $.ajax({
  47.             url: "https://yourPHPsitehere/index.php?target=ajax",
  48.             type: "POST",
  49.             data: jsonDatabase,
  50.             dataType: "json"
  51.         })
  52.     ).done(function() {
  53.         $("yourIMGtagselectorhere").attr("src", "https://yourPHPsitehere/index.php?target=display&user=" + myProps.d.DisplayName + "&refresh=" + new Date()).getTime();
  54.     }).fail(function() {
  55.         alert("Unable to send the current user's properties to the PHP page.");
  56.     });
  57. }).fail(function() {
  58.     alert("Unable to get the current user's properties.");
  59. });
Advertisement
Add Comment
Please, Sign In to add comment