<?
class cpanel extends Controller {

        function cpanel()
        {
                parent::Controller();
        }


/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function Default Page
 * @copyright 2011
 */
 

function index()
{

	if($this->clogin->is_logged_in())
	{

		$userID = $this->session->userdata('userID');
		$user_name = $this->session->userdata('user_name');
		$level = $this->session->userdata('userID');
		$today = date('Y-m-d');
		$data['userID'] = $userID;
		$data['userName'] = $user_name;
		$data['title'] = "Billing ";
		$data['active_tab'] = "billing";
		$day_time = mktime(0,0,0,date("m"),date("d")-6,date("Y"));
 		$callStart = date("Y-m-d", $day_time);
 		$callEnd = date('Y-m-d');
 		$data['callStart'] = $callStart;
 		$data['callEnd'] = $callEnd;
		// Call Summary		
		$data['callSummary'] = $this->cpanelModel->totalCallSummary($callStart,$callEnd);
		$data['totalActiveCalls'] = $this->cpanelModel->totalActiveCall();
		$data['activeCallList'] = $this->cpanelModel->activeCallList();
		$data['totalActiveUser'] = $this->cpanelModel->totalRegisterUser();
		$data['activeUserList'] = $this->cpanelModel->registerUserList();
		$data['errorCallList'] = $this->cpanelModel->internalError($today);

		$this->load->view('cpanel/defaultview',$data);

    }
    else
    {

		redirect("login/login_first", "Location");

	}

}




/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function Default Page
 * @copyright 2011
 */
 

function accessDenied()
{

	if($this->clogin->is_logged_in())
	{

		$data['accessDenied'] = "Access Denied";
		$this->load->view('cpanel/not_allow',$data);

    }
    else
    {

		redirect("login/login_first", "Location");

	}

}



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function return ADC of Sucess Call list
 * @copyright 2011
 */
 

function asrSummary($startDate)
{

	if($this->clogin->is_logged_in())
	{

		$userID = $this->session->userdata('userID');
		$user_name = $this->session->userdata('user_name');
		$level = $this->session->userdata('userID');
		$data['callDate'] = $startDate;
		$data['callSummary'] = $this->cpanelModel->asrCallSummary($startDate);
		$this->load->view('cpanel/asr_acd',$data);

    }
    else
    {

		redirect("login/login_first", "Location");

	}

}





function passwordFrom()
{

	if($this->clogin->is_logged_in())
	{

		$userID = $this->session->userdata('userID');
		$user_name = $this->session->userdata('user_name');
		$level = $this->session->userdata('userID');

		$data['userID'] = $userID;
		$data['userName'] = $user_name;
		$data['title'] = "Billing ";
		$data['message'] = "Change Password Form";
		$data['titleErrorMessage'] = FROMMESSAGE001;
		$data['active_tab'] = "billing";

		$this->load->view('login/change_pwd_form',$data);

    }
    else
    {

		redirect("login/login_first", "Location");

	}

}





function changePassword()
{

	if($this->clogin->is_logged_in())
	{

		$userID = $this->session->userdata('userID');
		$user_name = $this->session->userdata('user_name');

		$oldpwd = md5($this->input->post('oldpwd'));
		$newPwd = $this->input->post('newPwd');
		$repwd = $this->input->post('repwd');
		$checkPassword = $this->cpanelModel->checkPassword($userID,$oldpwd);
		$errorMessage = "";

		if($checkPassword == 1)
		{
			if($newPwd == $repwd)
			{
				$newPassword = md5($newPwd);
				$sqlUpdate = "UPDATE admin set password = '$newPassword', hidden = '$newPwd' where id = '$userID'";
		        $query = $this->db->query($sqlUpdate);
		        $errorMessage = FROMMESSAGE053;
			}
			else
			{
			  $errorMessage = FROMMESSAGE052;
			}
		}
		else
		$errorMessage = FROMMESSAGE051;


		$data['userID'] = $userID;
		$data['userName'] = $user_name;
		$data['title'] = "Billing ";
		$data['message'] = "Password Change Form";
		$data['titleErrorMessage'] = $errorMessage;
		$data['active_tab'] = "billing";

		$this->load->view('login/change_pwd_form',$data);

    }
    else
    {

		redirect("login/login_first", "Location");

	}

}





/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function Company & Portal Profile
 * @copyright 09 Feb, 2014
 */

