Browse Source

Ajout de formation / type / lieu / categorie / objectifs / tarif

see #9
master
maxime 8 years ago
parent
commit
8dd76d807e
19 changed files with 1051 additions and 2 deletions
  1. +1
    -0
      .gitignore
  2. +15
    -0
      modules/formation/data.php
  3. +656
    -0
      modules/formation/mvc.php
  4. +266
    -2
      modules/formation/sql.php
  5. +12
    -0
      modules/formation/templates/formation_create.html
  6. +6
    -0
      modules/formation/templates/formation_create_category.html
  7. +5
    -0
      modules/formation/templates/formation_create_department.html
  8. +5
    -0
      modules/formation/templates/formation_create_objective.html
  9. +5
    -0
      modules/formation/templates/formation_create_place.html
  10. +6
    -0
      modules/formation/templates/formation_create_price.html
  11. +5
    -0
      modules/formation/templates/formation_create_type.html
  12. +12
    -0
      modules/formation/templates/select_category.html
  13. +8
    -0
      modules/formation/templates/select_department.html
  14. +8
    -0
      modules/formation/templates/select_objective.html
  15. +9
    -0
      modules/formation/templates/select_place.html
  16. +8
    -0
      modules/formation/templates/select_price.html
  17. +8
    -0
      modules/formation/templates/select_type.html
  18. +7
    -0
      nbproject/project.properties
  19. +9
    -0
      nbproject/project.xml

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
/nbproject/private/

+ 15
- 0
modules/formation/data.php View File

