Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implemented admin tool management

  • Loading branch information...
commit a4a07996f0fedc4d797c2f4b9e4492bcb9fcb14a 1 parent 7330033
scriby authored August 31, 2011
4  mod/lti/edit_form.php
@@ -149,6 +149,10 @@ function definition() {
149 149
 //-------------------------------------------------------------------------------
150 150
         // Add a hidden element to signal a tool fixing operation after a problematic backup - restore process
151 151
         $mform->addElement('hidden', 'lti_fix');
  152
+        
  153
+        $tab = optional_param('tab', '', PARAM_ALPHAEXT);
  154
+        $mform->addElement('hidden', 'tab', $tab);
  155
+        
152 156
 
153 157
 //-------------------------------------------------------------------------------
154 158
         // Add standard buttons, common to all modules
17  mod/lti/lang/en/lti.php
@@ -50,7 +50,7 @@
50 50
 $string['activity'] = 'Activity';
51 51
 $string['addnewapp'] = 'Enable External Application';
52 52
 $string['addserver'] = 'Add new trusted server';
53  
-$string['addtype'] = 'Create a new Basic LTI activity';
  53
+$string['addtype'] = 'Add External Tool Configuration';
54 54
 $string['allow'] = 'Allow';
55 55
 $string['allowinstructorcustom'] = 'Allow instructors to add custom parameters';
56 56
 $string['allowroster'] = 'Tool may access course roster';
@@ -75,7 +75,6 @@
75 75
 $string['configresourceurl'] = 'Default Resource URL';
76 76
 $string['configtoolurl'] = 'Default Remote Tool URL';
77 77
 $string['configtypes'] = 'Enable Basic LTI Applications';
78  
-$string['configuredtools'] = 'Configured Basic LTI activities';
79 78
 $string['courseid'] = 'Course id number';
80 79
 $string['coursemisconf'] = 'Course is misconfigured';
81 80
 $string['curllibrarymissing'] = 'PHP Curl library must be installed to use LTI';
@@ -171,6 +170,20 @@
171 170
 $string['embed_no_blocks'] = 'Embed, without blocks';
172 171
 $string['new_window'] = 'New window';
173 172
 $string['default_launch_container'] = 'Default Launch Container';
  173
+$string['active'] = 'Active';
  174
+$string['pending'] = 'Pending';
  175
+$string['rejected'] = 'Rejected';
  176
+$string['baseurl'] = 'Base URL';
  177
+$string['action'] = 'Action';
  178
+$string['createdon'] = 'Created On';
  179
+$string['accept'] = 'Accept';
  180
+$string['update'] = 'Update';
  181
+$string['delete'] = 'Delete';
  182
+$string['reject'] = 'Reject';
  183
+$string['external_tool_types'] = 'External Tool Types';
  184
+$string['no_lti_configured'] = 'There are no active External Tools configured.';
  185
+$string['no_lti_pending'] = 'There are no pending External Tools.';
  186
+$string['no_lti_external'] = 'There are no rejected External Tools.';
174 187
 
175 188
 //New instructor strings
176 189
 $string['display_name'] = 'Display activity name when launched';
22  mod/lti/locallib.php
@@ -56,6 +56,10 @@
56 56
 define('LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS', 3);
57 57
 define('LTI_LAUNCH_CONTAINER_WINDOW', 4);
58 58
 
  59
+define('LTI_TOOL_STATE_CONFIGURED', 1);
  60
+define('LTI_TOOL_STATE_PENDING', 2);
  61
+define('LTI_TOOL_STATE_REJECTED', 3);
  62
+
59 63
 /**
60 64
  * Prints a Basic LTI activity
61 65
  *
@@ -302,7 +306,7 @@ function lti_get_type_config($typeid) {
302 306
 function lti_get_tools_by_domain($domain){
303 307
     global $DB;
304 308
     
305  
-    return $DB->get_records('lti_types', array('tooldomain' => $domain));
  309
+    return $DB->get_records('lti_types', array('tooldomain' => $domain, 'state' => LTI_TOOL_STATE_CONFIGURED));
306 310
 }
307 311
 
308 312
 /**
@@ -416,16 +420,24 @@ function lti_filter_print_types() {
416 420
 function lti_delete_type($id) {
417 421
     global $DB;
418 422
 
  423
+    //We should probably just copy the launch URL to the tool instances in this case... using a single query
  424
+    /*
419 425
     $instances = $DB->get_records('lti', array('typeid' => $id));
420 426
     foreach ($instances as $instance) {
421 427
         $instance->typeid = 0;
422 428
         $DB->update_record('lti', $instance);
423  
-    }
  429
+    }*/
424 430
 
425 431
     $DB->delete_records('lti_types', array('id' => $id));
426 432
     $DB->delete_records('lti_types_config', array('typeid' => $id));
427 433
 }
