Skip to content
This repository was archived by the owner on Jun 19, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
327b937
added namespace autoloader
akhtar-husain Oct 29, 2015
967c3f8
PSR-4 Autoloader Added
akhtar-husain Oct 29, 2015
0cf5e0e
Update .gitignore
akhtar-husain Oct 29, 2015
9962157
Delete composer.lock
akhtar-husain Oct 29, 2015
7b73f9c
Modified Files - Akhtar
akhtar-husain Oct 29, 2015
0291c26
cganged - Akhtar
akhtar-husain Oct 29, 2015
652c9dd
Changed config - Akhtar
akhtar-husain Oct 29, 2015
e1fecae
changed - Akhtar
akhtar-husain Oct 29, 2015
3da1952
Update README.md
akhtar-husain Oct 29, 2015
07b7356
New features added - Akhtar
akhtar-husain Oct 30, 2015
e036e1b
Add new files
akhtar-husain Oct 30, 2015
7401242
Todays final commit 30-Oct
akhtar-husain Oct 30, 2015
f657393
New update 02-Nov-15
akhtar-husain Nov 2, 2015
1f79cd6
add html to table dir
akhtar-husain Nov 2, 2015
1113068
Update README.md
akhtar-husain Nov 2, 2015
98188a0
add html to table dir
akhtar-husain Nov 2, 2015
441fc22
config changed
akhtar-husain Nov 2, 2015
d6f184e
final change on 02 Nov
akhtar-husain Nov 2, 2015
c8eb854
composer modified
akhtar-husain Nov 3, 2015
d504811
twig template added
akhtar-husain Nov 5, 2015
6b3f529
Delete index-old.php
akhtar-husain Nov 5, 2015
c60eb0a
Delete index.php
akhtar-husain Nov 5, 2015
206bc05
changed
akhtar-husain Nov 5, 2015
71d6e4f
change
akhtar-husain Nov 5, 2015
e9d6354
config changed
akhtar-husain Nov 5, 2015
5260353
config changed
akhtar-husain Nov 5, 2015
12e7e3c
Update README.md
akhtar-husain Nov 5, 2015
a6d1a98
Update README.md
akhtar-husain Nov 5, 2015
c6474c0
Update README.md
akhtar-husain Nov 5, 2015
d4fc053
composer changed
akhtar-husain Nov 5, 2015
a6c4057
added new features
akhtar-husain Nov 6, 2015
2a6b928
Update README.md
akhtar-husain Nov 6, 2015
c0f074d
changed
akhtar-husain Nov 6, 2015
dafa1a8
changed
akhtar-husain Nov 6, 2015
de70119
index added
akhtar-husain Nov 6, 2015
34dd2db
Update README.md
akhtar-husain Nov 6, 2015
992d5d0
changed core
akhtar-husain Nov 6, 2015
6a0b35b
Merge branch 'namespace' of https://github.com/akhtar-husain/Admin_Pa…
akhtar-husain Nov 6, 2015
4d64f33
index changed
akhtar-husain Nov 6, 2015
72a86af
Update index.php
akhtar-husain Jan 7, 2016
1220e94
Update index.php
akhtar-husain Jan 7, 2016
9e202f0
Update .htaccess
akhtar-husain Jan 7, 2016
7dc9d0f
Update .htaccess
akhtar-husain Jan 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/vendor
/uploads
/.idea
/templates
/cache

index-old.php
composer.lock
test.php
6 changes: 6 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RewriteEngine On
RewriteBase /admin-panel/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?_route=$1 [L]
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# PDO-Library
Simple PHP library with PDO and PHP 5.6.0
# PHP-PDO-Mini Framework
Simple PHP Mini Framework with PDO and PHP 5.6.0.

To use this library, you need to only include config.php file from 'lib' directory.
-- To load files automatically PSR 4 autoloading is used.

example : require_nce "lib/config.php";
-- For Templating Twig template engine.

-- For Debugging Kint debugger.

-- For SMTP mails phpMailer.

