Exemple #1
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));
     }
 }
Exemple #2
0
 function createModel($annee)
 {
     $u = $this->unite;
     $a = $annee;
     $m = new Wtk_Form_Model('inscrire');
     /* Pagination dans la pagination :-) */
     $pm = new Wtk_Pages_Model_Form($m);
     /* Sélection de l'individu à inscrire */
     $g = $m->addGroup('inscription');
     $candidats = $u->findCandidats($a);
     $enum = array();
     $enum['$$nouveau$$'] = 'Inscrire un nouveau';
     foreach ($candidats as $candidat) {
         $enum[$candidat->id] = $candidat->getFullname(false, false);
     }
     $i = $g->addEnum('individu', 'Individu', null, $enum);
     $m->addConstraintRequired($i);
     $roles = $u->findParentTypesUnite()->findRoles();
     $enum = array();
     foreach ($roles as $role) {
         $enum[$role->id . '__'] = $role->titre;
         foreach ($role->findTitres() as $titre) {
             $enum[$role->id . '__' . $titre->nom] = $titre->nom;
         }
     }
     $default = $u->findRolesCandidats($a)->current();
     $g->addEnum('role', 'Rôle', $default ? $default->id . '__' : end(array_keys($enum)), $enum);
     list($debut, $fin) = $this->calculerDates($annee);
     $g->addDate('debut', 'Début', $debut);
     $i0 = $g->addBool('clore', 'Se termine le', false);
     $i1 = $g->addDate('fin', 'Fin', $fin);
     $m->addConstraintDepends($i1, $i0);
     $g->addBool('continuer', "J'ai d'autres inscriptions à enregistrer", false);
     /* Enregistrement d'un nouvel individu */
     $g = $m->addGroup('fiche');
     $m->addConstraintRequired($g->addString('prenom', 'Prénom'));
     $m->addConstraintRequired($g->addString('nom', 'Nom'));
     $tu = $u->findParentTypesUnite();
     if ($tu->sexe == 'm') {
         $g->addEnum('sexe', 'Sexe', null, array('h' => 'Masculin', 'f' => 'Féminin'));
     } else {
         $g->addString('sexe', null, $tu->sexe)->setReadonly();
     }
     $g->addString('portable', "Mobile");
     $g->addString('adelec', "Adélec");
     /* Clore une inscription active */
     $g = $m->addGroup('cloture');
     $g->addBool('clore', "Ne l'est plus depuis", true);
     $g->addDate('fin', "Fin", $debut);
     /* Proposer la succession pour les chefs d'unité et les titres */
     $g = $m->addGroup('succession');
     $g->addBool('succeder', "a passé le flambeau le", false);
     $g->addDate('date', "Succession", $debut);
     return $pm;
 }
Exemple #3
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 #4
0
 function parametresAction()
 {
     $this->metas(array('DC.Title' => 'Paramètres'));
     $this->branche->append();
     $config = Zend_Registry::get('config');
     $this->view->model = $m = new Wtk_Form_Model('parametres');
     $g = $m->addGroup('metas', "Informations");
     $g->addString('title', 'Titre', $config->metas->title);
     $g->addString('short_title', 'Titre court', $config->system->short_title);
     $g->addString('subject', 'Mots clefs', $config->metas->subject);
     $g->addString('author', 'Créateur du site', $config->metas->author);
     $g->addInteger('creation', 'Date de création du site', $config->metas->creation);
     $g = $m->addGroup('system', 'Système');
     $enum = array();
     foreach (Wtk_Document_Style::listAvailables() as $style) {
         $enum[$style->id] = $style->title;
     }
     $g->addEnum('style', 'Style', $config->system->style, $enum);
     $g->addString('admin', 'E-mail système', $config->system->admin);
     $g = $g->addGroup('mail');
     $i0 = $g->addBool('enable', 'Envoyer les mails', $config->system->mail->enable);
     $i1 = $g->addString('smtp', 'Serveur SMTP', $config->system->mail->smtp);
     $m->addConstraintDepends($i1, $i0);
     $m->addNewSubmission('enregistrer', 'Enregistrer');
     if ($m->validate()) {
         $new = new Strass_Config_Php('strass', $m->get());
         /* Migration en douceur de mouvement vers association. */
         if ($config->system->mouvement) {
             $new->system->association = $config->system->mouvement;
             unset($new->system->mouvement);
         }
         $new->system->short_title = $new->metas->short_title;
         unset($new->metas->short_title);
         $config->merge($new);
         $config->write();
         $this->logger->warn("Configuration mise-à-jour");
         $this->redirectSimple('index');
     }
 }
 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');
     }
 }