<?php

include 'sproutvideo.php';

function register#record#video(){
	global $db;
	
	$#primarykey#=GETVAL('#primarykey#');
	$videokey=SGET('videokey');
	$videotoken=SGET('videotoken');
	
	//remove existing video
	$query="select * from #table# where #primarykey#=? and videokey!=''";
	$rs=sql_prep($query,$db,$#primarykey#);
	if ($myrow=sql_fetch_assoc($rs)){
		$oldkey=$myrow['videokey'];
		sproutvideo_delete($oldkey);
		logaction("removed a previous version of #c_record# #$#primarykey#",array('#primarykey#'=>$#primarykey#),array('rectype'=>'#record#video','recid'=>$#primarykey#));
	}
	
	
	$query="update #table# set videokey=?, videotoken='$videotoken', videostatus=0 where #primarykey#=?";
	sql_prep($query,$db,array($videokey,$#primarykey#));
	
	echo "#c_record# #$#primarykey# successfully uploaded as Video $videokey";	
	logaction("uploaded a video for #c_record# #$#primarykey#",array('#primarykey#'=>$#primarykey#),array('rectype'=>'#record#video','recid'=>$#primarykey#));
}