To use this library, you need to only include Bootstrap.php file from 'app' directory.
49 changes: 49 additions & 0 deletions app/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/*
* @author : Akhtar Husain <[email protected]>
* @package : Admin Panel
* @version : 1.0
*/
ob_start();
session_start();

const DS = DIRECTORY_SEPARATOR;

if( ENVIRONMENT == 'development' ){
error_reporting(-1);
//error_reporting(E_ALL & E_WARNING & E_NOTICE);
}
else{
error_reporting(0);
}

$basepath = realpath( dirname( dirname(__FILE__) ) );
$httpProt = isset($_SERVER['https']) ? 'https://' : 'http://';
$baseurl = $httpProt.$_SERVER['HTTP_HOST'].substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')). '/';

$basepath = $basepath.DS;
$curPage = basename($_SERVER['SCRIPT_NAME'], '.php');

define( 'BASEPATH', $basepath );
define( 'APP_PATH', BASEPATH . 'app' .DS );
define( 'BASEURL', $baseurl );
define( 'CURRENT_PAGE', $curPage );

const DIR_CONTROLLER = APP_PATH . 'Controllers' . DS;
const DIR_MODEL = APP_PATH . 'Models' . DS;
const DIR_VIEW = APP_PATH . 'Views' . DS;
/** ========== C O N S T A N T E N D S H E R E ============ **/

/**
*
* ========== I N C L U D E N E C E S S A R Y F I L E S ===========
*
*/
if( file_exists(BASEPATH . 'vendor'.DS.'autoload.php') ){
//require BASEPATH ."vendor/autoload.php";
require BASEPATH . 'vendor'.DS.'autoload.php';
}
else{
exit("Autoload file does not exists. Please try to regenerate autoload file using command `composer dump-autoload`");
}
/** =========== F I L E L O A D I N G E N D S H E R E =========== **/
20 changes: 20 additions & 0 deletions app/Controllers/Default_Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace App\Controllers;

use App\System\Controller;

class Default_Controller extends Controller
{
function __construct(){
parent::__construct();
}

public function index(){
if( \App\System\Auth::isLoggedIn() ){
$this->loadView("index.tpl", ['title'=>'Admin']);
}
else{
$this->loadView("login.tpl", ['title'=>'Login']);
}
}
}
Empty file added app/Controllers/index.html
Empty file.
9 changes: 6 additions & 3 deletions lib/tables/AdminUser.class.php → app/Models/AdminUser.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
namespace App\Models;
use App\System\Auth, App\System\DB, App\System\Password;

/*
* @author : Akhtar Husain <[email protected]>
* @package : Admin Panel
* @version : 1.0
*/

