<?php
/**
 * File handling ansVideoPlayerSettings
 *
 * PHP version 5.0
 *
 * @category	###Anova###
 * @package		###Ans videoplayer settings###
 * @author 		karthiselvam_75ag08
 * @copyright	Copyright (c) 2009 {@link http://www.agriya.com Agriya Infoway}
 * @license		http://www.agriya.com Agriya Infoway Licence
 * @version		SVN: $Id:
 * @since 		2008-12-23
 */
require_once('../../common/configs/config.inc.php');
$CFG['lang']['include_files'][] = 'languages/%s/'.$CFG['admin']['index']['anova_module'].'/admin/ansVideoPlayerSettings.php';
$CFG['html']['header'] = 'admin/html_header.php';
$CFG['html']['footer'] = 'admin/html_footer.php';

$CFG['mods']['include_files'][] = 'common/classes/class_AnovaHandler.lib.php';

//compulsory
$CFG['site']['is_module_page'] = $CFG['admin']['index']['anova_module'];
$CFG['mods']['is_include_only']['html_header'] = false;
$CFG['html']['is_use_header'] = false;
/**
 * To include application top file
 */
require($CFG['site']['project_path'].'common/application_top.inc.php');
class AddBookmark extends AnovaHandler
	{
		/**
		 * AddBookmark::resetFieldsArray()
		 *
		 * @return
		 */
		public function resetFieldsArray()
			{
				$this->setFormField('play_settings', 1);
				$this->setFormField('title', 0);
				$this->setFormField('share_link', 0);
				$this->setFormField('repeat_link', 1);
				$this->setFormField('skin', '');
				$this->setFormField('play_list_settings', 0);
				$this->setFormField('show_play_list_by', 'tags');
			}

		/**
		 * AddBookmark::getSkinArray()
		 *
		 * @return
		 */
		public function getSkinArray()
			{
				if ($handle = opendir('../../'.$this->CFG['admin']['flv']['skin_path']))
					{
					    $skin_array = array();
						while (false !== ($file = readdir($handle)))
							{
						        if ($file != "." && $file != ".." && strstr($file, '.xml') && !strstr($file, 'config.xml'))
									{
							            $file = str_replace('.xml', '', $file);
										$skin_array[$file] = $file;
							        }
						    }
					    closedir($handle);
						return $skin_array;
					}
			}

		/**
		 * AddBookmark::updateTable()
		 *
		 * @return
		 */
		public function updateTable()
			{
				$array = array($this->fields_arr['play_settings'], $this->fields_arr['title'],
							$this->fields_arr['share_link'], $this->fields_arr['repeat_link'],
							$this->fields_arr['skin'], $this->fields_arr['play_list_settings'],
							$this->fields_arr['show_play_list_by']);
				$sql = 'SELECT 1 FROM '.$this->CFG['db']['tbl']['ans_video_player_settings'];

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					trigger_db_error($this->dbObj);

				if($rs->PO_RecordCount())
					{
						$sql = 'UPDATE '.$this->CFG['db']['tbl']['ans_video_player_settings'].' SET'.
								' play_settings='.$this->dbObj->Param('play_settings').','.
								' title='.$this->dbObj->Param('title').','.
								' share_link='.$this->dbObj->Param('share_link').','.
								' repeat_link='.$this->dbObj->Param('repeat_link').','.
								' skin='.$this->dbObj->Param('skin').','.
								' play_list_settings='.$this->dbObj->Param('play_list_settings').','.
								' show_play_list_by='.$this->dbObj->Param('show_play_list_by').','.
								' date_added=NOW()';

						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, $array);
						if (!$rs)
							trigger_db_error($this->dbObj);
					}
				else
					{
						$sql = 'INSERT INTO '.$this->CFG['db']['tbl']['ans_video_player_settings'].' SET'.
								' play_settings='.$this->dbObj->Param('play_settings').','.
								' title='.$this->dbObj->Param('title').','.
								' share_link='.$this->dbObj->Param('share_link').','.
								' repeat_link='.$this->dbObj->Param('repeat_link').','.
								' skin='.$this->dbObj->Param('skin').','.
								' play_list_settings='.$this->dbObj->Param('play_list_settings').','.
								' show_play_list_by='.$this->dbObj->Param('show_play_list_by').','.
								' date_added=NOW()';

						$stmt = $this->dbObj->Prepare($sql);
						$rs = $this->dbObj->Execute($stmt, $array);
						if (!$rs)
							trigger_db_error($this->dbObj);
					}
			}

		/**
		 * AddBookmark::populateSettings()
		 *
		 * @return
		 */
		public function populateSettings()
			{
				$sql = 'SELECT play_settings, title, share_link, repeat_link, skin, play_list_settings, show_play_list_by'.
						' FROM '.$this->CFG['db']['tbl']['ans_video_player_settings'];

				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt);
				if (!$rs)
					trigger_db_error($this->dbObj);

				if($row = $rs->FetchRow())
					{
						$this->fields_arr['play_settings'] = $row['play_settings'];
						$this->fields_arr['title'] = $row['title'];
						$this->fields_arr['share_link'] = $row['share_link'];
						$this->fields_arr['repeat_link'] = $row['repeat_link'];
						$this->fields_arr['skin'] = $row['skin'];
						$this->fields_arr['play_list_settings'] = $row['play_list_settings'];
						$this->fields_arr['show_play_list_by'] = $row['show_play_list_by'];
					}
			}
	}
//<<<<<-------------- Class AddBookmark begins ---------------//
//-------------------- Code begins -------------->>>>>//
$PlayerSettings = new AddBookmark();
$PlayerSettings->left_navigation_div = 'anovaVideoPlayer';
$PlayerSettings->setPageBlockNames(array('playerSettingsBlock'));
//default form fields and values...
$PlayerSettings->setAllPageBlocksHide();
$PlayerSettings->setPageBlockShow('playerSettingsBlock');
$PlayerSettings->skin_array = $PlayerSettings->getSkinArray();
$PlayerSettings->resetFieldsArray();
$PlayerSettings->sanitizeFormInputs($_REQUEST);
if(isDemoSite() AND $PlayerSettings->isFormPOSTed($_POST, 'update'))
	{
		$PlayerSettings->setCommonErrorMsg($LANG['no_permission_for_demo_user']);
		$PlayerSettings->setPageBlockShow('block_msg_form_error');
	}
elseif($PlayerSettings->isFormPOSTed($_POST, 'update'))
	{
		$PlayerSettings->updateTable();
		$PlayerSettings->setCommonSuccessMsg($LANG['msg_success_updated']);
		$PlayerSettings->setPageBlockShow('block_msg_form_success');
	}
else
	{
		$PlayerSettings->populateSettings();
	}
//<<<<<-------------------- Code ends----------------------//
//-------------------- Page block templates begins -------------------->>>>>//
//include the header file
$PlayerSettings->includeHeader();
//include the content of the page
setTemplateFolder('admin/', $CFG['admin']['index']['anova_module']);
$smartyObj->display('ansvideoPlayerSettings.tpl');
//includ the footer of the page
//<<<<<-------------------- Page block templates ends -------------------//
$PlayerSettings->includeFooter();
?>