<?php
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');

$thisplugin->add_filter('file_data','special_edit_button');
function special_edit_button($info)
{
	if(special_edit_authenticate())
	{
		if($info['menu'] == "")
		{
			$info['menu'] = '<a href="index.php?file=special_edit/edit&id=' . $info['pid'] . '" class="admin_menu">Edit file information</a>';
		}
	}	
	return $info;	
}

function special_edit_authenticate()
{
	global $CONFIG;
	$result = cpg_db_query("SELECT g.group_id FROM {$CONFIG['TABLE_USERGROUPS']} AS g WHERE g.group_name = 'Caption'");
	$row = mysql_fetch_array($result);
	$CaptionMod['access_group_id'] = $row['group_id'];
	mysql_free_result($result);
	unset($row);

	$userID = (USER_ID);
	
	$result = cpg_db_query("SELECT u.user_group, u.user_group_list FROM {$CONFIG['TABLE_USERS']} AS u WHERE u.user_id = '{$userID}' ");
	$row = mysql_fetch_array($result);
	$CaptionMod['user_group_list'] = 			$row['user_group_list'];
	$CaptionMod['user_group'] = 				$row['user_group'];
	mysql_free_result($result);
	unset($row);

	$user_group_list_array = explode(",", $CaptionMod['user_group_list']);
	$num_of_groups = count($user_group_list_array);
	
	$access = false;
	
	for ($iq=0;$iq<$num_of_groups;$iq++)
	{
		if ($user_group_list_array[$iq] == $CaptionMod['access_group_id'])
		{
			$access = true;
		}
	}
	
	if ($CaptionMod['user_group'] == $CaptionMod['access_group_id'])
	{
		$access = true;
	}
	return $access;
}
?>