-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ecco come stanno le cose nel Marzo 2014 nel videocorso MVC in PHP nella videolezione num. 17, successivo commit dopo la conclusione del gestionale pagine. Dopo la repo verra spostata per iniziare altri esempi.
- Loading branch information
1 parent
9227cb9
commit 8268acd
Showing
31 changed files
with
1,122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Impostiamo la cofifica utf8 (la mia preferita) | ||
AddDefaultCharset utf8 | ||
|
||
# Per Quando saremo pigri | ||
php_flag short_open_tag on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
session_start(); | ||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf8"> | ||
<title>Admin Panel MVC</title> | ||
|
||
<link rel="stylesheet" href="/public/css/reset.css" media="all"> | ||
<link rel="stylesheet" href="/public/css/admin.css" media="all"> | ||
</head> | ||
|
||
<body> | ||
<nav id="homeNav"> | ||
<ol> | ||
<li><a href="admin.php">Home Page</a></li> | ||
<li><a href="admin.php?content">Gestione Contenuto</a></li> | ||
<li><a href="admin.php?menu">Gestione Menu</a></li> | ||
</ol> | ||
</nav> | ||
|
||
<?php | ||
define('ROOT', dirname(__FILE__)); | ||
define('DS', DIRECTORY_SEPARATOR); | ||
$param = 'backend'; | ||
|
||
if(isset($_GET['menu'])){ | ||
require_once ROOT.DS."views".DS."backend".DS."view_adm_menu.php"; | ||
} elseif(isset($_GET['content'])) { | ||
require_once ROOT.DS."views".DS."backend".DS."view_adm_content.php"; | ||
} | ||
?> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
// Classe con le configurazioni e Debug ----- per localhost <- | ||
class Conf { | ||
protected $DB_HOST = 'localhost'; | ||
protected $DB_USER = 'root'; | ||
protected $DB_PASS = 'qweqwe'; | ||
protected $DB_NAME = 'mvc'; | ||
|
||
static function debug($item){ // Funzione di debug | ||
echo '<pre>'; | ||
print_r($item); | ||
echo '</pre>'; | ||
} | ||
|
||
static function showerror(){ // Mostra errori mysql | ||
die("Errore".mysql_errno()." : ".mysql_error()); | ||
} | ||
} | ||
|
||
error_reporting(E_ALL); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
if($_SERVER['HTTP_HOST'] == 'mvc.ex'){ | ||
require_once ROOT.DS."config".DS."conf.php"; | ||
} else { | ||
require_once ROOT.DS."config".DS."sconf.php"; | ||
} | ||
|
||
class Db extends Conf { | ||
|
||
private $connectionResource; // Variabile che conterra @id della connessione | ||
|
||
private function dbConnection() { // Stabilisce connessione al DB | ||
$this->connectionResource =@ mysql_connect($this->DB_HOST,$this->DB_USER,$this->DB_PASS) or conf::showerror(); | ||
$dbSelect =@ mysql_select_db($this->DB_NAME,$this->connectionResource) or conf::showerror(); | ||
mysql_query("set names utf8") or conf::showerror(); | ||
} | ||
|
||
public function query($query) { // Esegue le interrogazioni al DB | ||
$this->result =@ mysql_query($query) or conf::showerror(); | ||
return $this->result; | ||
} | ||
|
||
function __construct() { | ||
$this->dbConnection(); | ||
} | ||
} | ||
|
||
$open = new Db(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
// Classe con le configurazioni e Debug ----- per Server WEB <- | ||
class Conf { | ||
protected $DB_HOST = '...'; | ||
protected $DB_USER = '...'; | ||
protected $DB_PASS = '...'; | ||
protected $DB_NAME = '...'; | ||
|
||
static function showerror(){ // Mostra errori mysql | ||
die("Errore".mysql_errno()." : Scusate per il disaggio, si é verificato un errore al DataBase"); | ||
} | ||
} | ||
|
||
error_reporting(0); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
require_once ROOT.DS."modules".DS."module_content.php"; | ||
|
||
class ConContent extends ModContent { | ||
|
||
function takeContent($view_param, $page_id = null){ | ||
$result = $this->select($view_param, $page_id); | ||
|
||
return $result; | ||
} | ||
|
||
function __construct(){ | ||
parent::__construct(); | ||
|
||
|
||
$action = (isset($_GET['action'])) ? $_GET['action'] : null ; | ||
$id = (isset($_GET['id'])) ? $_GET['id'] : null ; | ||
|
||
if(strlen($action) > 0) | ||
$this->manageAction($action, $id); | ||
} | ||
|
||
function cCreate($_POST){ | ||
if(isset($_POST['create'])){ | ||
$_SESSION['errors'] = null; | ||
|
||
$processor = new FormProcessor_Content(); | ||
$processor->processor($_POST); | ||
} | ||
|
||
$_POST = null; | ||
return require_once ROOT.DS.'views'.DS.'backend'.DS.'content'.DS.'create_tpl.php'; | ||
} | ||
|
||
function manageAction($action, $id){ | ||
switch($action){ | ||
case('visibleYes'): | ||
$visible = 1; | ||
if(!$this->visible($id,$visible)){ | ||
echo 'Errore nel cambiare lo stato alla pagina'; | ||
} else { | ||
header("Location: admin.php?content"); | ||
} | ||
break; | ||
case('visibleNo'): | ||
$visible = 0; | ||
if(!$this->visible($id,$visible)){ | ||
echo 'Errore nel cambiare lo stato alla pagina'; | ||
} else { | ||
header("Location: admin.php?content"); | ||
} | ||
break; | ||
case('edit'): | ||
/*$menu_item = $this->selectOne($id); | ||
echo ' | ||
<form method="POST" action=""> | ||
<p>Nome pagina: <input type="text" name="menu_name" value="'.$menu_item->page_name.'"/></p> | ||
<br> | ||
<p>Title della pagina:<input type="text" name="menu_title" value="'.$menu_item->page_title.'" /></p> | ||
<br> | ||
<input type="submit" name="edit" value="Modifica" /> | ||
</form>'; | ||
if($_POST['edit']){ | ||
$page_name = $_POST['menu_name']; | ||
$page_title = $_POST['menu_title']; | ||
if(!$this->edit($id,$page_name,$page_title)) { | ||
header("Location: admin.php?content&message=Errore!!! Pagina non modificata !"); | ||
} else { | ||
header("Location: admin.php?content&message=Pagina modificata !"); | ||
} | ||
}*/ | ||
echo 'Ancora in realizzazione ....'; | ||
break; | ||
case('delete'): | ||
if(!$this->delete($id)){ | ||
header("Location: admin.php?content&message=Errore!!! Pagina non eliminata!"); | ||
} else { | ||
header("Location: admin.php?content&message=Pagina eliminata!"); | ||
} | ||
break; | ||
case('create'): | ||
$this->cCreate($_POST); | ||
break; | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
require_once ROOT.DS."modules".DS."module_menu.php"; | ||
require_once ROOT.DS.'libraries'.DS.'FormProcessor'.DS.'FormProcessor_Menu.php'; | ||
|
||
class ConMenu extends ModMenu { | ||
|
||
function __construct($action = null, $id = null){ | ||
parent::__construct(); // chiamiamo il costruttore padre | ||
|
||
if(strlen($action) > 0) | ||
$this->manageMenu($action, $id); | ||
} | ||
|
||
function takeMenu($view_param){ | ||
$menu = $this->selectMenu($view_param); | ||
return $menu; | ||
} | ||
|
||
function cCreateMenu($_POST){ | ||
if(isset($_POST['submit'])){ | ||
$_SESSION['errors'] = null; | ||
|
||
$processor = new FormProcessor_Menu(); | ||
$processor->processor($_POST); | ||
} | ||
|
||
$_POST = null; | ||
return require_once ROOT.DS.'views'.DS.'backend'.DS.'menu'.DS.'form_createNew_tpl.php'; | ||
} | ||
|
||
function manageMenu($action, $id){ | ||
switch($action){ | ||
case('visibleYes'): | ||
$visible = 1; | ||
if(!$this->visibleMenu($id,$visible)){ | ||
echo 'Errore nel cambiare lo stato al menu'; | ||
} else { | ||
header("Location: admin.php?menu"); | ||
} | ||
break; | ||
case('visibleNo'): | ||
$visible = 0; | ||
if(!$this->visibleMenu($id,$visible)){ | ||
echo 'Errore nel cambiare lo stato al menu'; | ||
} else { | ||
header("Location: admin.php?menu"); | ||
} | ||
break; | ||
case('edit'): | ||
$menu_item = $this->selectOneMenu($id); | ||
|
||
echo ' | ||
<form method="POST" action=""> | ||
<p>Nome menu: <input type="text" name="menu_name" value="'.$menu_item->menu_name.'"/></p> | ||
<br> | ||
<p>Tag title del menu:<input type="text" name="menu_title" value="'.$menu_item->menu_title.'" /></p> | ||
<br> | ||
<input type="submit" name="menu_edit" value="Modifica" /> | ||
</form>'; | ||
if($_POST){ | ||
$menu_name = $_POST['menu_name']; | ||
$menu_title = $_POST['menu_title']; | ||
|
||
if(!$this->editMenu($id,$menu_name,$menu_title)) { | ||
header("Location: admin.php?menu&message=Errore!!! Menu non modificato !"); | ||
} else { | ||
header("Location: admin.php?menu&message=Menu modificato !"); | ||
} | ||
} | ||
break; | ||
case('delete'): | ||
if(!$this->deleteMenu($id)){ | ||
header("Location: admin.php?menu&message=Errore!!! Menu non eliminato!"); | ||
} else { | ||
header("Location: admin.php?menu&message=Menu eliminato!"); | ||
} | ||
break; | ||
case('create'): | ||
$this->cCreateMenu($_POST); | ||
break; | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
define('ROOT',dirname(__FILE__)); | ||
define('DS',DIRECTORY_SEPARATOR); | ||
$param = 'frontend'; | ||
require_once ROOT.DS."views".DS."frontend".DS."view_content.php"; // vista contenuto con dati sui meta key etc. | ||
|
||
require_once ROOT.DS."config".DS."db.php"; | ||
|
||
require_once ROOT.DS."views".DS."frontend".DS."blocks".DS."head.php"; | ||
|
||
require_once ROOT.DS."views".DS."frontend".DS."view_menu.php"; | ||
|
||
echo (isset($content)) ? $content : ''; // mandiamo in output il contenuto se e presente | ||
|
||
require_once ROOT.DS."views".DS."frontend".DS."blocks".DS."footer.php"; | ||
?> |
Oops, something went wrong.