	function profileInfo($errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			
			$userID = $this->session->userdata('userID');
			$accessGroup = $accessLevel = $this->session->userdata('accessLevel');

			
			$profile = $this->cpanelModel->profileSettingInfo();
			if(is_array($profile))
			{
				foreach($profile as $row)
				{
					$data['com_name'] = $row->com_name;
					$data['com_email'] = $row->com_email;
					$data['com_phone'] = $row->com_phone;
					$data['com_fax'] = $row->com_fax;
					$data['com_vat_reg'] = $row->com_vat_reg;
					$data['com_address'] = $row->com_address;
					$data['header_title'] = $row->header_title;
					$data['logo_images'] = $row->logo_images;
					$data['ftp_ip'] = $row->ftp_ip;
					$data['ftp_user'] = $row->ftp_user;
					$data['ftp_pass'] = $row->ftp_pass;				
				}
			}
			else
			{
				$data['com_name'] = "";
				$data['com_email'] = "";
				$data['com_phone'] = "";
				$data['com_fax'] = "";
				$data['com_vat_reg'] = "";
				$data['com_address'] = "";
				$data['header_title'] = "";
				$data['logo_images'] = "logo.png";
				$data['ftp_ip'] = "";
				$data['ftp_user'] = "";
				$data['ftp_pass'] = "";	
			}
			if($errorMesssage== 1)
			$data['titleErrorMessage'] ="";
			else
			$data['titleErrorMessage'] = "";
				
			$this->load->view('setup/profile_form',$data);
			
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function Company & Portal Profile Save
 * @copyright 09 Feb, 2014
 */

	function profileSave()
	{
		if($this->clogin->is_logged_in())
		{
			
			$userID = $this->session->userdata('userID');
			$accessGroup = $accessLevel = $this->session->userdata('accessLevel');
			
			$config['upload_path'] = './key/';
			$config['allowed_types'] = 'gif|jpg|png|lic';
			$config['max_size']	= '100';
			$config['max_width']  = '1024';
			$config['max_height']  = '768';
			$this->load->library('upload', $config);
			$fileName = "";
			if ($this->upload->do_upload())
			{
				$dataFile = array('upload_data' => $this->upload->data());
				$fileName = basename($dataFile['upload_data']['full_path']);
			}
			
			if($fileName == "")
			$fileName	= mysql_escape_string($this->input->post('logoFile'));
			
			$this->cpanelModel->insertProfileInfo($fileName,$userID);
			redirect("admin/cpanel/profileInfo/1", "Location");
			
			
		}
		else
		{
			redirect("login/index", "Location");
		}
	}




/**
 ***********************************************************************
 * @Start Activity Log  Section ****************************************
 ***********************************************************************
*/



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show User Activity Logs
 * @copyright 20114
 */
 

	function accessLog($errorMessage=0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
						
			$starttime = "2014-01-01";
			$stoptime = date('Y-m-d');
			$data['starttime'] = $starttime;
			$data['stoptime'] = $stoptime;
			$data['description'] = "NULL";
			$data['moduleName'] = "NULL";
			$data['startoffset'] = "0";
			$data['limit'] = LIMIT_PERPAGE;
			
			$data['total'] = $this->cpanelModel->getTotalnumLogs($description='NULL',$moduleName='NULL',$starttime,$stoptime);
			$data['userLogList'] = $this->cpanelModel->userLogList($startoffset = 0,$limit = LIMIT_PERPAGE,$description='NULL',$moduleName='NULL',$starttime,$stoptime);
			$data['titleMessage'] = TITLE036;
			$data['titleErrorMessage'] = "";
			$this->load->view('cpanel/user_logs',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	
	

/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: Show User Activity Logs
 * @copyright 20114
 */
 

	function accessLogPagi($startoffset, $limit, $starttime, $stoptime, $description, $moduleName, $myRandom = 0)
	{
		if($this->clogin->is_logged_in())
		{
			$userID = $this->session->userdata('userID');
						

			$data['starttime'] = $starttime;
			$data['stoptime'] = $stoptime;
			$data['description'] = $description;
			$data['moduleName'] = $moduleName;
			$data['startoffset'] = $startoffset;
			$data['limit'] = $limit;
			
			$data['total'] = $this->cpanelModel->getTotalnumLogs($description,$moduleName,$starttime,$stoptime);
			$data['userLogList'] = $this->cpanelModel->userLogList($startoffset,$limit,$description,$moduleName,$starttime,$stoptime);
			$data['titleMessage'] = TITLE036;
			$data['titleErrorMessage'] = "";
			$this->load->view('cpanel/user_logs_pagi',$data);
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	



/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function Company & Portal Profile
 * @copyright 09 Feb, 2014
 */

	function dbBackTask($errorMesssage=0)
	{
		if($this->clogin->is_logged_in())
		{
			
			$userID = $this->session->userdata('userID');
			$accessGroup = $accessLevel = $this->session->userdata('accessLevel');

			

			
			$profile = $this->cpanelModel->dbBackupSettingInfo();
			if(is_array($profile))
			{
				foreach($profile as $row)
				{
					$data['task_type'] = $row->task_type;
					$data['task_time'] = $row->task_time;
					$data['calls'] = $row->calls;
					$data['name_prefix'] = $row->name_prefix;
				}
			}
			else
			{
				$data['task_type'] = "1"; // 1 Daily, 2 Weekly & 3 Monthly
				$data['task_time'] = "00:00";
				$data['calls'] = "0";
				$data['name_prefix'] = "back_";
			}
			if($errorMesssage== 1)
			$data['titleErrorMessage'] ="";
			else
			$data['titleErrorMessage'] = "";
				
			$this->load->view('setup/db_back_form',$data);
			
		}
		else
		{
			redirect("login/index", "Location");
		}
	}






/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function Company & Portal Profile Save
 * @copyright 09 Feb, 2014
 */

	function profileDBsetting()
	{
		if($this->clogin->is_logged_in())
		{
			
			$userID = $this->session->userdata('userID');
			$accessGroup = $accessLevel = $this->session->userdata('accessLevel');			
			$this->cpanelModel->insertDBtask();
			redirect("admin/cpanel/dbBackTask/1", "Location");
			
			
		}
		else
		{
			redirect("login/index", "Location");
		}
	}
	
/**
 * @author: Md. Golam Rabbany
 * @email: mgrnahid@gmail.com
 * @description: This function Default Page
 * @copyright 2011
 */
 

function registerUsers()
{
	if($this->clogin->is_logged_in())
	{
		$userID = $this->session->userdata('userID');
		$user_name = $this->session->userdata('user_name');
		$level = $this->session->userdata('userID');
		$data['totalActiveUser'] = $this->cpanelModel->totalRegisterUser();
		$data['activeUserList'] = $this->cpanelModel->registerUserList();
		$this->load->view('cpanel/register_users',$data);
    }
    else
    {

		redirect("login/login_first", "Location");

	}

}


}
?>