<?php

if (!isset($gCms)) exit;


if (! $this->CheckPermission('Use Play'))
{
	return $this->ShowErrors($this->Lang('accessdenied'));
}

include_once dirname(__FILE__).'/class.record.php';
include_once dirname(__FILE__).'/class.player.php';
$checkffmpeg = $this->checkffmpeg();



echo $this->StartTabHeaders();
$active_tab = isset($params['active_tab']) ? $params['active_tab'] : false;
echo $this->SetTabHeader('records',$this->Lang('records'), ('records' == $active_tab));
echo $this->SetTabHeader('players',$this->Lang('players'), ('players' == $active_tab));
echo $this->SetTabHeader('ffmpeg',$this->Lang('ffmpeg'), ('ffmpeg' == $active_tab));
echo $this->EndTabHeaders();

echo $this->StartTabContent();
echo $this->StartTab('records', $params);

$records = getPlayRecords();
$items = array();
$rowclass = 'row1';


foreach ($records as $record)
{
	$row = new stdClass();
	$row->rowclass = $rowclass;
	$row->name = $record->name;
	$row->tag = '{cms_module module="Play" record="'.$record->id.'"}';
	$row->editlink = $this->CreateLink($id, 'editrecord', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/edit.gif', $this->Lang('editrecord'),'','','systemicon'), array('recordid' => $record->id));
	$row->copylink = $this->CreateLink($id, 'copyrecord', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/copy.gif', $this->Lang('copyrecord'),'','','systemicon'), array('recordid' => $record->id));
	$row->deletelink = $this->CreateLink($id, 'deleterecord', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/delete.gif', $this->Lang('deleterecord'),'','','systemicon'), array('recordid' => $record->id), $this->Lang('areyousure'));
	
	if (endswith($record->location,".flv") && $checkffmpeg)
	{
		$capturesize = @getimagesize($this->getthumb($record,$id,$returnid));
		$width = $capturesize[0];
		$height = $capturesize[1];
		if ($width>80) {$height = $height*80/$width;$width=80;}
		if ($width>60) {$width = $width*60/$height;$height=60;}
		$row->thumb = '<img src="'.$this->getthumb($record,$id,$returnid).'" alt="" width="'.$width.'" height="'.$height.'" />';
		//$row->thumb = '<img src="'.$this->CreateLink($id, 'grabpicture', $returnid, '', array('recordid'=>$record->id), '', true).'" alt="" />';
	}
	
	array_push($items, $row);
	$rowclass = ($rowclass=="row1" ? "row2" : "row1");
}

$this->smarty->assign_by_ref('items', $items);
$this->smarty->assign('itemcount', count($items));

$this->smarty->assign('addlink', $this->CreateLink($id, 'editrecord', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/newobject.gif', $this->Lang('editrecord'),'','','systemicon'), array('recordid'=>'new')) .' '. $this->CreateLink($id, 'editrecord', $returnid, $this->Lang('addrecord'), array('recordid'=>'new'), '', false, false, 'class="pageoptions"'));
echo $this->ProcessTemplate('recordlist.tpl');


echo $this->EndTab();

echo $this->StartTab('players', $params);

$players = getPlayPlayers();
$items = array();
$rowclass = 'row1';
foreach ($players as $player)
{
	$isused = false;
	$row = new stdClass();
	$row->rowclass = $rowclass;
	$row->name = $player->name;
	$row->editlink = $this->CreateLink($id, 'editplayer', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/edit.gif', $this->Lang('editplayer'),'','','systemicon'), array('playerid' => $player->id));
	$row->copylink = $this->CreateLink($id, 'copyplayer', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/copy.gif', $this->Lang('copyplayer'),'','','systemicon'), array('playerid' => $player->id));
	$isused = false;
	foreach ($records as $record) {if ($record->player == $player->id) {$isused = true;break;}}
	if (!$isused and !$player->islocked())
		$row->deletelink = $this->CreateLink($id, 'deleteplayer', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/delete.gif', $this->Lang('deleteplayer'),'','','systemicon'), array('playerid' => $player->id), $this->Lang('areyousure'));
	array_push($items, $row);
	$rowclass = ($rowclass=="row1" ? "row2" : "row1");
}

$this->smarty->assign_by_ref('items', $items);
$this->smarty->assign('itemcount', count($items));

$this->smarty->assign('addlink', $this->CreateLink($id, 'editplayer', $returnid, $gCms->variables['admintheme']->DisplayImage('icons/system/newobject.gif', $this->Lang('editplayer'),'','','systemicon'), array('playerid'=>'new')) .' '. $this->CreateLink($id, 'editplayer', $returnid, $this->Lang('addplayer'), array('playerid'=>'new'), '', false, false, 'class="pageoptions"'));
echo $this->ProcessTemplate('playerlist.tpl');

echo $this->EndTab();

echo $this->StartTab('ffmpeg', $params);

echo $this->CreateFormStart($id,"changeffmpeg",$returnid);
$this->smarty->assign('checkffmpeg', ($this->checkffmpeg() ? $this->lang('ffmpeg_checked') : $this->showerrors($this->lang('ffmpeg_notchecked'))));
$this->smarty->assign('ffmpegtext',$this->lang('ffmpeg_location'));
$this->smarty->assign('ffmpeginput',$this->createinputtext($id,'ffmpeg',$this->getpreference('ffmpeg','ffmpeg'),30));
$this->smarty->assign('submit', $this->CreateInputSubmit($id, 'submit', $this->lang('submit')));
echo $this->ProcessTemplate('ffmpeg.tpl');
echo $this->CreateFormEnd();


echo $this->EndTab();
echo $this->EndTabContent();

?>