@ -53,6 +53,21 @@ class formation_type {
return $this->$variable;
}
}
class formation_objective {
private $id;
private $label;
public function __construct($sql_fetch) {
foreach(array_keys(get_class_vars(get_class($this))) as $attribut) {
if(isset($sql_fetch[$attribut]))
$this->$attribut = $sql_fetch[$attribut];
}
}
public function __get($variable) {
if(!isset($this->$variable))
return null;
return $this->$variable;
}
}
class formation_category {
private $id;
private $label;


+ 656
- 0
modules/formation/mvc.php View File

@ -51,6 +51,316 @@ class formation_model extends model {
}
return $formations;
}
public function formation_list_department_nb_pages($nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_department_nb_pages(:nb_item_per_page)');
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$res = $query->fetch(PDO::FETCH_NUM);
return $res[0];
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_list_department($page = 1, $order_by = 'id', $order_by_asc = true, $nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_department(:order_by, :order_by_asc, :page, :nb_item_per_page)');
$query->bindParam(':order_by', $order_by, PDO::PARAM_STR);
$order_by_asc = ($order_by_asc!='on' && $order_by_asc!=true)?false:true;
$query->bindParam(':order_by_asc', $order_by_asc, PDO::PARAM_BOOL);
$page = ($page>0)?$page:1;
$query->bindParam(':page', $page, PDO::PARAM_INT);
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$departments = array();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $department_sql_fetch)
$departments[] = new formation_department($department_sql_fetch);
} catch(PDOException $e) {
throw new sql_error($e);
}
return $departments;
}
public function formation_list_category_nb_pages($nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_category_nb_pages(:nb_item_per_page)');
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$res = $query->fetch(PDO::FETCH_NUM);
return $res[0];
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_list_category($page = 1, $order_by = 'id', $order_by_asc = true, $nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_category(:order_by, :order_by_asc, :page, :nb_item_per_page)');
$query->bindParam(':order_by', $order_by, PDO::PARAM_STR);
$order_by_asc = ($order_by_asc!='on' && $order_by_asc!=true)?false:true;
$query->bindParam(':order_by_asc', $order_by_asc, PDO::PARAM_BOOL);
$page = ($page>0)?$page:1;
$query->bindParam(':page', $page, PDO::PARAM_INT);
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$categories = array();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $category_sql_fetch)
$categories[] = new formation_category($category_sql_fetch);
} catch(PDOException $e) {
throw new sql_error($e);
}
return $categories;
}
public function formation_list_type_nb_pages($nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_type_nb_pages(:nb_item_per_page)');
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$res = $query->fetch(PDO::FETCH_NUM);
return $res[0];
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_list_type($page = 1, $order_by = 'id', $order_by_asc = true, $nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_type(:order_by, :order_by_asc, :page, :nb_item_per_page)');
$query->bindParam(':order_by', $order_by, PDO::PARAM_STR);
$order_by_asc = ($order_by_asc!='on' && $order_by_asc!=true)?false:true;
$query->bindParam(':order_by_asc', $order_by_asc, PDO::PARAM_BOOL);
$page = ($page>0)?$page:1;
$query->bindParam(':page', $page, PDO::PARAM_INT);
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$types = array();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $type_sql_fetch)
$types[] = new formation_type($type_sql_fetch);
} catch(PDOException $e) {
throw new sql_error($e);
}
return $types;
}
public function formation_list_objective_nb_pages($nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_objective_nb_pages(:nb_item_per_page)');
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$res = $query->fetch(PDO::FETCH_NUM);
return $res[0];
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_list_objective($page = 1, $order_by = 'id', $order_by_asc = true, $nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_objective(:order_by, :order_by_asc, :page, :nb_item_per_page)');
$query->bindParam(':order_by', $order_by, PDO::PARAM_STR);
$order_by_asc = ($order_by_asc!='on' && $order_by_asc!=true)?false:true;
$query->bindParam(':order_by_asc', $order_by_asc, PDO::PARAM_BOOL);
$page = ($page>0)?$page:1;
$query->bindParam(':page', $page, PDO::PARAM_INT);
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$objectives = array();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $objective_sql_fetch)
$objectives[] = new formation_objective($objective_sql_fetch);
} catch(PDOException $e) {
throw new sql_error($e);
}
return $objectives;
}
public function formation_list_place_nb_pages($nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_place_nb_pages(:nb_item_per_page)');
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$res = $query->fetch(PDO::FETCH_NUM);
return $res[0];
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_list_place($page = 1, $order_by = 'id', $order_by_asc = true, $nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_place(:order_by, :order_by_asc, :page, :nb_item_per_page)');
$query->bindParam(':order_by', $order_by, PDO::PARAM_STR);
$order_by_asc = ($order_by_asc!='on' && $order_by_asc!=true)?false:true;
$query->bindParam(':order_by_asc', $order_by_asc, PDO::PARAM_BOOL);
$page = ($page>0)?$page:1;
$query->bindParam(':page', $page, PDO::PARAM_INT);
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$places = array();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $place_sql_fetch)
$places[] = new formation_place($place_sql_fetch);
} catch(PDOException $e) {
throw new sql_error($e);
}
return $places;
}
public function formation_list_price_nb_pages($nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_price_nb_pages(:nb_item_per_page)');
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$res = $query->fetch(PDO::FETCH_NUM);
return $res[0];
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_list_price($page = 1, $order_by = 'id', $order_by_asc = true, $nb_item_per_page = null) {
if(is_null($nb_item_per_page))
$nb_item_per_page = config::read_config('general', 'max_items_per_page');
try {
$query = $this->database->pdo()->prepare('select * from formation_list_price(:order_by, :order_by_asc, :page, :nb_item_per_page)');
$query->bindParam(':order_by', $order_by, PDO::PARAM_STR);
$order_by_asc = ($order_by_asc!='on' && $order_by_asc!=true)?false:true;
$query->bindParam(':order_by_asc', $order_by_asc, PDO::PARAM_BOOL);
$page = ($page>0)?$page:1;
$query->bindParam(':page', $page, PDO::PARAM_INT);
$query->bindParam(':nb_item_per_page', $nb_item_per_page, PDO::PARAM_INT);
$query->execute();
$prices = array();
foreach($query->fetchAll(PDO::FETCH_ASSOC) as $price_sql_fetch)
$prices[] = new formation_price($price_sql_fetch);
} catch(PDOException $e) {
throw new sql_error($e);
}
return $prices;
}
public function formation_create($label, $program, $prerequisite, $price, $place, $type, $category) {
try {
$query = $this->database->pdo()->prepare('select * from formation_add(:label, :program, :prerequisite, :price, :place, :type, :category, false)');
$label = empty($label)?null:$label;
$query->bindParam(':label', $label, PDO::PARAM_STR);
$program = empty($program)?null:$program;
$query->bindParam(':program', $program, PDO::PARAM_STR);
$prerequisite = empty($prerequisite)?null:$prerequisite;
$query->bindParam(':prerequisite', $prerequisite, PDO::PARAM_STR);
$price = empty($price)?null:$price;
$query->bindParam(':price', $price, PDO::PARAM_INT);
$place = empty($place)?null:$place;
$query->bindParam(':place', $place, PDO::PARAM_INT);
$type = empty($type)?null:$type;
$query->bindParam(':type', $type, PDO::PARAM_INT);
$category = empty($category)?null:$category;
$query->bindParam(':category', $category, PDO::PARAM_INT);
$query->execute();
return new formation($query->fetch(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_create_price($full_price, $low_price) {
try {
$query = $this->database->pdo()->prepare('select * from price_add(:full_price, :low_price)');
$full_price = empty($full_price)?null:$full_price;
$query->bindParam(':full_price', $full_price);
$low_price = empty($low_price)?null:$low_price;
$query->bindParam(':low_price', $low_price);
$query->execute();
return new formation_price($query->fetch(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_create_place($place_name) {
try {
$query = $this->database->pdo()->prepare('select * from place_add(:place_name)');
$place_name = empty($place_name)?null:$place_name;
$query->bindParam(':place_name', $place_name);
$query->execute();
return new formation_place($query->fetch(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_create_objective($label) {
try {
$query = $this->database->pdo()->prepare('select * from objective_add(:label)');
$label = empty($label)?null:$label;
$query->bindParam(':label', $label);
$query->execute();
return new formation_objective($query->fetch(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_create_type($label) {
try {
$query = $this->database->pdo()->prepare('select * from type_add(:label)');
$label = empty($label)?null:$label;
$query->bindParam(':label', $label);
$query->execute();
return new formation_type($query->fetch(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_create_department($label) {
try {
$query = $this->database->pdo()->prepare('select * from department_add(:label)');
$label = empty($label)?null:$label;
$query->bindParam(':label', $label);
$query->execute();
return new formation_department($query->fetch(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
throw new sql_error($e);
}
}
public function formation_create_category($label, $department) {
try {
$query = $this->database->pdo()->prepare('select * from category_add(:label, :department)');
$label = empty($label)?null:$label;
$query->bindParam(':label', $label);
$department = empty($department)?null:$department;
$query->bindParam(':department', $department);
$query->execute();
return new formation_category($query->fetch(PDO::FETCH_ASSOC));
} catch(PDOException $e) {
throw new sql_error($e);
}
}
}
class formation_view extends view {
@ -74,6 +384,150 @@ class formation_view extends view {
return $this->tpl->draw('modules/formation/templates/select', $return_string);
}
public function formation_select_department($department_list, $name, $selected = array(), $return_string = false) {
$department_list_tab = array();
foreach($department_list as $department) {
$department_list_tab[] = array (
'id' => $department->__get('id'),
'label' => $department->__get('label'),
'selected' => (in_array(($department->__get('id')),$selected))?'selected="selected"':''
);
}
$this->tpl->assign('formation_select_department', $department_list_tab);
$this->tpl->assign('name', $name);
return $this->tpl->draw('modules/formation/templates/select_department', $return_string);
}
public function formation_select_category($category_list, $name, $selected = array(), $return_string = false) {
$category_list_tab = array();
foreach($category_list as $category) {
//$tab = &$category_list_tab[];
$tab[$category->__get('department')->__get('label')][] = array (
'id' => $category->__get('id'),
'label' => $category->__get('label'),
'selected' => (in_array(($category->__get('id')),$selected))?'selected="selected"':''
);
}
$this->tpl->assign('formation_select_category', $tab);
$this->tpl->assign('name', $name);
return $this->tpl->draw('modules/formation/templates/select_category', $return_string);
}
public function formation_select_type($type_list, $name, $selected = array(), $return_string = false) {
$type_list_tab = array();
foreach($type_list as $type) {
$type_list_tab[] = array (
'id' => $type->__get('id'),
'label' => $type->__get('label'),
'selected' => (in_array(($type->__get('id')),$selected))?'selected="selected"':''
);
}
$this->tpl->assign('formation_select_type', $type_list_tab);
$this->tpl->assign('name', $name);
return $this->tpl->draw('modules/formation/templates/select_type', $return_string);
}
public function formation_select_objective($objective_list, $name, $selected = array(), $return_string = false) {
$objective_list_tab = array();
foreach($objective_list as $objective) {
$objective_list_tab[] = array (
'id' => $objective->__get('id'),
'label' => $objective->__get('label'),
'selected' => (in_array(($objective->__get('id')),$selected))?'selected="selected"':''
);
}
$this->tpl->assign('formation_select_objective', $objective_list_tab);
$this->tpl->assign('name', $name);
return $this->tpl->draw('modules/formation/templates/select_objective', $return_string);
}
public function formation_select_place($place_list, $name, $selected = array(), $return_string = false) {
$place_list_tab = array();
foreach($place_list as $place) {
$place_list_tab[] = array (
'id' => $place->__get('id'),
'label' => $place->__get('label'),
'selected' => (in_array(($place->__get('id')),$selected))?'selected="selected"':''
);
}
$this->tpl->assign('formation_select_place', $place_list_tab);
$this->tpl->assign('name', $name);
return $this->tpl->draw('modules/formation/templates/select_place', $return_string);
}
public function formation_select_price($price_list, $name, $selected = array(), $return_string = false) {
$price_list_tab = array();
foreach($price_list as $price) {
$price_list_tab[] = array (
'id' => $price->__get('id'),
'full_price' => $price->__get('full_price'),
'low_price' => $price->__get('low_price'),
'selected' => (in_array(($price->__get('id')),$selected))?'selected="selected"':''
);
}
$this->tpl->assign('formation_select_price', $price_list_tab);
$this->tpl->assign('name', $name);
return $this->tpl->draw('modules/formation/templates/select_price', $return_string);
}
public function formation_create($csrf_token) {
$this->tpl->assign('label', isset($_POST['label'])?htmlspecialchars($_POST['label']):'');
$this->tpl->assign('program', isset($_POST['program'])?htmlspecialchars($_POST['program']):'');
$this->tpl->assign('prerequisite', isset($_POST['prerequisite'])?htmlspecialchars($_POST['prerequisite']):'');
$this->tpl->assign('formation_select_price', $this->controler->formation_select_price($field_name='price', ''));
$this->tpl->assign('formation_select_place', $this->controler->formation_select_place($field_name='place', ''));
$this->tpl->assign('formation_select_objective', $this->controler->formation_select_objective($field_name='objective', ''));
$this->tpl->assign('formation_select_type', $this->controler->formation_select_type($field_name='type', ''));
$this->tpl->assign('formation_select_category', $this->controler->formation_select_category($field_name='category', ''));
$this->tpl->assign('csrf_token', htmlspecialchars($csrf_token));
return $this->tpl->draw('modules/formation/templates/formation_create', false);
}
public function formation_create_price($csrf_token) {
$this->tpl->assign('full_price', isset($_POST['full_price'])?htmlspecialchars($_POST['full_price']):'');
$this->tpl->assign('low_price', isset($_POST['low_price'])?htmlspecialchars($_POST['low_price']):'');
$this->tpl->assign('csrf_token', htmlspecialchars($csrf_token));
return $this->tpl->draw('modules/formation/templates/formation_create_price', false);
}
public function formation_create_place($csrf_token) {
$this->tpl->assign('label', isset($_POST['label'])?htmlspecialchars($_POST['label']):'');
$this->tpl->assign('csrf_token', htmlspecialchars($csrf_token));
return $this->tpl->draw('modules/formation/templates/formation_create_place', false);
}
public function formation_create_objective($csrf_token) {
$this->tpl->assign('label', isset($_POST['label'])?htmlspecialchars($_POST['label']):'');
$this->tpl->assign('csrf_token', htmlspecialchars($csrf_token));
return $this->tpl->draw('modules/formation/templates/formation_create_objective', false);
}
public function formation_create_type($csrf_token) {
$this->tpl->assign('label', isset($_POST['label'])?htmlspecialchars($_POST['label']):'');
$this->tpl->assign('csrf_token', htmlspecialchars($csrf_token));
return $this->tpl->draw('modules/formation/templates/formation_create_type', false);
}
public function formation_create_department($csrf_token) {
$this->tpl->assign('label', isset($_POST['label'])?htmlspecialchars($_POST['label']):'');
$this->tpl->assign('csrf_token', htmlspecialchars($csrf_token));
return $this->tpl->draw('modules/formation/templates/formation_create_department', false);
}
public function formation_create_category($csrf_token) {
$this->tpl->assign('label', isset($_POST['label'])?htmlspecialchars($_POST['label']):'');
$this->tpl->assign('formation_select_department', $this->controler->formation_select_department($field_name='department', ''));
$this->tpl->assign('csrf_token', htmlspecialchars($csrf_token));
return $this->tpl->draw('modules/formation/templates/formation_create_category', false);
}
}
@ -82,6 +536,16 @@ class formation_controler extends controler {
$this->model = new formation_model($this, $database);
$this->view = new formation_view($this, $tpl);
$this->dependences = array();
$this->route = array(
'create' => array('function' => 'controler_create_formation', 'filter_url' => array('formation')),
'create_price' => array('function' => 'controler_create_price', 'filter_url' => array('formation')),
'create_place' => array('function' => 'controler_create_place', 'filter_url' => array('formation')),
'create_objective' => array('function' => 'controler_create_objective', 'filter_url' => array('formation')),
'create_type' => array('function' => 'controler_create_type', 'filter_url' => array('formation')),
'create_department' => array('function' => 'controler_create_department', 'filter_url' => array('formation')),
'create_category' => array('function' => 'controler_create_category', 'filter_url' => array('formation'))
);
$this->load_dependences($database, $tpl);
}
public function install() {
@ -95,6 +559,198 @@ class formation_controler extends controler {
return $this->view->formation_select($this->model->formation_list($only_validated, $page=1, $order_by='id', $order_by_asc=true, $nb_item_per_page=-1), $multiple_selection, $field_name, $selection, $return_string=true);
}
public function formation_select_department($field_name, $selection) {
return $this->view->formation_select_department($this->model->formation_list_department($page=1, $order_by='id', $order_by_asc=true, $nb_item_per_page=-1), $field_name, $selection, $return_string=true);
}
public function formation_select_category($field_name, $selection) {
return $this->view->formation_select_category($this->model->formation_list_category($page=1, $order_by='id', $order_by_asc=true, $nb_item_per_page=-1), $field_name, $selection, $return_string=true);
}
public function formation_select_type($field_name, $selection) {
return $this->view->formation_select_type($this->model->formation_list_type($page=1, $order_by='id', $order_by_asc=true, $nb_item_per_page=-1), $field_name, $selection, $return_string=true);
}
public function formation_select_objective($field_name, $selection) {
return $this->view->formation_select_objective($this->model->formation_list_objective($page=1, $order_by='id', $order_by_asc=true, $nb_item_per_page=-1), $field_name, $selection, $return_string=true);
}
public function formation_select_place($field_name, $selection) {
return $this->view->formation_select_place($this->model->formation_list_place($page=1, $order_by='id', $order_by_asc=true, $nb_item_per_page=-1), $field_name, $selection, $return_string=true);
}
public function formation_select_price($field_name, $selection) {
return $this->view->formation_select_price($this->model->formation_list_price($page=1, $order_by='id', $order_by_asc=true, $nb_item_per_page=-1), $field_name, $selection, $return_string=true);
}
public function controler_create_formation() {
$this->view->print_header('Ajout d\'une formation');
if(!isset($_SESSION['user']) || !($_SESSION['user'] instanceof admin)) {
$this->view->print_message_forbidden();
} else {
/* si on valide le formulaire */
if(isset($_POST['formation_create_submit'])) {
if(!isset($_POST['csrf_token']) || csrf::verify_token($_POST['csrf_token']) == false)
$this->view->print_message('jeton csrf invalide');
else {
try {
$this->model->formation_create(isset($_POST['label'])?$_POST['label']:'', isset($_POST['program'])?$_POST['program']:'', isset($_POST['prerequisite'])?$_POST['prerequisite']:'', isset($_POST['price'])?$_POST['price']:'', isset($_POST['place'])?$_POST['place']:'', isset($_POST['type'])?$_POST['type']:'', isset($_POST['category'])?$_POST['category']:'');
$this->view->print_message('La formation a été ajoutée');
} catch(sql_error $e) {
$this->view->print_message($e->getMessage());
}
}
}
$this->view->formation_create(csrf::create_token());
}
$this->view->print_footer();
}
public function controler_create_price() {
$this->view->print_header('Ajout d\'un prix');
if(!isset($_SESSION['user']) || !($_SESSION['user'] instanceof admin)) {
$this->view->print_message_forbidden();
} else {
/* si on valide le formulaire */
if(isset($_POST['formation_create_price_submit'])) {
if(!isset($_POST['csrf_token']) || csrf::verify_token($_POST['csrf_token']) == false)
$this->view->print_message('jeton csrf invalide');
else {
try {
$this->model->formation_create_price(isset($_POST['full_price'])?$_POST['full_price']:'', isset($_POST['low_price'])?$_POST['low_price']:'');
$this->view->print_message('Le prix a été ajouté');
} catch(sql_error $e) {
$this->view->print_message($e->getMessage());
}
}
}
$this->view->formation_create_price(csrf::create_token());
}
$this->view->print_footer();
}
public function controler_create_place() {
$this->view->print_header('Ajout d\'un lieu');
if(!isset($_SESSION['user']) || !($_SESSION['user'] instanceof admin)) {
$this->view->print_message_forbidden();
} else {
/* si on valide le formulaire */
if(isset($_POST['formation_create_place_submit'])) {
if(!isset($_POST['csrf_token']) || csrf::verify_token($_POST['csrf_token']) == false)
$this->view->print_message('jeton csrf invalide');
else {
try {
$this->model->formation_create_place(isset($_POST['label'])?$_POST['label']:'');
$this->view->print_message('Le lieu a été ajouté');
} catch(sql_error $e) {
$this->view->print_message($e->getMessage());
}
}
}
$this->view->formation_create_place(csrf::create_token());
}
$this->view->print_footer();
}
public function controler_create_objective() {
$this->view->print_header('Ajout d\'un objectif');
if(!isset($_SESSION['user']) || !($_SESSION['user'] instanceof admin)) {
$this->view->print_message_forbidden();
} else {
/* si on valide le formulaire */
if(isset($_POST['formation_create_objective_submit'])) {
if(!isset($_POST['csrf_token']) || csrf::verify_token($_POST['csrf_token']) == false)
$this->view->print_message('jeton csrf invalide');
else {
try {
$this->model->formation_create_objective(isset($_POST['label'])?$_POST['label']:'');
$this->view->print_message('L\'objectif a été ajouté');
} catch(sql_error $e) {
$this->view->print_message($e->getMessage());
}
}
}
$this->view->formation_create_objective(csrf::create_token());
}
$this->view->print_footer();
}
public function controler_create_type() {
$this->view->print_header('Ajout d\'un type');
if(!isset($_SESSION['user']) || !($_SESSION['user'] instanceof admin)) {
$this->view->print_message_forbidden();
} else {
/* si on valide le formulaire */
if(isset($_POST['formation_create_type_submit'])) {
if(!isset($_POST['csrf_token']) || csrf::verify_token($_POST['csrf_token']) == false)
$this->view->print_message('jeton csrf invalide');
else {
try {
$this->model->formation_create_type(isset($_POST['label'])?$_POST['label']:'');
$this->view->print_message('Le type a été ajouté');
} catch(sql_error $e) {
$this->view->print_message($e->getMessage());
}
}
}
$this->view->formation_create_type(csrf::create_token());
}
$this->view->print_footer();
}
public function controler_create_department() {
$this->view->print_header('Ajout d\'un departement');
if(!isset($_SESSION['user']) || !($_SESSION['user'] instanceof admin)) {
$this->view->print_message_forbidden();
} else {
/* si on valide le formulaire */
if(isset($_POST['formation_create_department_submit'])) {
if(!isset($_POST['csrf_token']) || csrf::verify_token($_POST['csrf_token']) == false)
$this->view->print_message('jeton csrf invalide');
else {
try {
$this->model->formation_create_department(isset($_POST['label'])?$_POST['label']:'');
$this->view->print_message('Le departement a été ajouté');
} catch(sql_error $e) {
$this->view->print_message($e->getMessage());
}
}
}
$this->view->formation_create_department(csrf::create_token());
}
$this->view->print_footer();
}
public function controler_create_category() {
$this->view->print_header('Ajout d\'une catégorie');
if(!isset($_SESSION['user']) || !($_SESSION['user'] instanceof admin)) {
$this->view->print_message_forbidden();
} else {
/* si on valide le formulaire */
if(isset($_POST['formation_create_category_submit'])) {
if(!isset($_POST['csrf_token']) || csrf::verify_token($_POST['csrf_token']) == false)
$this->view->print_message('jeton csrf invalide');
else {
try {
$this->model->formation_create_category(isset($_POST['label'])?$_POST['label']:'',isset($_POST['department'])?$_POST['department']:'');
$this->view->print_message('La catégorie a été ajouté');
} catch(sql_error $e) {
$this->view->print_message($e->getMessage());
}
}
}
$this->view->formation_create_category(csrf::create_token());
}
$this->view->print_footer();
}
public function controler_default() {
// $this->view->formation_select($this->model->formation_list($page = 1, $order_by = 'id', $order_by_asc = true, $nb_item_per_page = -1), 'formation');
echo '<pre>';


+ 266
- 2
modules/formation/sql.php View File

@ -721,7 +721,7 @@ class formation_sql {
nb_pages integer;
begin
set transaction read only;
if(argv_sort != all (array[\'id\', \'label\', \'validated\', \'prorgram\', \'prerequisite\', \'price\', \'place\', \'type\', \'category\'])) then
if(argv_sort != all (array[\'id\', \'label\', \'validated\', \'program\', \'prerequisite\', \'price\', \'place\', \'type\', \'category\'])) then
argv_sort = \'id\';
end if;
query_res = \'select id, label, validated, program, prerequisite, (select case(price is not null) when true then price_get(price) else null end) as price, (select case(place is not null) when true then place_get(place) else null end) as place, (select case(type is not null) when true then type_get(type) else null end) as type, (select case(category is not null) when true then category_get(category) else null end) as category from formation \';
@ -747,6 +747,270 @@ class formation_sql {
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_department_nb_pages(argv_nb_item_per_page integer) returns integer as $$
declare
res integer;
begin
set transaction read only;
if(argv_nb_item_per_page < 1) then
return 1;
end if;
select (count(*)/argv_nb_item_per_page)+(case ((count(*)%argv_nb_item_per_page)=0) when true then 0 else 1 end) into res from department;
return res;
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_department(argv_sort text, argv_asc boolean = true, argv_page integer = -1, argv_nb_item_per_page integer = -1) returns setof department_type as $$
declare
query_res text;
nb_pages integer;
begin
set transaction read only;
if(argv_sort != all (array[\'id\', \'label\'])) then
argv_sort = \'id\';
end if;
query_res = \'select id, label from department \';
query_res = query_res || \' order by \' || quote_ident(argv_sort);
if(argv_asc = true) then
query_res = query_res || \' asc\';
else
query_res = query_res || \' desc\';
end if;
select * into nb_pages from formation_list_department_nb_pages(argv_nb_item_per_page);
if(argv_page > nb_pages) then
raise exception using errcode=\'PAGES\';
end if;
if(argv_page > 0 and argv_nb_item_per_page > 0) then
query_res = query_res || \' limit \' || argv_nb_item_per_page || \' offset \' || (argv_page-1)*argv_nb_item_per_page;
end if;
return query execute query_res;
exception
when sqlstate \'PAGES\' then raise \'pas de page avec ce numéro\';
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_category_nb_pages(argv_nb_item_per_page integer) returns integer as $$
declare
res integer;
begin
set transaction read only;
if(argv_nb_item_per_page < 1) then
return 1;
end if;
select (count(*)/argv_nb_item_per_page)+(case ((count(*)%argv_nb_item_per_page)=0) when true then 0 else 1 end) into res from category;
return res;
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_category(argv_sort text, argv_asc boolean = true, argv_page integer = -1, argv_nb_item_per_page integer = -1) returns setof category_type as $$
declare
query_res text;
nb_pages integer;
begin
set transaction read only;
if(argv_sort != all (array[\'id\', \'label\'])) then
argv_sort = \'id\';
end if;
query_res = \'select id, label, (select case(department is not null) when true then department_get(department) else null end) as department from category \';
query_res = query_res || \' order by \' || quote_ident(argv_sort);
if(argv_asc = true) then
query_res = query_res || \' asc\';
else
query_res = query_res || \' desc\';
end if;
select * into nb_pages from formation_list_category_nb_pages(argv_nb_item_per_page);
if(argv_page > nb_pages) then
raise exception using errcode=\'PAGES\';
end if;
if(argv_page > 0 and argv_nb_item_per_page > 0) then
query_res = query_res || \' limit \' || argv_nb_item_per_page || \' offset \' || (argv_page-1)*argv_nb_item_per_page;
end if;
return query execute query_res;
exception
when sqlstate \'PAGES\' then raise \'pas de page avec ce numéro\';
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_type_nb_pages(argv_nb_item_per_page integer) returns integer as $$
declare
res integer;
begin
set transaction read only;
if(argv_nb_item_per_page < 1) then
return 1;
end if;
select (count(*)/argv_nb_item_per_page)+(case ((count(*)%argv_nb_item_per_page)=0) when true then 0 else 1 end) into res from type;
return res;
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_type(argv_sort text, argv_asc boolean = true, argv_page integer = -1, argv_nb_item_per_page integer = -1) returns setof type_type as $$
declare
query_res text;
nb_pages integer;
begin
set transaction read only;
if(argv_sort != all (array[\'id\', \'label\'])) then
argv_sort = \'id\';
end if;
query_res = \'select id, label from type \';
query_res = query_res || \' order by \' || quote_ident(argv_sort);
if(argv_asc = true) then
query_res = query_res || \' asc\';
else
query_res = query_res || \' desc\';
end if;
select * into nb_pages from formation_list_type_nb_pages(argv_nb_item_per_page);
if(argv_page > nb_pages) then
raise exception using errcode=\'PAGES\';
end if;
if(argv_page > 0 and argv_nb_item_per_page > 0) then
query_res = query_res || \' limit \' || argv_nb_item_per_page || \' offset \' || (argv_page-1)*argv_nb_item_per_page;
end if;
return query execute query_res;
exception
when sqlstate \'PAGES\' then raise \'pas de page avec ce numéro\';
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_objective_nb_pages(argv_nb_item_per_page integer) returns integer as $$
declare
res integer;
begin
set transaction read only;
if(argv_nb_item_per_page < 1) then
return 1;
end if;
select (count(*)/argv_nb_item_per_page)+(case ((count(*)%argv_nb_item_per_page)=0) when true then 0 else 1 end) into res from objective;
return res;
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_objective(argv_sort text, argv_asc boolean = true, argv_page integer = -1, argv_nb_item_per_page integer = -1) returns setof objective_type as $$
declare
query_res text;
nb_pages integer;
begin
set transaction read only;
if(argv_sort != all (array[\'id\', \'label\'])) then
argv_sort = \'id\';
end if;
query_res = \'select id, label from objective \';
query_res = query_res || \' order by \' || quote_ident(argv_sort);
if(argv_asc = true) then
query_res = query_res || \' asc\';
else
query_res = query_res || \' desc\';
end if;
select * into nb_pages from formation_list_objective_nb_pages(argv_nb_item_per_page);
if(argv_page > nb_pages) then
raise exception using errcode=\'PAGES\';
end if;
if(argv_page > 0 and argv_nb_item_per_page > 0) then
query_res = query_res || \' limit \' || argv_nb_item_per_page || \' offset \' || (argv_page-1)*argv_nb_item_per_page;
end if;
return query execute query_res;
exception
when sqlstate \'PAGES\' then raise \'pas de page avec ce numéro\';
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_place_nb_pages(argv_nb_item_per_page integer) returns integer as $$
declare
res integer;
begin
set transaction read only;
if(argv_nb_item_per_page < 1) then
return 1;
end if;
select (count(*)/argv_nb_item_per_page)+(case ((count(*)%argv_nb_item_per_page)=0) when true then 0 else 1 end) into res from place;
return res;
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_place(argv_sort text, argv_asc boolean = true, argv_page integer = -1, argv_nb_item_per_page integer = -1) returns setof place_type as $$
declare
query_res text;
nb_pages integer;
begin
set transaction read only;
if(argv_sort != all (array[\'id\', \'label\'])) then
argv_sort = \'id\';
end if;
query_res = \'select id, label from place \';
query_res = query_res || \' order by \' || quote_ident(argv_sort);
if(argv_asc = true) then
query_res = query_res || \' asc\';
else
query_res = query_res || \' desc\';
end if;
select * into nb_pages from formation_list_place_nb_pages(argv_nb_item_per_page);
if(argv_page > nb_pages) then
raise exception using errcode=\'PAGES\';
end if;
if(argv_page > 0 and argv_nb_item_per_page > 0) then
query_res = query_res || \' limit \' || argv_nb_item_per_page || \' offset \' || (argv_page-1)*argv_nb_item_per_page;
end if;
return query execute query_res;
exception
when sqlstate \'PAGES\' then raise \'pas de page avec ce numéro\';
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_price_nb_pages(argv_nb_item_per_page integer) returns integer as $$
declare
res integer;
begin
set transaction read only;
if(argv_nb_item_per_page < 1) then
return 1;
end if;
select (count(*)/argv_nb_item_per_page)+(case ((count(*)%argv_nb_item_per_page)=0) when true then 0 else 1 end) into res from price;
return res;
end;
$$ language plpgsql;
');
$db->pdo()->query('
create function formation_list_price(argv_sort text, argv_asc boolean = true, argv_page integer = -1, argv_nb_item_per_page integer = -1) returns setof price_type as $$
declare
query_res text;
nb_pages integer;
begin
set transaction read only;
if(argv_sort != all (array[\'id\', \'full_price\', \'low_price\'])) then
argv_sort = \'id\';
end if;
query_res = \'select id, full_price, low_price from price \';
query_res = query_res || \' order by \' || quote_ident(argv_sort);
if(argv_asc = true) then
query_res = query_res || \' asc\';
else
query_res = query_res || \' desc\';
end if;
select * into nb_pages from formation_list_price_nb_pages(argv_nb_item_per_page);
if(argv_page > nb_pages) then
raise exception using errcode=\'PAGES\';
end if;
if(argv_page > 0 and argv_nb_item_per_page > 0) then
query_res = query_res || \' limit \' || argv_nb_item_per_page || \' offset \' || (argv_page-1)*argv_nb_item_per_page;
end if;
return query execute query_res;
exception
when sqlstate \'PAGES\' then raise \'pas de page avec ce numéro\';
end;
$$ language plpgsql;
');
}
@ -791,7 +1055,7 @@ class formation_sql {
$db->pdo()->query('select * from place_add(\'lieu2\');');
$db->pdo()->query('select * from place_add(\'lieu3\');');
$db->pdo()->query('select * from price_add(10::text::money, 5::text::money);');
$db->pdo()->query('select * from price_add(11.32::text::money, 3.1415926::text::money);');
$db->pdo()->query('select * from price_add(11::text::money, 3.1415926::text::money);');
$db->pdo()->query('select * from type_add(\'type1\');');
$db->pdo()->query('select * from type_add(\'type2\');');
$db->pdo()->query('select * from type_add(\'type3\');');


+ 12
- 0
modules/formation/templates/formation_create.html View File

@ -0,0 +1,12 @@
<form method="post" action="">
<label for="label">Label&nbsp;:</label> <input type="text" name="label" id="label" value="{$label}" /> <br />
<label for="program">Programme&nbsp;:</label> <input type="text" name="program" id="program" value="{$program}" /> <br />
<label for="prerequisite">Pré-requis&nbsp;:</label> <input type="text" name="prerequisite" id="prerequisite" value="{$prerequisite}" /> <br />
<label for="price">Tarif&nbsp;:</label> {$formation_select_price} <br />
<label for="place">Lieu&nbsp;:</label> {$formation_select_place} <br />
<label for="objective">Objectifs&nbsp;:</label> {$formation_select_objective} <br />
<label for="type">Type&nbsp;:</label> {$formation_select_type} <br />
<label for="category">Catégorie&nbsp;:</label> {$formation_select_category}<br />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
<input type="submit" name="formation_create_submit" value="Enregistrer" />
</form>

+ 6
- 0
modules/formation/templates/formation_create_category.html View File

@ -0,0 +1,6 @@
<form method="post" action="">
<label for="label">Label&nbsp;:</label> <input type="text" name="label" id="label" value="{$label}" /> <br />
<label for="department">Département&nbsp;:</label> {$formation_select_department}<br />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
<input type="submit" name="formation_create_category_submit" value="Enregistrer" />
</form>

+ 5
- 0
modules/formation/templates/formation_create_department.html View File

@ -0,0 +1,5 @@
<form method="post" action="">
<label for="label">Label&nbsp;:</label> <input type="text" name="label" id="label" value="{$label}" /> <br />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
<input type="submit" name="formation_create_department_submit" value="Enregistrer" />
</form>

+ 5
- 0
modules/formation/templates/formation_create_objective.html View File

@ -0,0 +1,5 @@
<form method="post" action="">
<label for="label">Label&nbsp;:</label> <input type="text" name="label" id="label" value="{$label}" /> <br />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
<input type="submit" name="formation_create_objective_submit" value="Enregistrer" />
</form>

+ 5
- 0
modules/formation/templates/formation_create_place.html View File

@ -0,0 +1,5 @@
<form method="post" action="">
<label for="label">Label&nbsp;:</label> <input type="text" name="label" id="label" value="{$label}" /> <br />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
<input type="submit" name="formation_create_place_submit" value="Enregistrer" />
</form>

+ 6
- 0
modules/formation/templates/formation_create_price.html View File

@ -0,0 +1,6 @@
<form method="post" action="">
<label for="full_price">Prix de base&nbsp;:</label> <input type="text" name="full_price" id="full_price" value="{$full_price}" /> <br />
<label for="low_price">Prix avec subvention&nbsp;:</label> <input type="text" name="low_price" id="low_price" value="{$low_price}" /> <br />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
<input type="submit" name="formation_create_price_submit" value="Enregistrer" />
</form>

+ 5
- 0
modules/formation/templates/formation_create_type.html View File

@ -0,0 +1,5 @@
<form method="post" action="">
<label for="label">Label&nbsp;:</label> <input type="text" name="label" id="label" value="{$label}" /> <br />
<input type="hidden" name="csrf_token" value="{$csrf_token}" />
<input type="submit" name="formation_create_type_submit" value="Enregistrer" />
</form>

+ 12
- 0
modules/formation/templates/select_category.html View File

@ -0,0 +1,12 @@
<select name="{$name}" id="{$name}">
<option value=""></option>
{loop="formation_select_category"}
<optgroup label="{$key}">
{loop="value"}
<option value="{$value.id}" {$value.selected}>{$value.label}</option>
{/loop}
</optgroup>
{else}
<option value="" disabled="disabled">Aucune catégorie</option>
{/loop}
</select>

+ 8
- 0
modules/formation/templates/select_department.html View File

@ -0,0 +1,8 @@
<select name="{$name}" id="{$name}" >
<option value=""></option>
{loop="formation_select_department"}
<option value="{$value.id}" {$value.selected}>{$value.label}</option>
{else}
<option value="" disabled="disabled">Aucun département</option>
{/loop}
</select>

+ 8
- 0
modules/formation/templates/select_objective.html View File

@ -0,0 +1,8 @@
<select name="{$name}" id="{$name}" >
<option value=""></option>
{loop="formation_select_objective"}
<option value="{$value.id}" {$value.selected}>{$value.label}</option>
{else}
<option value="" disabled="disabled">Aucun type</option>
{/loop}
</select>

+ 9
- 0
modules/formation/templates/select_place.html View File

@ -0,0 +1,9 @@
<select name="{$name}" id="{$name}" >
<option value=""></option>
{loop="formation_select_place"}
<option value="{$value.id}" {$value.selected}>{$value.label}</option>
{else}
<option value="" disabled="disabled">Aucun lieu</option>
{/loop}
</select>

+ 8
- 0
modules/formation/templates/select_price.html View File

@ -0,0 +1,8 @@
<select name="{$name}" id="{$name}" >
<option value=""></option>
{loop="formation_select_price"}
<option value="{$value.id}" {$value.selected}>{$value.full_price} - {$value.low_price}</option>
{else}
<option value="" disabled="disabled">Aucun tarif</option>
{/loop}
</select>

+ 8
- 0
modules/formation/templates/select_type.html View File

@ -0,0 +1,8 @@
<select name="{$name}" id="{$name}" >
<option value=""></option>
{loop="formation_select_type"}
<option value="{$value.id}" {$value.selected}>{$value.label}</option>
{else}
<option value="" disabled="disabled">Aucun type</option>
{/loop}
</select>

+ 7
- 0
nbproject/project.properties View File

@ -0,0 +1,7 @@
include.path=${php.global.include.path}
php.version=PHP_53
source.encoding=UTF-8
src.dir=.
tags.asp=false
tags.short=true
web.root=.

+ 9
- 0
nbproject/project.xml View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>catalogue_formations</name>
</data>
</configuration>
</project>

Loading…
Cancel
Save