[opw-web] rank_projects: allow mentors to see (but not edit) other projects.



commit bc4ad34e0d887937ffcab338061a091c27ea19fd
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sun Mar 9 23:48:01 2014 -0400

    rank_projects: allow mentors to see (but not edit) other projects.

 modules/mod_rank_projects.php                      |   23 +++++++++----------
 skins/easterngreen/html/tpl_rank_projects.html     |    4 +-
 .../easterngreen/html/tpl_rank_projects_item.html  |    2 +-
 utils.php                                          |    7 ++++-
 4 files changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/modules/mod_rank_projects.php b/modules/mod_rank_projects.php
index 26c9c4b..db10eda 100644
--- a/modules/mod_rank_projects.php
+++ b/modules/mod_rank_projects.php
@@ -42,18 +42,16 @@ $user->restrict($row['count'] > 0);
 // Get the role of the user
 $user->get_role($program_id, $role, $user_organization_id);
 
-// Non-admins can only rank their own organization
-if (!$user->is_admin)
-    $user->restrict($organization_id == $user_organization_id);
+if (!$user->is_admin && $organization_id <= 0)
+    $organization_id = $user_organization_id;
+
+$can_edit = $user->is_admin || ($organization_id == $user_organization_id);
 
 // Only admins and mentors can access
 $user->restrict($role == 'm', true);
 
-if ($user->is_admin)
-    $organization_select = build_organization_select($program_id, $organization_id, false,
-                                                     null, "organizationSelect");
-else
-    $organization_select = null;
+$organization_select = build_organization_select($program_id, $organization_id, false,
+                                                 null, "organizationSelect");
 
 if ($organization_id > 0) {
     $sql = "SELECT * FROM {$db->prefix}projects prj " .
@@ -67,7 +65,7 @@ if ($organization_id > 0) {
 }
 
 // See if we need to save anything
-if ($rankings_save) {
+if ($rankings_save && $can_edit) {
     foreach ($list_data as &$row) {
         $project_id = $row['project_id'];
         $ranking_field_name = 'ranking' . $project_id;
@@ -129,7 +127,7 @@ function compare_rankings($a, $b) {
 
 usort($list_data, "compare_rankings");
 
-$skin->assign('apprej_visibility', $user->is_admin);
+$skin->assign(array('apprej_visibility' => $skin->visibility($user->is_admin)));
 
 // Set the return URL (needed when approving projects)
 $return_url = urlencode($core->request_uri());
@@ -161,7 +159,8 @@ foreach ($list_data as &$row)
         'project_applicant'     => $profile,
         'ranking'               => $ranking,
         'ranking_name'          => 'ranking' . $row['project_id'],
-        'opinion_select'        => build_opinion_select($row['org_opinion'], 'opinion' . $row['project_id']),
+        'disabled'              => $can_edit ? '' : ' disabled',
+        'opinion_select'        => build_opinion_select($row['org_opinion'], 'opinion' . $row['project_id'], 
!$can_edit),
         'project_url'           => "?q=view_projects&amp;prg={$program_id}&amp;p={$row['id']}",
         'approve_url'           => "?q=view_projects&amp;a=approve&amp;prg={$program_id}" .
                                    "&amp;p={$row['id']}&amp;r={$return_url}",
@@ -180,7 +179,7 @@ $skin->assign(array(
     'view_title'            => $title,
     'organization_select'   => $organization_select,
     'projects_list'         => $projects_list,
-    'select_visibility'     => $skin->visibility($user->is_admin),
+    'disabled'              => $can_edit ? '' : ' disabled',
     'notice_visibility'     => $skin->visibility($organization_id > 0 && count($list_data) == 0),
     'list_visibility'       => $skin->visibility(count($list_data) > 0)
 ));
diff --git a/skins/easterngreen/html/tpl_rank_projects.html b/skins/easterngreen/html/tpl_rank_projects.html
index f1cb606..c3040f2 100644
--- a/skins/easterngreen/html/tpl_rank_projects.html
+++ b/skins/easterngreen/html/tpl_rank_projects.html
@@ -6,7 +6,7 @@
 <h1>[[view_title]]</h1>
 <hr class="hr-head" />
 
-<div class="[[select_visibility]]">
+<div>
   [[organization_select]]
   <a onclick='go_organization(event);' href="#" class="btn">{{go}}</a>
   <script type="text/javascript">
@@ -56,5 +56,5 @@
         </tbody>
     </table>
 
-    <button name="rankings_save" type="submit" class="btn btn-primary">{{save}}</button>
+    <button name="rankings_save" type="submit" class="btn btn-primary"[[disabled]]>{{save}}</button>
 </div>
diff --git a/skins/easterngreen/html/tpl_rank_projects_item.html 
b/skins/easterngreen/html/tpl_rank_projects_item.html
index a4a51ab..e5915ae 100644
--- a/skins/easterngreen/html/tpl_rank_projects_item.html
+++ b/skins/easterngreen/html/tpl_rank_projects_item.html
@@ -14,7 +14,7 @@
     </td>
 
     <td>
-        <input style="width:50px;" type="text" size="4" value="[[ranking]]" name="[[rankingName]]"></input>
+        <input style="width:50px;" type="text" size="4" value="[[ranking]]" 
name="[[rankingName]]"[[disabled]]></input>
     </td>
 
     <td>
diff --git a/utils.php b/utils.php
index 0ddcb02..3428a94 100644
--- a/utils.php
+++ b/utils.php
@@ -10,6 +10,7 @@ function build_organization_select($program_id, $current, $include_other, $name=
     $option_name = $lang->get('select_organization');
     $n = ($name !== null) ? " name='{$name}'" : '';
     $i = ($id !== null) ? " id='{$id}'" : '';
+
     $organization_select = "<select$n$i>";
 
     $selected = $current == 0 ? " selected" : "";
@@ -35,10 +36,12 @@ function build_organization_select($program_id, $current, $include_other, $name=
 
 $VALID_OPINIONS = array('n', 'c', 'x', 'w', 'f');
 
-function build_opinion_select($current, $name) {
+function build_opinion_select($current, $name, $disabled=false) {
     global $VALID_OPINIONS, $lang;
 
-    $result = "<select name='{$name}'>";
+    $d = $disabled ? ' disabled' : '';
+
+    $result = "<select name='{$name}'$d>";
 
     foreach ($VALID_OPINIONS as $opinion) {
         $selected = $opinion == $current ? ' selected' : '';


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