<?php
function userID()
{
	return _session('user_id');
}

function isAdmin()
{
	global $const_user_admin;
	return (_session('user_type_id')==$const_user_admin)?true:false;
}

function isCustomer()
{
	global $const_user_customer;	
	return (_session('user_type_id')==$const_user_customer)?true:false;
}

function notCustomer()
{
	global $const_user_customer;	
	return (_session('user_type_id')!=$const_user_customer)?true:false;
}

function isPartner()
{
	global $const_user_partner;	
	return (_session('user_type_id')==$const_user_partner)?true:false;
}
function isPartcustomer()
{
	global $const_user_partner;
		global $const_user_customer;
	return ((_session('user_type_id')==$const_user_partner) || (_session('user_type_id')==$const_user_customer))?true:false;
}

function isBookPartner()
{
	global $const_user_partner;	
	global $const_partner_book;
	return (_session('user_type_id')==$const_user_partner && in_array($const_partner_book,_session('partner_type_id')))?true:false;
}

function isEventPartner()
{
	global $const_user_partner;	
	global $const_partner_event;
	return (_session('user_type_id')==$const_user_partner && in_array($const_partner_event,_session('partner_type_id')))?true:false;
}

function isTVPartner()
{
	global $const_user_partner;	
	global $const_partner_tv;	
	return (_session('user_type_id')==$const_user_partner && in_array($const_partner_tv,_session('partner_type_id')))?true:false;
}

function isWebTVPartner()
{
	global $const_user_partner;	
	global $const_partner_webtv;	
	return (_session('user_type_id')==$const_user_partner && in_array($const_partner_webtv,_session('partner_type_id')))?true:false;
}
function isAnyTypeTVPartner()
{
	global $const_user_partner;	
	global $const_partner_tv;	
	global $const_partner_webtv;
	return (_session('user_type_id')==$const_user_partner && (in_array($const_partner_tv,_session('partner_type_id')) || in_array($const_partner_webtv,_session('partner_type_id'))))?true:false;
}


function isKhanaPartner()
{
	global $const_user_partner;	
	global $const_partner_khana;		
	return (_session('user_type_id')==$const_user_partner && in_array($const_partner_khana,_session('partner_type_id')))?true:false;
}

function isDealPartner()
{
	global $const_user_partner;	
	global $const_partner_deal;	
	return (_session('user_type_id')==$const_user_partner && in_array($const_partner_deal,_session('partner_type_id')))?true:false;
}

function isFashionPartner()
{
	global $const_user_partner;	
	global $const_partner_fashion;		
	return (_session('user_type_id')==$const_user_partner && in_array($const_partner_fashion,_session('partner_type_id')))?true:false;
}

function movieManager()
{
	return (isAdmin() || isMoviePartner())?true:false;
}

function bookManager()
{
	return (isAdmin() || isBookPartner())?true:false;
}

function tvManager()
{
	return (isAdmin() || isTVPartner())?true:false;
}

function webtvManager()
{
	return (isAdmin() || isWebTVPartner())?true:false;
}

function khanaManager()
{
	return (isAdmin() || isKhanaPartner())?true:false;
}

function dealManager()
{
	return (isAdmin() || isDealPartner())?true:false;
}

function fashionManager()
{
	return (isAdmin() || isFashionPartner())?true:false;
}
function dealsAllowed()
{
	return (isCustomer() || isAdmin() || isMoviePartner() || isTVPartner() || isWebTVPartner() || dealManager())?true:false;
}
function welcomeMail($emailID,$emailName,$bottomBanner,$bottomBannerLink)
{
	global $const_website_email;
	global $const_website_title;
	global $const_logo_url;
	global $const_website_url;
	global $const_website_email_name;
	global $mailer;
	
	_initPHPMailer();
				
	$mailer->SMTPDebug	= false;
	$mailer->setTo($emailID, $emailName);
	$mailer->setFrom($const_website_email,$const_website_title);
	$mailer->Subject			= "Welcome to ".$const_website_title;
	$mailer->template			= _emailTempate("welcome.tpl");
	
    foreach($bottomBanner as $key => $bottom_ban)
    		    {
    			    $mailer->data["bottomBanner".$key]	= $bottom_ban;
    			    $mailer->data["bottomBannerLink".$key]	=  $bottomBannerLink[$key];
    		    }

			
	$mailer->data["logo"]		= $const_logo_url;
	$mailer->data["name"]		= $emailName;
	$mailer->data["emailID"]	= $emailID;
	$mailer->data["siteName"]	= $const_website_title;
	$mailer->data["siteTeam"]	= $const_website_email_name;	
	$mailer->data["url"]		= $const_website_url."/login";
	$mailer->Send();
	$mailer->clear();	
}

function imageUpload($name,$resolutionArr)
{
	if($_FILES[$name]["tmp_name"]!='')
	{	
		$fileInfo = _contentUpload(date("Y")."/".date("m"),$name,'../');

		if($fileInfo && sizeof($resolutionArr))
		{
			foreach($resolutionArr as $each)
			{
				if($each["height"])
				createImageNew($fileInfo["path"].$fileInfo["originalFilename"],$each["width"]."x".$each["height"],$fileInfo["path"],$each["prefix"].$fileInfo["originalFilename"]);
				else		
				createImage($fileInfo["path"].$fileInfo["originalFilename"],$each["width"],$fileInfo["path"].$each["prefix"].$fileInfo["originalFilename"],false);
			}

			return 
			CMS::tables('images')
			->insert([ 
				"file"=>$fileInfo["filename"], 
				"ofile"=>$fileInfo["originalFilename"], 
				"year"=>date("Y"), 
				"month"=>date("m")				
			]);
		}
	}	
}

function imageDelete($img_id,$resolutionArr)
{
	global $setting_uploadPath;
	global $setting_publicPath;
	global $const_website_root_absPath;
	
	$file = CMS::tables('images')->where('id',$img_id);

	if($info = $file->first()->get())
	{
		$img = $info[year].'/'.$info[month].'/';
			
		if(sizeof($resolutionArr)) {
			
			foreach($resolutionArr as $each)
			_deleteFiles($const_website_root_absPath.$setting_publicPath.'/'.$setting_uploadPath."/".$img.$each["prefix"].$info[ofile]);
		}
		_deleteFiles($const_website_root_absPath.$setting_publicPath.'/'.$setting_uploadPath."/".$img.$info[ofile]);

		$file->delete();
		
		if(_isFolderEmpty($const_website_root_absPath.$setting_publicPath.'/'.$setting_uploadPath."/".$img))
			_deleteFiles($const_website_root_absPath.$setting_publicPath.'/'.$setting_uploadPath."/".$img);		
	}
}
?>