123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
- /*
- @name Room
- @author Valentin CARRUESCO <idleman@idleman.fr>
- @link http://blog.idleman.fr
- @licence CC by nc sa
- @version 1.0.0
- @type component
- @description Modele de plugin pour les modules
- */
- include('Room.class.php');
- function room_plugin_page($_){
- if(isset($_['module']) && $_['module']=='room'){
- $roomManager = new Room();
- $rooms = $roomManager->loadAll(array('state'=>'0'));
- //if (!isset($_['id']) && count($rooms)>0) $_['id'] = $rooms[0]->getId();
- $currentRoom = new Room();
- ?>
- <div class="row">
- <div class="span12">
- <ul class="nav nav-tabs">
- <li <?php if (!isset($_['id'])): ?> class="active" <?php endif ?>><a href="index.php?module=room"><i class="fa fa-angle-right"></i> Toutes les pièces</a></li>
- <?php foreach($rooms as $room){
- if(isset($_['id']) && $room->getId()==$_['id']) $currentRoom = $room;
- ?>
- <li <?php echo (isset($_['id']) && $room->getId()==$_['id'] ?'class="active"':''); ?>><a href="index.php?module=room&id=<?php echo $room->getId(); ?>"><i class="fa fa-angle-right"></i> <?php echo $room->getName(); ?></a></li>
- <?php } ?>
- </ul>
- </div>
- </div>
- <div class="row">
- <div class="span12">
- <?php
- if($currentRoom->getId()!=0){
- Plugin::callHook("node_display", array($currentRoom));
- }
- else
- {
- foreach($rooms as $room){
- Plugin::callHook("node_display", array($room));
- }
- }
- ?>
- </div>
- </div>
- <?php
- }
- }
- function room_plugin_setting_menu(){
- global $_;
- echo '<li '.(isset($_['section']) && $_['section']=='room'?'class="active"':'').'><a href="setting.php?section=room"><i class="fa fa-angle-right"></i> Pièces</a></li>';
-
- }
- function room_plugin_setting_page(){
- global $myUser,$_;
-
- if(isset($_['section']) && $_['section']=='room' ){
- if($myUser!=false){
- $roomManager = new Room();
- $rooms = $roomManager->loadAll(array('state'=>'0'));
- //Gestion des modifications
- if (isset($_['id'])){
- $id_mod = $_['id'];
- $selected = $roomManager->getById($id_mod);
- $description = $selected->GetName();
- $button = "Modifier";
- }
- else
- {
- $description = "Ajout d'une pièce";
- $button = "Ajouter";
- }
- ?>
- <div class="span9 userBloc">
- <h1>Pièces</h1>
- <p>Gestion des pièces</p>
- <form action="action.php?action=room_add_room" method="POST">
- <fieldset>
- <legend><?php echo $description ?></legend>
- <div class="left">
- <label for="nameRoom">Nom</label>
- <?php if(isset($selected)){echo '<input type="hidden" name="id" value="'.$id_mod.'">';} ?>
- <input type="text" value="<?php if(isset($selected)){echo $selected->getName();} ?>" id="nameRoom" name="nameRoom" placeholder="Cuisine,salon…"/>
- <label for="descriptionRoom">Description</label>
- <input type="text" value="<?php if(isset($selected)){echo $selected->getDescription();} ?>" name="descriptionRoom" id="descriptionRoom" />
- </div>
- <div class="clear"></div>
- <br/><button type="submit" class="btn"><?php echo $button; ?></button>
- </fieldset>
- <br/>
- </form>
- <table class="table table-striped table-bordered table-hover">
- <thead>
- <tr>
- <th>Nom</th>
- <th>Description</th>
- <th></th>
- </tr>
- </thead>
- <?php foreach($rooms as $room){ ?>
- <tr>
- <td><?php echo $room->getName(); ?></td>
- <td><?php echo $room->getDescription(); ?></td>
- <td>
- <a class="btn" href="setting.php?section=room&id=<?php echo $room->getId(); ?>"><i class="fa fa-pencil"></i></a>
- <a class="btn" href="action.php?action=room_delete_room&id=<?php echo $room->getId(); ?>"><i class="fa fa-times"></i></a></td>
- </tr>
- <?php } ?>
- </table>
- </div>
- <?php }else{ ?>
- <div id="main" class="wrapper clearfix">
- <article>
- <h3>Vous devez être connecté</h3>
- </article>
- </div>
- <?php
- }
- }
- }
- function room_action_room(){
- global $_,$myUser;
- //Erreur dans les droits sinon!
- $myUser->loadRight();
- switch($_['action']){
- case 'room_add_room':
- $right_toverify = isset($_['id']) ? 'u' : 'c';
- if($myUser->can('room',$right_toverify)){
- $room = new Room();
- if ($right_toverify == "u"){$room = $room->load(array("id"=>$_['id']));}
- $room->setName(ucfirst(strtolower($_['nameRoom'])));
- $room->setDescription(ucfirst(strtolower($_['descriptionRoom'])));
- $room->state=0;
- $room->save();
- header('location:setting.php?section=room');
- }
- else
- {
- header('location:setting.php?section=room&error=Vous n\'avez pas le droit de faire ça!');
- }
-
- break;
- case 'room_delete_room':
- if($myUser->can('room','d')){
- $roomManager = new Room();
- $room = $roomManager->getById($_['id']);
- $room->state= -1;
- $room->save();
- header('location:setting.php?section=room');
- }
- else
- {
- header('location:setting.php?section=room&error=Vous n\'avez pas le droit de faire ça!');
- }
- break;
- }
- }
- Plugin::addCss("/css/style.css");
- Plugin::addHook("setting_menu", "room_plugin_setting_menu");
- Plugin::addHook("setting_bloc", "room_plugin_setting_page");
- Plugin::addHook("action_post_case", "room_action_room");
- Plugin::addHook("home", "room_plugin_page");
-
- ?>
|