<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/
//
//$Id: WatchvideoController, v 1.0 2018/12/27 12:56:15
//
class WatchvideoController extends Controller {
        public function indexAction()    {
			$ObjWatchvideo   = 	new WatchvideoModel();
			$languageIDs		= 	$this->ObjView->languageIDs;		
                
			 list($limitFrom, $limitTo) = $this->getPageSettings($key = 'page', $rows = 10); 

            $listWatchvideo  = $ObjWatchvideo->listwatchvideo($limitFrom,$limitTo,$languageIDs);	
           // print_r($listWatchvideo);exit;
			$editPrivilege	=	$this->ObjCommon->hasPrivilege('watchvideo/addvideo/');
                $this->ObjView->assign("editPrivilege", $editPrivilege);
                $deletePrivilege	=	$this->ObjCommon->hasPrivilege('watchvideo/ajaxdestroy/');
                $this->ObjView->assign("deletePrivilege", $deletePrivilege);
				$addPrivilege	=	$this->ObjCommon->hasPrivilege('watchvideo/addvideo/');
                $this->ObjView->assign("addPrivilege", $addPrivilege);
                
			$resPagesCount = $this->setPagesCount($key = 'page');
            $this->ObjView->assign("listWatchvideo", $listWatchvideo); 
            $this->ObjView->display('Watchvideo.tpl');
        }
		public function addVideoAction()    { 
			$ObjProductCategory            = new ProductCategoryModel();
			$ObjWatchvideo    		= 	new WatchvideoModel();
            $languageIDs			= 	$this->ObjView->languageIDs;	
            $watchvideoID       =   $this->getRequestValue('id');
            $pdtCatID       	=   $this->getRequestValue('pid');
            $resWatchVideo          	=       array();
            $resWatchImageDetails  =       array();
            $resWatchVideoDetails    	=       array(); 
			$ObjProductCategory        = new ProductCategoryModel();
			$resProductCategories      = $ObjProductCategory->listallProductCategories($languageIDs);
        	//echo "<pre>";print_r($resProductCategories);exit;
			if ($this->ObjForm->isValid('formAttributeAdd', 'submitAttributeAdd'))
            {     
              //echo "<pre>";print_r($_POST);exit;
				$ObjWatchvideo->saveWatchvideo($_POST,$watchvideoID,$languageIDs);
                $this->setMessage("language.msgWatchvideoSaved", 3);
                 echo '<script type="text/javascript">parent.$.colorbox.close();parent.location.reload();</script>';
                exit;

            }
			 elseif (isset($_POST['attrOptionAddCount']))
            {
                $watchvideoID               = $_POST['watchvideoID'];      
                
                $this->ObjView->assign('resWatchVideoq', $_POST['attrOptionsGroup']);   
                $this->ObjView->assign('resWatchImageDetails', $_POST['attrOptionsGroup']);   
                $this->ObjView->assign('resWatchVideoDetails', $_POST['attrOptionsGroup']);   
                $this->ObjView->assign('postCallback', '1');
            } 
			if($pdtCatID >0){
			$resWatchVideo=$ObjWatchvideo->getWatchvideo($pdtCatID);
			$resWatchImageDetails=$ObjWatchvideo->getWatchvideo($pdtCatID);
			$resWatchVideoDetails=$ObjWatchvideo->getWatchvideo($pdtCatID);
			}	
            $this->ObjView->assign("watchvideoID", $watchvideoID);  
			$this->ObjView->assign("pdtCatID", $pdtCatID);
			$this->ObjView->assign("productCategoryID", $pdtCatID);
			$this->ObjView->assign("resProductCategories", $resProductCategories);
			$this->ObjView->assign("resWatchVideo", $resWatchVideo);  
			//$this->ObjView->assign("resWatchVideoq", $resWatchVideoq);  
            $this->ObjView->assign("resWatchImageDetails", $resWatchImageDetails); 
            $this->ObjView->assign("resWatchVideoDetails", $resWatchVideoDetails); 
            $this->ObjView->display('AddVideo.tpl');
        }
        
        private function createCategoryTree(&$list, $parent) {
        $tree = array();
        if (is_array($parent)) {
            foreach ($parent as $k => $l) {
                if (isset($list[$l['productCategoryParent']]) && !empty($list[$l['productCategoryID']])) {
                    $l['children'] = $this->createCategoryTree($list, $list[$l['productCategoryID']]);
                }
                $tree[] = $l;
            }
        }
        return $tree;
    }
    public function ajaxLoadOptionsAction()
        {
            $attrOptionCount = $this->escape($_POST["attrOptionCount"]);     
            $fileType        = !empty($_POST["filetype"])?$_POST["filetype"]:'I';
            $this->ObjView->assign('attrOptionCount', $attrOptionCount + 1);   
            $this->ObjView->assign('fileType', $fileType);  
            $this->ObjView->assign('attrOptionCountVd', $attrOptionCount + 1);
            $this->ObjView->display('AddVideoAjax.tpl');
        }   
     public function ajaxchangestatusAction() {
            $ObjWatchvideo    		= 	new WatchvideoModel();
            $videoIDs       = array(
                $_POST['data']
            );
            $changeStatus    = $_POST['status'];
            $resStatus = $ObjWatchvideo->changeStatus($videoIDs, $changeStatus, $this->ObjCommon->hasPrivilege('watchvideo/index/'));
            if ($changeStatus == 'Deleted') {
                $this->setMessage("language.msgWinnerItemDelete", 3);
            } else {
                $this->setMessage("language.lblOrderstatusstatusUpdatedSuccess", 3);
            }
        }
		public function ajaxdestroyAction() {
            $ObjWatchvideo    		= 	new WatchvideoModel();
            $id    = $_POST['id'];
            $resStatus = $ObjWatchvideo->deletewatchVideo($id);
			$this->setMessage("language.msgWatchvideoDelete", 3);
            
        }		
       
        
}