[opw-web] Allow admins to fully edit mentors through the project edit screen.
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [opw-web] Allow admins to fully edit mentors through the project edit screen.
- Date: Mon, 5 May 2014 19:36:04 +0000 (UTC)
commit eafe4db048964a2dd9cd2a76d39ee4de20141880
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Mon May 5 15:05:14 2014 -0400
Allow admins to fully edit mentors through the project edit screen.
Allow multiple mentors separated with spaces and - to remove all
mentors.
lang/en-gb.php | 2 +-
modules/mod_view_projects.php | 79 ++++++++++++++++++++++++-----------------
2 files changed, 47 insertions(+), 34 deletions(-)
---
diff --git a/lang/en-gb.php b/lang/en-gb.php
index e33147e..f30f25e 100644
--- a/lang/en-gb.php
+++ b/lang/en-gb.php
@@ -218,7 +218,7 @@ $lang_data = array(
'mentors' => 'Mentors',
'no_projects' => 'No projects were found in this category',
'new_mentor' => 'New mentor',
- 'new_mentor_exp' => 'Leave blank if you do not wish to change the mentor',
+ 'new_mentor_exp' => 'Leave blank if you do not wish to change the mentor; separate multiple
mentors with spaces; use - to remove all mentors',
'new_mentor_student' => 'The mentor you have selected is a participant in this program',
'new_student' => 'New applicant',
'new_student_exp' => 'Leave blank if you do not wish to change the applicant',
diff --git a/modules/mod_view_projects.php b/modules/mod_view_projects.php
index 912853a..97aadd2 100644
--- a/modules/mod_view_projects.php
+++ b/modules/mod_view_projects.php
@@ -219,36 +219,45 @@ if ($action == 'editor')
// Update mentor name
if ($user->is_admin && !empty($new_mentor))
{
- // Get existing role of the new mentor
- $sql = "SELECT role FROM {$db->prefix}roles " .
- "WHERE username = :new_mentor " .
- "AND program_id = :program_id";
- $role_data = $db->query($sql, $params, true);
+ if ($new_mentor == '-')
+ $new_mentors = array();
+ else
+ $new_mentors = preg_split('/\s+/', $new_mentor);
- // New mentor has an already defined role
- if ($role_data !== false)
- {
- if ($role_data['role'] != 's')
+ foreach ($new_mentors as $mentor) {
+ $params['new_mentor'] = $mentor;
+
+ // Get existing role of the new mentor
+ $sql = "SELECT role FROM {$db->prefix}roles " .
+ "WHERE username = :new_mentor " .
+ "AND program_id = :program_id";
+ $role_data = $db->query($sql, $params, true);
+
+ // New mentor has an already defined role
+ if ($role_data !== false)
{
- // Update role to mentor
- $sql = "UPDATE {$db->prefix}roles " .
- "SET role = 'm' " .
- "WHERE username = :new_mentor " .
- "AND program_id = :program_id ";
- $db->query($sql, $params);
+ if ($role_data['role'] != 's')
+ {
+ // Update role to mentor
+ $sql = "UPDATE {$db->prefix}roles " .
+ "SET role = 'm' " .
+ "WHERE username = :new_mentor " .
+ "AND program_id = :program_id ";
+ $db->query($sql, $params);
+ }
+ else
+ {
+ $error_message = $lang->get('new_mentor_student');
+ }
}
else
{
- $error_message = $lang->get('new_mentor_student');
+ $sql = "INSERT INTO {$db->prefix}roles " .
+ "(username, program_id, role) " .
+ "VALUES (:new_mentor, :program_id, 'm')";
+ $db->query($sql, $params);
}
}
- else
- {
- $sql = "INSERT INTO {$db->prefix}roles " .
- "(username, program_id, role) " .
- "VALUES (:new_mentor, :program_id, 'm')";
- $db->query($sql, $params);
- }
if (empty($error_message))
{
@@ -258,11 +267,15 @@ if ($action == 'editor')
"AND role = 'm'";
$db->query($sql, $params);
- // Insert the new mentor
- $sql = "INSERT INTO {$db->prefix}participants " .
- "(username, project_id, program_id, role) " .
- "VALUES (:new_mentor, :project_id, :program_id, 'm')";
- $db->query($sql, $params);
+ foreach ($new_mentors as $mentor) {
+ $params['new_mentor'] = $mentor;
+
+ // Insert the new mentor
+ $sql = "INSERT INTO {$db->prefix}participants " .
+ "(username, project_id, program_id, role) " .
+ "VALUES (:new_mentor, :project_id, :program_id, 'm')";
+ $db->query($sql, $params);
+ }
}
}
@@ -306,13 +319,13 @@ if ($action == 'editor')
// Message to subscribe to a mailing list - should be a config variable
// note confusing use of isset() below - = false won't work
// $show_subscribe = true;
- }
- // Purge the project cache
- $cache->purge('projects');
+ // Purge the project cache
+ $cache->purge('projects');
- // Redirect to the view screen for the project
- $core->redirect("?q=view_projects&prg={$program_id}&p={$project_id}");
+ // Redirect to the view screen for the project
+ $core->redirect("?q=view_projects&prg={$program_id}&p={$project_id}");
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]