MSV FM

dot.antimicrobial@66.96.161.157: ~ $
Path : /hermes/bosweb/b1705/silverkeyhomesinc.ca/admin_dawncs_backup/app/Controller/
File Upload :
Current < : /hermes/bosweb/b1705/silverkeyhomesinc.ca/admin_dawncs_backup/app/Controller/AppController.php

<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */

App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package        app.Controller
 * @link        http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
class AppController extends Controller
{
	public $components = array(
		'Session',
		'Flash',
		'Auth' => array(
			'authorize' => 'Controller',
			'unauthorizedRedirect' => array(
				'controller' => 'users',
				'action' => 'login'
			),
			'loginAction' => array(
				'controller' => 'users',
				'action' => 'login'
			),
			'loginRedirect' => array(
				'controller' => 'pages',
				'dashboard' => 'dashboard'
			),
			'logoutRedirect' => array(
				'controller' => 'users',
				'action' => 'logout'
			),
			'authError' => 'You must be logged in to view this page.',
			'loginError' => 'Invalid Username or Password entered, please try again.'
		)
	);


	public function beforeFilter()
	{
		$groups = array('1' => 'admin', '2' => 'agent');
		if (isset($this->params['prefix'])) {
			$prefixes = Configure::read('Routing.prefixes');
			if (in_array($this->params ['prefix'], $prefixes)) {
				$this->layout = $this->params ['prefix'];
			}
			// if already logged-in, redirect
			if ($this->Session->check('Auth.User')) {

				// set notifications
				$this->set('notifications', $this->getNotifications());


				$get_prefix = $groups[$this->Auth->user('group_id')];
				if ($get_prefix != $this->params['prefix']) {
					$this->Auth->logout();
					$this->redirect('/login');
				}
			} elseif (empty($this->Session->check('Auth.User'))) {
				$this->redirect('/login');
			}
		} else {
			$server_name = array(
				'dawncounselling.com',
				'dawncounselling.ca',
				'dawncs.ca'
			);
			if (!in_array($_SERVER['SERVER_NAME'], $server_name)) {
				//@redirection to coming soon page.
				/***
				$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=" . $this->getRealIpAddr());
				if ($xml->geoplugin_countryCode == 'CA') {
					$this->layout = 'blocked';
				}
				 * **/
			}
			//
			$ourservices = array(
				'immigration',
				'quebec_skilled_worker_visa',
				'self_employed_program',
				'sponsorship',
				'provincial_nominee_program',
				'immigrant_investor_program',
				'business_class_visa',
				'visitor_class_visa',
				'live_in_caregiver_class_visa',
				'temporary_foreign_worker_class_visa',
				'express_entry'
			);
		}

		/*if ($this->Auth->user('group_id') == 1) {
			///$this->Auth->allow();
		}*/
	}

	public function isAuthorized($user)
	{
		// Here is where we should verify the role and give access based on role
		return true;
	}

	static function removePTag($str)
	{
		$str = str_replace('<p>', '', $str);
		return str_replace('</p>', '', $str);
	}

	function getRealIpAddr()
	{
		if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
		{
			$ip = $_SERVER['HTTP_CLIENT_IP'];
		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
		{
			$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
		} else {
			$ip = $_SERVER['REMOTE_ADDR'];
		}
		return $ip;
	}

	function payment_methods($id = null, $excepts = array())
	{
		$this->loadModel('Bank');
		if (!empty($excepts)) {
			$list = $this->Bank->find('list', array('conditions' => array('id NOT IN' => $excepts)));
		} else {
			$list = $this->Bank->find('list');
		}

		if ($id != null) {
			return $list[$id];
		}
		return $list;
	}

	function getNotifications() {
		$this->loadModel('Notification');
		$data = $this->Notification->find('all', array(
			'fields' => array('Notification.*', 'User.name'),
			'conditions' => array('to_user_id' => $this->Auth->user('id')),
			'order' => 'Notification.created DESC'
		));

		$output = array();
		$output['read'] = array();
		$output['unread'] = array();

		if (!empty($data)) {
			foreach($data as $row) {
				if($row['Notification']['is_read']) {
					$output['read'][] = $row;
				} else {
					$output['unread'][] = $row;
				}
			}
		}
		return $output;
	}


}