Index: trunk/core/units/general/my_application.php =================================================================== diff -u -r2320 -r2363 --- trunk/core/units/general/my_application.php (.../my_application.php) (revision 2320) +++ trunk/core/units/general/my_application.php (.../my_application.php) (revision 2363) @@ -76,6 +76,48 @@ unset($event); } } + + /** + * Raise specific events based on non-standard (no described in config files) + * params given in url if no other params are given + * @todo by now is called before $event_manager->ProcessRequrest() method anyway + * @author Alex + */ + function ProcessSpecialURL() + { + $affiliate = $this->GetVar('affiliate'); + if($affiliate) + { + $user_idfield = $this->getUnitOption('u','IDField'); + $user_table = $this->getUnitOption('u','TableName'); + $sql = 'SELECT %s FROM %s WHERE (CRC32(Email) = %s) AND (Status = 1)'; + $user_id = $this->DB->GetOne( sprintf($sql, $user_idfield, $user_table, $this->DB->qstr($affiliate) ) ); + + if($user_id) // user is found with such email + { + $affiliate_user = $this->recallObject('u.affiliate', null, Array('skip_autoload'=>true) ); + $affiliate_user->Load($user_id); + + $user_groups = $affiliate_user->getMembershipGroups(true); + $affiliate_group_id = $this->ConfigValue('Comm_AffiliateGroup'); + if( is_array($user_groups) && in_array($affiliate_group_id, $user_groups) ) // user is really affiliate for a moment + { + $affiliate_storage_method = $this->ConfigValue('Comm_AffiliateStorageMethod'); + switch($affiliate_storage_method) + { + case 1: // per session + $this->StoreVar('affiliate_id', $user_id); + break; + + case 2: // in cookie + setcookie('affiliate_id', $user_id); + break; + } + } + } + $this->Redirect(); + } + } } ?> \ No newline at end of file