Attached Files |
change_in_display_to_public_processing.patch [^] (14,122 bytes) 2009-11-24 08:00
[Show Content]
Index: admin_templates/users/users_edit.tpl
===================================================================
--- admin_templates/users/users_edit.tpl (revision 12940)
+++ admin_templates/users/users_edit.tpl (working copy)
@@ -81,6 +81,7 @@
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="State" title="la_fld_State"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Zip" title="la_fld_Zip"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Country" title="la_fld_Country" has_empty="1"/>
+ <inp2:m_RenderElement name="inp_edit_multioptions" prefix="u" field="DisplayToPublic" title="la_fld_DisplayToPublic"/>
<inp2:m_RenderElement name="subsection" prefix="u" fields="Status,CreatedOn" title="la_section_Properties"/>
<inp2:m_RenderElement name="inp_edit_radio" prefix="u" field="Status" title="la_fld_Status"/>
Index: install/install_schema.sql
===================================================================
--- install/install_schema.sql (revision 12940)
+++ install/install_schema.sql (working copy)
@@ -250,6 +250,7 @@
PwResetConfirm varchar(255) DEFAULT NULL,
PwRequestTime int(11) unsigned DEFAULT NULL,
MinPwResetDelay int(11) NOT NULL DEFAULT '1800',
+ DisplayToPublic text,
PRIMARY KEY (PortalUserId),
UNIQUE KEY ResourceId (ResourceId),
UNIQUE KEY Login (Login),
Index: install/upgrades.php
===================================================================
--- install/upgrades.php (revision 12940)
+++ install/upgrades.php (working copy)
@@ -1316,6 +1316,64 @@
$this->Conn->Query($sql);
}
}
+
+ $this->processDisplayToPublic();
}
}
+
+ function processDisplayToPublic()
+ {
+ $profile_mapping = Array (
+ 'pp_firstname' => 'FirstName',
+ 'pp_lastname' => 'LastName',
+ 'pp_dob' => 'dob',
+ 'pp_email' => 'Email',
+ 'pp_phone' => 'Phone',
+ 'pp_street' => 'Street',
+ 'pp_city' => 'City',
+ 'pp_state' => 'State',
+ 'pp_zip' => 'Zip',
+ 'pp_country' => 'Country',
+ );
+
+ $fields = array_keys($profile_mapping);
+ $fields = array_map(Array (&$this->Conn, 'qstr'), $fields);
+ $where_clause = 'VariableName IN (' . implode(',', $fields) . ')';
+
+ // 1. get user, that have saved their profile at least once
+ $sql = 'SELECT DISTINCT PortalUserId
+ FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE ' . $where_clause;
+ $users = $this->Conn->GetCol($sql);
+
+ foreach ($users as $user_id) {
+ // 2. convert to new format
+ $sql = 'SELECT VariableValue, VariableName
+ FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE (PortalUserId = ' . $user_id . ') AND ' . $where_clause;
+ $user_variables = $this->Conn->GetCol($sql, 'VariableName');
+
+ // go through mapping to preserve variable order
+ $value = Array ();
+
+ foreach ($profile_mapping as $from_name => $to_name) {
+ if (array_key_exists($from_name, $user_variables) && $user_variables[$from_name]) {
+ $value[] = $to_name;
+ }
+ }
+
+ if ($value) {
+ $fields_hash = Array (
+ 'DisplayToPublic' => '|' . implode('|', $value) . '|',
+ );
+
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'PortalUser', 'PortalUserId = ' . $user_id);
+ }
+
+ // 3. delete old style variables
+ $sql = 'DELETE FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE (PortalUserId = ' . $user_id . ') AND ' . $where_clause;
+ $this->Conn->Query($sql);
+ }
+ }
}
\ No newline at end of file
Index: install/upgrades.sql
===================================================================
--- install/upgrades.sql (revision 12940)
+++ install/upgrades.sql (working copy)
@@ -1612,4 +1612,6 @@
UPDATE Phrase SET Phrase = 'lu_btn_SendPassword' WHERE Phrase = 'LU_BTN_SENDPASSWORD';
ALTER TABLE Category DROP IsIndex;
-DELETE FROM Phrase WHERE Phrase IN ('la_CategoryIndex', 'la_Container', 'la_fld_IsIndex');
\ No newline at end of file
+DELETE FROM Phrase WHERE Phrase IN ('la_CategoryIndex', 'la_Container', 'la_fld_IsIndex');
+
+ALTER TABLE PortalUser ADD DisplayToPublic TEXT NULL;
\ No newline at end of file
Index: kernel/application.php
===================================================================
--- kernel/application.php (revision 12948)
+++ kernel/application.php (working copy)
@@ -2014,9 +2014,8 @@
if (!$user_id && $user_id != -1) {
$user_id = -2;
+ }
- }
-
$this->SetVar('u.current_id', $user_id);
if (!$this->isAdmin) {
Index: kernel/db/db_tag_processor.php
===================================================================
--- kernel/db/db_tag_processor.php (revision 12940)
+++ kernel/db/db_tag_processor.php (working copy)
@@ -2552,4 +2552,26 @@
return false;
}
+
+ /**
+ * Checks, that requested option is checked inside field value
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function Selected($params)
+ {
+ $object =& $this->getObject($params);
+ /* @var $object kDBItem */
+
+ $field = $this->SelectParam($params, 'name,field');
+ $value = $object->GetDBField($field);
+
+ if (strpos($value, '|') !== false) {
+ $value = explode('|', substr($value, 1, -1));
+ return in_array($params['value'], $value);
+ }
+
+ return $value;
+ }
}
\ No newline at end of file
Index: units/user_profile/user_profile_eh.php
===================================================================
--- units/user_profile/user_profile_eh.php (revision 12940)
+++ units/user_profile/user_profile_eh.php (working copy)
@@ -46,9 +46,42 @@
return ;
}
+ $public_profile_add = Array ();
+ $public_profile_remove = Array ();
+ $profile_mapping = $this->Application->getUnitOption('u', 'UserProfileMapping');
+
foreach ($field_values as $variable_name => $variable_value) {
- $this->Application->StorePersistentVar($variable_name, unhtmlentities($variable_value));
+ if (array_key_exists($variable_name, $profile_mapping)) {
+ // old style variable for displaying fields in public profile (named "pp_*")
+ if ($variable_value) {
+ $public_profile_add[] = $profile_mapping[$variable_name];
+ }
+ else {
+ $public_profile_remove[] = $profile_mapping[$variable_name];
+ }
+ }
+ else {
+ $this->Application->StorePersistentVar($variable_name, unhtmlentities($variable_value));
+ }
}
+
+ if ($public_profile_add || $public_profile_remove) {
+ $user =& $this->Application->recallObject('u.current');
+ /* @var $user kDBItem */
+
+ // get current value
+ $display_to_public_old = $user->GetDBField('DisplayToPublic');
+ $display_to_public_new = $display_to_public_old ? explode('|', substr($display_to_public_old, 1, -1)) : Array ();
+
+ // update value
+ $display_to_public_new = array_diff(array_merge($display_to_public_new, $public_profile_add), $public_profile_remove);
+ $display_to_public_new = array_unique($display_to_public_new);
+ $display_to_public_new = $display_to_public_new ? '|' . implode('|', $display_to_public_new) . '|' : '';
+
+ if ($display_to_public_new != $display_to_public_old) {
+ $user->SetDBField('DisplayToPublic', $display_to_public_new);
+ $user->Update();
+ }
+ }
}
-
}
\ No newline at end of file
Index: units/user_profile/user_profile_tp.php
===================================================================
--- units/user_profile/user_profile_tp.php (revision 12940)
+++ units/user_profile/user_profile_tp.php (working copy)
@@ -18,14 +18,22 @@
function Field($params)
{
- $profile_mapping = $this->getProfileMapping();
$field = $this->SelectParam($params, 'name,field');
+ $profile_mapping = $this->Application->getUnitOption('u', 'UserProfileMapping');
+ $user_field = array_key_exists($field, $profile_mapping) ? $profile_mapping[$field] : false;
- if (isset($params['profile_field']) && $params['profile_field']) {
- $params['name'] = $profile_mapping[$field];
+ if (array_key_exists('profile_field', $params) && $params['profile_field']) {
+ // get variable from mapping
+ $params['name'] = $user_field;
$value = $this->Application->ProcessParsedTag('u.profile', 'Field', $params);
}
+ elseif ($user_field) {
+ // old style variable for displaying fields in public profile (named "pp_*")
+ $block_params = Array ('name' => 'DisplayToPublic', 'value' => $user_field);
+ $value = $this->Application->ProcessParsedTag($this->getUserPrefixSpecial(), 'Selected', $block_params);
+ }
else {
+ // get variable by name
$value = $this->recallUserProfileVar($field);
}
@@ -38,19 +46,13 @@
}
/**
- * Returns user_id to view profile from (same as u:getPassedID)
+ * Returns prefix and special of user to operate with
*
- * @return int
+ * @return string
*/
- function getProfileUserID()
+ function getUserPrefixSpecial()
{
- $profile_user_id = $this->Application->GetVar('user_id');
- if (!$profile_user_id) {
- // if none user_id given use current user id
- $profile_user_id = $this->Application->RecallVar('user_id');
- }
-
- return $profile_user_id;
+ return $this->Application->GetVar('user_id') ? 'u.profile' : 'u.current';
}
/**
@@ -60,28 +62,28 @@
* @param string $var_name
* @return mixed
*/
- function recallUserProfileVar($var_name, $user_id = null)
+ function recallUserProfileVar($var_name)
{
- static $cached_vars = null;
+ static $cache = null;
- if (!isset($cached_vars)) {
- if (!isset($user_id)) {
- $user_id = $this->getProfileUserID();
- }
+ if (!isset($cache)) {
+ $user =& $this->Application->recallObject( $this->getUserPrefixSpecial() );
+ /* @var $user kDBItem */
$sql = 'SELECT VariableValue, VariableName
- FROM '.TABLE_PREFIX.'PersistantSessionData
- WHERE (PortalUserId = '.$user_id.')';
- $cached_vars = $this->Conn->GetCol($sql, 'VariableName');
+ FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE (PortalUserId = ' . $user->GetID() . ')';
+ $cache = $this->Conn->GetCol($sql, 'VariableName');
}
- if (isset($cached_vars[$var_name])) {
+ if (array_key_exists($var_name, $cache)) {
// get variable value from persistent session
- return $cached_vars[$var_name];
+ return $cache[$var_name];
}
else {
// not found in persistent session -> get default value from config variable with same name
$config_value = $this->Application->ConfigValue($var_name);
+
if ($config_value !== false) {
return $config_value;
}
@@ -90,28 +92,7 @@
return false;
}
- /**
- * Returns mapping between persistent var name and user profile field
- *
- * @return Array
- */
- function getProfileMapping()
- {
- $profile_mapping = Array (
- 'pp_firstname' => 'FirstName',
- 'pp_lastname' => 'LastName',
- 'pp_dob' => 'dob',
- 'pp_email' => 'Email',
- 'pp_phone' => 'Phone',
- 'pp_street' => 'Street',
- 'pp_city' => 'City',
- 'pp_state' => 'State',
- 'pp_zip' => 'Zip',
- 'pp_country' => 'Country',
- );
- return $profile_mapping;
- }
/**
* Returns visible field count in user profile
@@ -124,13 +105,11 @@
static $field_count = null;
if (!isset($field_count)) {
- $profile_mapping = $this->getProfileMapping();
- $field_count = 0;
- foreach ($profile_mapping as $var_name => $field_name) {
- if ($this->recallUserProfileVar($var_name) == 1) {
- $field_count++;
- }
- }
+ $user =& $this->Application->recallObject( $this->getUserPrefixSpecial() );
+ /* @var $user kDBItem */
+
+ $display_to_public = $user->GetDBField('DisplayToPublic');
+ $field_count = $display_to_public ? substr_count($display_to_public, '|') - 1 : 0;
}
return $field_count;
@@ -158,10 +137,9 @@
*/
function prepareInputName($params)
{
- list ($id, $field) = parent::prepareInputName($params);
- $id = $this->Application->RecallVar('user_id');
+ $params['force_id'] = $this->Application->RecallVar('user_id');
- return Array($id, $field);
+ return parent::prepareInputName($params);
}
}
\ No newline at end of file
Index: units/users/users_config.php
===================================================================
--- units/users/users_config.php (revision 12940)
+++ units/users/users_config.php (working copy)
@@ -331,6 +331,22 @@
)
),
+ /**
+ * Required for depricated public profile templates to work
+ */
+ 'UserProfileMapping' => Array (
+ 'pp_firstname' => 'FirstName',
+ 'pp_lastname' => 'LastName',
+ 'pp_dob' => 'dob',
+ 'pp_email' => 'Email',
+ 'pp_phone' => 'Phone',
+ 'pp_street' => 'Street',
+ 'pp_city' => 'City',
+ 'pp_state' => 'State',
+ 'pp_zip' => 'Zip',
+ 'pp_country' => 'Country',
+ ),
+
'CalculatedFields' => Array(
'' => Array(
'PrimaryGroup' => 'g.Name',
@@ -390,6 +406,16 @@
'PwResetConfirm' => Array('type' => 'string','default' => null),
'PwRequestTime' => Array('type' => 'int','default' => null),
'MinPwResetDelay' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array(300 => '5', 600 => '10', 900 => '15', 1800 => '30', 3600 => '60'), 'use_phrases' => 0, 'not_null' => '1', 'default' => 1800),
+ 'DisplayToPublic' => Array (
+ 'type' => 'string',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (
+ 'FirstName' => 'lu_fld_FirstName', 'LastName' => 'lu_fld_LastName', 'dob' => 'lu_fld_BirthDate',
+ 'Email' => 'lu_fld_Email', 'Phone' => 'lu_fld_Phone', 'Street' => 'lu_fld_AddressLine1',
+ 'Street2' => 'lu_fld_AddressLine2', 'City' => 'lu_fld_City', 'State' => 'lu_fld_State',
+ 'Zip' => 'lu_fld_Zip', 'Country' => 'lu_fld_Country',
+ ), 'use_phrases' => 1, 'multiple' => 1,
+ 'default' => NULL
+ ),
),
'VirtualFields' => Array(
change_in_display_to_public_processing_v2.patch [^] (14,456 bytes) 2010-08-02 12:51
[Show Content]
Index: admin_templates/users/users_edit.tpl
===================================================================
--- admin_templates/users/users_edit.tpl (revision 13756)
+++ admin_templates/users/users_edit.tpl (working copy)
@@ -81,6 +81,7 @@
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="State" title="la_fld_State"/>
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Zip" title="la_fld_Zip"/>
<inp2:m_RenderElement name="inp_edit_options" prefix="u" field="Country" title="la_fld_Country" has_empty="1"/>
+ <inp2:m_RenderElement name="inp_edit_multioptions" prefix="u" field="DisplayToPublic" title="la_fld_DisplayToPublic"/>
<inp2:m_RenderElement name="subsection" prefix="u" fields="Status,CreatedOn" title="la_section_Properties"/>
<inp2:m_RenderElement name="inp_edit_radio" prefix="u" field="Status" title="la_fld_Status"/>
Index: install/english.lang
===================================================================
--- install/english.lang (revision 13824)
+++ install/english.lang (working copy)
@@ -408,6 +408,7 @@
<PHRASE Label="la_fld_Display" Module="Core" Type="1">RGlzcGxheQ==</PHRASE>
<PHRASE Label="la_fld_DisplayInGrid" Module="Core" Type="1">RGlzcGxheSBpbiBHcmlk</PHRASE>
<PHRASE Label="la_fld_DisplayName" Module="Core" Type="1">RmllbGQgTGFiZWw=</PHRASE>
+ <PHRASE Label="la_fld_DisplayToPublic" Module="Core" Type="1">RGlzcGxheSBUbyBQdWJsaWM=</PHRASE>
<PHRASE Label="la_fld_DomainIPRange" Module="Core" Type="1">UmFuZ2Ugb2YgSVBz</PHRASE>
<PHRASE Label="la_fld_DomainName" Module="Core" Type="1">RG9tYWluIE5hbWU=</PHRASE>
<PHRASE Label="la_fld_DoNotEncode" Module="Core" Type="1">QXMgUGxhaW4gVGV4dA==</PHRASE>
Index: install/install_schema.sql
===================================================================
--- install/install_schema.sql (revision 13824)
+++ install/install_schema.sql (working copy)
@@ -264,6 +264,7 @@
PwRequestTime int(11) unsigned DEFAULT NULL,
MinPwResetDelay int(11) NOT NULL DEFAULT '1800',
AdminLanguage int(11) DEFAULT NULL,
+ DisplayToPublic text,
PRIMARY KEY (PortalUserId),
UNIQUE KEY ResourceId (ResourceId),
UNIQUE KEY Login (Login),
Index: install/upgrades.php
===================================================================
--- install/upgrades.php (revision 13824)
+++ install/upgrades.php (working copy)
@@ -1698,4 +1698,72 @@
$this->Conn->Query($sql);
}
}
+
+ /**
+ * Update to 5.1.1-B1; Transforms DisplayToPublic logic
+ *
+ * @param string $mode when called mode {before, after)
+ */
+ function Upgrade_5_1_1_B1($mode)
+ {
+ if ($mode == 'after') {
+ $this->processDisplayToPublic();
+ }
+ }
+
+ function processDisplayToPublic()
+ {
+ $profile_mapping = Array (
+ 'pp_firstname' => 'FirstName',
+ 'pp_lastname' => 'LastName',
+ 'pp_dob' => 'dob',
+ 'pp_email' => 'Email',
+ 'pp_phone' => 'Phone',
+ 'pp_street' => 'Street',
+ 'pp_city' => 'City',
+ 'pp_state' => 'State',
+ 'pp_zip' => 'Zip',
+ 'pp_country' => 'Country',
+ );
+
+ $fields = array_keys($profile_mapping);
+ $fields = array_map(Array (&$this->Conn, 'qstr'), $fields);
+ $where_clause = 'VariableName IN (' . implode(',', $fields) . ')';
+
+ // 1. get user, that have saved their profile at least once
+ $sql = 'SELECT DISTINCT PortalUserId
+ FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE ' . $where_clause;
+ $users = $this->Conn->GetCol($sql);
+
+ foreach ($users as $user_id) {
+ // 2. convert to new format
+ $sql = 'SELECT VariableValue, VariableName
+ FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE (PortalUserId = ' . $user_id . ') AND ' . $where_clause;
+ $user_variables = $this->Conn->GetCol($sql, 'VariableName');
+
+ // go through mapping to preserve variable order
+ $value = Array ();
+
+ foreach ($profile_mapping as $from_name => $to_name) {
+ if (array_key_exists($from_name, $user_variables) && $user_variables[$from_name]) {
+ $value[] = $to_name;
+ }
+ }
+
+ if ($value) {
+ $fields_hash = Array (
+ 'DisplayToPublic' => '|' . implode('|', $value) . '|',
+ );
+
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'PortalUser', 'PortalUserId = ' . $user_id);
+ }
+
+ // 3. delete old style variables
+ $sql = 'DELETE FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE (PortalUserId = ' . $user_id . ') AND ' . $where_clause;
+ $this->Conn->Query($sql);
+ }
+ }
}
\ No newline at end of file
Index: install/upgrades.sql
===================================================================
--- install/upgrades.sql (revision 13824)
+++ install/upgrades.sql (working copy)
@@ -1937,3 +1937,6 @@
ALTER TABLE FormSubmissions
ADD MessageId VARCHAR(255) NULL DEFAULT NULL AFTER Notes,
ADD INDEX (MessageId);
+
+# ===== v 5.1.1-B1 =====
+ALTER TABLE PortalUser ADD DisplayToPublic TEXT NULL;
\ No newline at end of file
Index: kernel/db/db_tag_processor.php
===================================================================
--- kernel/db/db_tag_processor.php (revision 13756)
+++ kernel/db/db_tag_processor.php (working copy)
@@ -2757,4 +2757,26 @@
return false;
}
+
+ /**
+ * Checks, that requested option is checked inside field value
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function Selected($params)
+ {
+ $object =& $this->getObject($params);
+ /* @var $object kDBItem */
+
+ $field = $this->SelectParam($params, 'name,field');
+ $value = $object->GetDBField($field);
+
+ if (strpos($value, '|') !== false) {
+ $value = explode('|', substr($value, 1, -1));
+ return in_array($params['value'], $value);
+ }
+
+ return $value;
+ }
}
\ No newline at end of file
Index: units/user_profile/user_profile_eh.php
===================================================================
--- units/user_profile/user_profile_eh.php (revision 13756)
+++ units/user_profile/user_profile_eh.php (working copy)
@@ -46,9 +46,42 @@
return ;
}
+ $public_profile_add = Array ();
+ $public_profile_remove = Array ();
+ $profile_mapping = $this->Application->getUnitOption('u', 'UserProfileMapping');
+
foreach ($field_values as $variable_name => $variable_value) {
- $this->Application->StorePersistentVar($variable_name, unhtmlentities($variable_value));
+ if (array_key_exists($variable_name, $profile_mapping)) {
+ // old style variable for displaying fields in public profile (named "pp_*")
+ if ($variable_value) {
+ $public_profile_add[] = $profile_mapping[$variable_name];
+ }
+ else {
+ $public_profile_remove[] = $profile_mapping[$variable_name];
+ }
+ }
+ else {
+ $this->Application->StorePersistentVar($variable_name, unhtmlentities($variable_value));
+ }
}
+
+ if ($public_profile_add || $public_profile_remove) {
+ $user =& $this->Application->recallObject('u.current');
+ /* @var $user kDBItem */
+
+ // get current value
+ $display_to_public_old = $user->GetDBField('DisplayToPublic');
+ $display_to_public_new = $display_to_public_old ? explode('|', substr($display_to_public_old, 1, -1)) : Array ();
+
+ // update value
+ $display_to_public_new = array_diff(array_merge($display_to_public_new, $public_profile_add), $public_profile_remove);
+ $display_to_public_new = array_unique($display_to_public_new);
+ $display_to_public_new = $display_to_public_new ? '|' . implode('|', $display_to_public_new) . '|' : '';
+
+ if ($display_to_public_new != $display_to_public_old) {
+ $user->SetDBField('DisplayToPublic', $display_to_public_new);
+ $user->Update();
+ }
+ }
}
-
}
\ No newline at end of file
Index: units/user_profile/user_profile_tp.php
===================================================================
--- units/user_profile/user_profile_tp.php (revision 13756)
+++ units/user_profile/user_profile_tp.php (working copy)
@@ -18,14 +18,22 @@
function Field($params)
{
- $profile_mapping = $this->getProfileMapping();
$field = $this->SelectParam($params, 'name,field');
+ $profile_mapping = $this->Application->getUnitOption('u', 'UserProfileMapping');
+ $user_field = array_key_exists($field, $profile_mapping) ? $profile_mapping[$field] : false;
- if (isset($params['profile_field']) && $params['profile_field']) {
- $params['name'] = $profile_mapping[$field];
+ if (array_key_exists('profile_field', $params) && $params['profile_field']) {
+ // get variable from mapping
+ $params['name'] = $user_field;
$value = $this->Application->ProcessParsedTag('u.profile', 'Field', $params);
}
+ elseif ($user_field) {
+ // old style variable for displaying fields in public profile (named "pp_*")
+ $block_params = Array ('name' => 'DisplayToPublic', 'value' => $user_field);
+ $value = $this->Application->ProcessParsedTag($this->getUserPrefixSpecial(), 'Selected', $block_params);
+ }
else {
+ // get variable by name
$value = $this->recallUserProfileVar($field);
}
@@ -38,19 +46,13 @@
}
/**
- * Returns user_id to view profile from (same as u:getPassedID)
+ * Returns prefix and special of user to operate with
*
- * @return int
+ * @return string
*/
- function getProfileUserID()
+ function getUserPrefixSpecial()
{
- $profile_user_id = $this->Application->GetVar('user_id');
- if (!$profile_user_id) {
- // if none user_id given use current user id
- $profile_user_id = $this->Application->RecallVar('user_id');
- }
-
- return $profile_user_id;
+ return $this->Application->GetVar('user_id') ? 'u.profile' : 'u.current';
}
/**
@@ -60,28 +62,28 @@
* @param string $var_name
* @return mixed
*/
- function recallUserProfileVar($var_name, $user_id = null)
+ function recallUserProfileVar($var_name)
{
- static $cached_vars = null;
+ static $cache = null;
- if (!isset($cached_vars)) {
- if (!isset($user_id)) {
- $user_id = $this->getProfileUserID();
- }
+ if (!isset($cache)) {
+ $user =& $this->Application->recallObject( $this->getUserPrefixSpecial() );
+ /* @var $user kDBItem */
$sql = 'SELECT VariableValue, VariableName
- FROM '.TABLE_PREFIX.'PersistantSessionData
- WHERE (PortalUserId = '.$user_id.')';
- $cached_vars = $this->Conn->GetCol($sql, 'VariableName');
+ FROM ' . TABLE_PREFIX . 'PersistantSessionData
+ WHERE (PortalUserId = ' . $user->GetID() . ')';
+ $cache = $this->Conn->GetCol($sql, 'VariableName');
}
- if (isset($cached_vars[$var_name])) {
+ if (array_key_exists($var_name, $cache)) {
// get variable value from persistent session
- return $cached_vars[$var_name];
+ return $cache[$var_name];
}
else {
// not found in persistent session -> get default value from config variable with same name
$config_value = $this->Application->ConfigValue($var_name);
+
if ($config_value !== false) {
return $config_value;
}
@@ -90,28 +92,7 @@
return false;
}
- /**
- * Returns mapping between persistent var name and user profile field
- *
- * @return Array
- */
- function getProfileMapping()
- {
- $profile_mapping = Array (
- 'pp_firstname' => 'FirstName',
- 'pp_lastname' => 'LastName',
- 'pp_dob' => 'dob',
- 'pp_email' => 'Email',
- 'pp_phone' => 'Phone',
- 'pp_street' => 'Street',
- 'pp_city' => 'City',
- 'pp_state' => 'State',
- 'pp_zip' => 'Zip',
- 'pp_country' => 'Country',
- );
- return $profile_mapping;
- }
/**
* Returns visible field count in user profile
@@ -124,13 +105,11 @@
static $field_count = null;
if (!isset($field_count)) {
- $profile_mapping = $this->getProfileMapping();
- $field_count = 0;
- foreach ($profile_mapping as $var_name => $field_name) {
- if ($this->recallUserProfileVar($var_name) == 1) {
- $field_count++;
- }
- }
+ $user =& $this->Application->recallObject( $this->getUserPrefixSpecial() );
+ /* @var $user kDBItem */
+
+ $display_to_public = $user->GetDBField('DisplayToPublic');
+ $field_count = $display_to_public ? substr_count($display_to_public, '|') - 1 : 0;
}
return $field_count;
@@ -158,10 +137,9 @@
*/
function prepareInputName($params)
{
- list ($id, $field) = parent::prepareInputName($params);
- $id = $this->Application->RecallVar('user_id');
+ $params['force_id'] = $this->Application->RecallVar('user_id');
- return Array($id, $field);
+ return parent::prepareInputName($params);
}
}
\ No newline at end of file
Index: units/users/users_config.php
===================================================================
--- units/users/users_config.php (revision 13812)
+++ units/users/users_config.php (working copy)
@@ -322,6 +322,21 @@
'show_pending' => Array('label' => 'la_Pending', 'on_sql' => '', 'off_sql' => '%1$s.Status != 2' ),
)
),
+ /**
+ * Required for depricated public profile templates to work
+ */
+ 'UserProfileMapping' => Array (
+ 'pp_firstname' => 'FirstName',
+ 'pp_lastname' => 'LastName',
+ 'pp_dob' => 'dob',
+ 'pp_email' => 'Email',
+ 'pp_phone' => 'Phone',
+ 'pp_street' => 'Street',
+ 'pp_city' => 'City',
+ 'pp_state' => 'State',
+ 'pp_zip' => 'Zip',
+ 'pp_country' => 'Country',
+ ),
'CalculatedFields' => Array(
'' => Array(
@@ -387,6 +402,16 @@
'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Language ORDER BY PackName', 'option_key_field' => 'LanguageId', 'option_title_field' => 'LocalName',
'default' => NULL
),
+ 'DisplayToPublic' => Array (
+ 'type' => 'string',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (
+ 'FirstName' => 'lu_fld_FirstName', 'LastName' => 'lu_fld_LastName', 'dob' => 'lu_fld_BirthDate',
+ 'Email' => 'lu_fld_Email', 'Phone' => 'lu_fld_Phone', 'Street' => 'lu_fld_AddressLine1',
+ 'Street2' => 'lu_fld_AddressLine2', 'City' => 'lu_fld_City', 'State' => 'lu_fld_State',
+ 'Zip' => 'lu_fld_Zip', 'Country' => 'lu_fld_Country',
+ ), 'use_phrases' => 1, 'multiple' => 1,
+ 'default' => NULL
+ ),
),
'VirtualFields' => Array(
|