room.plugin.enabled.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /*
  3. @name Room
  4. @author Valentin CARRUESCO <idleman@idleman.fr>
  5. @link http://blog.idleman.fr
  6. @licence CC by nc sa
  7. @version 1.0.0
  8. @type component
  9. @description Modele de plugin pour les modules
  10. */
  11. include('Room.class.php');
  12. function room_plugin_page($_){
  13. if(isset($_['module']) && $_['module']=='room'){
  14. $roomManager = new Room();
  15. $rooms = $roomManager->loadAll(array('state'=>'0'));
  16. //if (!isset($_['id']) && count($rooms)>0) $_['id'] = $rooms[0]->getId();
  17. $currentRoom = new Room();
  18. ?>
  19. <div class="row">
  20. <div class="span12">
  21. <ul class="nav nav-tabs">
  22. <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>
  23. <?php foreach($rooms as $room){
  24. if(isset($_['id']) && $room->getId()==$_['id']) $currentRoom = $room;
  25. ?>
  26. <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>
  27. <?php } ?>
  28. </ul>
  29. </div>
  30. </div>
  31. <div class="row">
  32. <div class="span12">
  33. <?php
  34. if($currentRoom->getId()!=0){
  35. Plugin::callHook("node_display", array($currentRoom));
  36. }
  37. else
  38. {
  39. foreach($rooms as $room){
  40. Plugin::callHook("node_display", array($room));
  41. }
  42. }
  43. ?>
  44. </div>
  45. </div>
  46. <?php
  47. }
  48. }
  49. function room_plugin_setting_menu(){
  50. global $_;
  51. 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>';
  52. }
  53. function room_plugin_setting_page(){
  54. global $myUser,$_;
  55. if(isset($_['section']) && $_['section']=='room' ){
  56. if($myUser!=false){
  57. $roomManager = new Room();
  58. $rooms = $roomManager->loadAll(array('state'=>'0'));
  59. //Gestion des modifications
  60. if (isset($_['id'])){
  61. $id_mod = $_['id'];
  62. $selected = $roomManager->getById($id_mod);
  63. $description = $selected->GetName();
  64. $button = "Modifier";
  65. }
  66. else
  67. {
  68. $description = "Ajout d'une pièce";
  69. $button = "Ajouter";
  70. }
  71. ?>
  72. <div class="span9 userBloc">
  73. <h1>Pièces</h1>
  74. <p>Gestion des pièces</p>
  75. <form action="action.php?action=room_add_room" method="POST">
  76. <fieldset>
  77. <legend><?php echo $description ?></legend>
  78. <div class="left">
  79. <label for="nameRoom">Nom</label>
  80. <?php if(isset($selected)){echo '<input type="hidden" name="id" value="'.$id_mod.'">';} ?>
  81. <input type="text" value="<?php if(isset($selected)){echo $selected->getName();} ?>" id="nameRoom" name="nameRoom" placeholder="Cuisine,salon…"/>
  82. <label for="descriptionRoom">Description</label>
  83. <input type="text" value="<?php if(isset($selected)){echo $selected->getDescription();} ?>" name="descriptionRoom" id="descriptionRoom" />
  84. </div>
  85. <div class="clear"></div>
  86. <br/><button type="submit" class="btn"><?php echo $button; ?></button>
  87. </fieldset>
  88. <br/>
  89. </form>
  90. <table class="table table-striped table-bordered table-hover">
  91. <thead>
  92. <tr>
  93. <th>Nom</th>
  94. <th>Description</th>
  95. <th></th>
  96. </tr>
  97. </thead>
  98. <?php foreach($rooms as $room){ ?>
  99. <tr>
  100. <td><?php echo $room->getName(); ?></td>
  101. <td><?php echo $room->getDescription(); ?></td>
  102. <td>
  103. <a class="btn" href="setting.php?section=room&id=<?php echo $room->getId(); ?>"><i class="fa fa-pencil"></i></a>
  104. <a class="btn" href="action.php?action=room_delete_room&id=<?php echo $room->getId(); ?>"><i class="fa fa-times"></i></a></td>
  105. </tr>
  106. <?php } ?>
  107. </table>
  108. </div>
  109. <?php }else{ ?>
  110. <div id="main" class="wrapper clearfix">
  111. <article>
  112. <h3>Vous devez être connecté</h3>
  113. </article>
  114. </div>
  115. <?php
  116. }
  117. }
  118. }
  119. function room_action_room(){
  120. global $_,$myUser;
  121. //Erreur dans les droits sinon!
  122. $myUser->loadRight();
  123. switch($_['action']){
  124. case 'room_add_room':
  125. $right_toverify = isset($_['id']) ? 'u' : 'c';
  126. if($myUser->can('room',$right_toverify)){
  127. $room = new Room();
  128. if ($right_toverify == "u"){$room = $room->load(array("id"=>$_['id']));}
  129. $room->setName(ucfirst(strtolower($_['nameRoom'])));
  130. $room->setDescription(ucfirst(strtolower($_['descriptionRoom'])));
  131. $room->state=0;
  132. $room->save();
  133. header('location:setting.php?section=room');
  134. }
  135. else
  136. {
  137. header('location:setting.php?section=room&error=Vous n\'avez pas le droit de faire ça!');
  138. }
  139. break;
  140. case 'room_delete_room':
  141. if($myUser->can('room','d')){
  142. $roomManager = new Room();
  143. $room = $roomManager->getById($_['id']);
  144. $room->state= -1;
  145. $room->save();
  146. header('location:setting.php?section=room');
  147. }
  148. else
  149. {
  150. header('location:setting.php?section=room&error=Vous n\'avez pas le droit de faire ça!');
  151. }
  152. break;
  153. }
  154. }
  155. Plugin::addCss("/css/style.css");
  156. Plugin::addHook("setting_menu", "room_plugin_setting_menu");
  157. Plugin::addHook("setting_bloc", "room_plugin_setting_page");
  158. Plugin::addHook("action_post_case", "room_action_room");
  159. Plugin::addHook("home", "room_plugin_page");
  160. ?>