428 434
 
  435
+function lti_set_state_for_type($id, $state){
  436
+    global $DB;
  437
+    
  438
+    $DB->update_record('lti_types', array('id' => $id, 'state' => $state));
  439
+}
  440
+
429 441
 /**
430 442
  * Transforms a basic LTI object to an array
431 443
  *
@@ -494,9 +506,9 @@ function lti_get_type_type_config($id) {
494 506
     $config = lti_get_type_config($id);
495 507
 
496 508
     $type->lti_typename = $basicltitype->name;
497  
-    if (isset($config['toolurl'])) {
498  
-        $type->lti_toolurl = $config['toolurl'];
499  
-    }
  509
+    
  510
+    $type->lti_toolurl = $basicltitype->baseurl;
  511
+    
500 512
     if (isset($config['resourcekey'])) {
501 513
         $type->lti_resourcekey = $config['resourcekey'];
502 514
     }
233  mod/lti/settings.php
@@ -47,37 +47,224 @@
47 47
 
48 48
 defined('MOODLE_INTERNAL') || die;
49 49
 
  50
+global $PAGE, $CFG;
  51
+
  52
+require_once($CFG->dirroot.'/mod/lti/locallib.php');
  53
+
  54
+function blti_get_tool_table($tools, $id){
  55
+    global $CFG, $USER;
  56
+    $html = '';
  57
+    
  58
+    $typename = get_string('typename', 'lti');
  59
+    $baseurl = get_string('baseurl', 'lti');
  60
+    $action = get_string('action', 'lti');
  61
+    $createdon = get_string('createdon', 'lti');
  62
+    
  63
+    if (!empty($tools)) {
  64
+        if($id == 'lti_configured'){
  65
+            $html .= '<a style="margin-top:.25em" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a>';
  66
+        }
  67
+        
  68
+        $html .= <<<HTML
  69
+        <div id="{$id}_container" style="margin-top:.5em;margin-bottom:.5em">
  70
+            <table id="{$id}_tools">
  71
+                <thead>
  72
+                    <tr>
  73
+                        <th>$typename</th>
  74
+                        <th>$baseurl</th>
  75
+                        <th>$createdon</th>
  76
+                        <th>$action</th>
  77
+                    </tr>
  78
+                </thead>
  79
+HTML;
  80
+        
  81
+        foreach ($tools as $type) {
  82
+            $date = userdate($type->timecreated);
  83
+            $accept = get_string('accept', 'lti');
  84
+            $update = get_string('update', 'lti');
  85
+            $delete = get_string('delete', 'lti');
  86
+            
  87
+            $accepthtml = <<<HTML
  88
+                <a class="editing_accept" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action=accept&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$accept}">
  89
+                    <img class="iconsmall" alt="{$accept}" src="{$CFG->wwwroot}/pix/t/clear.gif"/>
  90
+                </a>
  91
+HTML;
  92
+
  93
+            $deleteaction = 'delete';
  94
+                    
  95
+            if($type->state == LTI_TOOL_STATE_CONFIGURED){
  96
+                $accepthtml = '';
  97
+            }
  98
+            
  99
+            if($type->state != LTI_TOOL_STATE_REJECTED) {
  100
+                $deleteaction = 'reject';
  101
+                $delete = get_string('reject', 'lti');
  102
+            }
  103
+                    
  104
+            $html .= <<<HTML
  105
+            <tr>
  106
+                <td>
  107
+                    {$type->name}
  108
+                </td>
  109
+                <td>
  110
+                    {$type->baseurl}
  111
+                </td>
  112
+                <td>
  113
+                    {$date}
  114
+                </td>
  115
+                <td align="center">
  116
+                    {$accepthtml}
  117
+                    <a class="editing_update" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action=update&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$update}">
  118
+                        <img class="iconsmall" alt="{$update}" src="{$CFG->wwwroot}/pix/t/edit.gif"/>
  119
+                    </a>
  120
+                    <a class="editing_delete" href="{$CFG->wwwroot}/mod/lti/typessettings.php?action={$deleteaction}&amp;id={$type->id}&amp;sesskey={$USER->sesskey}&amp;tab={$id}" title="{$delete}">
  121
+                        <img class="iconsmall" alt="{$delete}" src="{$CFG->wwwroot}/pix/t/delete.gif"/>
  122
+                    </a>
  123
+                </td>
  124
+            </tr>
  125
+HTML;
  126
+        }
  127
+        $html .= '</table></div>';
  128
+    } else {
  129
+        $html .= get_string('no_' . $id, 'lti');
  130
+    }
  131
+    
  132
+    return $html;
  133
+}
  134
+
50 135
 if ($ADMIN->fulltree) {
51 136
     require_once($CFG->dirroot.'/mod/lti/locallib.php');
52 137
 
53  
-    $str = '';
  138
+    $configuredtoolshtml = '';
  139
+    $pendingtoolshtml = '';
  140
+    $rejectedtoolshtml = '';
54 141
 
  142
+    $active = get_string('active', 'lti');
  143
+    $pending = get_string('pending', 'lti');
  144
+    $rejected = get_string('rejected', 'lti');
  145
+    $typename = get_string('typename', 'lti');
  146
+    $baseurl = get_string('baseurl', 'lti');
  147
+    $action = get_string('action', 'lti');
  148
+    $createdon = get_string('createdon', 'lti');
  149
+    
55 150
     $types = lti_filter_get_types();
56  
-    if (!empty($types)) {
57  
-        $str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a></h4>';
58  
-        $str .= '<table>';
59  
-
60  
-        foreach ($types as $type) {
61  
-            $str .= '<tr>'.
62  
-            '<td>'.$type->name.'</td>'.
63  
-            '<td align="center"><a class="editing_update" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=update&amp;id='.$type->id.'&amp;sesskey='.$USER->sesskey.'" title="Update">'.
64  
-            '<img class="iconsmall" alt="Update" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>'.'&nbsp;&nbsp;'.
65  
-            '<a class="editing_delete" href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=delete&amp;id='.$type->id.'&amp;sesskey='.$USER->sesskey.'" title="Delete">'.
66  
-            '<img class="iconsmall" alt="Delete" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/>'.
67  
-            '</a>'.
68  
-            '</td>'.
69  
-            '</tr>';
  151
+    
  152
+    $configuredtools = array_filter($types, function($value){
  153
+        return $value->state == LTI_TOOL_STATE_CONFIGURED;
  154
+    });
  155
+    
  156
+    $configuredtoolshtml = blti_get_tool_table($configuredtools, 'lti_configured');
70 157
 
71  
-        }
72  
-        $str .= '</table>';
73  
-    } else {
74  
-        $str .= '<center>';
75  
-        $str .= '<h4 class="main"><a href="'.$CFG->wwwroot.'/mod/lti/typessettings.php?action=add&amp;sesskey='.$USER->sesskey.'">'.get_string('addtype', 'lti').'</a></h4>';
76  
-        $str .= get_string('notypes', 'lti');
77  
-        $str .= '</center>';
  158
+    $pendingtools = array_filter($types, function($value){
  159
+        return $value->state == LTI_TOOL_STATE_PENDING;
  160
+    });
  161
+    
  162
+    $pendingtoolshtml = blti_get_tool_table($pendingtools, 'lti_pending');
  163
+    
  164
+    $rejectedtools = array_filter($types, function($value){
  165
+        return $value->state == LTI_TOOL_STATE_REJECTED;
  166
+    });
  167
+    
  168
+    $rejectedtoolshtml = blti_get_tool_table($rejectedtools, 'lti_rejected');
  169
+    
  170
+    $tab = optional_param('tab', '', PARAM_ALPHAEXT);
  171
+    $activeselected = '';
  172
+    $pendingselected = '';
  173
+    $rejectedselected = '';
  174
+    switch($tab){
  175
+        case 'lti_pending':
  176
+            $pendingselected = 'class="selected"';
  177
+            break;
  178
+        case 'lti_rejected':
  179
+            $rejectedselected = 'class="selected"';
  180
+            break;
  181
+        default:
  182
+            $activeselected = 'class="selected"';
  183
+            break;
78 184
     }
  185
+    
  186
+    $template = <<<HTML
  187
+<div id="lti_tabs" class="yui-navset">
  188
+    <ul id="lti_tab_heading" class="yui-nav" style="display:none">
  189
+        <li {$activeselected}>
  190
+            <a href="#tab1">
  191
+                <em>$active</em>
  192
+            </a>
  193
+        </li>
  194
+        <li {$pendingselected}>
  195
+            <a href="#tab2">
  196
+                <em>$pending</em>
  197
+            </a>
  198
+        </li>
  199
+        <li {$rejectedselected}>
  200
+            <a href="#tab3">
  201
+                <em>$rejected</em>
  202
+            </a>
  203
+        </li>
  204
+    </ul>
  205
+    <div class="yui-content">
  206
+        <div>
  207
+            $configuredtoolshtml
  208
+        </div>
  209
+        <div>
  210
+            $pendingtoolshtml
  211
+        </div>
  212
+        <div>
  213
+            $rejectedtoolshtml
  214
+        </div>
  215
+    </div>
  216
+</div>
  217
+
  218
+<script type='text/javascript'>
  219
+//<![CDATA[
  220
+    (function(){
  221
+        //If javascript is disabled, they will just see the three tabs one after another
  222
+        var lti_tab_heading = document.getElementById('lti_tab_heading');
  223
+        lti_tab_heading.style.display = '';
  224
+
  225
+        new YAHOO.widget.TabView('lti_tabs');
  226
+    
  227
+        var setupTools = function(id, sort){
  228
+            var lti_tools = YAHOO.util.Dom.get(id + "_tools");
  229
+    
  230
+            if(lti_tools){
  231
+                var dataSource = new YAHOO.util.DataSource(lti_tools);
  232
+    
  233
+                var configuredColumns = [
  234
+                    {key:"name", label:"$typename", sortable:true},
  235
+                    {key:"baseURL", label:"$baseurl", sortable:true},
  236
+                    {key:"timecreated", label:"$createdon", sortable:true, formatter:YAHOO.widget.DataTable.formatDate},
  237
+                    {key:"action", label:"$action"}
  238
+                ];
  239
+
  240
+                dataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
  241
+                dataSource.responseSchema = {
  242
+                    fields: [
  243
+                        {key:"name"},
  244
+                        {key:"baseURL"},
  245
+                        {key:"timecreated", parser:"date"},
  246
+                        {key:"action"}
  247
+                    ]
  248
+                };
79 249
 
  250
+                new YAHOO.widget.DataTable(id + "_container", configuredColumns, dataSource,
  251
+                    {
  252
+                        sortedBy: sort
  253
+                    }
  254
+                );
  255
+            }
  256
+        };
80 257
 
81  
-    $settings->add(new admin_setting_heading('lti_types', get_string('configuredtools', 'lti'), $str));
  258
+        setupTools('lti_configured', {key:"name", dir:"asc"});
  259
+        setupTools('lti_pending', {key:"timecreated", dir:"desc"});
  260
+        setupTools('lti_rejected', {key:"timecreated", dir:"desc"});
  261
+    })();
  262
+//]]
  263
+</script>
  264
+HTML;
82 265
     
  266
+    $PAGE->requires->yui2_lib('tabview');
  267
+    $PAGE->requires->yui2_lib('datatable');
  268
+   
  269
+    $settings->add(new admin_setting_heading('lti_types', get_string('external_tool_types', 'lti'), $template /*  $str*/));
83 270
 }
