Пример #1
0
 function __construct($text, $current = null, $len = 4096)
 {
     $pages = array();
     $text = trim(str_replace("\r", "", $text));
     // :(
     $titles = array();
     if (strpos($text, "\n++ ") === false) {
         $pattern = "/^(.{1," . $len . "}\n\n).{" . $len / 2 . ",}/s";
         $i = 1;
         while (preg_match($pattern, $text, $res)) {
             $text = str_replace($res[1], '', $text);
             $titles[$i] = $i;
             $pages[$i++] = $res[1];
         }
         $pages[$i] = $text;
         $titles[$i] = $i;
     } else {
         $slices = preg_split('/^\\+\\+ (.*)$/m', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
         for ($i = 0; $i < count($slices); $i += 2) {
             $id = wtk_strtoid($slices[$i]);
             $titles[$id] = $slices[$i];
             $pages[$id] = "++ " . $slices[$i] . $slices[$i + 1];
         }
     }
     parent::__construct($pages, 1, $current);
     $this->titles = $titles;
     $this->pages_id = array_keys($titles);
     $this->current = in_array($current, $this->pages_id) ? $current : reset($this->pages_id);
 }
Пример #2
0
 function createSlug($base, $current = null)
 {
     $base = wtk_strtoid($base);
     $s = $this->getAdapter()->select()->from($this->_name, array('slug'))->where('slug LIKE ?', $base . '%');
     if ($current) {
         $s->where('slug <> ?', $current);
     }
     $r = $this->getAdapter()->query($s)->fetchAll();
     $existants = array();
     foreach ($r as $row) {
         array_push($existants, $row['slug']);
     }
     $i = 0;
     do {
         $candidat = $base;
         if ($i) {
             $candidat .= '-' . $i;
         }
         if (in_array($candidat, $existants)) {
             $i++;
         } else {
             return $candidat;
         }
     } while (true);
 }
Пример #3
0
 public function cvScout($apps, $admin = false)
 {
     $this->view->document->addStyleComponents('unites');
     $m = new Wtk_Table_Model('unite_slug', 'unite_type', 'unite_nom', 'unite_lien', 'role', 'accr', 'acl', 'debut', 'fin', 'url-editer', 'url-supprimer');
     $individu = null;
     foreach ($apps as $app) {
         if (!$individu) {
             $individu = $app->findParentIndividus();
         }
         $role = $app->findParentRoles();
         $unite = $app->findParentUnites();
         $url_unite = $this->view->url(array('controller' => 'unites', 'action' => 'effectifs', 'unite' => $unite->slug, 'annee' => $app->getAnnee()), true);
         $url_editer = $this->view->url(array('controller' => 'individus', 'action' => 'reinscrire', 'inscription' => $app->id), true);
         $url_suppr = $this->view->url(array('controller' => 'individus', 'action' => 'desinscrire', 'inscription' => $app->id), true);
         $fin = $app->fin ? strftime('au %x', strtotime($app->fin)) : "à aujourd'hui";
         $m->append($unite->slug, $unite->findParentTypesUnite()->slug, $unite->getFullName(), $url_unite, array($role->slug, wtk_strtoid($app->titre)), $app->getAccronyme(), $role->acl_role, strftime('du %x', strtotime($app->debut)), $fin, $url_editer, $url_suppr);
     }
     $t = new Wtk_Table($m, true, array('acl', 'role'));
     $config = Zend_Registry::get('config');
     $t->addFlags('effectifs', $config->system->association, 'appartenances');
     $t->addNewColumn('Poste', new Wtk_Table_CellRenderer_Text('text', 'accr'));
     $t->addNewColumn('Unité', new Wtk_Table_CellRenderer_Link('href', 'unite_lien', 'label', 'unite_nom'), 'unite');
     $t->addNewColumn('Début', new Wtk_Table_CellRenderer_Text('text', 'debut'));
     $t->addNewColumn('Fin', new Wtk_Table_CellRenderer_Text('text', 'fin'));
     if ($admin && $this->view->assert(null, $individu, 'inscrire')) {
         $t->addNewColumn(null, new Wtk_Table_CellRenderer_Link('href', 'url-editer', 'label', 'Éditer', 'flags', array('adminlink', 'editer')));
         $t->addNewColumn(null, new Wtk_Table_CellRenderer_Link('href', 'url-supprimer', 'label', 'Supprimer', 'flags', array('adminlink', 'critical', 'supprimer')));
     }
     return $t;
 }
Пример #4
0
 function __construct(Exception $e)
 {
     $i = $e->getInstance();
     $this->message = new Wtk_Paragraph();
     if ($i instanceof Wtk_Form_Model_Instance) {
         // remplacer tout les %s par des liens vers l'instance.
         $inlines = explode("%s", $e->getFormat());
         $href = $_SERVER['REQUEST_URI'] . "#" . wtk_strtoid($i->path);
         $label = $e->getInstance()->label;
         $ils = array();
         foreach ($inlines as $inline) {
             $ils[] = new Wtk_Inline($inline);
         }
         $pre = null;
         foreach ($ils as $il) {
             if ($pre) {
                 $this->message->addChild(new Wtk_Link($href, $label));
             }
             $this->message->addChild($il);
             $pre = $il;
         }
     } else {
         $this->message->addChild(new Wtk_Inline($e->getFormat()));
     }
 }
Пример #5
0
 function getViewScript($action, $controller = false)
 {
     $script = parent::getViewScript($action, is_string($controller) ? true : $controller);
     if (is_string($controller)) {
         $script = wtk_strtoid($controller) . DIRECTORY_SEPARATOR . $script;
     }
     return $script;
 }
Пример #6
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);
 }
