[opw-web] Allow mentors to resign from the program



commit a1b0990dc2850d3202898e373641f838e6defae4
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Mar 11 14:07:27 2014 -0400

    Allow mentors to resign from the program
    
    Allow mentors (and pending mentors) to resign from the program
    as long as they are not mentoring projects that have already been
    accepted.

 index.php                                     |    6 ++-
 lang/en-gb.php                                |    5 ++-
 modules/mod_view_projects.php                 |   59 ++++++++++++++++++++++++-
 skins/easterngreen/html/tpl_program_home.html |   17 +++++--
 skins/neverland/html/tpl_program_home.html    |    2 +-
 5 files changed, 80 insertions(+), 9 deletions(-)
---
diff --git a/index.php b/index.php
index 1fda478..55925bc 100644
--- a/index.php
+++ b/index.php
@@ -27,6 +27,10 @@ $skin->assign(array(
 ));
 
 // Output the page
-$skin->title($module_title . ' &bull; ' . $config->site_name);
+if ($module_title)
+    $skin->title($module_title . ' &bull; ' . $config->site_name);
+else
+    $skin->title($config->site_name);
+
 $skin->output();
 
diff --git a/lang/en-gb.php b/lang/en-gb.php
index 420daee..38ccaac 100644
--- a/lang/en-gb.php
+++ b/lang/en-gb.php
@@ -126,7 +126,7 @@ $lang_data = array(
     'mentor_project_sel'    => 'Select project to mentor',
     'cancel_mentor'         => 'Cancel mentor application',
     'view_proposals'        => 'View project proposals',
-    'resign_student'        => 'Resign from this program',
+    'resign_program'        => 'Resign from this program',
     'role_student'          => 'You are applying for this program',
     'role_mentor'           => 'You are a mentor for this program',
     'role_resigned'         => 'You have resigned from this program and cannot participate again',
@@ -211,6 +211,9 @@ $lang_data = array(
                                'Mentor Mailing List</a>, if you haven\'t done it already.',
     'confirm_resign'        => 'Confirm resignation',
     'confirm_resign_exp'    => 'Are you sure you want to resign? Your submissions will get invalidated.',
+    'confirm_resign_mentor_exp' => 'Are you sure you want to resign? You will be removed from any projects 
where you are currently listed as the mentor.',
+    'cannot_resign'         => 'Cannot resign',
+    'cannot_resign_mentor_exp' => 'Cannot resign as a mentor since you are currently mentoring accepted 
projects. Please contact an adminstrator to arrange for your projects to be transferred to another mentor.',
 
     /* Module: user_profile */
     'user_profile'          => 'User profile',
diff --git a/modules/mod_view_projects.php b/modules/mod_view_projects.php
index 998af74..087013d 100644
--- a/modules/mod_view_projects.php
+++ b/modules/mod_view_projects.php
@@ -900,9 +900,66 @@ else if ($action == 'apply')
     $module_title = $lang->get('apply_mentor');
     $module_data = $skin->output('tpl_apply_mentor');
 }
+else if ($action == 'resign' || ($role == 'm' || $role == 'i'))
+{
+    // See if mentoring any accepted projected projects
+
+    $params = array('username'   => $user->username,
+                    'program_id' => $program_id);
+
+    $sql = "SELECT COUNT(*) as count " .
+           "FROM {$db->prefix}projects prj " .
+           "LEFT JOIN {$db->prefix}participants prt " .
+                "ON prj.id = prt.project_id " .
+                "WHERE prt.username = :username " .
+                  "AND prt.role = 'm' " .
+                  "AND prt.program_id = :program_id " .
+                  "AND prj.is_accepted";
+    $row = $db->query($sql, $params, true);
+    $is_accepted_mentor = $row['count'] > 0;
+
+    if ($is_accepted_mentor) {
+        $skin->assign(array(
+            'message_title'     => $lang->get('cannot_resign'),
+            'message_body'      => $lang->get('cannot_resign_mentor_exp'),
+            'return_url'        => "?q=program_home&amp;prg={$program_id}",
+        ));
+
+        $module_title = null;
+        $module_data = $skin->output('tpl_error_box');
+    } else if ($confirm) {
+        $sql = "DELETE FROM {$db->prefix}participants " .
+               "WHERE username = :username " .
+                 "AND program_id = :program_id";
+        $db->query($sql, $params);
+
+        // For students, we have a 'resigned' role, but it doesn't
+        // seem useful for mentors. That means that you can erase
+        // your resigned student role by applying as a mentor and
+        // resigning, but there's only so much history we can represent
+        // in a single character...
+
+        $sql = "DELETE FROM {$db->prefix}roles " .
+               "WHERE username = :username " .
+                 "AND program_id = :program_id";
+        $db->query($sql, $params);
+
+        $core->redirect("?q=program_home&amp;prg={$program_id}");
+
+    } else {
+        $skin->assign(array(
+            'message_title'     => $lang->get('confirm_resign'),
+            'message_body'      => $lang->get('confirm_resign_mentor_exp'),
+            'cancel_url'        => "?q=program_home&amp;prg={$program_id}",
+        ));
+
+        $module_title = null;
+        $module_data = $skin->output('tpl_confirm_box');
+    }
+}
 else if ($action == 'resign')
 {
-    // Only students can resign
+    // Only students can resign (mentors handled above)
     $user->restrict($role == 's');
 
     // We need program ID for this action
diff --git a/skins/easterngreen/html/tpl_program_home.html b/skins/easterngreen/html/tpl_program_home.html
index a983aef..efbbff0 100644
--- a/skins/easterngreen/html/tpl_program_home.html
+++ b/skins/easterngreen/html/tpl_program_home.html
@@ -96,7 +96,7 @@
 
             <div class="resign-block">
                 <a href="?q=view_projects&amp;prg=[[program_id]]&amp;a=resign" class="btn btn-danger 
btn-mini">
-                    {{resign_student}}
+                    {{resign_program}}
                 </a>
             </div>
         </div>
@@ -107,10 +107,11 @@
                 {{role_intermediate}}
             </h4>
 
-            <a href="?q=view_projects&amp;prg=[[program_id]]&amp;a=proposed" class="btn btn-large">
-                <img src="[[skin_path]]/images/proposals.png" width="26" height="26" alt="" />
-                {{view_proposals}}
-            </a>
+            <div class="resign-block">
+                <a href="?q=view_projects&amp;prg=[[program_id]]&amp;a=resign" class="btn btn-danger 
btn-mini">
+                    {{resign_program}}
+                </a>
+            </div>
         </div>
 
         <div class="[[prg_mentor_visibility]]">
@@ -128,6 +129,12 @@
                 <img src="[[skin_path]]/images/projects.png" width="26" height="26" alt="" />
                 {{view_my_projects}}
             </a>
+
+            <div class="resign-block">
+                <a href="?q=view_projects&amp;prg=[[program_id]]&amp;a=resign" class="btn btn-danger 
btn-mini">
+                    {{resign_program}}
+                </a>
+            </div>
         </div>
 
         <div class="[[prg_rejected_visibility]]">
diff --git a/skins/neverland/html/tpl_program_home.html b/skins/neverland/html/tpl_program_home.html
index 8ad8542..c5e4adc 100644
--- a/skins/neverland/html/tpl_program_home.html
+++ b/skins/neverland/html/tpl_program_home.html
@@ -103,7 +103,7 @@
 
             <div class="resign-block">
                 <a href="?q=view_projects&amp;prg=[[program_id]]&amp;a=resign" class="btn btn-danger 
btn-mini">
-                    {{resign_student}}
+                    {{resign_program}}
                 </a>
             </div>
         </div>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]