All pastes #763058 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-11-06 03:01 UTC
rendered paste body
<?php
// This is the main class file for the admin area...

    class admin {

        public function __construct() {
         
	    // include smarty
	    require_once('./libs/smarty/Smarty.class.php');
	    $this->smarty = new Smarty();
	    // need libs/ because this is being called from the API directory (browser accesses API/*.php)
        
	    $this->smarty->force_compile = 1;
	    $this->smarty->caching = 0;
	    
	    $this->smarty->template_dir = '/var/www/vhosts/iptriple.com/httpdocs/API/admin/templates';
	    $this->smarty->compile_dir 	= '/var/www/vhosts/iptriple.com/httpdocs/API/libs/smarty/templates_c';
	    $this->smarty->cache_dir 	= '/var/www/vhosts/iptriple.com/httpdocs/API/libs/smarty/cache';
	    $this->smarty->config_dir 	= '/var/www/vhosts/iptriple.com/httpdocs/API/libs/smarty/configs';
	
		//require_once('./libs/classes/database.Class.php');
		$this->db = new database();
		$this->user = new user();
		
		// Get a list of databases
		$this->dbs = $this->db->getDatabases();
	    
        }
		
        public function act() {
			//$_SESSION['reqaction'] = $this->action != 'login' ? $this->action : $_SESSION['reqaction'];
			var_dump($_SESSION);
			$this->title = $this->action;
			$this->reqaction = $this->action != 'login' ? $this->action : NULL;
			// $this->user->login();
			$this->user->authorize();
			print $this->user->authenticated;
			print $this->action;
			if ($this->user->authenticated == true && $this->action == 'login') {
				
				// header('Location: http://216.30.168.241/API/admin.php?action=' . $_SESSION['reqaction']);

			} elseif($this->user->authenticated != true) {
				$this->title = "Login Required";
				$this->action = 'login';

			}
			$this->{$this->action}();
			$this->display();

    	}
		private function login() {
			if (isset($_POST['username']) && isset($_POST['password'])) {
				
				$this->user->username = $_POST['username'];
				$this->user->pass = $_POST['password'];
				
				$this->user->login();
			} else {
				
				print "You must enter a username and password!";
				
			}
		}
        
		private function logout() {
			$this->user->logout();
			
		}
        protected function display () {
			
			$this->smarty->assign('title', $this->title);
			$this->smarty->assign('action', $this->action);
			$this->smarty->assign('loggedin', $this->user->authenticated);
			// need the ../../ because this is being called from libs/classes
			// display the template..
			$this->smarty->display('../../admin/templates/index.tpl');


        }

		private function dashboard() {

			
			
		}
        
        private function manage_licenses() {
            
		
                
        }
        
        
        private function manage_numbers() {
                
                
        }
        
        private function manage_settings() {
                
                
        }
		
		private function manage_cdrs() {
			
			
		}
		
		private function manage_invoices() {
			
			
		}
		
		private function pull_cdr() {
			
			
			
		}
		
		
		private function generate_invoices () {
			
			
		}
		
    }

?>

<?php

	class user {
		public $username;
		public $password;
		public function __construct() {
		
		
			$this->db = new Database();
		
		
		}
	
		public function authorize() {

		if(isset($_SESSION) && isset($_SESSION['info'])){
				$this->authenticated = true;
				
			} else {
				$this->authenticated = false;
			}

		}
		public function login() {
			
			$db =& $this->db;
			$this->pass = md5($this->pass);
			$db->set_conn('iptriple');
			$db->set_on("username = '{$this->username}' AND password = '{$this->pass}'");
			print $db->select('ab_account');
			// $qu = "SELECT * FROM `ab_account` WHERE username = '{$this->username}' AND password = '{$this->pass}'";

			// $db->query($qu);
			$db->fetch_assoc();
			$this->info = $db->result;
			$db->set_on("account_id = '{$this->info['id']}'");
			$db->select('ab_account_group');
			// $qu = "SELECT * FROM `ab_account_group` WHERE account_id = '{$this->info['id']}' AND group_id IN ('4','1001')";
			// $db->query($qu);
			if ($db->rows > 0) {
				// user is authenticated
				$this->authenticated = true;
				$_SESSION['info'] = $this->info;
				// we dont want to store the password in the session variable for security reasons...
				unset($_SESSION['info']['password']);

			} else {

				$this->authenticated = false;
			}
			
		}
		
		public function logout() {
			session_destroy();
			
		}
	
	}
?>
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'on');
// start our session (to remember logins) ;)
session_start();
/* everything in this file is processed by admin.Class.php...*/


// include the init file...
include('init.php');

// pass the action to the admin class for processing...

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "dashboard";
$admin->action = $action;
$admin->act();


?>