Carma trial

From TMM Wiki
Revision as of 16:49, 3 March 2009 by Tmmdan (talk | contribs) (New page: Below is a sample smarty function for CARMA to verify if a NATS member is a trial or full member. The below code is meant as an example, you may need to adjust it to get it to work for y...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Below is a sample smarty function for CARMA to verify if a NATS member is a trial or full member. The below code is meant as an example, you may need to adjust it to get it to work for your setup. We can not provide tech support for this plugin as it is provided for free and without warranty. The below code is meant for NATS 4, for NATS 3 you have to replace this line:

		$res = mysql_query("SELECT trial FROM member WHERE siteid='{$siteid}' AND username='{$_SESSION[carma_username]}' AND status=1", $link);

with this line:

		$res = mysql_query("SELECT trial FROM members WHERE siteid='{$siteid}' AND username='{$_SESSION[carma_username]}' AND status=1", $link);


Sample Usage: If your CARMA trial sections were 4, 5, 7, with section 4 being the trial index page, full member index section of 0 and the NATS site id was 5 you would put this as the first line in your header templates: http://smarty.net/manual/en/plugins.php

{trial trial_sections='1,5,7' default_trial_section=0 default_full_section=4 siteid=5}


You also need to fill in your NATS database information below. For more information about smarty plugins please refer to the smarty website:


<?php

function smarty_function_trial($params, &$smarty) {

		//NATS DB login info
	$NATS_DB_HOST = 'localhost';
	$NATS_DB_NAME = 'nats';
	$NATS_DB_USER = 'username';
	$NATS_DB_PASSWORD = 'password';
	
	$default_full_section = $params['default_full_section'];    //the section id of the main full member section
	$default_trial_section = $params['default_trial_section'];  //the section id of the main trial section
	$siteid = $params['site'];
	$sections = explode(',',$params['trial_sections']);
		
	if(!isset($_SESSION['trial'])) {
		$link = mysql_connect($NATS_DB_HOST, $NATS_DB_USER, $NATS_DB_PASSWORD) or die('cant connect to db');
		mysql_select_db($NATS_DB_NAME) or die('cant select db');
		
		$res = mysql_query("SELECT trial FROM member WHERE siteid='{$siteid}' AND username='{$_SESSION[carma_username]}' AND status=1", $link);
		if(!mysql_num_rows($res))
			return;
			
		list($trial) = mysql_fetch_row($res);
		$_SESSION['trial'] = $trial;
	
	}
	else if($_REQUEST['full'] == 1 && $_SESSION['trial'] == 1){
		$_SESSION['trial'] = 0;
	}
	
	
	if($_SESSION['trial'] && !in_array($_REQUEST['section'], $sections)) {
		header("Location: {$_SERVER['HTTP_HOST']}index.php?section={$default_trial_section}");
	}
	if(!$_SESSION['trial'] && in_array($_REQUEST['section'], $sections)) {
		header("Location: {$_SERVER['HTTP_HOST']}index.php?section={$default_full_section}");
	}

	return;
}
?>