Skip to content

Commit 2d2fac7

Browse files
committed
Committed changes
0 parents  commit 2d2fac7

File tree

246 files changed

+57461
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+57461
-0
lines changed

Database - storedb/storedb database - SQL Dump File - PhpMyAdmin Export.sql

Lines changed: 644 additions & 0 deletions
Large diffs are not rendered by default.

Project Screenshots/.gitkeep

Whitespace-only changes.

app/config/config.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
if(!defined('DS')) {
4+
define('DS', DIRECTORY_SEPARATOR);
5+
}
6+
7+
define('APP_PATH', realpath(dirname(__FILE__)) . DS . '..');
8+
define('VIEWS_PATH', APP_PATH . DS . 'views' . DS);
9+
define('TEMPLATE_PATH', APP_PATH . DS . 'template' . DS);
10+
define('LANGUAGES_PATH', APP_PATH . DS . 'languages' . DS);
11+
12+
define('CSS', '/css/');
13+
define('JS', '/js/');
14+
15+
// Database Credentials
16+
defined('DATABASE_HOST_NAME') ? null : define ('DATABASE_HOST_NAME', 'localhost');
17+
defined('DATABASE_USER_NAME') ? null : define ('DATABASE_USER_NAME', 'root');
18+
defined('DATABASE_PASSWORD') ? null : define ('DATABASE_PASSWORD', '0000');
19+
defined('DATABASE_DB_NAME') ? null : define ('DATABASE_DB_NAME', 'storedb');
20+
defined('DATABASE_PORT_NUMBER') ? null : define ('DATABASE_PORT_NUMBER', 3306);
21+
defined('DATABASE_CONN_DRIVER') ? null : define ('DATABASE_CONN_DRIVER', 1);
22+
23+
// Default application language
24+
defined('APP_DEFAULT_LANGUAGE') ? null : define ('APP_DEFAULT_LANGUAGE', 'ar');
25+
26+
// Session configuration
27+
defined('SESSION_NAME') ? null : define ('SESSION_NAME', '_ESTORE_SESSION');
28+
defined('SESSION_LIFE_TIME') ? null : define ('SESSION_LIFE_TIME', 0);
29+
defined('SESSION_SAVE_PATH') ? null : define ('SESSION_SAVE_PATH', APP_PATH . DS . '..' . DS . 'sessions');
30+
31+
// SALT
32+
defined('APP_SALT') ? null : define ('APP_SALT', '$2a$07$yeNCSNwRpYopOhv0TrrReP$');
33+
34+
// Check for access privileges
35+
defined('CHECK_FOR_PRIVILEGES') ? null : define('CHECK_FOR_PRIVILEGES', 1);
36+
37+
// define the path to our uploaded files
38+
defined('UPLOAD_STORAGE') ? null : define ('UPLOAD_STORAGE', APP_PATH . DS . '..' . DS . 'public' . DS . 'uploads');
39+
defined('IMAGES_UPLOAD_STORAGE') ? null : define ('IMAGES_UPLOAD_STORAGE', UPLOAD_STORAGE . DS . 'images');
40+
defined('DOCUMENTS_UPLOAD_STORAGE') ? null : define ('DOCUMENTS_UPLOAD_STORAGE', UPLOAD_STORAGE . DS . 'documents');
41+
defined('MAX_FILE_SIZE_ALLOWED') ? null : define ('MAX_FILE_SIZE_ALLOWED', ini_get('upload_max_filesize'));