Пример #7
0
 function _finalize()
 {
     $form = $this->getParent('Wtk_Form');
     $model = $form->getModel();
     try {
         $i = $model->getInstance($this->title);
         $this->title = $i->label;
         $this->prefix = $i->path;
         $this->setId(wtk_strtoid($this->prefix));
     } catch (Exception $e) {
         $this->setId(wtk_strtoid($this->title));
     }
     $this->title = new Wtk_Inline($this->title);
     $this->_finalizeChildren();
 }
Пример #8
0
 function __construct(Wtk_Form_Model_Instance $instance)
 {
     parent::__construct();
     $this->instance = $instance;
     if ($instance->valid === FALSE) {
         $this->addFlags('invalid');
     } else {
         if ($instance->valid === TRUE) {
             $this->addFlags('valid');
         }
     }
     $this->useLabel();
     $this->setReadonly($instance->readonly);
     $this->name = $this->getName();
     $this->value = $this->instance->get();
     $this->wtkConstraint = array();
     $this->setId(wtk_strtoid($this->instance->path));
 }
Пример #9
0
 function append($model, $apps, $racine)
 {
     $m = $model;
     $acl = Zend_Registry::get('acl');
     foreach ($apps as $app) {
         $individu = $app->findParentIndividus();
         $role = $app->findParentRoles();
         $unite = $app->findParentUnites();
         if ($acl->isAllowed(null, $individu, 'fiche')) {
             $url_fiche = $this->view->urlIndividu($individu, 'fiche', 'individus', true);
         } else {
             $url_fiche = null;
         }
         $url_unite = $this->view->url(array('controller' => 'unites', 'action' => 'effectifs', 'unite' => $unite->slug));
         $etape = $individu->findParentEtapes();
         $maitrise = $racine && $unite->id == $racine->id && !$unite->isTerminale();
         // insertion du tuple
         $m->append($unite->slug, $unite->findParentTypesUnite()->slug, $maitrise ? 'Maîtrise' : $unite->getName(), $url_unite, $individu->getFullname(true, false), array($role->slug, wtk_strtoid($app->titre)), $app->getAccronyme(), $role->acl_role, $etape ? $etape->slug : null, $url_fiche, $individu->adelec, wtk_nbsp($individu->fixe), wtk_nbsp($individu->portable), wtk_nbsp($individu->portable ? $individu->portable : $individu->fixe), wtk_nbsp(preg_replace("`\r?\n`", " – ", trim($individu->adresse))), strftime('%d-%m-%Y', strtotime($individu->naissance)), $individu->getAge(), $individu->totem, $individu->numero ? $individu->numero : null, $maitrise ? 'maitrise' : null);
     }
 }