35  mod/lti/typessettings.php
@@ -67,13 +67,18 @@
67 67
 
68 68
 admin_externalpage_setup('managemodules'); // Hacky solution for printing the admin page
69 69
 
  70
+$tab = optional_param('tab', '', PARAM_ALPHAEXT);
  71
+$redirect = "$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti&tab={$tab}";
  72
+
70 73
 /// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
71 74
 
72 75
 $statusmsg = '';
73 76
 $errormsg  = '';
74 77
 $focus = '';
75 78
 
76  
-if ($data = data_submitted() and confirm_sesskey() and isset($data->submitbutton)) {
  79
+$data = data_submitted();
  80
+
  81
+if (confirm_sesskey() && isset($data->submitbutton)) {
77 82
     $type = new StdClass();
78 83
     $type->name = $data->lti_typename;
79 84
     $type->baseurl = $data->lti_toolurl;
@@ -104,11 +109,12 @@
104 109
                 }
105 110
             }
106 111
         }
107  
-        redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
  112
+        redirect($redirect);
108 113
         die;
109 114
     } else {
110 115
         $type->createdby = $USER->id;
111 116
         $type->timecreated = time();
  117
+        $type->state = LTI_TOOL_STATE_CONFIGURED;
112 118
         
113 119
         //Create a salt value to be used for signing passed data to extension services
114 120
         $data->lti_servicesalt = uniqid('', true);
@@ -133,22 +139,29 @@
133 139
         } else {
134 140
             $errormsg = get_string('errorwithsettings', 'admin');
135 141
         }