app/config/templateconfig.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
return [
4+
'template' => [
5+
'wrapper_start' => TEMPLATE_PATH . 'wrapperstart.php',
6+
'header' => TEMPLATE_PATH . 'header.php',
7+
'nav' => TEMPLATE_PATH . 'nav.php',
8+
':view' => ':action_view',
9+
'wrapper_end' => TEMPLATE_PATH . 'wrapperend.php'
10+
],
11+
'header_resources' => [
12+
'css' => [
13+
'normalize' => CSS . 'normalize.css',
14+
'fawsome' => CSS . 'fawsome.min.css',
15+
'gicons' => CSS . 'googleicons.css',
16+
'main' => CSS . 'main' . $_SESSION['lang'] . '.css'
17+
],
18+
'js' => [
19+
'modernizr' => JS . 'vendor/modernizr-2.8.3.min.js'
20+
]
21+
],
22+
'footer_resources' => [
23+
'jquery' => JS . 'vendor/jquery-1.12.0.min.js',
24+
'helper' => JS . 'helper.js',
25+
'datatables' => JS . 'datatables' . $_SESSION['lang'] . '.js',
26+
'main' => JS . 'main.js'
27+
]
28+
];
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
namespace PHPMVC\Controllers;
3+
4+
use PHPMVC\LIB\FrontController;
5+
use PHPMVC\LIB\Template;
6+
use PHPMVC\Lib\Validate;
7+
8+
class AbstractController
9+
{
10+
11+
use Validate;
12+
13+
protected $_controller;
14+
protected $_action;
15+
protected $_params;
16+
/**
17+
* @var Template\Template
18+
*/
19+
protected $_template;
20+
protected $_registry;
21+
22+
protected $_data = [];
23+
24+
public function __get($key)
25+
{
26+
return $this->_registry->$key;
27+
}
28+
29+
public function notFoundAction()
30+
{
31+
$this->_view();
32+
}
33+
34+
public function setController ($controllerName)
35+
{
36+
$this->_controller = $controllerName;
37+
}
38+
39+
public function setAction ($actionName)
40+
{
41+
$this->_action = $actionName;
42+
}
43+
44+
public function setTemplate($template)
45+
{
46+
$this->_template = $template;
47+
}
48+
49+
public function setRegistry($registry)
50+
{
51+
$this->_registry = $registry;
52+
}
53+
54+
public function setParams ($params)
55+
{
56+
$this->_params = $params;
57+
}
58+
59+
protected function _view()
60+
{
61+
$view = VIEWS_PATH . $this->_controller . DS . $this->_action . '.view.php';
62+
if($this->_action == FrontController::NOT_FOUND_ACTION || !file_exists($view)) {
63+
$view = VIEWS_PATH . 'notfound' . DS . 'notfound.view.php';
64+
}
65+
$this->_data = array_merge($this->_data, $this->language->getDictionary());
66+
$this->_template->setRegistry($this->_registry);
67+
$this->_template->setActionViewFile($view);
68+
$this->_template->setAppData($this->_data);
69+
$this->_template->renderApp();
70+
}
71+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace PHPMVC\Controllers;
4+
5+
class AccessDeniedController extends AbstractController
6+
{
7+
public function defaultAction()
8+
{
9+
$this->language->load('template.common');
10+
$this->_view();
11+
}
12+
}

app/controllers/authcontroller.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace PHPMVC\Controllers;
3+
4+
use PHPMVC\LIB\Helper;
5+
use PHPMVC\lib\Messenger;
6+
use PHPMVC\Models\UserModel;
7+
8+
class AuthController extends AbstractController
9+
{
10+
use Helper;
11+
public function loginAction()
12+
{
13+
$this->language->load('auth.login');
14+
15+
$this->_template->swapTemplate(
16+
[
17+
':view' => ':action_view'
18+
]);
19+
20+
if(isset($_POST['login'])) {
21+
$isAuthorized = UserModel::authenticate($_POST['ucname'], $_POST['ucpwd'], $this->session);
22+
if($isAuthorized == 2) {
23+
$this->messenger->add($this->language->get('text_user_disabled'), Messenger::APP_MESSAGE_ERROR);
24+
} elseif ($isAuthorized == 1) {
25+
$this->redirect('/');
26+
} elseif ($isAuthorized === false) {
27+
$this->messenger->add($this->language->get('text_user_not_found'), Messenger::APP_MESSAGE_ERROR);
28+
}
29+
}
30+
31+
$this->_view();
32+
}
33+
34+
public function logoutAction()
35+
{
36+
// TODO: check the cookie deletion
37+
$this->session->kill();
38+
$this->redirect('/auth/login');
39+
}
40+
}

app/controllers/clientscontroller.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
namespace PHPMVC\Controllers;
3+
4+
use PHPMVC\LIB\Helper;
5+
use PHPMVC\LIB\InputFilter;
6+
use PHPMVC\lib\Messenger;
7+
use PHPMVC\Models\ClientModel;
8+
9+
class ClientsController extends AbstractController
10+
{
11+
12+
use InputFilter;
13+
use Helper;
14+
15+
private $_createActionRoles =
16+
[
17+
'Name' => 'req|alpha|between(3,40)',
18+
'Email' => 'req|email',
19+
'PhoneNumber' => 'alphanum|max(15)',
20+
'Address' => 'req|alphanum|max(50)'
21+
];
22+
23+
public function defaultAction()
24+
{
25+
$this->language->load('template.common');
26+
$this->language->load('clients.default');
27+
28+
$this->_data['clients'] = ClientModel::getAll();
29+
30+
$this->_view();
31+
}
32+
33+
public function createAction()
34+
{
35+
36+
$this->language->load('template.common');
37+
$this->language->load('clients.create');
38+
$this->language->load('clients.labels');
39+
$this->language->load('clients.messages');
40+
$this->language->load('validation.errors');
41+
42+
if(isset($_POST['submit']) && $this->isValid($this->_createActionRoles, $_POST)) {
43+
44+
$client = new ClientModel();
45+
46+
$client->Name = $this->filterString($_POST['Name']);
47+
$client->Email = $this->filterString($_POST['Email']);
48+
$client->PhoneNumber = $this->filterString($_POST['PhoneNumber']);
49+
$client->Address = $this->filterString($_POST['Address']);
50+
51+
if($client->save()) {
52+
$this->messenger->add($this->language->get('message_create_success'));
53+
} else {
54+
$this->messenger->add($this->language->get('message_create_failed'), Messenger::APP_MESSAGE_ERROR);
55+
}
56+
$this->redirect('/clients');
57+
}
58+
59+
$this->_view();
60+
}
61+
62+
public function editAction()
63+
{
64+
65+
$id = $this->filterInt($this->_params[0]);
66+
$client = ClientModel::getByPK($id);
67+
68+
if($client === false) {
69+
$this->redirect('/clients');
70+
}
71+
72+
$this->_data['client'] = $client;
73+
74+
$this->language->load('template.common');
75+
$this->language->load('clients.edit');
76+
$this->language->load('clients.labels');
77+
$this->language->load('clients.messages');
78+
$this->language->load('validation.errors');
79+
80+
if(isset($_POST['submit']) && $this->isValid($this->_createActionRoles, $_POST)) {
81+
82+
$client->Name = $this->filterString($_POST['Name']);
83+
$client->Email = $this->filterString($_POST['Email']);
84+
$client->PhoneNumber = $this->filterString($_POST['PhoneNumber']);
85+
$client->Address = $this->filterString($_POST['Address']);
86+
87+
if($client->save()) {
88+
$this->messenger->add($this->language->get('message_create_success'));
89+
} else {
90+
$this->messenger->add($this->language->get('message_create_failed'), Messenger::APP_MESSAGE_ERROR);
91+
}
92+
$this->redirect('/clients');
93+
}
94+
95+
$this->_view();
96+
}
97+
98+
public function deleteAction()
99+
{
100+
101+
$id = $this->filterInt($this->_params[0]);
102+
$client = ClientModel::getByPK($id);
103+
104+
if($client === false) {
105+
$this->redirect('/clients');
106+
}
107+
108+
$this->language->load('clients.messages');
109+
110+
if($client->delete()) {
111+
$this->messenger->add($this->language->get('message_delete_success'));
112+
} else {
113+
$this->messenger->add($this->language->get('message_delete_failed'), Messenger::APP_MESSAGE_ERROR);
114+
}
115+
$this->redirect('/clients');
116+
}
117+
}

0 commit comments

Comments
 (0)