Пример #10
0
 function addColumn(Wtk_Table_Column $column)
 {
     $cols = $this->columns;
     array_push($cols, $column);
     $this->columns = $cols;
     $cclasses = $this->cclasses;
     $props = $column->getRenderer()->getProperties();
     $classes = array();
     foreach ($props as $prop) {
         if (is_array($prop)) {
             continue;
         }
         if (!array_key_exists($prop, $this->model->columns)) {
             continue;
         }
         array_push($classes, wtk_strtoid($prop));
     }
     $classes = array_merge($classes, $column->flags);
     array_push($cclasses, $classes);
     $this->cclasses = $cclasses;
     return $column;
 }
Пример #11
0
 function getFilename($view)
 {
     $page = Zend_Registry::get('page');
     return wtk_strtoid($page->metas->get('DC.Title')) . '.' . $this->_suffix;
 }
Пример #12
0
 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));
     }
 }
Пример #13
0
 function ecrireAction()
 {
     if ($this->_getParam('article')) {
         $a = $this->_helper->Article();
         $j = $a->findParentJournaux();
         try {
             $a->findDocument();
             $this->redirectSimple('envoyer');
         } catch (Strass_Db_Table_NotFound $e) {
         }
     } else {
         $a = null;
         $j = $this->_helper->Journal();
     }
     $this->view->unite = $u = $j->findParentUnites();
     $this->metas(array('DC.Title' => "Écrire un article"));
     $this->assert(null, $j, 'ecrire', "Vous n'avez pas le droit d'écrire un nouvel article dans ce journal");
     $publier = $this->assert(null, $j, 'publier');
     $this->view->model = $m = new Wtk_Form_Model('ecrire');
     $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->addString('titre', "Titre", $a ? $a->titre : null);
     $m->addConstraintRequired($i);
     if ($publier) {
         $m->addEnum('public', 'Publication', $a ? $a->public : null, array(0 => 'Brouillon', 1 => 'Publier'));
     }
     $m->addString('boulet', "Boulet", $a ? $a->boulet : null);
     $i = $m->addString('article', "Article", $a ? $a->article : null);
     $m->addConstraintRequired($i);
     $t = $m->addTable('images', "Images", array('image' => array('File', "Image"), 'nom' => array('String', "Renommer en"), 'origin' => array('String')), false);
     if ($a) {
         foreach ($a->getImages() as $image) {
             $t->addRow(null, $image, $image);
         }
     }
     $t->addRow();
     $m->addNewSubmission('poster', "Poster");
     if ($m->validate()) {
         $t = new Articles();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             if ($a) {
                 $a->slug = $t->createSlug(wtk_strtoid($m->titre), $a->slug);
                 $c = $a->findParentCommentaires();
                 $message = "Article édité";
             } else {
                 $c = new Commentaire();
                 $a = new Article();
                 $a->slug = $t->createSlug(wtk_strtoid($m->titre));
                 $message = "Nouvel article";
             }
             $c->auteur = $m->auteur;
             $c->save();
             $a->journal = $j->id;
             $a->titre = $m->titre;
             $a->boulet = $m->boulet;
             $a->article = $m->article;
             try {
                 $a->public = (int) $m->public;
             } catch (Exception $e) {
             }
             $a->commentaires = $c->id;
             $a->save();
             $oldImages = $a->getImages();
             $newImages = array();
             $table = $m->getInstance('images');
             foreach ($table as $row) {
                 if ($row->origin && $row->origin != $row->nom) {
                     $a->renameImage($row->origin, $row->nom);
                     array_push($newImages, $row->nom);
                 } else {
                     $if = $row->getChild('image');
                     if ($if->isUploaded()) {
                         $nom = $row->nom ? $row->nom : $if->getBasename();
                         $a->storeImage($if->getTempFilename(), $nom);
                         array_push($newImages, $nom);
                     } else {
                         array_push($newImages, $row->nom);
                     }
                 }
             }
             $oldImages = array_unique($oldImages);
             $newImages = array_filter($newImages);
             /* Nettoyage des images */
             foreach ($oldImages as $image) {
                 if (!in_array($image, $newImages)) {
                     $a->deleteImage($image);
                 }
             }
             $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();
             }
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('consulter', 'journaux', null, array('article' => $a->slug), true);
     }
 }
