Difference between revisions of "Carma trial"

From TMM Wiki
Jump to navigationJump to search
 
Line 28: Line 28:
 
$default_full_section = $params['default_full_section'];    //the section id of the main full member section
 
$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
 
$default_trial_section = $params['default_trial_section'];  //the section id of the main trial section
$siteid = $params['site'];
+
$siteid = $params['siteid'];
 
$sections = explode(',',$params['trial_sections']);
 
$sections = explode(',',$params['trial_sections']);
 
 

Latest revision as of 11:55, 22 June 2010

CARMA
Extras
The Support Admin
Admin Areas
CARMA Home
Pseudo Streaming
Flash Player
Using mp4 Videos
Zipping Content
Third Party Content
X-Sendfile
Xmoov-php
TMMid

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 see notes after sample code.


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['siteid'];
	$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;
}
?>


NATS 3 has a slightly different database so you will need to adjust the databse query. You should only 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 new line:

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