136  
-        redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
  142
+        redirect($redirect);
137 143
         die;
138 144
     }
  145
+} else if(isset($data->cancel)){
  146
+    redirect($redirect);
  147
+    die;
139 148
 }
140 149
 
141  
-if ($action == 'delete') {
142  
-    lti_delete_type($id);
143  
-    redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
  150
+if ($action == 'accept') {
  151
+    lti_set_state_for_type($id, LTI_TOOL_STATE_CONFIGURED);
  152
+    redirect($redirect);
144 153
     die;
145 154
 }
146 155
 
147  
-if (($action == 'fix') && isset($useexisting)) {
148  
-    $instance = $DB->get_record('lti', array('id' => $id));
149  
-    $instance->typeid = $useexisting;
150  
-    $DB->update_record('lti', $instance);
151  
-    redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettinglti");
  156
+if ($action == 'reject') {
  157
+    lti_set_state_for_type($id, LTI_TOOL_STATE_REJECTED);
  158
+    redirect($redirect);
  159
+    die;
  160
+}
  161
+
  162
+if ($action == 'delete') {
  163
+    lti_delete_type($id);
  164
+    redirect($redirect);
152 165
     die;
153 166
 }
154 167
 
6  mod/lti/view.php
@@ -92,8 +92,8 @@
92 92
                         $basiclti->launchcontainer;
93 93
 
94 94
 if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){
95  
-    $PAGE->set_pagelayout('frametop'); //Use the frametop layout to get the navbar, but no footer
96  
-    $PAGE->blocks->show_only_fake_blocks(); //Disable blocks
  95
+    $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks
  96
+    $PAGE->blocks->show_only_fake_blocks(); //Disable blocks for layouts which do include pre-post blocks
97 97
 } else {
98 98
     $PAGE->set_pagelayout('incourse');
99 99
 }
@@ -159,7 +159,7 @@
159 159
 
160 160
                 setInterval(resize, 250);
161 161
             })();
162  
-        //]]    
  162
+        //]]
163 163
         </script>
164 164
 SCRIPT;
165 165
     

0 notes on commit a4a0799

Please sign in to comment.
Something went wrong with that request. Please try again.