<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Video extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		$this->load->model('users_model');
		$this->load->helper('common_helper');
		$this->load->helper('text');
		if(get_cookie('admin_id'))
		{
			$this->session->set_userdata('admin_id',get_cookie('admin_id'));
		}
		//echo $this->session->userdata('admin_id'); print_r($this->session->userdata()); print_r($_SESSION); die;
		if(!$this->session->userdata('admin_id'))
		{
			redirect('admin/login');
		}
	}
		
	public function accept($enc_userID='')
	{
		if($enc_userID!='')
		{
			$ugalId=base64_decode($enc_userID);
			$imageDetails = $this->common_model->getAllRow('sys_videos',array('id'=>$ugalId));
			if(!empty($imageDetails))
			{
				$this->common_model->UpdateData('sys_videos',array('accepted'=>1, 'created_at'=>date('Y-m-d H:i:s',time()-8*60*60)),array('id'=>$ugalId));
			}
			//echo $this->db->last_query(); die;
			$video_name = explode('.', $imageDetails['filename']);
            if(count($video_name)>1){
				@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.mp4');
				@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.webm');
			}			
			$userdata = $this->common_model->getAllRowMultipleJoin('sys_videos',array('sys_videos.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = sys_videos.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));
			if(!empty($userdata))
			{
				$this->common_model->insertData('notification',array('from_id'=>$userdata['user_id'],'to_id'=>1,'type'=>15,'created'=>time(),'video_id'=>$imageDetails['id']));
				/**********************MAIL**************************/
					//$to = 'sayan@digitalaptech.com';
					$to = $userdata['email'];
					$sub = getAdminLang('Notification:_Video_has_been_accepted',$userdata['userlanguage']);
					//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];
					//$body= '<p>Dear '.$userdata['username'].',</p>';
					$body= '<p>'.getAdminLang('We_are_happy_to_let_you',$userdata['userlanguage']).'</p>';
					$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';
					$body.= '<p>'.getAdminLang('we_are_now_create_a_virtual_world',$userdata['userlanguage']).'</p>';
					$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['userlanguage']).'<p>';
					//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';

					$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
	                    <tr>
	                       <td>
	                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
	                             <tr>
	                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
	                                   <h2>Dear <span style="text-transform:capitalize">'.$userdata['username'].'</span> </h2>
	                                </td>
	                             </tr>
	                             <tr>
	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                                   '.$body.'
	                                </td>
	                             </tr>
	                             <tr>
	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
	                             		'.getAdminLang('Best_regards',$userdata['userlanguage']).' <br>
	                             		<p style="margin:5px 0 0">'.getAdminLang('Your_team_of_castleevents',$userdata['userlanguage']).'</p> 
	                             	</td>
	                             </tr>
	                          </table>
	                       </td>
	                    </tr>
	                </table>';

				$this->utility->sendCIMail($to,$sub,$bodys);
				/**********************MAIL**************************/
			}
			$this->utility->setMsg('Video accepted','SUCCESS');	
			redirect(base_url().'admin/dashboard');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/dashboard');
		}
	}
	public function reject($enc_userID='')
	{
		if($enc_userID!='')
		{
			$ugalId=base64_decode($enc_userID);
			$imageDetails = $this->common_model->getAllRow('sys_videos',array('id'=>$ugalId));
			$userdata = $this->common_model->getAllRowMultipleJoin('sys_videos',array('sys_videos.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = sys_videos.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));
			//echo $this->db->last_query(); die;
			//print_r($userdata); die;
			if(!empty($userdata))
			{
				/**********************MAIL**************************/
					//$to = 'sayan@digitalaptech.com';
					$to = $userdata['email'];
					$sub = getAdminLang('Notification:_Video_has_been_removed',$userdata['userlanguage']);
					//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];
					//$body= '<p>Dear '.$userdata['username'].',</p>';
					$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';
					$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';
					$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';
					$body.= '<ul>';
					$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';
					$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';
					$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';
					$body.= '</ul>';
					$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['userlanguage']).'</p>';
					//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';

					$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
	                    <tr>
	                       <td>
	                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
	                             <tr>
	                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
	                                   <h2>Dear <span style="text-transform:capitalize">'.$userdata['username'].'</span> </h2>
	                                </td>
	                             </tr>
	                             <tr>
	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                                   '.$body.'
	                                </td>
	                             </tr>
	                             <tr>
	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
	                             		'.getAdminLang('Best_regards',$userdata['userlanguage']).' <br>
	                             		<p style="margin:5px 0 0">'.getAdminLang('Your_team_of_castleevents',$userdata['userlanguage']).'</p> 
	                             	</td>
	                             </tr>
	                          </table>
	                       </td>
	                    </tr>
	                </table>';

				$this->utility->sendCIMail($to,$sub,$bodys);
				/**********************MAIL**************************/
			}
			$this->load->library('s3_upload');
  			$file_url = $this->s3_upload->remove_file($imageDetails['filename'], $imageDetails['user_id']);
			$video_name = explode('.', $imageDetails['filename']);
            if(count($video_name)>1){
				@unlink(FCPATH.'assets/videos/uploads/thumb/'.$video_name[0].'.jpg');
				@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.mp4');
				@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.webm');
			}
			@unlink(FCPATH.'assets/videos/uploads/'.$imageDetails['filename']);
			$this->common_model->deleteData('sys_videos',array('id'=>$ugalId));
			$this->utility->setMsg('Video rejected','SUCCESS');	
			redirect(base_url().'admin/dashboard');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/dashboard');
		}
	}
	public function approve_all()
	{
		$ugalIds=explode(',',$this->input->post('ids'));
		if(count($ugalIds)>0)
		{
			foreach ($ugalIds as $key => $ugalId) {
				$imageDetails = $this->common_model->getAllRow('sys_videos',array('id'=>$ugalId));
				if(!empty($imageDetails))
				{
					$this->common_model->UpdateData('sys_videos',array('accepted'=>1, 'created_at'=>date('Y-m-d H:i:s',time()-8*60*60)),array('id'=>$ugalId));
				}
				//echo $this->db->last_query(); die;
				$video_name = explode('.', $imageDetails['filename']);
	            if(count($video_name)>1){
					@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.mp4');
					@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.webm');
				}
				$userdata = $this->common_model->getAllRowMultipleJoin('sys_videos',array('sys_videos.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = sys_videos.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));
				
				if(!empty($userdata))
				{
					$this->common_model->insertData('notification',array('from_id'=>$userdata['user_id'],'to_id'=>1,'type'=>15,'created'=>time(),'video_id'=>$imageDetails['id']));
					/**********************MAIL**************************/
						//$to = 'sayan@digitalaptech.com';
						$to = $userdata['email'];
						$sub = getAdminLang('Notification:_Video_has_been_accepted',$userdata['userlanguage']);
						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];
						//$body= '<p>Dear '.$userdata['username'].',</p>';
						$body= '<p>'.getAdminLang('We_are_happy_to_let_you',$userdata['userlanguage']).'</p>';
						$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';
						$body.= '<p>'.getAdminLang('we_are_now_create_a_virtual_world',$userdata['userlanguage']).'</p>';
						$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['userlanguage']).'<p>';
						//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';

						$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
		                    <tr>
		                       <td>
		                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
		                             <tr>
		                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
		                                   <h2>Dear <span style="text-transform:capitalize">'.$userdata['username'].'</span> </h2>
		                                </td>
		                             </tr>
		                             <tr>
		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
		                                   '.$body.'
		                                </td>
		                             </tr>
		                             <tr>
		                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
		                             		'.getAdminLang('Best_regards',$userdata['userlanguage']).' <br>
		                             		<p style="margin:5px 0 0">'.getAdminLang('Your_team_of_castleevents',$userdata['userlanguage']).'</p> 
		                             	</td>
		                             </tr>
		                          </table>
		                       </td>
		                    </tr>
		                </table>';

					$this->utility->sendCIMail($to,$sub,$bodys);
					/**********************MAIL**************************/
				}
			}
		}
		$this->utility->setMsg('Videos accepted','SUCCESS');	
		redirect(base_url().'admin/dashboard');
	
	}
	public function reject_all(){
		$this->load->library('s3_upload');
		$ugalIds=explode(',',$this->input->post('ids'));
		if(count($ugalIds)>0){
			foreach ($ugalIds as $key => $ugalId) {
				$imageDetails = $this->common_model->getAllRow('sys_videos',array('id'=>$ugalId));
				$userdata = $this->common_model->getAllRowMultipleJoin('sys_videos',array('sys_videos.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = sys_videos.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));
				
	  			$file_url = $this->s3_upload->remove_file($imageDetails['filename'], $imageDetails['user_id']);
				$video_name = explode('.', $imageDetails['filename']);
	            if(count($video_name)>1){
					@unlink(FCPATH.'assets/videos/uploads/thumb/'.$video_name[0].'.jpg');
					@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.mp4');
					@unlink(FCPATH.'assets/videos/uploads/'.$video_name[0].'.webm');
				}
				@unlink(FCPATH.'assets/videos/uploads/'.$imageDetails['filename']);
				$this->common_model->deleteData('sys_videos',array('id'=>$imageDetails['id']));
				
				if(!empty($userdata))
				{
					/**********************MAIL**************************/
						//$to = 'sayan@digitalaptech.com';
						$to = $userdata['email'];
						$sub = getAdminLang('Notification:_Video_has_been_removed',$userdata['userlanguage']);
						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];
						//$body= '<p>Dear '.$userdata['username'].',</p>';
						$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';
						$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';
						$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';
						$body.= '<ul>';
						$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';
						$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';
						$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';
						$body.= '</ul>';
						$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['userlanguage']).'</p>';
						//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';

						$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
		                    <tr>
		                       <td>
		                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
		                             <tr>
		                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
		                                   <h2>Dear <span style="text-transform:capitalize">'.$userdata['username'].'</span> </h2>
		                                </td>
		                             </tr>
		                             <tr>
		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
		                                   '.$body.'
		                                </td>
		                             </tr>
		                             <tr>
		                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
		                             		'.getAdminLang('Best_regards',$userdata['userlanguage']).' <br>
		                             		<p style="margin:5px 0 0">'.getAdminLang('Your_team_of_castleevents',$userdata['userlanguage']).'</p> 
		                             	</td>
		                             </tr>
		                          </table>
		                       </td>
		                    </tr>
		                </table>';

					$this->utility->sendCIMail($to,$sub,$bodys);
					/**********************MAIL**************************/
				}
			}
		}
		$this->utility->setMsg('Videos rejected','SUCCESS');	
		redirect(base_url().'admin/dashboard');
	}
}	
