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 Drupal Modules (Moderator: Donald Lobo) »
  • workaround found - user-profile.tpl.php
Pages: [1]

Author Topic: workaround found - user-profile.tpl.php  (Read 5103 times)

joemaine

  • I post occasionally
  • **
  • Posts: 114
  • Karma: 3
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.14
  • MySQL version: 5.1
  • PHP version: 5.2
workaround found - user-profile.tpl.php
June 23, 2009, 10:05:01 pm
Need to expose the following values in the Drupal user-profile.tpl.php
First Name
Middle Name
Last Name
Job Title
Current Employer
Display Name
CiviCRM userID
$user->og_groups; (should be account user not "user")



The code below used to work (for a great admin view of a user's account) until the recent release - Help - where am I going wrong

______

<?php
// $Id: user-profile.tpl.php,v 1.2 2007/08/07 08:39:36 goba Exp $

/**
 * @file user-profile.tpl.php
 * Default theme implementation to present all user profile data.
 *
 * This template is used when viewing a registered member's profile page,
 * e.g., example.com/user/123. 123 being the users ID.
 *
 * By default, all user profile data is printed out with the $user_profile
 * variable. If there is a need to break it up you can use $profile instead.
 * It is keyed to the name of each category or other data attached to the
 * account. If it is a category it will contain all the profile items. By
 * default $profile['summary'] is provided which contains data on the user's
 * history. Other data can be included by modules. $profile['picture'] is
 * available by default showing the account picture.
 *
 * Also keep in mind that profile items and their categories can be defined by
 * site administrators. They are also available within $profile. For example,
 * if a site is configured with a category of "contact" with
 * fields for of addresses, phone numbers and other related info, then doing a
 * straight print of $profile['contact'] will output everything in the
 * category. This is useful for altering source order and adding custom
 * markup for the group.
 *
 * To check for all available data within $profile, use the code below.
 *
 *   <?php print '<pre>'. check_plain(print_r($profile, 1)) .'</pre>'; ?>
 *
 * @see user-profile-category.tpl.php
 *      where the html is handled for the group.
 * @see user-profile-field.tpl.php
 *      where the html is handled for each item in the group.
 *
 * Available variables:
 * - $user_profile: All user profile data. Ready for print.
 * - $profile: Keyed array of profile categories and their items or other data
 *   provided by modules.
 *
 * @see template_preprocess_user_profile()
 */

// Get the user's id from the query string
$user_id = arg(1);

// Get the user's CiviCRM id based on their Drupal ID
$idSQL = "SELECT uf_match.contact_id FROM DATABASE.civicrm_uf_match uf_match
        WHERE uf_match.uf_id = '{$user_id}'";
        
if ($idResult = mysql_query($idSQL)) {
   $idRow = mysql_fetch_array($idResult);
   if (strlen($idRow['contact_id']) > 0) {
      // We have the user's CiviCRM id, so now get the possible current employers
      $currentEmployerSQL = "SELECT relationship.contact_id_b AS employer_id, contact.display_name AS employer
                        FROM DATABASE.civicrm_relationship relationship
                        LEFT JOIN DATABASE.civicrm_contact contact ON relationship.contact_id_b = contact.id
                        WHERE relationship.contact_id_a = {$idRow['contact_id']} AND
                        relationship.relationship_type_id = 4 AND
                        relationship.is_active = 1
                        ORDER BY relationship.id DESC LIMIT 1";
                       
      if ($currentEmployerResult = mysql_query($currentEmployerSQL)) {
         $currentEmployerRow = mysql_fetch_array($currentEmployerResult);
      } // end of if
      else {
         echo mysql_error();
      } // end of else
                       
   } // end of if
} // end of if
else {
   echo mysql_error();
} // end of else

?>
<div class="profile">
<?php // print $user_profile;
if (module_exists('civicrm')) {

   //initialize civicrm
   civicrm_initialize(TRUE);
   
   //required to use crm_uf_get_match_id function
   require_once 'api/UFGroup.php';
   
   //get user id from CIVICRM, using the $uid from the contact you're looking at
   $userID = crm_uf_get_match_id( $user_id );
   
   // Get the user's employer id
   require_once 'api/v2/Relationship.php';
   $params = array('contact_id' => $userID,);
   $relationship_information = civicrm_get_relationships( $params );
   
   if (@is_array($relationship_information)) {
      foreach ($relationship_information['result'] as $key => $value) {
         if ($relationship_information['result'][$key]['cid'] > 0) {
            $cid = $relationship_information['result'][$key]['cid'];
         } // end of if
      } // end of foreach
   } // end of if

   // We will find the values from this contact using it's userID
   $retrieve = array( contact_id => $userID  );
   
   //required to use civicrm_contact_get function
   require_once 'api/v2/Contact.php';
   $getContact = civicrm_contact_get( $retrieve );
   // $userobject = get_user_object($user->uid);
   //remove comments from line when you want to take a look at the whole array
   // print_r($getContact); ?>
  
  <div class="picture"></div>
<?php if (in_array('administrator user',$GLOBALS['user']->roles)): ?>
   <p id="content-profile-view"><a href="/user/<?= $account->uid ?>/edit/Personal%20Profile">Edit <?= $getContact['first_name'] ?>'s Drupal Personal Profile.</a><br /><a href="http://<?= $_SERVER['HTTP_HOST'] ?>/civicrm/contact/view?reset=1&cid=<?= $getContact['contact_id'] ?>">View <?= $getContact['first_name'] ?>'s CiviCRM Profile.</a><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://<?= $_SERVER['HTTP_HOST'] ?>/civicrm/contact/view/delete?reset=1&delete=1&cid=<?= $getContact['contact_id'] ?>">Delete <?= $getContact['first_name'] ?>'s CiviCRM Profile.</a></strong><br />

    <?php if ($cid > 0) { ?>
      <a href="http://<?= $_SERVER['HTTP_HOST'] ?>/civicrm/contact/relatedcontact?action=update&reset=1&cid=<?= $cid ?>">Edit <?= $getContact['first_name'] ?>'s Company Profile.</a>
   <?php } // end of if ?>
</p>

<?php endif; ?>
<a href="/user/<?= $user->uid ?>/edit/Personal%20Profile">Edit your Personal Profile.</a><br></p>

    <h3>Personal Profile for <?= $getContact['display_name'] ?></h3>
    <dl>
      <dt></dt>
    <dd><div id="crm-container" xml:lang="en" lang="en">
    <fieldset>
    <table class="form-layout-compressed">                              
      <tbody>
      <tr><td class="label">First Name</td><td class="view-value"><?= $getContact['first_name'] ?></td></tr>
      <tr><td class="label">Middle Name</td><td class="view-value"><?= $getContact['middle_name'] ?></td></tr>
      <tr><td class="label">Last Name</td><td class="view-value"><?= $getContact['last_name'] ?></td></tr>
      <tr><td class="label">Job Title</td><td class="view-value"><?= $getContact['job_title'] ?></td></tr>
      <tr><td class="label">Current Employer</td><td class="view-value"><?= $getContact['current_employer'] ?></td></tr>
      </tbody>
    </table>
    </fieldset>
    </div>

    <h3>History</h3>

    <?php

   // Get the registered events information
   require_once 'api/v2/Participant.php';
   
   // Get all the events that the user is registered for
   $registeredSQL = "SELECT id AS participant_id FROM civicrm_participant
                 WHERE contact_id = ".$userID." ORDER BY register_date DESC";
                 
   if ($registeredResult = mysql_query($registeredSQL)) {
      if (mysql_num_rows($registeredResult) > 0) {
         echo "<h4 style=\"margin-bottom: 0;\">Event Registrations</h4>\n"; ?>
         <table border="0" cellpadding="4" cellspacing="0" width="100%" id="registered_events_list">
         <tr>
               <th>Event</th>
                <th>Fee Level</th>
                <th>Fee Amount</th>
                <th>Event Date</th>
                <th>Status</th>
            </tr>
         <?php
         while ($registeredRow = mysql_fetch_array($registeredResult)) {
            
            $params = array('participant_id' => $registeredRow['participant_id'],);

            $event = & civicrm_participant_get($params);
            
            $startdate = date('l, M j Y',strtotime($event['event_start_date']));
            $startmonth = date('M',strtotime($event['event_start_date']));
            $startday = date('j',strtotime($event['event_start_date']));
            $startyear = date('Y',strtotime($event['event_start_date']));
            
            $starttime = date('g:i', strtotime($event['event_start_date']));
            $starttimeAMPM = date('A', strtotime($event['event_start_date']));
            
            $enddate = date('l, M j Y',strtotime($event['event_end_date']));
            $endmonth = date('M',strtotime($event['event_end_date']));
            $endday = date('j',strtotime($event['event_end_date']));
            $endyear = date('Y',strtotime($event['event_end_date']));
            
            $endtime = date('g:i', strtotime($event['event_end_date']));
            $endtimeAMPM = date('A', strtotime($event['event_end_date']));
            
            ?>
            
                <tr>
               <td<?php if ($even_odd == "even") echo " class=\"even\""; ?>><a href="/civicrm/event/info?reset=1&id=<?= $event['event_id'] ?>"><?= $event['event_title'] ?></a></td>
                    <td<?php if ($even_odd == "even") echo " class=\"even\""; ?>><?= $event['participant_fee_level'] ?>&nbsp;</td>
               <td<?php if ($even_odd == "even") echo " class=\"even\""; ?>><?php if (strlen($event['participant_fee_amount']) > 0) echo "$".number_format($event['participant_fee_amount'], 2); ?>&nbsp;</td>
                    <td<?php if ($even_odd == "even") echo " class=\"even\""; ?>>
                       <?php
                  
                  // Figure out how to display the date
                  if ($startdate == $enddate) {
                     echo $startdate;
                  } // end of if
                  
                  ?>&nbsp;
                    </td>
                    <td<?php if ($even_odd == "even") echo " class=\"even\""; ?>>
                       <?php if ($event['participant_is_pay_later'] == 1) {
                     echo "Pending ( Pay Later )";
                  } // end of if
                  else {
                     echo "Registered";
                  } // end of else ?>
                    </td>
            <?php
            
            if ($even_odd == "even") {
               $even_odd = "odd";
            } // end of if
            else {
               $even_odd = "even";
            } // end of else
            
         } // end of while
         echo "</table>\n";
      } // end of if
   } // end of if
   else {
      echo mysql_error();
      exit;
   } // end of else
   
   ?>
<h3>My Groups</h3>
<div class="item-list"><ul>
<?php
$groups = $user->og_groups;
if($groups){
    foreach($groups as $group){
    echo "<li>";
        print l($group[title], 'node/'.$group[nid]);
    echo "</li>";
    }
}
else {
    echo "<li>$user->name has not yet joined a group</li>";
}
?>
</ul><p><a href="/og">View all of the Groups</a></p></div>
    <?php } // end of if ?>
</div>

<?php

/*

print "<pre>";
print_r ($getContact);
print "</pre>";

*/

?>

« Last Edit: July 01, 2009, 03:39:09 pm by joemaine »
--
Joe

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: $50 donation to Social Source Foundation for a solution - user-profile.tpl.php
June 24, 2009, 11:05:04 am
Can you clarify what's not working? Have you put in debug / print statements to see where things are breaking down?
Protect your investment in CiviCRM by  becoming a Member!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: $50 donation to Social Source Foundation for a solution - user-profile.tpl.php
June 24, 2009, 11:58:54 am
I assume you're trying to load a Drupal "My Account" page (e.g. example.com/user/123) - so I'm not sure how or why CRM_Contact_Page_View_Tabbed is being called (that for viewing a contact record "inside" CiviCRM - civicrm/contact/view?cid=102). I guess your best bet if someone doesn't come along and see the problem in your code  is to step through bit by bit with print and exit statements til you see where it's blowing up.
Protect your investment in CiviCRM by  becoming a Member!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: $50 donation to Social Source Foundation for a solution - user-profile.tpl.php
June 25, 2009, 09:59:33 am
Is "Personal Profile" a custom data group? What's the value of "Used For" when you look at the settings on that custom data group (from Admin CiviCRM >> Custom Data)?

Is this field checked: "Does this Custom Data Group allow multiple records?" (custom data groups which allow multiple records can only be edited in a Tab  - not Inline)?
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • workaround found - user-profile.tpl.php

This forum was archived on 2017-11-26.