Пример #14
0
 /**
  * @dataProvider slugifyFixtures
  */
 function testSlugify($label, $slug)
 {
     $this->assertEquals(wtk_strtoid($label), $slug);
 }
Пример #15
0
 function editerAction()
 {
     $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' => 'Éditer ' . $u->getFullname()));
     $this->view->model = $m = new Wtk_Form_Model('editer');
     $enum = array(null => 'Orpheline');
     foreach ($u->findParenteCandidates() as $c) {
         $enum[$c->id] = $c->getFullname();
     }
     $m->addEnum('parente', "Unité parente", $u->parent, $enum);
     $m->addString('nom', "Nom", $u->nom);
     $m->addString('extra', $u->findParentTypesUnite()->extra, $u->extra);
     $m->addFile('image', "Nouvelle");
     $m->addBool('supprimer_image', "Supprimer l'image");
     $m->addNewSubmission('enregistrer', "Enregistrer");
     if ($m->validate()) {
         $t = $u->getTable();
         $db = $t->getAdapter();
         $db->beginTransaction();
         try {
             $u->parent = $m->parente ? $m->parente : null;
             $u->nom = $m->nom;
             $u->slug = $t->createSlug(wtk_strtoid($u->getFullname()), $u->slug);
             $u->extra = $m->extra;
             $u->save();
             $i = $m->getInstance('image');
             if ($i->isUploaded()) {
                 $u->storeImage($i->getTempFilename());
             } elseif ($m->supprimer_image) {
                 $u->supprimerImage();
             }
             $this->logger->info("Édition de " . $u->getFullname(), array('controller' => 'unites', 'action' => 'index', 'unite' => $u->slug));
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         $this->redirectSimple('index', 'unites', null, array('unite' => $u->slug));
     }
 }
Пример #16
0
><?php 
        echo $caption;
        ?>
</option>
<?php 
    }
    ?>
