CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • How can a user update their own profile?
Pages: 1 [2] 3

Author Topic: How can a user update their own profile?  (Read 21551 times)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How can a user update their own profile?
July 21, 2008, 06:27:08 pm

i went in and fixed the regex's, so in 2.1 we are back to normal behavior. You can backport the patch from here:

http://fisheye.civicrm.org/changelog/CiviCRM/trunk?cs=15982

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

tonyg

  • Guest
Re: How can a user update their own profile?
July 22, 2008, 09:35:29 am
Great Lobo! Thanks. Jason at DT will work on backporting it.

This is a great feature and I think will really help a lot of organizations. I'll update the documentation once we're all done.

thanks
tony

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: How can a user update their own profile?
July 23, 2008, 05:53:38 pm
Thanks Lobo!

Here's the patch for a clean 1.9.13 installation for anyone that's interested.

--- Mailing.php   2008-07-23 18:37:55.000000000 -0600
+++ Mailing.php.new   2008-07-23 18:38:49.000000000 -0600
@@ -441,11 +441,16 @@
             // if so then call this function again to get the token dataFunc
             // and assign the type 'embedded'  so that the data retrieving function
             // will know what how to handle this token.
-            if ( preg_match('/(\{\w+\.\w+\})/', $token, $matches) ) {
+            if ( preg_match_all('/(\{\w+\.\w+\})/', $token, $matches) ) {
                 $funcStruct['type'] = 'embedded_url';
-                $preg_token = '/'.preg_quote($matches[1],'/').'/';
-                $funcStruct['embed_parts'] = preg_split($preg_token,$token,2);
-                $funcStruct['token'] = $this->getDataFunc($matches[1]);
+                $funcStruct['embed_parts'] = $funcStruct['token'] = array( );
+                foreach ( $matches[1] as $match ) {
+                    $preg_token = '/'.preg_quote($match,'/').'/';
+                    $list = preg_split($preg_token,$token,2);
+                    $funcStruct['embed_parts'][] = $list[0];
+                    $token = $list[1];
+                    $funcStruct['token'][] = $this->getDataFunc($match);
+                }
             } else {
                 $funcStruct['type'] = 'url';
             }
@@ -933,6 +938,7 @@
                     $token_data = $this->getTokenData($token, $html, $contact, $verp, $urls, $event_queue_id);
                     array_push($pEmail, $template[$idx]);
                     array_push($pEmail, $token_data);
+
                 }
             } else {
                 array_push($pEmail, $template[$idx]);
@@ -965,6 +971,7 @@
                        $contact['preferred_mail_format'] == 'Both' ||
                        ( $contact['preferred_mail_format'] == 'HTML' && !array_key_exists('html',$pEmails) ) ) ) {
             $message->setTxtBody( join( '', $text ) );
+
         }
         
         if ( $html && ( $test ||  ( $contact['preferred_mail_format'] == 'HTML' ||
@@ -1011,10 +1018,19 @@
         $data = $token;
 
         if ($type == 'embedded_url') {
-            $embed_data = $this->getTokenData($token, $html = false, $contact, $verp, $urls, $event_queue_id);
-            $url = join($token_a['embed_parts'],$embed_data);
+            $embed_data = array( );
+            foreach ( $token as $t ) {
+                $embed_data[] = $this->getTokenData($t, $html = false, $contact, $verp, $urls, $event_queue_id);
+            }
+            $numSlices = count( $embed_data );
+            $url = '';
+            for ( $i = 0; $i < $numSlices; $i++ ) {
+                $url .= "{$token_a['embed_parts'][$i]}{$embed_data[$i]}";
+            }
+            if ( isset( $token_a['embed_parts'][$numSlices] ) ) {
+                $url .= $token_a['embed_parts'][$numSlices];
+            }
             $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($url, $this->id, $event_queue_id);
-           
         } else if ( $type == 'url' ) {
             $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id);
         } else if ( $type == 'mailing' ) {

http://dharmatech.org
oss@dharmatech.org
801.541.8671

dharmatech

  • I post frequently
  • ***
  • Posts: 280
  • Karma: 53
    • dharmatech.org
Re: How can a user update their own profile?
August 04, 2008, 04:23:09 pm
... and here's the patch for a clean 2.0.5 installation.

--- Mailing.php   2008-08-04 17:07:12.000000000 -0600
+++ Mailing.php.new   2008-08-04 17:17:05.000000000 -0600
@@ -456,11 +456,17 @@
             // if so then call this function again to get the token dataFunc
             // and assign the type 'embedded'  so that the data retrieving function
             // will know what how to handle this token.
-            if ( preg_match('/(\{\w+\.\w+\})/', $token, $matches) ) {
+            if ( preg_match_all('/(\{\w+\.\w+\})/', $token, $matches) ) {
                 $funcStruct['type'] = 'embedded_url';
-                $preg_token = '/'.preg_quote($matches[1],'/').'/';
-                $funcStruct['embed_parts'] = preg_split($preg_token,$token,2);
-                $funcStruct['token'] = $this->getDataFunc($matches[1]);
+                $funcStruct['embed_parts'] = $funcStruct['token'] = array( );
+                foreach ( $matches[1] as $match ) {
+                    $preg_token = '/'.preg_quote($match,'/').'/';
+                    $list = preg_split($preg_token,$token,2);
+                    $funcStruct['embed_parts'][] = $list[0];
+                    $token = $list[1];
+                    $funcStruct['token'][] = $this->getDataFunc($match);
+                }
+
             } else {
                 $funcStruct['type'] = 'url';
             }
@@ -1025,10 +1031,19 @@
         $data = $token;
 
         if ($type == 'embedded_url') {
-            $embed_data = $this->getTokenData($token, $html = false, $contact, $verp, $urls, $event_queue_id);
-            $url = join($token_a['embed_parts'],$embed_data);
+            $embed_data = array( );
+            foreach ( $token as $t ) {
+                $embed_data[] = $this->getTokenData($t, $html = false, $contact, $verp, $urls, $event_queue_id);
+            }
+            $numSlices = count( $embed_data );
+            $url = '';
+            for ( $i = 0; $i < $numSlices; $i++ ) {
+                $url .= "{$token_a['embed_parts'][$i]}{$embed_data[$i]}";
+            }
+            if ( isset( $token_a['embed_parts'][$numSlices] ) ) {
+                $url .= $token_a['embed_parts'][$numSlices];
+            }
             $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($url, $this->id, $event_queue_id);
-           
         } else if ( $type == 'url' ) {
             $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id);
         } else if ( $type == 'contact' ) {

http://dharmatech.org
oss@dharmatech.org
801.541.8671

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How can a user update their own profile?
September 03, 2008, 02:00:02 pm
Originally posted here http://forum.civicrm.org/index.php/topic,4620.msg20154.html#msg20154

Hi Lobo - we have just tried to use this set up http://forum.civicrm.org/index.php/topic,3905.0.html so that - if I understood it - we could flip out an email that would, say, include all the {contact.address} type tokens so the person can see the address details we have for them, and then click on a link that would take them to a profile that would show the same fields as recorded on the database, and allow them to update the data.

Now we may have gotten the wrong end of the stick, or just implemented it properly but ...

Firstly, with Track Click Throughs on we end up with the same problem as here, namely that the URL provided for the profile gets preceded with that sort of address so we get
http://(our.web.site.address)/sites/all/modules/civicrm/extern/href=%22http://(our.web.site.address)/civicrm/profile/edit?reset=1&gid=1&cs=82040e6e5e0ed56201080d2e6e66a9da_1220440559_168

Second, if I strip off the first bit in the browser, or turn Track Clicks off, and get the correct URL, then for an Anonymous User, using a browser I am not currenly logged in on, I do not end up with any of the fields showing the existing data.

So, first point is, is this another example of the Track Click Through's 'interfering' with a function that should work (ie this ticket)

Second, are we atttempting the impossible with getting the fields to show the existing data for an Anonymous User, or is this what forum topic 3905 is attempting to achieve. If so perhaps we should continue this second part of the conversation back on that posting ;-)

To which Lobo replied
Quote
The functionality is supposed to work for anonymous user for a limited time period (1 week)

So I need to figure whether we have taken a wrong step anywhere in the process. Is this currently working on Sandbox? But I guess the civiMail isnt fully set up so I can't test it.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: How can a user update their own profile?
September 03, 2008, 03:14:44 pm
So, what we're seeing is this:

If we disable Clickthru Tracking, we just see an unreplaced {contact.checksum} in the URL, but other replacements in the same message occur correctly.

OR

If "Track Clickthroughs" is activated, the {contact.checksum} gets replaced, but we also get an additional redirect (as would be expected) and some bung quoting.

In this case, if we supply,
Code: [Select]
<a href="http://example.com/civicrm/profile/edit?reset=1&gid=1&{contact.checksum}">here</a>
then we get
Code: [Select]
<a href="http://example.com/sites/all/modules/civicrm/extern/href=%22http://example.com/civicrm/profile/edit?reset=1&gid=1&cs=82040e6e5e0ed56201080d2e6e66a9da_1220440559_168">here</a>

Maybe one of those regexes is being matched too loosely.

Also - should {contact.checksum} add a cid parameter, or is it embedded in the cs parameter?


Just to clarify the code we're running (only the first chunk of the Dharmatech 2.0.5 patch above applied cleanly, so I inserted the second block manually) ...

In CRM_Utils_Token::getContactTokenReplacement() and CRM_Utils_Token::replaceOrgTokens() we have:
Code: [Select]
        } else if ( $token == 'checksum' ) {
            $cs = CRM_Contact_BAO_Contact::generateChecksum( $contact['contact_id'] );
            $value = "cs={$cs}";
        } else {

In CRM_Mailing_BAO_Mailing::getDataFunc() we have:
Code: [Select]
        if ( ( preg_match('/^href/i',$token) || preg_match('/^http/i',$token) ) && $this->url_tracking ) {
            // it is a url so we need to check to see if there are any tokens embedded
            // if so then call this function again to get the token dataFunc
            // and assign the type 'embedded'  so that the data retrieving function
            // will know what how to handle this token.
            if ( preg_match_all('/(\{\w+\.\w+\})/', $token, $matches) ) {
                $funcStruct['type'] = 'embedded_url';
                $funcStruct['embed_parts'] = $funcStruct['token'] = array( );
                foreach ( $matches[1] as $match ) {
                    $preg_token = '/'.preg_quote($match,'/').'/';
                    $list = preg_split($preg_token,$token,2);
                    $funcStruct['embed_parts'][] = $list[0];
                    $token = $list[1];
                    $funcStruct['token'][] = $this->getDataFunc($match);
                }

            } else {
                $funcStruct['type'] = 'url';
            }
       
        } else // ...

and CRM_Mailing_BAO_Mailing::getTokenData() is
Code: [Select]
    private function getTokenData(&$token_a, $html = false, &$contact, &$verp, &$urls, $event_queue_id)
    {
        $type = $token_a['type'];
        $token = $token_a['token'];
        $data = $token;

        if ($type == 'embedded_url') {
//            $embed_data = $this->getTokenData($token, $html = false, $contact, $verp, $urls, $event_queue_id);
//            $url = join($token_a['embed_parts'],$embed_data);
            $embed_data = array( );
            foreach ( $token as $t ) {
                $embed_data[] = $this->getTokenData($t, $html = false, $contact, $verp, $urls, $event_queue_id);
            }
            $numSlices = count( $embed_data );
            $url = '';
            for ( $i = 0; $i < $numSlices; $i++ ) {
                $url .= "{$token_a['embed_parts'][$i]}{$embed_data[$i]}";
            }
            if ( isset( $token_a['embed_parts'][$numSlices] ) ) {
                $url .= $token_a['embed_parts'][$numSlices];
            }
            $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($url, $this->id, $event_queue_id);
           
        } else if ( $type == 'url' ) {
            $data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id);
        } else if ( $type == 'contact' ) {
          $data = CRM_Utils_Token::getContactTokenReplacement($token, $contact);
        } else if ( $type == 'action' ) {
          $data = CRM_Utils_Token::getActionTokenReplacement($token, $verp, $urls, $html);
        }
        return $data;
    }   

It may be relevant that we've recently applied the patch from CRM-3484, but that's a pretty minor change.

I tried attaching our patched Mailing.php and Token.php to illustrate, but was warned that "the upload folder is full". So
 * Mailing.php
 * Token.php
« Last Edit: September 03, 2008, 05:06:59 pm by xurizaemon »
@xurizaemon ● www.fuzion.co.nz

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How can a user update their own profile?
September 03, 2008, 08:29:32 pm

i've fixed the upload folder message. Also reduced the attachment size limit (so we grow it at a slower rate)
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

tonyg

  • Guest
Re: How can a user update their own profile?
September 05, 2008, 11:22:52 am
Hello peterd and xurizaemon. First question, what versions are you running?

To peterd: Regarding your first point, yes there have been issues with CiviMail incorrectly "rewriting" a link to make trackable. One issue had to do with having two tokens in one path.  Secondly, you are not attempting the impossible. Allowing anonymous users to see and update their existing data in a profile is the idea behind the checksum token and what we've been trying to make work.

Have not had a chance yet to test on 2.1, but in a 2.0.6 installation, it works once the patch is applied. 
What i mean by "work":
1. I insert this path with these tokens in the body of a civimail message: http://yoursite.org/civicrm/profile/edit?reset=1&gid=1&id={contact.contact_id}&{contact.checksum}
GID is the ID of the profile i want people to go to and have prefilled with their contact data.
2. Inserting this path with the checksum in the footer also works.

To xurizaemon: To answer your questions regarding if the checksum token also supplies the CID parameter, the answer is no.  Basically, you need to supply and additional token, the contact ID token like in my example above.  So the id and checksum tokens work together.

There are additional bugs with this as we've seen.  But hopefully we can get them ironed out. It is a really cool feature that many groups can and would utilize.

hope this helps
tony

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How can a user update their own profile?
September 05, 2008, 12:54:17 pm
Thanks Tony - we are both working on 2.0.5 (? latest).
I think that for 2.0 I am still unclear if there a problem of including 2
Quote from: Donald Lobo on July 21, 2008, 04:40:05 pm

So the bug is with having two tokens in a URL :(. It did not work for me in either html or text mode. The regex's there are a bit hairy and i'm punting the issue to 2.2

however for 2.1, i've expanded the {contact.checksum} token to include both the contact id and the checksum, since checksum needs the contact id.

Anyhow I tried inserting http://yoursite.org/civicrm/profile/edit?reset=1&gid=1&id={contact.contact_id}&{contact.checksum} in case - and it is not working for us but will await chris/xuri running his eyes over this thread again.

This will be an incredibly helpful function (as will being able to move an anonymous user who can get to one profile via this route to then be able to move on to a second profile ;-))
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How can a user update their own profile?
September 05, 2008, 01:09:02 pm
Shreik (pete jumps up and down like 13 year old)

 ;D could have been something to do with me sending the email from our live site while the checksum was set up to work on our test site.  ::)

Yay it works - brilliant. Though (note Chris) it is still prepending the URL with the extra code (though I note this didn't happen on the live site which may offer a clue?)

Onward and upward
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How can a user update their own profile?
September 05, 2008, 02:05:24 pm
Okay - so anyone have a clue as to what is required (is it possible) that if the Profile is set up so that the REQUIRED URL is another PROFILE then upon hitting SAVE on the first profile the second profile opens up, still using the {checksum} and {contact.id} so that the second profile is opened up with the contacts data filled in. This would be truly awesome.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How can a user update their own profile?
September 05, 2008, 02:14:40 pm
Or is it not a case of using the Required URL - basically as I see all I am wanting to do is move from

/civicrm/profile/edit?reset=1&gid=48&id=13242&cs=400e5236ea1df200d92ac05da7e0ff67_1220646885_168 to, for example

/civicrm/profile/edit?reset=1&gid=29&id=13242&cs=400e5236ea1df200d92ac05da7e0ff67_1220646885_168

when the user hits SAVE on the first profile
« Last Edit: September 05, 2008, 02:17:24 pm by peterd »
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: How can a user update their own profile?
September 05, 2008, 03:40:47 pm

anything reasonable is possible in software if you are willing to hack the code :). The below will require a hack. Chris can ping me on IRC and i can help him get started. once we have a hack in place, we'll figure out how to generalize it :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How can a user update their own profile?
September 05, 2008, 07:24:04 pm
Sure - thanks - again I imagine this would be of interest to many users - and in the mean time I can try including links to several profiles in the same email suggesting that they can not only go and update their contact details but can also check other data and update it.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: How can a user update their own profile?
September 08, 2008, 09:44:55 pm
This really does feel like a huge breakthrough so big thanks to all who have helped us get here.

Now, what hurdles do we have to get over to be able to use this to send people to a Donation page that already has their details in the included Profile??
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: 1 [2] 3
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • How can a user update their own profile?

This forum was archived on 2017-11-26.