We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Quote from: BobRay at Oct 29, 2014, 03:33 PM
    It should work fine with extended fields, but the proper way to do that is with a recursive function to generate the output. I'll try to get to it later today or tomorrow.

    Thanks Bob smiley Hugely appreciated!
    • discuss.answer
      • 3749
      • 24,544 Posts
      I think this version of CheckProfile will do it.

      <?php
      function generateOutput($old, $new, &$msg) {
          foreach($old as $key => $oldValue) {
              if (is_array($oldValue)) {
                 $msg .= generateOutput($oldValue, $new[$key], $msg);
              } else {
                  $newValue = empty($new[$key])? '(empty)' : $new[$key];
                  $oldValue = empty($oldValue)? '(empty)' : $oldValue;
                  
                  if ($newValue != $oldValue) {
                      $msg .= "\n" . $key . ' changed from ' . $oldValue . ' to ' . $newValue;
                  }
              }
          }
      }
      
      $oldProfile = isset($_SESSION['user_profile'])? $_SESSION['user_profile'] : 'No Profile';
      
      
      $newProfile = $modx->user->getOne('Profile')->toArray();
      
      $msg = '';
      generateOutput($oldProfile, $newProfile, $msg);
      
      /* foreach($oldProfile as $key => $oldValue) {
          $msg .= generateOutput(
          $newValue = empty($newProfile[$key])? '(empty)' : $newProfile[$key];
          $oldValue = empty($oldValue)? '(empty)' : $oldValue;
          if ($newValue != $oldValue) {
              $msg .= "\n" . $key . ' changed from ' . $oldValue . ' to ' . $newValue;
          }
      }
      */
      
      /* Email $msg here after debugging */
      
      
      /* When through debugging, comment out
         these three lines */
      
       $chunk = $modx->getObject('modChunk', array('name' => 'Debug'));
       $chunk->setContent($msg);
       $chunk->save();
      
      return true;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 8168
        • 1,118 Posts
        Bob - you are the man! Works a treat - thank you soooooo much for helping here and working so hard with me to get it working - what an asset to the MODX solution you are! True legend. Thank you.
          • 3749
          • 24,544 Posts
          Thanks for the kind words -- sorry it took so long to get it right. Did I mention that Bob's Guides accepts donations? wink

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 8168
            • 1,118 Posts
            How does one donate to the Bobsguides foundation Bob?

            Also - how can I get the $msg variable to spit out its contents into my mail sending code? I am trying to call in the contents of the Debug chunk but not working... ?

            FIXED it >
            '.$modx->getChunk('Debug',array());'
            [ed. note: dubbs last edited this post 9 years, 7 months ago.]
              • 3749
              • 24,544 Posts
              http://bobsguides.com/support-this-site.html

              About the $msg variable, can't you just do this?

              mail($to, $subject, $msg, $headers);


              You shouldn't need the debug chunk at all.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 8168
                • 1,118 Posts
                Quote from: BobRay at Oct 30, 2014, 02:51 PM
                http://bobsguides.com/support-this-site.html

                About the $msg variable, can't you just do this?

                mail($to, $subject, $msg, $headers);


                You shouldn't need the debug chunk at all.


                Thanks Bob - I am adding in other content to the message within the mail so I just render the output of the chunk - works well.
                  • 8168
                  • 1,118 Posts
                  Bob - also just donated $40 smiley Thanks once more!
                    • 3749
                    • 24,544 Posts
                    Thank you! smiley
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting