/**
  * Retourne le niveau de droit de la personne connectée
  * @param integer $idAgenda l'identifiant de l'agenda
  */
 public function getCapability($idAgenda)
 {
     if (!$idAgenda) {
         return 0;
     }
     if (!($d = _sessionGet('modules|agenda|rights|' . $idAgenda))) {
         $d = Kernel::getModRight('MOD_AGENDA', $idAgenda);
         _sessionSet('modules|agenda|rights|' . $idAgenda, $d);
     }
     if ($d >= PROFILE_CCV_MEMBER) {
         $res = AgendaAuth::getModerate();
     } elseif ($d >= PROFILE_CCV_READ) {
         $res = AgendaAuth::getRead();
     } else {
         $res = AgendaAuth::getNone();
     }
     //print_r ("idAgenda=$idAgenda / res=$res<br>");
     return $res;
 }
 public function _createContent(&$toReturn)
 {
     $serviceAuth = new AgendaAuth();
     $tpl = new CopixTpl();
     //gestion des erreurs
     if ($this->getParam('e') == 1) {
         $tpl->assign('showError', $this->getParam('e'));
     }
     $tpl->assign('arError', $this->getParam('errors'));
     $tpl->assign('importParams', $this->getParam('importParams'));
     //vérification des droits d'écriture sur les agendas
     $listeFiltre = $this->getParam('arTitleAgendasAffiches');
     //on vérifie les droits de lecture des utilisateurs
     foreach ((array) $listeFiltre as $key => $title_agenda) {
         //on vérifie si l'utilisateur a les droits de lecture sur la liste des agendas
         if ($serviceAuth->getCapability($key) < $serviceAuth->getModerate()) {
             unset($listeFiltre[$key]);
         }
     }
     $tpl->assign('arTitleAgendasAffiches', $listeFiltre);
     $toReturn = $tpl->fetch('import.agenda.tpl');
     return true;
 }
 /**
  * Fonction appelée lorsque l'on clique sur le bouton 'import'
  * Appel la méthode privée _validFromFormImportParams
  * vérifie les infos saisies dans le formulaire
  * stock l'objet en session
  * @author Audrey Vassal <*****@*****.**>
  */
 public function doImport()
 {
     $serviceAuth = new AgendaAuth();
     //demande de mettre l'objet à jour en fonction des valeurs saisies dans le formulaire
     if (!($importParams = $this->_getSessionImport())) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.error.cannotFindSession'), 'back' => CopixUrl::get('agenda|agenda|vueSemaine')));
     }
     $this->_validFromFormImportParams($importParams);
     //on vérifie les droits
     if ($serviceAuth->getCapability($importParams['id_agenda']) < $serviceAuth->getModerate()) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.error.enableToWrite'), 'back' => CopixUrl::get('agenda|agenda|vueSemaine')));
     }
     $errors = $this->_checkImport();
     if (count($errors) > 0) {
         $this->_setSessionImport($importParams);
         return CopixActionGroup::process('agenda|ImportExport::getPrepareImport', array('e' => 1, 'errors' => $errors));
     } else {
         if (is_uploaded_file($_FILES['import_ordi']['tmp_name'])) {
             move_uploaded_file($_FILES['import_ordi']['tmp_name'], CopixConfig::get('agenda|tempfiles') . 'import.ics');
             $file = CopixConfig::get('agenda|tempfiles') . 'import.ics';
         } else {
             if (_request('import_internet') != null) {
                 $filename = _request('import_internet');
                 $handle = fopen($filename, "rb");
                 $contents = '';
                 while (!feof($handle)) {
                     $contents .= fread($handle, 8192);
                 }
                 $handleToWrite = fopen(CopixConfig::get('agenda|tempfiles') . 'import.ics', 'w+');
                 fwrite($handleToWrite, $contents);
                 $file = CopixConfig::get('agenda|tempfiles') . 'import.ics';
             } else {
                 return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.error.cannotDownloadFile'), 'back' => CopixUrl::get('agenda|importexport|prepareImport')));
             }
         }
         _classInclude('agenda|importServices');
         $nbInsertions = ImportServices::import($file, $importParams['id_agenda'], $importParams['option'] == 1 ? false : true);
     }
     //on efface le fichier temporaire créé pour faire l'import
     unlink(CopixConfig::get('agenda|tempfiles') . 'import.ics');
     //on vide la session
     //$this->_setSessionImport(null);
     return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('agenda|importexport|afterImport', array('nbInsertions' => $nbInsertions)));
 }
 /**
  * Liste des agendas disponibles
  * @author Christophe Beyer <*****@*****.**>
  * @since 2006/08/24
  * @param integer $id Id de l'agenda (si aucun, l'envoie dans l'agenda perso)
  */
 public function processAgendaList()
 {
     $serviceAuth = new AgendaAuth();
     $serviceType = new AgendaType();
     $serviceAgenda = new AgendaService();
     $tpl = new CopixTpl();
     $agendaDispos = AgendaService::getAvailableAgenda();
     $agendaAffiches = AgendaService::getAgendaAffiches();
     $ableToWrite = $ableToModerate = false;
     //on vérifie les droits des utilisateurs sur la liste des agendas affichés
     foreach ((array) $agendaAffiches as $id_agenda) {
         //on vérifie si l'utilisateur a les droits d'écriture sur un des agendas affiché
         //print_r($serviceAuth->getWriteAgenda());
         if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getWriteAgenda()) {
             $ableToWrite = true;
             break;
         }
     }
     //on vérifie les droits des utilisateurs sur la liste des agendas affichés
     foreach ((array) $agendaAffiches as $id_agenda) {
         //on vérifie si l'utilisateur a les droits d'import
         if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getModerate()) {
             $ableToModerate = true;
             break;
         }
     }
     $listeFiltre = $agendaDispos;
     //on vérifie les droits de lecture des utilisateurs
     foreach ((array) $listeFiltre as $key => $agenda) {
         //on vérifie si l'utilisateur a les droits de lecture sur la liste des agendas
         if ($serviceAuth->getCapability($agenda->id_agenda) < $serviceAuth->getRead()) {
             unset($listeFiltre[$key]);
         }
     }
     //on construit le tableau de couleurs associées au type d'agenda
     $arColorByIdAgenda = array();
     foreach ((array) $listeFiltre as $agenda) {
         $arColor = $serviceType->getColors($serviceAgenda->getTypeAgendaByIdAgenda($agenda->id_agenda));
         $i = 0;
         foreach ($arColorByIdAgenda as $idAgenda => $couleurAgenda) {
             if ($arColorByIdAgenda[$idAgenda] == $arColor[$i]) {
                 $i = $i + 1;
             }
         }
         if ($i < count($arColor)) {
             $arColorByIdAgenda[$agenda->id_agenda] = $arColor[$i];
         } else {
             $arColorByIdAgenda[$agenda->id_agenda] = $arColor[0];
         }
     }
     $ppo = new CopixPPO();
     $ppo->arColorByIdAgenda = $arColorByIdAgenda;
     $ppo->listAgendas = $listeFiltre;
     $ppo->agendasSelectionnes = $agendaAffiches;
     CopixHTMLHeader::addCSSLink(_resource("styles/module_agenda.css"));
     return _arPPO($ppo, array('template' => 'popup_agendalist.agenda.tpl', 'mainTemplate' => 'main|main_fancy.php'));
 }
 /**
  * Fonction qui est appel�e lors de la suppression d'un �v�nement
  * R�cup�re l'objet 'event' en  base de donn�es gr�ce � l'id_event
  * Supprime l'objet en base de donn�es
  */
 public function doDelete()
 {
     $serviceAuth = new AgendaAuth();
     if (!_request('id_event')) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.error.missingParameters'), 'back' => CopixUrl::get('agenda|agenda|vueSemaine')));
     }
     $daoEvent =& CopixDAOFactory::getInstanceOf('event');
     if (!($toDelete = $daoEvent->get(_request('id_event')))) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.unableToFind'), 'back' => CopixUrl::get('agenda|agenda|vueSemaine')));
     }
     //on v�rifie si l'utilisateur a les droits de suppression sur l'agenda concern�
     if ($serviceAuth->getCapability($toDelete->id_agenda) < $serviceAuth->getModerate()) {
         return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('agenda.error.enableToWrite'), 'back' => CopixUrl::get('agenda|agenda|vueSemaine')));
     }
     //Confirmation screen ?
     if (!_request('confirm')) {
         return CopixActionGroup::process('genericTools|Messages::getConfirm', array('title' => CopixI18N::get('agenda.title.confirmdelevent'), 'message' => CopixI18N::get('agenda.message.confirmdelevent'), 'confirm' => CopixUrl::get('agenda|event|delete', array('id_event' => $toDelete->id_event, 'confirm' => '1')), 'cancel' => CopixUrl::get('agenda|agenda|vueSemaine')));
     }
     //Delete event
     $daoEvent->delete($toDelete->id_event);
     return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('agenda|agenda|vueSemaine'));
 }
 public function _createContent(&$toReturn)
 {
     $service = new DateService();
     $serviceAgenda = new AgendaService();
     $serviceType = new AgendaType();
     $serviceAuth = new AgendaAuth();
     //on determine la date du jour en timestamp
     $dimanche = $service->numweekToDate($this->getParam('elementsSemaineAffichee')->numSemaine, $this->getParam('elementsSemaineAffichee')->annee, 0);
     $lundi = $service->numweekToDate($this->getParam('elementsSemaineAffichee')->numSemaine, $this->getParam('elementsSemaineAffichee')->annee, 1);
     $mardi = $service->numweekToDate($this->getParam('elementsSemaineAffichee')->numSemaine, $this->getParam('elementsSemaineAffichee')->annee, 2);
     $mercredi = $service->numweekToDate($this->getParam('elementsSemaineAffichee')->numSemaine, $this->getParam('elementsSemaineAffichee')->annee, 3);
     $jeudi = $service->numweekToDate($this->getParam('elementsSemaineAffichee')->numSemaine, $this->getParam('elementsSemaineAffichee')->annee, 4);
     $vendredi = $service->numweekToDate($this->getParam('elementsSemaineAffichee')->numSemaine, $this->getParam('elementsSemaineAffichee')->annee, 5);
     $samedi = $service->numweekToDate($this->getParam('elementsSemaineAffichee')->numSemaine, $this->getParam('elementsSemaineAffichee')->annee, 6);
     $tpl = new CopixTpl();
     //date du jour
     $tpl->assign('dimanche', date('d', $dimanche));
     $tpl->assign('lundi', date('d', $lundi));
     $tpl->assign('mardi', date('d', $mardi));
     $tpl->assign('mercredi', date('d', $mercredi));
     $tpl->assign('jeudi', date('d', $jeudi));
     $tpl->assign('vendredi', date('d', $vendredi));
     $tpl->assign('samedi', date('d', $samedi));
     $tpl->assign('date_deb', date('Ymd', $lundi));
     $tpl->assign('date_fin', date('Ymd', $dimanche));
     $tpl->assign('moisDebutSemaine', $service->moisNumericToMoisLitteral(date('m', $lundi)));
     $tpl->assign('moisFinSemaine', $service->moisNumericToMoisLitteral(date('m', $dimanche)));
     $tpl->assign('semaine', $this->getParam('elementsSemaineAffichee')->numSemaine);
     $tpl->assign('annee', $this->getParam('elementsSemaineAffichee')->annee);
     //on vérifie si un agenda de classe est affiché
     //$lecon = false;
     $readLecon = false;
     $writeLecon = false;
     $idAgendaScolaire = null;
     $agendasAffiches = $this->getParam('agendasAffiches', null);
     foreach ($this->getParam('elementsSemaineAffichee')->agendas as $id_agenda) {
         if ($serviceAgenda->getTypeAgendaByIdAgenda($id_agenda) == $serviceType->getClassRoom()) {
             //on vérifie si l'utilisateur peut écrire des leçons
             if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getWriteLecon()) {
                 $writeLecon = true;
                 //$lecon = true;
                 $idAgendaScolaire = $id_agenda;
                 break;
             }
             //on vérifie si l'utilisateur peut lire les leçons
             if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getRead()) {
                 $readLecon = true;
                 //$lecon = true;
                 //$idAgendaScolaire = $id_agenda;
                 //break;
             }
         }
     }
     //on vérifie si l'utilisateur a les droits d'écriture sur un des agendas affichés
     $writeAgenda = false;
     $agendasAffiches = $this->getParam('agendasAffiches', null);
     foreach ($this->getParam('elementsSemaineAffichee')->agendas as $id_agenda) {
         if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getWriteAgenda()) {
             $writeAgenda = true;
             break;
         }
     }
     //on construit un tableau de droits pour chaque agenda affiché
     $arDroits = array();
     foreach ($this->getParam('elementsSemaineAffichee')->agendas as $id_agenda) {
         if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getRead()) {
             $arDroits[$id_agenda]->canRead = true;
         } else {
             $arDroits[$id_agenda]->canRead = false;
         }
         if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getWriteAgenda()) {
             $arDroits[$id_agenda]->canWrite = true;
         } else {
             $arDroits[$id_agenda]->canWrite = false;
         }
         if ($serviceAuth->getCapability($id_agenda) >= $serviceAuth->getModerate()) {
             $arDroits[$id_agenda]->canModerate = true;
         } else {
             $arDroits[$id_agenda]->canModerate = false;
         }
     }
     //on construit le tableau de couleurs associées au type d'agenda
     $arColorByIdAgenda = array();
     foreach ($this->getParam('elementsSemaineAffichee')->agendas as $id_agenda) {
         $arColor = $serviceType->getColors($serviceAgenda->getTypeAgendaByIdAgenda($id_agenda));
         $i = 0;
         foreach ($arColorByIdAgenda as $idAgenda => $couleurAgenda) {
             if ($arColorByIdAgenda[$idAgenda] == $arColor[$i]) {
                 $i = $i + 1;
             }
         }
         if ($i < count($arColor)) {
             $arColorByIdAgenda[$id_agenda] = $arColor[$i];
         } else {
             $arColorByIdAgenda[$id_agenda] = $arColor[0];
         }
     }
     $tpl->assign('arColorByIdAgenda', $arColorByIdAgenda);
     //on détermine l'heure de début et de fin pour l'affichage du calendrier
     $tpl->assign('heure_deb', $this->getParam('heureDeb'));
     $tpl->assign('heure_fin', $this->getParam('heureFin'));
     $tpl->assign('arEventByDay', $this->getParam('arEventByDay'));
     $tpl->assign('readLecon', $readLecon);
     $tpl->assign('writeLecon', $writeLecon);
     $tpl->assign('agendaScolaire', $idAgendaScolaire);
     $tpl->assign('arLecons', $this->getParam('arLecons'));
     $tpl->assign('arTravauxEnClasse', $this->getParam('arTravauxEnClasse'));
     $tpl->assign('arTravauxAFaire', $this->getParam('arTravauxAFaire'));
     $tpl->assign('agenda2cahier', $this->getParam('agenda2cahier'));
     $tpl->assign('writeAgenda', $writeAgenda);
     $tpl->assign('arDroits', $arDroits);
     $tpl->assign('todayJour', date('d'));
     $tpl->assign('todaySemaine', date('W'));
     $tpl->assign('todayAnnee', date('Y'));
     //paramètres pour passer d'une semaine à l'autre
     $tpl->assign('semaine_precedente', $service->dateToWeeknum(mktime(0, 0, 0, date('m', $lundi), date('d', $lundi) - 7, date('Y', $lundi))));
     $tpl->assign('semaine_suivante', $service->dateToWeeknum(mktime(0, 0, 0, date('m', $lundi), date('d', $lundi) + 7, date('Y', $lundi))));
     $tpl->assign('annee_precedente', date('Y', mktime(0, 0, 0, date('m', $lundi), date('d', $lundi) - 4, date('Y', $lundi))));
     $tpl->assign('annee_suivante', date('Y', mktime(0, 0, 0, date('m', $lundi), date('d', $lundi) + 10, date('Y', $lundi))));
     $listAgendas = $this->getParam('listAgendas', null);
     $tpl->assign('listAgendas', $listAgendas);
     $toReturn = $tpl->fetch('vuesemaine.agenda.ptpl');
     return true;
 }
 /**
  * Renvoie le menu des agendas
  * @author Christophe Beyer <*****@*****.**>
  * @since 2010/10/20
  * @param string $iCurrent Onglet a allumer
  * @return array Tableau du menu a afficher
  */
 public function getAgendaMenu($iCurrent)
 {
     $menu = array();
     // Affichage hebdomadaire
     $menu_txt = CopixI18N::get('agenda.menu.back');
     $menu_type = 'week';
     $menu_url = CopixUrl::get('agenda|agenda|vueSemaine');
     $menu[] = array('txt' => $menu_txt, 'type' => $menu_type, 'current' => $iCurrent == $menu_type, 'url' => $menu_url);
     // Liste des agendas (popup)
     $menu_txt = CopixI18N::get('agenda|agenda.menu.agendalist');
     $menu_type = 'agendalist';
     $menu_behavior = 'fancybox';
     $menu_url = CopixUrl::get('agenda|agenda|agendaList');
     $menu[] = array('txt' => $menu_txt, 'type' => $menu_type, 'current' => $iCurrent == $menu_type, 'behavior' => $menu_behavior, 'url' => $menu_url);
     // Nouvel evenement
     $listAgendasAffiches = AgendaService::getAgendaAffiches();
     $ableToWrite = false;
     $ableToModerate = false;
     //on vérifie les droits des utilisateurs sur la liste des agendas affichés
     foreach ((array) $listAgendasAffiches as $id_agenda) {
         //on vérifie si l'utilisateur a les droits d'écriture sur un des agendas affiché
         if (AgendaAuth::getCapability($id_agenda) >= AgendaAuth::getWriteAgenda()) {
             $ableToWrite = true;
         }
         if (AgendaAuth::getCapability($id_agenda) >= AgendaAuth::getModerate()) {
             $ableToModerate = true;
         }
     }
     if ($ableToWrite) {
         $menu_txt = CopixI18N::get('agenda.menu.ajoutEvent');
         $menu_type = 'create';
         $menu_url = CopixUrl::get('agenda|event|create');
         $menu[] = array('txt' => $menu_txt, 'type' => $menu_type, 'current' => $iCurrent == $menu_type, 'url' => $menu_url);
     }
     if ($ableToModerate) {
         $menu_txt = CopixI18N::get('agenda.menu.import');
         $menu_type = 'import';
         $menu_url = CopixUrl::get('agenda|importexport|prepareImport');
         $menu[] = array('txt' => $menu_txt, 'type' => $menu_type, 'current' => $iCurrent == $menu_type, 'url' => $menu_url);
     }
     // Export
     $menu_txt = CopixI18N::get('agenda.menu.export');
     $menu_type = 'export';
     $menu_url = CopixUrl::get('agenda|importexport|prepareExport');
     $menu[] = array('txt' => $menu_txt, 'type' => $menu_type, 'current' => $iCurrent == $menu_type, 'url' => $menu_url);
     return $menu;
 }