/src/2.071.0/_Agenda.class.php

https://github.com/crepeausucre/soothERP · PHP · 230 lines · 162 code · 39 blank · 29 comment · 37 complexity · 169a0d62f35d5f9a083353613576fa63 MD5 · raw file

  1. <?php
  2. // *************************************************************************************************************
  3. // CLASSES REGISSANT LES INFORMATIONS SUR UN AGENDA
  4. // *************************************************************************************************************
  5. // 4 CLASSES
  6. // Agenda <: AgendaReservationRessource
  7. // Agenda <: AgendaContact
  8. // Agenda <: AgendaLoacationMateriel
  9. // *************************************************************************************************************
  10. // CLASSE Agenda
  11. // *************************************************************************************************************
  12. abstract class Agenda implements IGestionnaireEvenements{
  13. //voir dans la BD la TABLE : AGENDAS
  14. private $ref_agenda; //varchar(32) NOT NULL
  15. private $lib_agenda; //varchar(64) NOT NULL
  16. //voir dans la BD la table : agendas_couleurs
  17. private $id_agenda_couleurs; //smallint(5) unsigned default 1
  18. private $couleur_1; //varchar(7) ex "#ffffff"
  19. private $couleur_2; //varchar(7) ex "#ffffff"
  20. private $couleur_3; //varchar(7) ex "#000000"
  21. //voir dans la BD la table : AGENDA_EVENTS
  22. private $events; //liste des Events de l'agenda
  23. public function __construct($ref_agenda){
  24. global $bdd;
  25. if (!is_numeric($this->getId_type_agenda()))
  26. return false;
  27. $query = "SELECT ag.ref_agenda, ag.lib_agenda, agsr.id_agenda_couleurs, agsr.agenda_couleur_rule_1,
  28. agsr.agenda_couleur_rule_2, agsr.agenda_couleur_rule_3
  29. FROM agendas ag
  30. LEFT JOIN agendas_couleurs agsr ON agsr.id_agenda_couleurs = ag.id_agenda_couleurs
  31. WHERE ag.ref_agenda = '".$ref_agenda."'";
  32. $resultat = $bdd->query(($query));
  33. if (!$r = $resultat->fetchObject())
  34. return false;
  35. $this->events = null;
  36. $this->ref_agenda = ($r->ref_agenda);
  37. $this->lib_agenda = stripslashes($r->lib_agenda);
  38. $this->id_agenda_couleurs = intval($r->id_agenda_couleurs);
  39. $this->couleur_1 = ($r->agenda_couleur_rule_1);
  40. $this->couleur_2 = ($r->agenda_couleur_rule_2);
  41. $this->couleur_3 = ($r->agenda_couleur_rule_3);
  42. }
  43. // *************************************************************************************************************
  44. // Getters & Setters
  45. // *************************************************************************************************************
  46. public function getRef_agenda()
  47. { return $this->ref_agenda;}
  48. public function getLib_agenda()
  49. { return $this->lib_agenda;}
  50. public function setLib_agenda($lib_agenda){
  51. if($lib_agenda == null || $lib_agenda == "")return false;
  52. if($lib_agenda != $this->lib_agenda){
  53. global $bdd;
  54. $query = "UPDATE agendas SET lib_agenda = '".addslashes($lib_agenda)."'
  55. WHERE ref_agenda = '".$this->ref_agenda."' ";
  56. $resultat = $bdd->query(($query));
  57. $this->lib_agenda = $lib_agenda;
  58. }
  59. return true;
  60. }
  61. public function &addNewEvent(&$event_Parent, $lib_event, $note_event, $date_event, $duree_event){
  62. $newEvent =& Event::newEvent($this, $event_Parent, $lib_event, $note_event, $date_event, $duree_event);
  63. if(is_null($newEvent))
  64. { return null;}
  65. if(is_null($this->events))
  66. { $this->events = array();}
  67. $this->events[$newEvent->getRef_event()] =& $newEvent;
  68. return $newEvent;
  69. }
  70. public function addEvent(&$event){
  71. if( $event == null || !($event instanceof Event) )
  72. { return false;}
  73. if(is_null($this->events))
  74. { $this->events = array();}
  75. $event->setAgenda($this);
  76. $this->events[$event->getRef_event()] =& $event;
  77. return true;
  78. }
  79. public function &getEvents(){
  80. if(is_null($this->events)){
  81. global $bdd;
  82. $query = "SELECT age.ref_agenda_event
  83. FROM agendas_events age
  84. WHERE ag.ref_agenda = '".$this->ref_agenda."'";
  85. $resultat = $bdd->query(($query));
  86. while ($r = $resultat->fetchObject())
  87. $this->addEvent(new Event(($r->ref_agenda_event)));
  88. }
  89. return $this->events;
  90. }
  91. public function &getEvent($ref_event){
  92. if(is_set($this->events[$ref_event]))
  93. { return $this->events[$ref_event];}
  94. else{$res = null; return res;}//null
  95. }
  96. //retourne la couleur n°1 sous forme d'une chaine de charactčre de la forme #e3a869
  97. public function getCouleur_1(){
  98. return $this->couleur_1;
  99. }
  100. //retourne la couleur n°2 sous forme d'une chaine de charactčre de la forme #e3a869
  101. public function getCouleur_2(){
  102. return $this->couleur_2;
  103. }
  104. //retourne la couleur n°3 sous forme d'une chaine de charactčre de la forme #e3a869
  105. public function getCouleur_3(){
  106. return $this->couleur_3;
  107. }
  108. public function setCouleur_1($couleur){
  109. if($couleur == null || $couleur == "" || !preg_match('`#[0-9a-fA-F]{6}`', $couleur))
  110. return false;
  111. //else
  112. global $bdd;
  113. $query = "UPDATE agendas_couleurs SET agenda_couleur_rule_1 = '".$couleur."'
  114. WHERE id_agenda_couleurs = '".$this->id_agenda_couleurs."' ";
  115. $resultat = $bdd->query(($query));
  116. return true;
  117. }
  118. public function setCouleur_2($couleur){
  119. if($couleur == null || $couleur == "" || !preg_match('`#[0-9a-fA-F]{6}`', $couleur))
  120. return false;
  121. //else
  122. global $bdd;
  123. $query = "UPDATE agendas_couleurs SET agenda_couleur_rule_2 = '".$couleur."'
  124. WHERE id_agenda_couleurs = '".$this->id_agenda_couleurs."' ";
  125. $resultat = $bdd->query(($query));
  126. return true;
  127. }
  128. public function setCouleur_3($couleur){
  129. if($couleur == null || $couleur == "" || !preg_match('`#[0-9a-fA-F]{6}`', $couleur))
  130. return false;
  131. //else
  132. global $bdd;
  133. $query = "UPDATE agendas_couleurs SET agenda_couleur_rule_3 = '".$couleur."'
  134. WHERE id_agenda_couleurs = '".$this->id_agenda_couleurs."' ";
  135. $resultat = $bdd->query(($query));
  136. return true;
  137. }
  138. public function getId_agenda_style_rule()
  139. { return $this->id_agenda_couleurs;}
  140. public function setId_agenda_style_rule($id_agenda_couleurs){
  141. global $bdd;
  142. if(!is_numeric($id_agenda_couleurs))
  143. return false;
  144. //else
  145. $query = "UPDATE agendas SET id_agenda_couleurs = '".$id_agenda_couleurs."'
  146. WHERE ref_agenda = '".$this->ref_agenda."' ";
  147. $resultat = $bdd->query(($query));
  148. if (!$r = $resultat->fetchObject())return false;
  149. $this->loadagendas_couleurs();
  150. return true;
  151. }
  152. public function loadagendas_couleurs(){
  153. global $bdd;
  154. $query = "SELECT agsr.id_agenda_couleurs, agsr.agenda_couleur_rule_1, agsr.agenda_couleur_rule_2, agsr.agenda_couleur_rule_3
  155. FROM agendas_couleurs agsr
  156. LEFT JOIN agendas ag ON agsr.id_agenda_couleurs = ag.id_agenda_couleurs
  157. WHERE ag.ref_agenda = '".$this->ref_agenda."'";
  158. $resultat = $bdd->query(($query));
  159. if (!$r = $resultat->fetchObject())return false;
  160. $this->id_agenda_couleurs = intval($r->id_agenda_couleurs);
  161. $this->$couleur_1 = ($r->agenda_couleur_rule_1);
  162. $this->$couleur_2 = ($r->agenda_couleur_rule_2);
  163. $this->$couleur_3 = ($r->agenda_couleur_rule_3);
  164. }
  165. // *************************************************************************************************************
  166. // FONCTION DE SUPPRESSION
  167. // *************************************************************************************************************
  168. public function delete_Event_by_Ref($ref_event){
  169. if(isset($this->events[$ref_event])){
  170. unset($this->events[$ref_event]);
  171. return true;
  172. }
  173. return false;
  174. }
  175. public function delete_Event(&$event){
  176. if(isset($this->events[$event->getRef_event()])){
  177. unset($this->events[$event->getRef_event()]);
  178. return true;
  179. }
  180. return false;
  181. }
  182. // *************************************************************************************************************
  183. // ATTRIBUTS ET FONCTIONS "STATIC"
  184. // *************************************************************************************************************
  185. public abstract function AGENDA_ID_REFERENCE_TAG();
  186. public abstract function setLib_type($lib_type);
  187. public abstract function getLib_type();
  188. public abstract function getId_type_agenda();
  189. public abstract function loadType_informations();
  190. }
  191. ?>