Index: admin_templates/user_selector.tpl =================================================================== --- admin_templates/user_selector.tpl (revision 15437) +++ admin_templates/user_selector.tpl (working copy) @@ -49,7 +49,7 @@ Index: install/install_data.sql =================================================================== --- install/install_data.sql (revision 15552) +++ install/install_data.sql (working copy) @@ -114,7 +114,7 @@ # Section "in-portal:configure_users": INSERT INTO SystemSettings VALUES(DEFAULT, 'User_Allow_New', '3', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_users_allow_new', 'radio', '', '1=la_opt_UserInstantRegistration||2=la_opt_UserNotAllowedRegistration||3=la_opt_UserUponApprovalRegistration||4=la_opt_UserEmailActivation', 10.01, 0, 1, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'AdvancedUserManagement', '0', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_prompt_AdvancedUserManagement', 'checkbox', NULL, NULL, 10.011, 0, 1, NULL); -INSERT INTO SystemSettings VALUES(DEFAULT, 'RegistrationUsernameRequired', '1', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_config_RegistrationUsernameRequired', 'checkbox', NULL, NULL, 10.02, 0, 0, NULL); +INSERT INTO SystemSettings VALUES(DEFAULT, 'RegistrationUsernameRequired', '0', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_config_RegistrationUsernameRequired', 'checkbox', NULL, NULL, 10.02, 0, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'RegistrationCaptcha', '0', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_registration_captcha', 'checkbox', NULL, NULL, 10.025, 0, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'Min_UserName', '3', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_text_min_username', 'text', '', 'style="width: 50px;"', 10.03, 1, 0, NULL); INSERT INTO SystemSettings VALUES(DEFAULT, 'MaxUserName', '', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_text_min_username', 'text', '', 'style="width: 50px;"', 10.03, 2, 0, NULL); Index: kernel/constants.php =================================================================== --- kernel/constants.php (revision 15437) +++ kernel/constants.php (working copy) @@ -131,6 +131,7 @@ define('SUBMISSION_LOG_ATTACHMENT_PATH', WRITEBALE_BASE . '/user_files/submission_log/'); define('TIMENOW', adodb_mktime()); // for faster message processing + define('USER_TITLE_FIELD', 'IF(Email = "", Username, Email)'); // site domains define('SITE_DOMAIN_REDIRECT_CURRENT', 1); Index: kernel/db/cat_event_handler.php =================================================================== --- kernel/db/cat_event_handler.php (revision 15437) +++ kernel/db/cat_event_handler.php (working copy) @@ -2174,21 +2174,7 @@ $object = $event->getObject(); /* @var $object kDBItem */ - $user_id = $object->GetDBField($id_field); - $options = $object->GetFieldOptions($id_field); - - if ( isset($options['options'][$user_id]) ) { - $object->SetDBField($cached_field, $options['options'][$user_id]); - } - else { - $id_field = $this->Application->getUnitOption('u', 'IDField'); - $table_name = $this->Application->getUnitOption('u', 'TableName'); - - $sql = 'SELECT Username - FROM ' . $table_name . ' - WHERE ' . $id_field . ' = ' . $user_id; - $object->SetDBField($cached_field, $this->Conn->GetOne($sql)); - } + $object->SetDBField($cached_field, $object->GetField($id_field)); } /** Index: kernel/utility/formatters/left_formatter.php =================================================================== --- kernel/utility/formatters/left_formatter.php (revision 15437) +++ kernel/utility/formatters/left_formatter.php (working copy) @@ -46,7 +46,10 @@ if ( !isset($options['options'][$value]) ) { // required option is not defined in config => query for it - $sql = sprintf($options['left_sql'], $options['left_title_field'], $options['left_key_field'], $this->Conn->escape($value)); + $display_field = $this->_escapeField($options['left_title_field']); + $match_field = $this->_escapeField($options['left_key_field']); + + $sql = sprintf($options['left_sql'], $display_field, $match_field . ' = ' . $this->Conn->qstr($value)); $options['options'][$value] = $this->Conn->GetOne($sql); if ( $options['options'][$value] === false ) { @@ -58,6 +61,22 @@ } /** + * Escape field names, but not expressions + * + * @param string $field_name + * @return string + * @access protected + */ + protected function _escapeField($field_name) + { + if ( preg_match('/^[a-z_]+$/i', $field_name) ) { + return '`' . $field_name . '`'; + } + + return $field_name; + } + + /** * Performs basic type validation on form field value * * @param mixed $value @@ -81,7 +100,10 @@ } // requested option is not found in field options -> query for it - $sql = sprintf($options['left_sql'], $options['left_key_field'], $options['left_title_field'], $this->Conn->escape($value)); + $display_field = $this->_escapeField($options['left_key_field']); + $match_field = $this->_escapeField($options['left_title_field']); + + $sql = sprintf($options['left_sql'], $display_field, $match_field . ' = ' . $this->Conn->qstr($value)); $found = $this->Conn->GetOne($sql); if ( $found !== false ) { @@ -90,7 +112,7 @@ } $skip_errors = array_key_exists('skip_errors', $options) && $options['skip_errors']; - + if ( $found === false && !$skip_errors ) { // option not found at all -> return not formatted value & set error $object->SetError($field_name, 'invalid_option', 'la_error_InvalidOption'); Index: units/categories/categories_config.php =================================================================== --- units/categories/categories_config.php (revision 15471) +++ units/categories/categories_config.php (working copy) @@ -327,7 +327,7 @@ 'MetaKeywords' => Array ('type' => 'string', 'formatter' => 'kFormatter', 'using_fck' => 1, 'default' => null), 'CachedDescendantCatsQty' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), 'CachedNavbar' => Array ('type' => 'string', 'formatter' => 'kMultiLanguage', 'default' => null), - 'CreatedById' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'default' => NULL), + 'CreatedById' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'default' => NULL), 'ResourceId' => Array ('type' => 'int', 'default' => null), 'ParentPath' => Array ('type' => 'string', 'default' => null), 'TreeLeft' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), @@ -339,7 +339,7 @@ 'NewItem' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (2 => 'la_Auto', 1 => 'la_Always', 0 => 'la_Never'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 2), 'PopItem' => Array ('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (2 => 'la_Auto', 1 => 'la_Always', 0 => 'la_Never'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 2), 'Modified' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'), - 'ModifiedById' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'default' => NULL), + 'ModifiedById' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'default' => NULL), 'CachedTemplate' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''), 'CachedTemplateHash' => Array ('type' => 'string', 'not_null' => 1, 'default' => 0), Index: units/helpers/page_helper.php =================================================================== --- units/helpers/page_helper.php (revision 15437) +++ units/helpers/page_helper.php (working copy) @@ -32,7 +32,7 @@ 'pr.IsDraft = 1', ); - $sql = 'SELECT CASE pr.CreatedById WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE u.Username END + $sql = 'SELECT CASE pr.CreatedById WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(u.Username = "", u.Email, u.Username) END FROM ' . $this->Application->getUnitOption('page-revision', 'TableName') . ' pr LEFT JOIN ' . TABLE_PREFIX . 'Users u ON u.PortalUserId = pr.CreatedById WHERE (' . implode(') AND (', $where_clause) . ')'; Index: units/logs/system_logs/system_logs_config.php =================================================================== --- units/logs/system_logs/system_logs_config.php (revision 15552) +++ units/logs/system_logs/system_logs_config.php (working copy) @@ -86,7 +86,7 @@ 'CalculatedFields' => Array ( '' => Array ( - 'Username' => 'CASE %1$s.LogUserId WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(u.FirstName, u.LastName) <> "", CONCAT(u.FirstName, " ", u.LastName), u.Username) END', + 'Username' => 'CASE %1$s.LogUserId WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(u.FirstName, u.LastName) <> "", CONCAT(u.FirstName, " ", u.LastName), IF(u.Username = "", u.Email, u.Username)) END', ), ), Index: units/mailing_lists/mailing_lists_config.php =================================================================== --- units/mailing_lists/mailing_lists_config.php (revision 15461) +++ units/mailing_lists/mailing_lists_config.php (working copy) @@ -98,7 +98,8 @@ 'type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array (USER_ROOT => 'root'), - 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', + 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE %s', + 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'required' => 1, 'not_null' => 1, 'default' => USER_ROOT, ), Index: units/page_revisions/page_revisions_config.php =================================================================== --- units/page_revisions/page_revisions_config.php (revision 15437) +++ units/page_revisions/page_revisions_config.php (working copy) @@ -57,7 +57,7 @@ 'CalculatedFields' => Array ( '' => Array ( - 'CreatedBy' => 'created_by.Username', + 'CreatedBy' => 'IF(created_by.Username = "", created_by.Email, created_by.Username)', 'IsLive' => 'IF(%1$s.RevisionNumber = c.LiveRevisionNumber, 1, 0)', ), ), @@ -74,7 +74,7 @@ 'FromRevisionId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), 'CreatedById' => Array ( 'type' => 'int', - 'formatter' => 'kLEFTFormatter', 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'sample_value' => 'Guest', 'required' => 1, + 'formatter' => 'kLEFTFormatter', 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'sample_value' => 'Guest', 'required' => 1, 'default' => NULL ), 'CreatedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'), Index: units/reviews/reviews_config.php =================================================================== --- units/reviews/reviews_config.php (revision 15437) +++ units/reviews/reviews_config.php (working copy) @@ -138,10 +138,8 @@ 'type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), - 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users - WHERE `%s` = \'%s\' ', - 'left_key_field' => 'PortalUserId', - 'left_title_field' => 'Username', + 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE %s', + 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'required' => 1, 'default' => NULL, 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), ), Index: units/spam_reports/spam_reports_config.php =================================================================== --- units/spam_reports/spam_reports_config.php (revision 15437) +++ units/spam_reports/spam_reports_config.php (working copy) @@ -64,7 +64,7 @@ 'CalculatedFields' => Array ( '' => Array ( 'ItemName' => 'IF(%1$s.ItemPrefix LIKE "%rev", review.ReviewText, "")', - 'ReportedBy' => 'reported_by.Username', + 'ReportedBy' => 'IF(reported_by.Username = "", reported_by.Email, reported_by.Username)', ), ), @@ -86,7 +86,7 @@ 'ReportedOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'), 'ReportedById' => Array ( 'type' => 'int', - 'formatter' => 'kLEFTFormatter', 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'sample_value' => 'Guest', + 'formatter' => 'kLEFTFormatter', 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'sample_value' => 'Guest', 'default' => NULL ) ), Index: units/structure/structure_config.php =================================================================== --- units/structure/structure_config.php (revision 15437) +++ units/structure/structure_config.php (working copy) @@ -141,7 +141,7 @@ 'MetaKeywords' => Array('type' => 'string', 'default' => null), 'CachedDescendantCatsQty' => Array('type' => 'int', 'not_null' => 1, 'default' => 0), 'CachedNavbar' => Array('type' => 'string', 'formatter' => 'kMultiLanguage', 'default' => null), - 'CreatedById' => Array('type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array(USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'default' => NULL), + 'CreatedById' => Array('type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array(USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'default' => NULL), 'ResourceId' => Array('type' => 'int', 'default' => null), 'ParentPath' => Array('type' => 'string', 'default' => null), 'TreeLeft' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0), @@ -153,7 +153,7 @@ 'NewItem' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (2 => 'la_Auto', 1 => 'la_Always', 0 => 'la_Never'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 2), 'PopItem' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (2 => 'la_Auto', 1 => 'la_Always', 0 => 'la_Never'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 2), 'Modified' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'), - 'ModifiedById' => Array('type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array(USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'default' => NULL), + 'ModifiedById' => Array('type' => 'int', 'formatter' => 'kLEFTFormatter', 'options' => Array(USER_ROOT => 'root', USER_GUEST => 'Guest'),'left_sql'=>'SELECT %s FROM '.TABLE_PREFIX.'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'default' => NULL), 'CachedTemplate' => Array('type' => 'string', 'not_null' => 1, 'default' => ''), 'CachedTemplateHash' => Array ('type' => 'string', 'not_null' => 1, 'default' => 0), Index: units/system_event_subscriptions/system_event_subscriptions_config.php =================================================================== --- units/system_event_subscriptions/system_event_subscriptions_config.php (revision 15437) +++ units/system_event_subscriptions/system_event_subscriptions_config.php (working copy) @@ -80,7 +80,7 @@ '' => Array ( 'BindToSystemEvent' => 'ee.BindToSystemEvent', 'EmailEventName' => 'ee.Event', - 'Username' => 'CASE %1$s.UserId WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(u.FirstName, u.LastName) <> "", CONCAT(u.FirstName, " ", u.LastName), IF(%1$s.UserId IS NULL, "Guest", u.Username)) END', + 'Username' => 'CASE %1$s.UserId WHEN ' . USER_ROOT . ' THEN "root" WHEN ' . USER_GUEST . ' THEN "Guest" ELSE IF(CONCAT(u.FirstName, u.LastName) <> "", CONCAT(u.FirstName, " ", u.LastName), IF(%1$s.UserId IS NULL, "Guest", IF(u.Username = "", u.Email, u.Username))) END', 'CategoryName' => 'c.l%2$s_Name', 'ItemName' => '%1$s.ItemId', 'ParentItemName' => '%1$s.ParentItemId', @@ -101,7 +101,7 @@ 'required' => 1, 'default' => NULL ), 'SubscriberEmail' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), - 'UserId' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE `%s` = \'%s\'', 'left_key_field' => 'PortalUserId', 'left_title_field' => 'Username', 'default' => NULL), + 'UserId' => Array ('type' => 'int', 'formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (USER_ROOT => 'root', USER_GUEST => 'Guest'), 'left_sql' => 'SELECT %s FROM ' . TABLE_PREFIX . 'Users WHERE %s', 'left_key_field' => 'PortalUserId', 'left_title_field' => USER_TITLE_FIELD, 'default' => NULL), 'CategoryId' => Array ('type' => 'int', 'default' => NULL), 'IncludeSublevels' => Array ( 'type' => 'int', Index: units/user_groups/user_groups_config.php =================================================================== --- units/user_groups/user_groups_config.php (revision 15437) +++ units/user_groups/user_groups_config.php (working copy) @@ -37,7 +37,7 @@ 'CalculatedFields' => Array ( '' => Array( 'UserName' => 'CONCAT(u.LastName, \' \', u.FirstName)', - 'UserLogin' => 'u.Username', + 'UserLogin' => 'IF(u.Username = "", u.Email, u.Username)', 'PrimaryGroup' => 'IF(u.PrimaryGroupId = %1$s.GroupId, 1, 0)', ), ), Index: units/users/users_tag_processor.php =================================================================== --- units/users/users_tag_processor.php (revision 15517) +++ units/users/users_tag_processor.php (working copy) @@ -359,4 +359,19 @@ $user_helper->loginUserById( $login_user->GetID() ); } } + + /** + * Returns user selector title + * + * @param Array $params + * @return string + * @access protected + */ + protected function UserSelectorTitle($params) + { + $object = $this->getObject($params); + /* @var $object kDBItem */ + + return $object->GetDBField('Email') ? $object->GetDBField('Email') : $object->GetDBField('Username'); + } } \ No newline at end of file Index: units/visits/visits_config.php =================================================================== --- units/visits/visits_config.php (revision 15437) +++ units/visits/visits_config.php (working copy) @@ -85,11 +85,11 @@ 'CalculatedFields' => Array ( '' => Array ( - 'UserName' => 'IF( ISNULL(u.Username), IF (%1$s.PortalUserId = ' . USER_ROOT . ', \'root\', IF (%1$s.PortalUserId = ' . USER_GUEST . ', \'Guest\', \'n/a\')), u.Username)', + 'UserName' => 'IF( ISNULL(u.Username), IF (%1$s.PortalUserId = ' . USER_ROOT . ', \'root\', IF (%1$s.PortalUserId = ' . USER_GUEST . ', \'Guest\', \'n/a\')), IF(u.Username = "", u.Email, u.Username))', ), 'incommerce' => Array ( - 'UserName' => 'IF( ISNULL(u.Username), IF (%1$s.PortalUserId = ' . USER_ROOT . ', \'root\', IF (%1$s.PortalUserId = ' . USER_GUEST . ', \'Guest\', \'n/a\')), u.Username)', - 'AffiliateUser' => 'IF( LENGTH(au.Username),au.Username,\'!la_None!\')', + 'UserName' => 'IF( ISNULL(u.Username), IF (%1$s.PortalUserId = ' . USER_ROOT . ', \'root\', IF (%1$s.PortalUserId = ' . USER_GUEST . ', \'Guest\', \'n/a\')), IF(u.Username = "", u.Email, u.Username))', + 'AffiliateUser' => 'IF(au.PortalUserId IS NULL, "!la_None!", IF(au.Username = "", au.Email, au.Username))', 'AffiliatePortalUserId' => 'af.PortalUserId', 'OrderTotalAmount' => 'IF(ord.Status = 4, ord.SubTotal+ord.ShippingCost+ord.VAT, 0)', 'OrderAffiliateCommission' => 'IF(ord.Status = 4, ord.AffiliateCommission, 0)', @@ -133,7 +133,7 @@ 'VisitDate' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'custom_filter' => 'date_range', 'default' => NULL), 'Referer' => Array ('type' => 'string','not_null' => '1','default' => ''), 'IPAddress' => Array ('type' => 'string','not_null' => '1','default' => ''), - 'AffiliateId' => Array ('type' => 'int','formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (0 => 'lu_None'), 'left_sql' => 'SELECT %s FROM '.TABLE_PREFIX.'Affiliates af LEFT JOIN '.TABLE_PREFIX.'Users pu ON pu.PortalUserId = af.PortalUserId WHERE `%s` = \'%s\'','left_key_field' => 'AffiliateId','left_title_field' => 'Username','not_null'=>1,'default'=>0), + 'AffiliateId' => Array ('type' => 'int','formatter' => 'kLEFTFormatter', 'error_msgs' => Array ('invalid_option' => '!la_error_UserNotFound!'), 'options' => Array (0 => 'lu_None'), 'left_sql' => 'SELECT %s FROM '.TABLE_PREFIX.'Affiliates af LEFT JOIN '.TABLE_PREFIX.'Users u ON u.PortalUserId = af.PortalUserId WHERE %s','left_key_field' => 'AffiliateId','left_title_field' => 'IF(u.Email = "", u.Username, u.Email)','not_null'=>1,'default'=>0), 'PortalUserId' => Array ('type' => 'int','not_null' => '1','default' => USER_GUEST), ),