Enable category edition for newsletters.
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 5 May 2011 19:48:55 +0000 (21:48 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 5 May 2011 21:24:20 +0000 (23:24 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
modules/axletter.php
modules/epletter.php
modules/newsletter.php

index 2c8a8d8..a9f4596 100644 (file)
@@ -35,6 +35,7 @@ class AXLetterModule extends NewsletterModule
             'ax/admin/edit/valid'  => $this->make_hook('admin_nl_valid',  AUTH_MDP),
             'ax/admin/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_MDP),
             'ax/admin/edit/delete' => $this->make_hook('admin_nl_delete', AUTH_MDP),
+            'ax/admin/categories'  => $this->make_hook('admin_nl_cat',    AUTH_MDP),
         );
     }
 
index ac4ef72..0cb1c0f 100644 (file)
@@ -35,6 +35,7 @@ class EPLetterModule extends NewsletterModule
             'epletter/admin/edit/valid'  => $this->make_hook('admin_nl_valid',  AUTH_MDP),
             'epletter/admin/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_MDP),
             'epletter/admin/edit/delete' => $this->make_hook('admin_nl_delete', AUTH_MDP),
+            'epletter/admin/categories'  => $this->make_hook('admin_nl_cat',    AUTH_MDP),
         );
     }
 
index 3accf5f..02efc32 100644 (file)
@@ -431,11 +431,30 @@ class NewsletterModule extends PLModule
     }
 
     function handler_admin_nl_cat($page, $action = 'list', $id = null) {
+        $nl = $this->getNl();
+        if (!$nl) {
+            return PL_NOT_FOUND;
+        }
+
+        if (!$nl->mayEdit()) {
+            return PL_FORBIDDEN;
+        }
+
         $page->setTitle('Administration - Newsletter : Catégories');
         $page->assign('title', 'Gestion des catégories de la newsletter');
-        $table_editor = new PLTableEditor('admin/newsletter/categories','newsletter_cat','cid');
+        $table_editor = new PLTableEditor($nl->adminPrefix() . '/categories', 'newsletter_cat','cid');
         $table_editor->describe('title','intitulé',true);
         $table_editor->describe('pos','position',true);
+        if ($nl->group == Newsletter::GROUP_XORG) {
+            $table_editor->add_option_table('newsletters', 'newsletters.id = t.nlid');
+            $table_editor->add_option_field('newsletters.name', 'newsletter_name', 'Newsletter', null, 'nlid');
+            $table_editor->describe('nlid', 'ID NL', true);
+        } else {
+            $table_editor->force_field_value('nlid', $nl->id);
+            $table_editor->describe('nlid', 'nlid', false);
+        }
+        // Prevent deletion.
+        $table_editor->on_delete(null, null);
         $table_editor->apply($page, $action, $id);
     }
 }