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

class userGuide extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('9', 'transaction');
		if(!$query){
			echo '<script>alert("Not authorised..");
				window.location.replace("'.base_url().'Error");
				</script>';
		}
		$this->load->library('layouts');
		$this->load->helper('form');
		$this->load->helper('menu');
		$this->load->model('User_guide');
		$this->load->model('menu');
		$this->layouts->set_title('iAccount');	
		$this->lang->load("ugcont",$this->session->userdata('language'));	
		$this->lang->load("ug_topic",$this->session->userdata('language'));
	}

	public function index(){

	}

	//UG content
	public function add(){

		if($this->input->post('data') != ''){
			$data = json_decode($this->input->post('data'));
			$isCont = $this->User_guide->update($data);
			echo $isCont;
		}else{
			$data['ugTopic'] = $this->User_guide->getTopic();
			$this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-'.$this->session->userdata('language').'.js')
	                            ->add_includes('js/accounting.js')
	                            ->add_includes('js/validationengine/jquery.validationEngine.js');
			$this->layouts->view('userguide/addnew', '', $data);
		}
	}
/*******************Related Topic transactions*********************/
	//Add video link
	public function addTopic(){
		$this->User_guide->addTopic($this->input->post('ugID'),$this->input->post('topicID'));		
	}

	//Delete video link
	public function delTopic(){
		$this->User_guide->delTopic($this->input->post('topicID'));
	}
/*******************Related Topic transactions*********************/
/*******************Video link transactions*********************/
	//Add video link
	public function addVideo(){
		$this->User_guide->addVideo($this->input->post('ugID'),$this->input->post('videoLink'));		
	}

	//Delete video link
	public function delVideo(){
		$this->User_guide->delVideo($this->input->post('vidID'));
	}
/*******************Video link transactions*********************/

	//UG retrive content
	public function getContent(){
		if($this->input->post('ugID') != ''){
			$cont =	$this->User_guide->getCont($this->input->post('ugID'));
			if(!empty($cont['relatedTopic'])){
				foreach($cont['relatedTopic'] as &$v){
					$v->name = $this->lang->line($v->name);
				}
			}
			echo json_encode($cont);
		}
	}
}
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

