Ejemplo n.º 1
0
 function inscriptionAction()
 {
     $this->metas(array('DC.Title' => "Fiche d'inscription"));
     $this->branche->append();
     $m = new Wtk_Form_Model('inscription');
     // FICHE INDIVIDU
     $g = $m->addGroup('fiche');
     $i = $g->addString('prenom', "Prénom");
     $m->addConstraintRequired($i);
     $i = $g->addString('nom', "Nom");
     $m->addConstraintRequired($i);
     $t = new Unites();
     $sexes = $t->findSexesAccueillis();
     if (in_array('m', $sexes) || count($sexes) > 1) {
         $enum = array('h' => 'Masculin', 'f' => 'Féminin');
         $i = $g->addEnum('sexe', 'Sexe', null, $enum);
         $m->addConstraintRequired($i);
     } else {
         $i = $g->addString('sexe', 'Sexe', $sexes[0])->setReadonly(true);
     }
     $i = $g->addDate('naissance', "Date de naissance", 0);
     $m->addConstraintRequired($i);
     // COMPTE
     $g = $m->addGroup('compte');
     $i = $g->addEMail('adelec', "Adresse électronique");
     $t = new Inscriptions();
     $m->addConstraintForbid($i, $t->findAllEMails(), "Cette adresse électronique est déjà utilisée");
     $i0 = $g->addString('motdepasse', "Mot de passe");
     $m->addConstraintLength($i0, 6);
     $i1 = $g->addString('confirmer', "Confirmer");
     $m->addConstraintEqual($i1, $i0);
     $i = $g->addString('presentation', "Présentation");
     $m->addConstraintRequired($i);
     $this->view->model = $pm = new Wtk_Pages_Model_Form($m);
     if ($pm->validate()) {
         $data = $m->get('fiche');
         $data['adelec'] = strtolower($m->get('compte/adelec'));
         $data['password'] = Users::hashPassword($m->get('compte/adelec'), $m->get('compte/motdepasse'));
         $data['presentation'] = $m->compte->presentation;
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $k = $t->insert($data);
             $i = $t->findOne($k);
             $this->logger->info("Nouvelle inscription", $this->_helper->Url('valider', 'membres', null, array('adelec' => $i->adelec)));
             $this->_helper->Flash->info("Inscription en modération");
             $mail = new Strass_Mail_Inscription($i);
             try {
                 $mail->send();
             } catch (Zend_Mail_Transport_Exception $e) {
                 $this->logger->error("Échec de l'envoi de mail aux admins", null, $e);
             }
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('index', 'unites', null, array(), true);
     }
 }
Ejemplo n.º 2
0
 function indexAction()
 {
     $m = new Wtk_Form_Model('installation');
     $g = $m->addGroup('site', "Le site");
     $i = $g->addEnum('association', "Association", null, self::$associations);
     $m->addConstraintRequired($i);
     $g = $m->addGroup('admin', "Votre compte");
     $i = $g->addString('prenom', "Votre prénom");
     $m->addConstraintRequired($i);
     $i = $g->addString('nom', "Votre nom");
     $m->addConstraintRequired($i);
     $i = $g->addEnum('sexe', "Sexe", null, array('h' => 'Masculin', 'f' => 'Féminin'));
     $m->addConstraintRequired($i);
     $i = $g->addDate('naissance', "Date de naissance", 0);
     $m->addConstraintRequired($i);
     $i = $g->addString('adelec', "Adélec");
     $m->addConstraintRequired($i);
     $i = $i0 = $g->addString('motdepasse', "Mot de passe");
     $m->addConstraintRequired($i);
     $i = $i1 = $g->addString('confirmation', "Confirmation");
     $m->addConstraintEqual($i1, $i0);
     $this->view->model = $pm = new Wtk_Pages_Model_Form($m);
     if ($pm->validate()) {
         $installer = new Strass_Installer($m->get());
         $installer->run();
         /* Autologin. Écrire dans la session l'identité de l'admin */
         $t = new Users();
         $admin = $t->findByUsername($m->get('admin/adelec'));
         $auth = Zend_Auth::getInstance();
         $auth->getStorage()->write($admin->getIdentity());
         $this->_redirect('/', array('prependBase' => false, 'exit' => true));
     }
 }