final public class AdminUser extends Auth
final class AdminUser extends Auth
{
/////////////////////////////////////////////////
// PROPERTIES, PUBLIC
Expand Down Expand Up @@ -39,6 +41,7 @@ function __construct($var=0)
if($var>0)
{
$db = new DB();
$db->where(['id' => $var]);
$obj = $db->getRow( $this->table, '*' );

if(is_object($obj))
Expand Down Expand Up @@ -83,7 +86,7 @@ function commit()
function update()
{
$db = new DB();
$pass = new Password( md5($this->password) );
$pass = new Password( $this->password );

$fieldSet = ['display_name' => $this->display_name, 'email' => $this->email, 'password' => $pass->password, 'hash' => $pass->hash, 'updated_on' => date('Y-m-d H:i:s')];
$db->where( ['id'=>$this->id] );
Expand All @@ -98,7 +101,7 @@ function update()
function add()
{
$db = new DB();
$pass = new Password( md5($this->password) );
$pass = new Password( $this->password );

$fieldSet = ['username' => $this->username, 'email' => $this->email, 'password' => $pass->password, 'hash' => $pass->hash, 'display_name' => $this->display_name, 'updated_on' => date('Y-m-d H:i:s'), 'status'=>'1'];
$id = $db->insert( $this->table, $fieldSet );
Expand Down
81 changes: 81 additions & 0 deletions app/Models/Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
namespace App\Models;
use App\System\DB;

/*
* @author : Akhtar Husain <[email protected]>
* @package : Admin Panel
* @version : 1.0
*/

final class Options
{
public $table = "options";
/**
* Perform Update Query for User.
* @return pointer
*/
function update($arrField = array())
{
if(count($arrField) > 1){
return FALSE;
}
$key = array_keys($arrField);
$val = $arrField[$key[0]];
$db = new DB();
$fieldSet = ['option_value' => $val];
$db->where( ['option_key' => $key[0]] );
return $db->update( $this->table, $fieldSet );
}

/**
* Perform Inser Query for Option.
* @return inserted id
*/

/*----------- USED FOR FIRST TIME TO CONFIGE OPTION TABLE -----------*/
function add($arrField = array())
{
if(count($arrField) > 1){
return FALSE;
}
$key = array_keys($arrField);
$val = $arrField[$key[0]];
$db = new DB();
$fieldSet = ['option_key' => $key[0], 'option_value' => $val];
$id = $db->insert( $this->table, $fieldSet );
$this->id = $id;
return $id;
}

function getOption($key = "")
{
if($key != "")
{
$db = new DB();
$db->where(['option_key' => $key]);
$obj = $db->getRow($this->table, ['option_value']);

if(is_object($obj))
{
return $obj->option_value;
}
}
else
return FALSE;

}

/**
* Delete user's record.
* @return pointer
*/
function remove($key)
{
$db = new DB();

$db->where( ['option_key' => $key] );
return $db->delete( $this->table );
}

}
Empty file added app/Models/index.html
Empty file.
49 changes: 49 additions & 0 deletions app/System/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace App\System;
use App\System\DB, App\System\Password;

/*
* @author : Akhtar Husain <[email protected]>
* @package : Admin Panel
* @version : 1.0
*/

abstract class Auth
{
//protected function initialize();
public function login(){
$pass = new Password( $this->password );
$db = new DB();
$db->where( ['email' => $this->email, 'username' => $this->username],'AND', "OR" );
$db->where( ['password' => $this->password],'AND' );
$data = $db->getRow($this->table);
//_print_r($data);
if( $data->id > 0 && $pass->verifyPassword() ){
if( $n = $pass->needRehash() ){
$newHash = $pass->reHashPassword();
$db->where( ['email' => $this->email, 'username' => $this->username],'AND', "OR" );
$db->where( ['password' => $this->password],'AND' );
$db->update($this->table,['hash' => $newHash]);
}

/************ SET SESSION VARIABLES HERE **************/
//session_start();
$_SESSION['logged'] = TRUE;
$_SESSION['userid'] = $data->id;
$_SESSION['username'] = $data->username;
$_SESSION['name'] = $data->display_name ? $data->display_name : "";
/****************** END SESSION SETTINGS **************/
return $data;
}
}
public static function isLoggedIn(){
if( isset($_SESSION['logged']) ){
return $_SESSION['logged'];
}
}
public static function logout(){
unset( $_SESSEION );
session_destroy();
header("Location:".BASEURL);
}
}
35 changes: 35 additions & 0 deletions app/System/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace App\System;
use Twig_Autoloader;
abstract class Controller
{
public $twig;
function __construct(){

/*-------------- Initialize Twig Template Engine -----------------*/

Twig_Autoloader::register();
$loader = new \Twig_Loader_Filesystem(DIR_VIEW);
$this->twig = new \Twig_Environment($loader, (ENVIRONMENT == 'production') ? array('cache' => 'cache') : array() );

}

/*-------------- FUNCTION TO LOAD VIEW -----------------*/
public function loadView($template, $data=array()){
if( ! is_array($data) ){
return;
}
$data['BASEPATH'] = BASEPATH;
$data['BASEURL'] = BASEURL;

$template = $this->twig->loadTemplate($template);
$template->display($data);
}

/*-------------- FUNCTION TO LOAD MODEL -----------------*/
public function loadModel($model){
if( file_exists(DIR_MODEL . $model . '.php') ){
require_once DIR_MODEL . $model . '.php';
}
}
}
Loading