Page 1 of 1

[solved] Building aTutorial for FEU/SelfRegistration/CompanyDirectory

Posted: Tue Oct 07, 2008 2:33 am
by kendo451
It seems many people post questions on how to use CompanyDirectory with FEU/SelfRegister so site members can edit their own company listing.  There isn't a complete tutorial post on how to do this, so I am trying to write a tutorial that takes you from A to Z all the steps to do it.

In order to do that I have to get my own working, and I could use some help on one thing.

Having setup FEU/CC/SelfRegister and CompanyDirectory, how do we create a new CompanyDirectory record for the newly registered user automatically?  I was thinking of using the username from FEU as the company_id in {CompanyDirectory}.

The question is, will this create a new entry, if the company_id doesn't exist?
{CompanyDirectory action='fe_edit' companyid=$ccuser->property('username')}

If not, is there a simple way to create a new CompanyDirectory record for a new SelfRegistered user, automatically - with no administrator interaction?

Re: Building aTutorial for FEU/SelfRegistration/CompanyDirectory

Posted: Tue Oct 07, 2008 12:16 pm
by kendo451
The answer is no.

In order to create a new CD record, you have to create a UDT.

Below is a UDT I cobbled together using elements from the CompanyDirectory module that creations a new record and adds the CD id to an FEUsers field called "cid".

I named it create_cd_record, and it takes two mandatory parameters: userID and company_name.  In my case, the business name is also part of the FEU properties, so here is the tag use to create a new CD record and update FEUsers with the new cid that is created:

{create_cd_record uid=$ccuser->loggedin() company_name=$ccuser->property('bname')}

And here is the code for the User Defined Tag:

Code: Select all

global $gCms;
$smarty =& $gCms->GetSmarty();
if( !isset($gCms) ) exit;

$config =& $gCms->GetConfig();
$db = &$gCms->db;

$feusers =& CMSModule::GetModuleInstance('FrontEndUsers');
if( !$feusers )
  {
    $error='Error: FrontEndUsers Module not found.';	
	return $error;
  }


$company_name = '';
if (isset($params['company_name']))
{
	$company_name = $params['company_name'];
}

if ($company_name != '')
	{
		$query = 'INSERT INTO '.cms_db_prefix().'module_compdir_companies (company_name, address, telephone, fax, contact_email, website, details, picture_location, logo_location, create_date, modified_date, status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)';
		$db->Execute($query, array($company_name, '', '', '', '', '', '', '', '', trim($db->DBTimeStamp(time()), "'"), trim($db->DBTimeStamp(time()), "'"), 'draft'));
		
		$cid = $db->Insert_ID();

		$result=$feusers->SetUserProperty('cid',$cid);
	
	}
	else
	{
		$error = 'Error: Parameter company_name is empty!';
		return $error;
	}

return;

Re: [solved] Building aTutorial for FEU/SelfRegistration/Com

Posted: Mon Jan 07, 2013 6:08 pm
by Milan J.
Hi,

this is the solution I've been looking for! Can you please let me know where exactly do I need to put the UDT?

I've placed it to User registration, but it doesn't work.

Thanks

Re: [solved] Building aTutorial for FEU/SelfRegistration/Com

Posted: Tue Jan 08, 2013 1:54 am
by calguy1000
There is no need for a UDT or anything now. There is sufficient information in the CompanyDirectory module's help and settings to setup this type of an environment.