Ejemplo n.º 3
0
 function inscrireAction()
 {
     $this->view->individu = $individu = $this->_helper->Individu();
     $this->metas(array('DC.Title' => 'Éditer le CV'));
     $this->branche->append();
     $this->assert(null, $individu, 'inscrire', "Vous n'avez pas le droit d'inscrire cet individu dans une unité.");
     $this->view->apps = $individu->findAppartenances();
     /* CV scout */
     $apps = $individu->findInscriptionsActives();
     $unites = $individu->findUnitesCandidates();
     $m = new Wtk_Form_Model('inscrire');
     $g = $m->addGroup('actuel');
     $g->addDate('date', "Date d'inscription");
     $gg = $g->addGroup('apps');
     $default_next = null;
     if ($apps->count()) {
         $default_next = $apps->rewind()->current()->unite;
         foreach ($apps as $app) {
             $gg->addBool($app->id, "N'est plus " . $app->getShortDescription(), true);
         }
     }
     if ($unites->count()) {
         $i0 = $g->addBool('inscrire', "Inscrire dans une autre unité ou promouvoir", true)->setReadonly((bool) $apps->count() == 0);
         $i1 = $g->addEnum('unite', "Unité", $default_next);
         foreach ($unites as $u) {
             $i1->addItem($u->id, $u->getFullname());
         }
         if ($apps->count()) {
             $m->addConstraintDepends($i1, $i0);
         }
     } else {
         $message = "Aucune unité pour " . $individu->getFullname() . " !";
         $aide = "Les contraintes d'âge et de sexe ne permettent pas " . "d'inscrire {$individu->getFullname()} dans une unité.";
         throw new Strass_Controller_Action_Exception_Notice($message, 500, $aide);
     }
     $g = $m->addGroup('role');
     $g->addEnum('role', 'Rôle');
     $i0 = $g->addBool('clore', "Ne l'est plus depuis", $apps->count() > 0);
     $i1 = $g->addDate('fin', "Date de fin", $m->get('actuel/date'));
     $m->addConstraintDepends($i1, $i0);
     $this->view->model = $pm = new Wtk_Pages_Model_Form($m);
     $tu = new Unites();
     $tr = new Roles();
     $page = $pm->partialValidate();
     if ($pm->pageCmp($page, 'role') == 0 && !$m->get('actuel/inscrire')) {
         $page = $pm->gotoEnd();
     }
     /* si on veut inscrire, et qu'on connait l'unité */
     if ($pm->pageCmp($page, 'role') >= 0 && $m->get('actuel/inscrire')) {
         $g = $m->getInstance('role');
         /* Sélections des rôles ou on peut l'inscrire */
         $unite = $tu->findOne($m->get('actuel/unite'));
         $roles = $unite->findParentTypesUnite()->findRoles();
         $i = $g->getChild('role');
         foreach ($roles as $role) {
             $i->addItem($role->id . '__', $role->titre);
             foreach ($role->findTitres() as $titre) {
                 $i->addItem($role->id . '__' . $titre->nom, $titre->nom);
             }
         }
     }
     /* Ne préremplir le role que si la page role va etre affichée */
     if ($pm->pageCmp($page, 'role') == 0) {
         $g = $m->getInstance('role');
         $i = $g->getChild('role');
         /* Préselection du role */
         $candidats = $individu->findRolesCandidats($unite);
         if ($candidats->count()) {
             $i->set($candidats->current()->id);
         }
         /* Présélection de la date */
         $annee = intval(strtok($m->get('actuel/date'), '/'));
         if ($app = $individu->findInscriptionSuivante($annee)) {
             /* on a trouvé un successeur, donc potentiellement on clot */
             $m->getInstance('role/clore')->set(TRUE);
             $m->getInstance('role/fin')->set($app->debut);
         } else {
             $i = $m->getInstance('actuel/date');
             $fin = $i->getDateArray();
             $fin['year'] += 1;
             $future = $fin['year'] > date('%Y');
             $m->getInstance('role/clore')->set(!$future);
             $m->getInstance('role/fin')->set($fin);
         }
     }
     if ($pm->validate()) {
         $t = new Appartenances();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             foreach ($m->get('actuel/apps') as $k => $clore) {
                 if (!$clore) {
                     continue;
                 }
                 $app = $t->findOne($k);
                 $app->fin = $m->get('actuel/date');
                 $app->save();
             }
             if ($m->get('actuel/inscrire')) {
                 $app = new Appartient();
                 $app->individu = $individu->id;
                 $app->unite = $m->get('actuel/unite');
                 list($role, $titre) = explode('__', $m->get('role/role'));
                 $app->role = intval($role);
                 $app->titre = $titre;
                 $app->debut = $m->get('actuel/date');
                 if ($m->get('role/clore')) {
                     $app->fin = $m->get('role/fin');
                 }
                 $app->save();
             }
             $this->logger->info("Inscription éditée", $this->_helper->Url('fiche'));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('fiche');
     }
 }