</select>
<?php 
} else {
    foreach ($items as $value => $caption) {
        $for = wtk_strtoid($name . $value);
        ?>
<label<?php 
        wtk_attr('for', $for);
        wtk_classes(wtk_strtoid($value));
        ?>
><input<?php 
        wtk_attr('id', $for);
        wtk_attr('name', $name . ($multiple ? '[]' : ''));
        wtk_attr('value', $value);
        wtk_attr('type', $multiple ? 'checkbox' : 'radio');
        wtk_attr('checked', is_array($selected) ? in_array($value, $selected) : $value == $selected ? 'checked' : NULL);
        ?>
 />
<?php 
        echo $caption;
        ?>
</label>
<?php 
    }
Пример #17
0
 function getFlags()
 {
     return array($this->getFlag(), 'depends-' . wtk_strtoid($this->ref->path));
 }
Пример #18
0
 function getAnneesOuvertes()
 {
     $cacheId = wtk_strtoid('annes-ouvertes-' . $this->slug, '_');
     $cache = Zend_Registry::get('cache');
     if (($annees = $cache->load($cacheId)) === false) {
         // sélectionner les années où l'unité à eut au moins un membre
         $db = $this->getTable()->getAdapter();
         $t = new Individus();
         // DISTINCT ON dans SQLite est fait avec MIN() hors group by.
         $select = $t->select()->setIntegrityCheck(false)->from('appartenance', array('debut' => "strftime('%Y', debut)", 'fin' => "strftime('%Y', fin)", 'unite' => 'appartenance.unite'))->join('unite_role', 'unite_role.id = appartenance.role', array('role' => 'unite_role.acl_role', 'ordre' => 'MIN(unite_role.ordre)'))->join('individu', 'individu.id = appartenance.individu', array('individu.*', 'homonymes' => 'COUNT(individu.prenom)'))->join('unite', 'unite.id = appartenance.unite', array())->group('debut')->order('debut ASC');
         $virtuelle = $this->findParentTypesUnite()->virtuelle;
         if ($virtuelle) {
             $select->where("unite.id = ?", $this->parent);
         } else {
             $select->where('unite.id = ? OR unite.parent = ?', intval($this->id));
         }
         $is = $t->fetchAll($select);
         $annees = array();
         $cette_annee = intval(strftime('%Y', time() - 243 * 24 * 60 * 60));
         $homonymes = array();
         foreach ($is as $individu) {
             /* pour le dernier chef en cours, inclure l'année courante *incluse* */
             $fin = $individu->fin ? $individu->fin : $cette_annee + 1;
             /* Si le futur chef est déjà inscrit, afficher l'année suivante */
             $fin = max($fin, $individu->debut + 1);
             for ($annee = $individu->debut; $annee < $fin; $annee++) {
                 /* on a pas de chef */
                 if (!array_key_exists($annee, $annees)) {
                     $annees[$annee] = '##SANSCHEF##';
                 }
                 if (is_object($chef = $annees[$annee])) {
                     continue;
                 }
                 if ($individu->unite == $this->id || $virtuelle && $individu->unite == $this->parent) {
                     if ($individu->role == 'chef') {
                         $annees[$annee] = $individu;
                         /* Récolte des homonymes */
                         if (!array_key_exists($individu->prenom, $homonymes)) {
                             $homonymes[$individu->prenom] = array($individu->slug);
                         } else {
                             array_push($homonymes[$individu->prenom], $individu->slug);
                         }
                     } else {
                         // on a des assistant, mais pas de chef
                         $annees[$annee] = '##INCONNU##';
                     }
                 }
             }
         }
         foreach ($annees as $chef) {
             if (is_object($chef)) {
                 $chef->homonymes = count(array_unique($homonymes[$chef->prenom]));
             }
         }
         ksort($annees);
         $cache->save($annees, $cacheId, array('unites', 'apps'));
     }
     return $annees;
 }
Пример #19
0
 function validate($annee, $pm, $data)
 {
     extract($data);
     $m = $pm->data;
     $u = $this->unite;
     $a = $annee;
     $t = new Appartenances();
     $tr = new Roles();
     $ti = new Individus();
     $db = $t->getAdapter();
     $db->beginTransaction();
     $tu = $u->findParentTypesUnite();
     try {
         if ($m->get('inscription/individu') == '$$nouveau$$') {
             $i = new Individu();
             $i->prenom = $m->get('fiche/prenom');
             $i->nom = $m->get('fiche/nom');
             $i->sexe = $m->get('fiche/sexe');
             $i->naissance = $a - $tu->age_min . '-01-01';
             $i->portable = $m->get('fiche/portable');
             $i->adelec = $m->get('fiche/adelec');
             $i->slug = $i->getTable()->createSlug(wtk_strtoid($i->getFullname(false, false)));
             $i->save();
         } else {
             $i = $ti->findOne($m->get('inscription/individu'));
             $app_active = $i->findInscriptionsActives()->current();
             if ($app_active) {
                 if ($m->get('cloture/clore')) {
                     $app_active->fin = $m->get('cloture/fin');
                     $app_active->save();
                 }
             }
         }
         if ($m->get('succession/succeder')) {
             $role = $m->get('inscription/role');
             list($role, $titre) = explode('__', $role);
             $r = $tr->findOne($role);
             $apps = $u->findFuturPredecesseurs($r, $titre);
             $app_predecesseur = $apps->current();
             if ($apps->count()) {
                 $app_predecesseur = $apps->current();
                 $app_predecesseur->fin = $m->get('succession/date');
                 $app_predecesseur->save();
             }
         }
         $app = new Appartient();
         $app->unite = $u->id;
         $app->individu = $i->id;
         $app->debut = $m->get('inscription/debut');
         list($role, $titre) = explode('__', $m->get('inscription/role'));
         $app->role = intval($role);
         $app->titre = $titre;
         if ($m->get('inscription/clore')) {
             $app->fin = $m->get('inscription/fin');
         }
         $app->save();
         $message = $i->getFullname(false, false) . " inscrit.";
         $this->controller->logger->info($message);
         $this->controller->_helper->Flash->info($message);
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
     if ($m->get('inscription/continuer')) {
         $this->controller->redirectSimple();
     } else {
         $this->controller->redirectSimple('effectifs');
     }
 }
Пример #20
0
 function findIndividus()
 {
     $t = new Individus();
     $s = $t->select()->where('slug LIKE ?', wtk_strtoid($this->getFullname()) . '%');
     return $t->fetchAll($s)->current();
 }
Пример #21
0
 function validerAction()
 {
     $this->metas(array('DC.Title' => "Valider une inscription"));
     $this->branche->append("Inscriptions", array('action' => 'inscriptions', 'adelec' => null));
     $t = new Inscriptions();
     $this->assert(null, $t, 'valider', "Vous n'avez pas le droit de valider les inscriptions en attente.");
     $adelec = $this->_getParam('adelec');
     if ($adelec) {
         try {
             $ins = $t->findByEMail($adelec);
         } catch (Strass_Db_Table_NotFound $e) {
             $this->view->model = null;
             return;
         }
     } else {
         if (!($ins = $t->fetchAll()->current())) {
             $this->view->model = null;
             return;
         }
     }
     $this->view->individu = $ind = $ins->findIndividus();
     $this->view->inscription = $ins;
     $this->branche->append($ins->getFullname());
     $this->view->model = $m = new Wtk_Form_Model('valider');
     $i = $m->addString('prenom', 'Prénom', $ins->prenom);
     $i->setReadonly((bool) $ind);
     $m->addConstraintRequired($i);
     $i = $m->addString('nom', 'Nom', $ins->nom);
     $i->setReadonly((bool) $ind);
     $m->addConstraintRequired($i);
     if ($ind) {
         $enum = array($ind->id => "Oui, rattacher à " . $ind->getFullname(), '$$nouveau$$' => "Non, c'est un homonyme, créer une nouvelle fiche");
         $m->addEnum('fiche', null, $ind->id, $enum);
     }
     $m->addString('message', "Message à " . $ins->getFullname());
     $m->addNewSubmission('accepter', 'Accepter');
     $m->addNewSubmission('refuser', 'Spam !');
     if ($s = $m->validate()) {
         $tu = new Users();
         $ti = new Individus();
         $db = $ti->getAdapter();
         if ($s->id == 'accepter') {
             $creer = !$ind || $m->get('fiche') == '$$nouveau$$';
             if ($creer) {
                 $ind = new Individu();
                 $ind->slug = $ti->createSlug(wtk_strtoid($ins->getFullname()));
                 $ind->prenom = $m->prenom;
                 $ind->nom = $m->nom;
                 $ind->sexe = $ins->sexe;
                 $ind->naissance = $ins->naissance;
                 $ind->adelec = $ins->adelec;
             }
             $db->beginTransaction();
             try {
                 if ($creer) {
                     $ind->save();
                 }
                 $user = $ind->findUser();
                 if (!$user->isMember()) {
                     $user = new User();
                 }
                 $user->individu = $ind->id;
                 $user->username = $ins->adelec;
                 $user->password = $ins->password;
                 $user->save();
                 $mail = new Strass_Mail_InscriptionValide($user, $m->get('message'));
                 $mail->send();
                 $this->logger->info("Inscription acceptée", $this->_helper->Url('fiche', 'individus', null, array('individu' => $ind->slug)), (string) $ind);
                 $ins->delete();
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             $this->_helper->Flash->info("Inscription acceptée");
         } else {
             $db->beginTransaction();
             try {
                 $this->logger->warn("Inscription de {$ins->adelec} refusée", $this->_helper->Url('inscriptions', 'membres', null, null, true));
                 $mail = new Strass_Mail_InscriptionRefus($ins, $m->get('message'));
                 $mail->send();
                 $ins->delete();
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollBack();
                 throw $e;
             }
             $this->_helper->Flash->info("Inscription refusée");
         }
         if ($this->_getParam('adelec')) {
             $this->redirectSimple('inscriptions', 'membres', null, null, true);
         } else {
             $this->redirectSimple('valider');
         }
     }
 }
Пример #22
0
 function getFilename($view)
 {
     return wtk_strtoid($view->ics->_title) . '.' . $this->_suffix;
 }