function editerAction()
 {
     $tc = new Citation();
     $this->assert(null, $tc, 'editer', "Vous n'avez pas le droit d'éditer les citations.");
     $citation = $tc->find($this->_getParam('citation'))->current();
     $this->metas(array('DC.Title' => 'Éditer une citation'));
     $this->view->model = $m = new Wtk_Form_Model('citation');
     $m->addConstraintRequired($m->addString('auteur', 'Auteur', $citation->auteur));
     $m->addConstraintRequired($m->addString('texte', 'Citation', $citation->texte));
     $m->addNewSubmission('enregistrer', 'Enregistrer');
     if ($m->validate()) {
         $db = $tc->getAdapter();
         $db->beginTransaction();
         try {
             $data = $m->get();
             $citation->auteur = $data['auteur'];
             $citation->texte = $data['texte'];
             $citation->save();
             $this->logger->info("Citation éditée", array('controller' => 'citation'));
             $db->commit();
             $this->redirectSimple('index');
         } catch (Exception $e) {
             $db->rollback();
             throw $e;
         }
     }
 }
Exemple #2
0
 function fetch($annee = NULL)
 {
     if (!$this->activite) {
         return array('activites' => $this->unite->findActivites($annee));
     } else {
         $this->controller->assert(null, $this->activite, 'envoyer-photo', "Vous n'avez pas le droit d'envoyer de photo de " . $this->activite->getIntituleComplet() . ".");
     }
     $m = new Wtk_Form_Model('envoyer');
     $i = $m->addString('titre', 'Titre');
     $m->addConstraintRequired($i);
     $m->addFile('photo', "Photo");
     $m->addString('commentaire', 'Votre commentaire');
     $m->addBool('envoyer', "J'ai d'autres photos à envoyer", true);
     $m->addNewSubmission('envoyer', "Envoyer");
     $t = new Photos();
     if ($m->validate()) {
         $p = new Photo();
         $p->titre = $m->titre;
         $p->slug = $t->createSlug(wtk_strtoid($m->titre));
         $p->activite = $this->activite->id;
         $action = $m->envoyer ? 'envoyer' : 'consulter';
         $c = new Commentaire();
         $c->auteur = Zend_Registry::get('individu')->id;
         $c->message = $m->commentaire;
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $c->save();
             $p->commentaires = $c->id;
             $p->save();
             $i = $m->getInstance('photo');
             if ($i->isUploaded()) {
                 $tmp = $i->getTempFilename();
                 $p->storeFile($tmp);
             }
             $url = $this->controller->_helper->Url('voir', 'photos', null, array('photo' => $p->slug), true);
             $this->controller->logger->info("Photo envoyée", $url);
             foreach ($this->activite->findUnitesParticipantesExplicites() as $u) {
                 $ident = new Identification();
                 $ident->photo = $p->id;
                 $ident->unite = $u->id;
                 $ident->save();
                 $this->controller->logger->info("Unité identifiée sur une photo", $url);
             }
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->controller->_helper->Flash->info("Photo envoyée");
         $this->controller->redirectSimple($action, null, null, array('album' => $this->activite->slug));
     }
     $photos = $this->activite->findPhotos($t->select()->order('date'));
     return array('unite' => $this->unite, 'annee' => $annee, 'model' => $m, 'activite' => $this->activite, 'photos' => $photos);
 }
 function editerAction()
 {
     $this->view->photo = $p = $this->_helper->Photo(false);
     $this->metas(array('DC.Title' => 'Éditer un commentaire'));
     $this->view->commentaire = $c = $this->_helper->Commentaire();
     $this->assert(null, $c, 'editer', "Vous n'avez pas le droit d'éditer ce commentaire !");
     $this->view->model = $m = new Wtk_Form_Model('editer');
     $m->addNewSubmission('enregistrer', 'Enregistrer');
     $m->addString('message', "Message", $c->message);
     if ($m->validate()) {
         $c->message = $m->get('message');
         if ($p) {
             $url = $this->_helper->Url('voir', 'photos', null, array('message' => null));
         } else {
             $url;
         }
         $db = $c->getTable()->getAdapter();
         $db->beginTransaction();
         try {
             $c->save();
             $this->logger->info('Commentaire édité', $url);
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         if ($p) {
             $this->redirectSimple('voir', 'photos', null, array('message' => null));
         }
     }
 }
Exemple #4
0
 function fetch($annee = NULL)
 {
     $ta = new Activites();
     $as = $ta->findByAnnee($annee);
     $activite = null;
     if ($as->count() == 1) {
         $activite = $as->current();
         $this->controller->_helper->Album->setBranche($activite);
     }
     $m = new Wtk_Form_Model('editer');
     $i = $m->addString('titre', 'Titre', $this->photo->titre);
     $m->addConstraintRequired($i);
     $enum = array();
     foreach ($as as $a) {
         if ($this->controller->assert(null, $a, 'editer-photo')) {
             $enum[$a->id] = $a->getIntituleComplet();
         }
     }
     if ($enum) {
         $m->addEnum('activite', "Activité", $this->photo->activite, $enum);
     }
     $m->addFile('photo', "Photo");
     $m->addBool('promouvoir', "Promouvoir en page d'accueil", $this->photo->promotion);
     $m->addNewSubmission('enregistrer', "Enregistrer");
     if ($m->validate()) {
         $t = $this->photo->getTable();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $i = $m->getInstance('photo');
             if ($i->isUploaded()) {
                 $tmp = $i->getTempFilename();
                 $this->photo->storeFile($tmp);
             }
             try {
                 $this->photo->activite = $m->activite;
             } catch (Exception $e) {
             }
             $this->photo->titre = $m->titre;
             $this->photo->slug = $t->createSlug($m->titre, $this->photo->slug);
             $this->photo->promotion = (int) $m->promouvoir;
             $this->photo->save();
             $this->controller->_helper->Flash->info("Photo éditée");
             $this->controller->logger->info("Photo éditée", $this->controller->_helper->Url('voir', null, null, array('photo' => $this->photo->slug)));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->controller->redirectSimple('voir', null, null, array('photo' => $this->photo->slug));
     }
     return array('unite' => $this->unite, 'annee' => $annee, 'form_model' => $m, 'activite' => $activite, 'photo' => $this->photo);
 }
Exemple #5
0
 public function routeStartup()
 {
     $this->initAcl();
     $config = Zend_Registry::get('config');
     try {
         $lifetime = $config->system->duree_connexion;
         Zend_Session::setOptions(array('cookie_path' => '/', 'cookie_lifetime' => $lifetime, 'cache_expire' => $lifetime));
     } catch (Exception $e) {
         error_log((string) $e);
     }
     // models formulaire
     $m = new Wtk_Form_Model('login');
     $i = $m->addString('username', "Courriel");
     $m->addConstraintRequired($i);
     $i = $m->addString('password', "Mot de passe");
     $m->addConstraintRequired($i);
     $m->addNewSubmission('login', "Identifier");
     Zend_Registry::set('login_model', $m);
     $m = new Wtk_Form_Model('logout');
     $m->addNewSubmission('logout', "Déconnecter");
     Zend_Registry::set('logout_model', $m);
     $db = Zend_Registry::get('db');
     // initialise les méthodes d'authentifications.
     $auth = Zend_Auth::getInstance();
     // DB AUTH
     $this->db = new Strass_Auth_Adapter_DbTable($db, 'user', 'username', 'password');
     // HTTP_AUTH
     $config = array('accept_schemes' => 'digest', 'realm' => $config->system->realm, 'digest_domains' => '/', 'nonce_timeout' => $config->system->duree_connexion);
     $this->http = new Zend_Auth_Adapter_Http($config);
     $resolver = new Strass_Auth_Adapter_Http_Resolver_DbTable($db, 'user', 'username', 'password');
     $this->http->setDigestResolver($resolver);
     // SUDO AUTH
     $this->sudo = new Strass_Auth_Adapter_Sudo();
     $this->sudo();
     $this->form();
     $this->getUser();
 }
Exemple #6
0
 function voirAction()
 {
     $this->view->photo = $photo = $this->_helper->Photo();
     $this->view->activite = $a = $photo->findParentActivites();
     $this->metas(array('DC.Title' => $photo->titre, 'DC.Subject' => 'photo', 'DC.Date.created' => $photo->date));
     $this->actions->append("Identifier", array('action' => 'identifier'), array(null, $photo));
     $this->actions->append("Éditer", array('action' => 'editer'), array(null, $photo));
     $this->actions->append("Supprimer", array('action' => 'supprimer'), array(null, $photo));
     $ps = $a->findPhotos($photo->getTable()->select()->order('date'));
     $data = array();
     foreach ($ps as $p) {
         $data[$p->slug] = $p;
     }
     $this->view->model = $m = new Wtk_Pages_Model_Assoc($data, $photo->slug);
     $i = Zend_Registry::get('individu');
     if ($this->assert(null, $photo, 'commenter')) {
         /* Si l'utilisateur peut commenter mais ne l'a pas fait, lui
            présenter le formulaire */
         try {
             $photo->findCommentaire($i);
         } catch (Strass_Db_Table_NotFound $e) {
             $this->view->com_model = $m = new Wtk_Form_Model('commentaire');
             $m->addString('message', "Message");
             $m->addNewSubmission('commenter', "Commenter");
             if ($m->validate()) {
                 $t = new Commentaires();
                 $tuple = array('parent' => $photo->commentaires, 'auteur' => $i->id, 'message' => $m->get('message'));
                 $db = $t->getAdapter();
                 $db->beginTransaction();
                 try {
                     $t->insert($tuple);
                     $this->logger->info("Photo commentée");
                     unset($this->view->com_model);
                     $db->commit();
                 } catch (Exception $e) {
                     $db->rollBack();
                     throw $e;
                 }
             }
         }
     }
     /* Lister les commentaires après l'insertion  */
     $this->view->commentaires = $photo->findCommentaires();
 }
 function editerAction()
 {
     $page = $this->_getParam('page');
     if (!$page) {
         throw new Strass_Controller_Action_Exception("Aucune page à éditer");
     }
     $this->view->statique = $page = new Statique($page);
     $this->metas(array('DC.Title' => "Éditer " . $page->getTitle()));
     $this->branche->append($page->getTitle(), array('action' => 'index'));
     $this->branche->append('Éditer');
     $this->assert(null, $page, 'editer', "Vous n'avez pas le droit d'éditer cette page");
     $this->view->model = $m = new Wtk_Form_Model('editer');
     $m->addNewSubmission('enregistrer', 'Enregistrer');
     $m->addString('wiki', 'Texte', $page->read());
     if ($m->validate()) {
         $page->write($m->get('wiki'));
         $this->redirectSimple('index');
     }
 }
 function envoyerAction()
 {
     $this->view->doc = $d = $this->_helper->Document(false);
     if ($d) {
         $this->metas(array('DC.Title' => 'Éditer'));
         $this->view->unite = $unite = $d->findUnite();
     } else {
         $this->view->unite = $unite = $this->_helper->Unite(false);
         $this->branche->append('Documents', array('action' => 'index'));
         $this->metas(array('DC.Title' => 'Envoyer un document', 'DC.Title.alternative' => 'Envoyer'));
         $this->branche->append();
     }
     $t = new Unites();
     $unites = $t->fetchAll();
     $envoyables = array();
     foreach ($unites as $u) {
         if ($this->assert(null, $u, 'envoyer-document')) {
             $envoyables[$u->id] = $u->getFullName();
         }
     }
     if (!count($envoyables)) {
         throw new Strass_Controller_Action_Exception_Forbidden("Vous n'avez le droit d'envoyer de document pour aucune unité");
     }
     $this->view->model = $m = new Wtk_Form_Model('envoyer');
     $m->addNewSubmission('envoyer', "Envoyer");
     $m->addEnum('unite', "Unité", $unite->id, $envoyables);
     $i = $m->addString('titre', "Titre", $d ? $d->titre : null);
     $m->addConstraintRequired($i);
     $m->addString('auteur', "Auteur", $d ? $d->auteur : null);
     $m->addDate('date', "Date", $d ? $d->date : strftime('%F %T'));
     $m->addString('description', "Description", $d ? $d->description : null);
     $i = $m->addInstance('File', 'fichier', "Fichier");
     if (!$d) {
         $m->addConstraintRequired($i);
     }
     if ($m->validate()) {
         $t = new Documents();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             if ($d) {
                 $message = "Document modifié";
                 $du = $d->findDocsUnite()->current();
             } else {
                 if (!$d) {
                     $message = "Document envoyé";
                     $d = new Document();
                     $du = new DocUnite();
                 }
             }
             $d->slug = $t->createSlug(wtk_strtoid($m->titre), $d->slug);
             $d->titre = $m->titre;
             $d->auteur = $m->auteur;
             $d->date = $m->date;
             $d->description = $m->description;
             if ($i->isUploaded()) {
                 $d->suffixe = strtolower(end(explode('.', $m->fichier['name'])));
                 $d->save();
                 $d->storeFile($i->getTempFilename());
             } else {
                 $d->save();
             }
             $du->document = $d->id;
             $du->unite = $m->unite;
             $du->save();
             $this->logger->info($message, $this->_helper->Url('index', null, null, array('unite' => $du->findParentUnites()->slug), true));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('details', null, null, array('document' => $d->slug));
     }
 }
 function envoyerAction()
 {
     if ($this->_getParam('article')) {
         $a = $this->_helper->Article();
         $j = $a->findParentJournaux();
         $c = $a->findParentCommentaires();
         try {
             $d = $a->findDocument();
         } catch (Strass_Db_Table_NotFound $e) {
             $this->redirectSimple('ecrire');
         }
         $message = "Article édité";
     } else {
         $a = null;
         $j = $this->_helper->Journal();
         $message = "Article envoyé";
     }
     $this->metas(array('DC.Title' => "Envoyer"));
     $this->branche->append();
     if ($a) {
         $this->assert(null, $a, null, "Vous n'avez pas le droit d'éditer " . $a);
     } else {
         $this->assert(null, $j, null, "Vous n'avez pas le droit d'envoyer un PDF dans " . $j);
     }
     $this->view->unite = $u = $j->findParentUnites();
     $publier = $this->assert(null, $j, 'publier');
     $this->view->model = $m = new Wtk_Form_Model('envoyer');
     $me = Zend_Registry::get('individu');
     if ($publier) {
         $i = $m->addEnum('auteur', "Auteur");
         /* on inclus les membres de sous-unité : le scout peuvent écrire
            dans la gazette de troupe */
         foreach ($u->findInscrits(null, 1) as $individu) {
             $i->addItem($individu->id, $individu->getFullname(false));
         }
         if (!count($i)) {
             throw new Strass_Controller_Action_Exception_Notice("L'auteur de l'article doit être un membre, mais cette unité n'a aucun membre !");
         }
         if ($a) {
             $i->set($a->findAuteur()->id);
         } else {
             $i->set($me->id);
         }
     } else {
         $i = $m->addInteger('auteur', "Auteur", $me->id, true);
     }
     $i = $m->addInstance('File', 'fichier', "Fichier");
     if (!$a) {
         $m->addConstraintRequired($i);
     }
     $i = $m->addString('titre', "Titre", $a ? $a->titre : null);
     $m->addConstraintRequired($i);
     $m->addDate('date', 'Date', $a ? $c->date : null);
     if ($publier) {
         $m->addEnum('public', 'Publication', $a ? $a->public : null, array(0 => 'Brouillon', 1 => 'Publier'));
     }
     $m->addNewSubmission('envoyer', "Envoyer");
     if ($m->validate()) {
         $td = new Documents();
         $db = $td->getAdapter();
         $db->beginTransaction();
         try {
             $da = (bool) $a;
             if (!$a) {
                 $a = new Article();
                 $c = new Commentaire();
                 $d = new Document();
             }
             $d->slug = $td->createSlug($j->slug . '-' . $m->titre, $d->slug);
             $d->titre = $m->titre;
             $d->date = $m->date;
             $i = $m->getInstance('fichier');
             if ($i->isUploaded()) {
                 $d->suffixe = strtolower(end(explode('.', $m->fichier['name'])));
                 $d->storeFile($i->getTempFilename());
             }
             $d->save();
             $c->auteur = $m->auteur;
             $c->date = $m->date;
             $c->save();
             $a->slug = $a->getTable()->createSlug($m->titre, $a->slug);
             $a->journal = $j->id;
             $a->titre = $m->titre;
             $a->article = '!document';
             try {
                 $a->public = (int) $m->public;
             } catch (Exception $e) {
             }
             $a->commentaires = $c->id;
             $a->save();
             if (!$da) {
                 $da = new DocArticle();
                 $da->article = $a->id;
                 $da->document = $d->id;
                 $da->save();
             }
             $this->logger->info($message, $this->_helper->url('consulter', 'journaux', null, array('article' => $a->slug), true));
             if (!$this->assert(null, $j, 'publier')) {
                 $mail = new Strass_Mail_Article($a);
                 $mail->send();
             }
             $this->_helper->Flash->info($message);
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('consulter', 'journaux', null, array('article' => $a->slug), true);
     }
 }
 function editerAction()
 {
     $this->view->activite = $a = $this->_helper->Activite();
     $this->assert(null, $a, 'editer', "Vous n'avez pas le droit d'éditer cettes activités");
     $this->metas(array('DC.Title' => 'Éditer ' . $a->getIntitule()));
     $this->view->model = $m = new Wtk_Form_Model('activite');
     $t = new Unites();
     $explicites = $a->findUnitesParticipantesExplicites();
     $enum = array();
     foreach ($t->fetchAll() as $unite) {
         if ($this->assert(null, $unite, 'prevoir')) {
             $enum[$unite->id] = $unite->getFullname();
         }
     }
     $values = array();
     foreach ($explicites as $unite) {
         $values[] = $unite->id;
     }
     $i = $m->addEnum('unites', 'Unités participantes', $values, $enum, true);
     // multiple
     $m->addConstraintRequired($i);
     $m->addString('intitule', 'Intitulé explicite', $a->intitule);
     $m->addString('lieu', 'Lieu', $a->lieu);
     $m->addDate('debut', 'Début', $a->debut, '%Y-%m-%d %H:%M');
     $m->addDate('fin', 'Fin', $a->fin, '%Y-%m-%d %H:%M');
     $m->addString('description', 'Description', $a->description);
     $enum = array(null => 'Nouveau document');
     foreach ($explicites->rewind()->current()->findDocuments() as $doc) {
         $enum[$doc->id] = $doc->titre;
     }
     $t = $m->addTable('documents', "Pièces-jointes", array('document' => array('Enum', "Document", $enum), 'fichier' => array('File', "Fichier"), 'titre' => array('String', "Titre"), 'origin' => array('Integer')), false);
     foreach ($a->findPiecesJointes() as $pj) {
         $doc = $pj->findParentDocuments();
         $titre = $doc->countLiaisons() > 1 ? null : $doc->titre;
         $t->addRow($pj->document, null, $titre, $pj->id);
     }
     $t->addRow();
     $m->addNewSubmission('enregistrer', 'Enregistrer');
     if ($m->validate()) {
         $t = new Activites();
         $tu = new Unites();
         $tpj = new PiecesJointes();
         $td = new Documents();
         $unites = call_user_func_array(array($tu, 'find'), (array) $m->unites);
         $db = $a->getTable()->getAdapter();
         $db->beginTransaction();
         try {
             $champs = array('debut', 'fin', 'lieu', 'description');
             foreach ($champs as $champ) {
                 $a->{$champ} = $m->{$champ};
             }
             $a->updateUnites($unites);
             $a->intitule = $m->intitule;
             $a->slug = $t->createSlug($a->getIntituleComplet(), $a->slug);
             $a->save();
             $old = $a->findPiecesJointes();
             $new = array();
             /* création et mise à jour de pièce jointe */
             foreach ($m->getInstance('documents') as $row) {
                 $d = null;
                 if ($row->document) {
                     $d = $td->findOne($row->document);
                 }
                 if ($row->origin) {
                     $pj = $tpj->findOne($row->origin);
                     if (!$d) {
                         $d = $pj->findParentDocuments();
                     }
                 } else {
                     $pj = new PieceJointe();
                     $pj->activite = $a->id;
                     if (!$d) {
                         $d = new Document();
                     }
                 }
                 /* On ne met à jour que les pièces jointes exclusives */
                 if (!$row->document) {
                     /* requérir un titre pour les documents exclusifs */
                     $if = $row->getChild('fichier');
                     if (!$row->titre && ($if->isUploaded() || $row->origin)) {
                         throw new Wtk_Form_Model_Exception("Titre obligatoire", $row->getChild('titre'));
                     }
                     $d->slug = $d->getTable()->createSlug($row->titre);
                     $d->titre = $row->titre;
                     if ($if->isUploaded()) {
                         $d->suffixe = end(explode('.', $row->fichier['name']));
                         $d->storeFile($if->getTempFilename());
                     } elseif (!$row->origin) {
                         continue;
                     }
                     /* ligne vide */
                     $d->save();
                 }
                 $pj->document = $d->id;
                 $pj->save();
                 $new[] = $pj->id;
             }
             // Nettoyage des documents supprimés
             foreach ($old as $opj) {
                 if (in_array($opj->id, $new)) {
                     continue;
                 }
                 $opj->delete();
             }
             $this->logger->info("Activité mise-à-jour", $this->_helper->Url('consulter', null, null, array('activite' => $a->slug)));
             $db->commit();
             $this->redirectSimple('consulter', null, null, array('activite' => $a->slug));
         } catch (Wtk_Form_Model_Exception $e) {
             $db->rollBack();
             $m->errors[] = $e;
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
     }
 }
Exemple #11
0
 function parametresAction()
 {
     $moi = Zend_Registry::get('user');
     $this->view->user = $user = $this->_helper->Membre($moi);
     $this->view->individu = $individu = $user->findParentIndividus();
     $this->assert($moi, $user, 'parametres', "Vous n'avez pas le droit de modifier les paramètres de cet utilisateur.");
     $this->metas(array('DC.Title' => "Éditer l'utilisateur " . $user->username));
     $autoedit = $moi->id == $user->id;
     $db = Zend_Registry::get('db');
     /* Migration de l'identifiant */
     if ($autoedit && $user->username != $individu->adelec) {
         $this->view->migrate = $m = new Wtk_Form_Model('migrate');
         $m->addConstraintRequired($m->addString('motdepasse', 'Mot de passe'));
         $m->addNewSubmission('migrer', 'Migrer');
         if ($m->validate()) {
             $db->beginTransaction();
             try {
                 if (!$user->testPassword($m->get('motdepasse'))) {
                     throw new Wtk_Form_Model_Exception('Mot de passe erroné', $m->getInstance('motdepasse'));
                 }
                 $user->username = $individu->adelec;
                 $user->setPassword($m->get('motdepasse'));
                 $user->save();
                 $this->logger->info("Migration du compte", $this->_helper->Url('fiche', 'individus', null, array('individu' => $individu->slug)));
                 $db->commit();
                 $auth = Zend_Auth::getInstance();
                 $id = $auth->getIdentity();
                 $id['username'] = $user->username;
                 $auth->getStorage()->write($id);
             } catch (Wtk_Form_Model_Exception $e) {
                 $db->rollBack();
                 $m->errors[] = $e;
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             $this->redirectSimple('fiche', 'individus', null, array('individu' => $individu->slug), true);
         }
     }
     /* Changement d'adélec */
     if ($autoedit) {
         $this->view->adelec = $m = new Wtk_Form_Model('adelec');
         $i = $m->addString('adelec', 'Adelec', $individu->adelec);
         $m->addConstraintRequired($i);
         $m->addConstraintEMail($i);
         $m->addConstraintRequired($m->addString('motdepasse', 'Mot de passe'));
         $m->addNewSubmission('enregistrer', 'Enregistrer');
         if ($m->validate()) {
             $db->beginTransaction();
             try {
                 if (!$user->testPassword($m->get('motdepasse'))) {
                     throw new Wtk_Form_Model_Exception('Mot de passe erroné', $m->getInstance('motdepasse'));
                 }
                 if ($user->username == $individu->adelec) {
                     $user->username = $m->get('adelec');
                     $user->setPassword($m->get('motdepasse'));
                     $user->save();
                     $auth = Zend_Auth::getInstance();
                     $id = $auth->getIdentity();
                     $id['username'] = $user->username;
                     $auth->getStorage()->write($id);
                 }
                 $individu->adelec = $m->get('adelec');
                 $individu->save();
                 $this->logger->info("Changement d'adélec", $this->_helper->Url('fiche', 'individus', null, array('individu' => $individu->slug)));
                 $db->commit();
             } catch (Wtk_Form_Model_Exception $e) {
                 $db->rollBack();
                 $m->errors[] = $e;
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             $this->redirectSimple('fiche', 'individus', null, array('individu' => $individu->slug), true);
         }
     }
     /* Changement de mot de passe */
     $this->view->change = $m = new Wtk_Form_Model('chpass');
     $g = $m->addGroup('mdp', "Change le mot de passe");
     if (!$this->assert(null) || $autoedit) {
         $m->addConstraintRequired($g->addString('ancien', 'Ancien'));
     }
     $m->addConstraintRequired($g->addString('nouveau', 'Nouveau'));
     $m->addConstraintRequired($g->addString('confirmation', "Confirmation"));
     $m->addNewSubmission('valider', 'Valider');
     if ($m->validate()) {
         $db->beginTransaction();
         try {
             $mdp = $m->get('mdp');
             if (array_key_exists('ancien', $mdp)) {
                 if (!$user->testPassword($mdp['ancien'])) {
                     throw new Wtk_Form_Model_Exception("Ancien mot de passe erroné.", $m->getInstance('mdp/ancien'));
                 }
             }
             if ($mdp['nouveau'] != $mdp['confirmation']) {
                 throw new Wtk_Form_Model_Exception("Le mot de passe de confirmation n'est pas identique " . "au nouveau.");
             }
             $user->setPassword($mdp['nouveau']);
             $user->save();
             $this->logger->info("Mot de passe changé", $this->_helper->Url('fiche', 'individus', null, array('individu' => $individu->slug)));
             $db->commit();
         } catch (Wtk_Form_Model_Exception $e) {
             $db->rollBack();
             $m->errors[] = $e;
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('fiche', 'individus', null, array('individu' => $individu->slug), true);
     }
     /* Notifications */
     $this->view->notifications = $m = new Wtk_Form_Model('notifications');
     $m->addBool('send_mail', "Recevoir des notifications par mail", $user->send_mail);
     $m->addNewSubmission('valider', 'Valider');
     if ($m->validate()) {
         $db->beginTransaction();
         try {
             $user->send_mail = (bool) $m->get('send_mail');
             $user->save();
             $db->commit();
             if ($user->send_mail) {
                 $msg = "Notifications activées";
             } else {
                 $msg = "Notifications désactivées";
             }
             $this->logger->info($msg, $this->_helper->Url('fiche', 'individus', null, array('individu' => $individu->slug)));
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('fiche', 'individus', null, array('individu' => $individu->slug), true);
     }
     /* Promotion à l'administration */
     if ($this->assert($moi, $user, 'admin') && !$autoedit) {
         $this->view->admin = $m = new Wtk_Form_Model('admin');
         $m->addBool('admin', "Accorder tous les privilèges sur le site à " . $user->findParentIndividus()->getFullName(), $user->admin);
         $m->addNewSubmission('valider', 'Valider');
         if ($m->validate()) {
             $db->beginTransaction();
             try {
                 $user->admin = $m->get('admin');
                 $user->save();
                 $db->commit();
                 $msg = $user->admin ? "Privilèges accordés" : "Privilèges refusés";
                 $this->logger->warn($msg, $this->_helper->Url('fiche', 'individus', null, array('individu' => $individu->slug)));
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             $this->redirectSimple('fiche', 'individus', null, array('individu' => $individu->slug), true);
         }
     }
 }
Exemple #12
0
 function parametresAction()
 {
     static $blocs = array('branches' => 'Les branches', 'unites' => 'Les unités', 'photos' => 'Photos aléatoires', 'activites' => 'Activités marquantes', 'documents' => 'Documents');
     $this->view->unite = $u = $this->_helper->Unite();
     $this->assert(null, $u, null, "Vous n'avez pas le droit de modifier cette unité");
     $this->metas(array('DC.Title' => 'Paramètres ' . $u->getFullname()));
     $this->view->model = $m = new Wtk_Form_Model('parametres');
     $w = $u->getWiki(null, false);
     $m->addString('presentation', "Message d'accueil", is_readable($w) ? file_get_contents($w) : '');
     $config = new Strass_Config_Php($u->slug);
     $t = $m->addTable('blocs', "Blocs de la page d'accueil", array('id' => array('String'), 'nom' => array('String', 'Bloc', true), 'enable' => array('Bool', 'Actif')), true, false);
     $enabled = $config->blocs;
     if ($enabled) {
         $enabled = $enabled->toArray();
     } else {
         $enabled = array();
     }
     foreach ($enabled as $k) {
         $r = $t->addRow($k, $blocs[$k], true);
     }
     /* nouveau blocs */
     foreach ($blocs as $k => $v) {
         if (!in_array($k, $enabled)) {
             $r = $t->addRow($k, $v, false);
         }
     }
     $m->addNewSubmission('enregistrer', "Enregistrer");
     if ($m->validate()) {
         $u->storePresentation($m->presentation);
         $blocs = array();
         foreach ($m->blocs as $row) {
             if ($row['enable']) {
                 array_push($blocs, $row['id']);
             }
         }
         $config->blocs = $blocs;
         $config->write();
         $this->logger->info("Configuration de page d'accueil");
         $this->redirectSimple('index', 'unites', null, array('unite' => $u->slug));
     }
 }
 function reinscrireAction()
 {
     $this->view->app = $app = $this->_helper->Inscription();
     $this->metas(array('DC.Title' => "Éditer l'inscription"));
     $this->view->individu = $individu = $app->findParentIndividus();
     $this->assert(null, $individu, 'inscrire', "Vous n'avez pas le droit d'inscrire " . $individu->getFullname() . " dans une unité.");
     $this->view->model = $m = new Wtk_Form_Model('inscription');
     $this->view->unite = $unite = $app->findParentUnites();
     $i = $m->addEnum('role', 'Rôle', $app->role);
     $roles = $individu->findRolesCandidats($unite, false);
     foreach ($roles as $role) {
         $i->addItem($role->id, $role->titre);
     }
     $m->addString('titre', 'Titre', $app->titre);
     $m->addDate('debut', 'Début', $app->debut);
     $i0 = $m->addBool('clore', 'Clore', (bool) $app->fin);
     $i1 = $m->addDate('fin', 'Fin', $app->fin);
     $m->addConstraintDepends($i1, $i0);
     $m->addNewSubmission('enregistrer', "Enregistrer");
     if ($m->validate()) {
         $app->role = $m->role;
         $app->titre = $m->titre;
         $app->debut = $m->debut;
         if ($m->clore) {
             $app->fin = $m->fin;
         } else {
             $app->fin = null;
         }
         $db = $app->getTable()->getAdapter();
         $db->beginTransaction();
         try {
             $app->save();
             $this->logger->info("Inscription éditée");
             $this->_helper->Flash->info("Inscription éditée");
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('fiche', 'individus', null, array('individu' => $individu->slug), true);
     }
 }
Exemple #14
0
 function fetch($annee = NULL)
 {
     $u = $this->unite;
     $a = $annee;
     $m = new Wtk_Form_Model('prevoir');
     $t = new Unites();
     $enum = array();
     foreach ($t->fetchAll() as $unite) {
         if ($this->controller->assert(null, $unite, 'prevoir')) {
             $enum[$unite->id] = $unite->getFullname();
         }
     }
     if (!$enum) {
         throw new Strass_Controller_Action_Exception_Notice("Vous ne pouvez pas enregistrer une activité");
     }
     $i = $m->addEnum('unites', 'Unités participantes', $u->id, $enum, true);
     // multiple
     $m->addConstraintRequired($i);
     $annee = $this->controller->_helper->Annee(false);
     /* On cherche la date probable de l'activité qu'on veut prévoir. Soit
      * aucune activité n'est prévue cette année, alors on propose une date
      * près de la rentrée. Soit le calendrier est déjà remplis, alors on
      * propose comme date 4 semaines après la dernière activité
      * prévue. Comme ça on enchaîne l'enregistrement des activités. */
     $repere = $u->findLastDate($annee);
     if (!$repere) {
         $repere = Strass_Controller_Action_Helper_Annee::dateDebut($annee);
     } else {
         $debut = strftime('%Y-%m-%d', strtotime($repere . ' next saturday +4 weeks'));
         $fin = strftime('%Y-%m-%d', strtotime($repere . ' next sunday +4 weeks'));
     }
     $m->addDate('debut', 'Début', $debut . ' 14:30', '%Y-%m-%d %H:%M');
     $m->addDate('fin', 'Fin', $fin . '17:00', '%Y-%m-%d %H:%M');
     $m->addString('intitule', 'Intitulé explicite', "");
     $m->addBool('prevoir', "J'ai d'autres activités à prévoir", true);
     $m->addNewSubmission('ajouter', 'Ajouter');
     $m->addConstraintRequired($m->getInstance('unites'));
     if ($m->validate()) {
         $t = new Activites();
         $tu = new Unites();
         $td = new Documents();
         $a = new Activite();
         $a->debut = $m->debut;
         $a->fin = $m->fin;
         $unites = call_user_func(array($tu, 'find'), (array) $m->unites);
         // génération de l'intitulé
         $type = $unites->current()->findParentTypesUnite();
         $a->intitule = $m->intitule;
         $intitule = $type->getIntituleCompletActivite($a);
         $a->slug = $slug = $t->createSlug($intitule);
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $a->save();
             $a->updateUnites($unites);
             $this->controller->_helper->Flash->info("Activité enregistrée");
             $this->controller->logger->info("Nouvelle activite", $this->controller->_helper->Url('consulter', null, null, array('activite' => $a->slug)));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         if ($m->get('prevoir')) {
             $this->controller->redirectSimple('prevoir');
         } else {
             $this->controller->redirectSimple('consulter', null, null, array('activite' => $slug));
         }
     }
     return array('model' => $m, 'calendrier' => $u->findActivites($this->current));
 }