function LTI_update_consumer($tool_guid, $name, $consumer_name, $url, $enable, $instance_guid, $secret, $state) { // Deleting the instance allows us to update the key (if required) $consumerInstance = new LTI_Tool_Consumer_Instance(elgg_get_config('dbprefix'), $tool_guid); // Update consumer $consumer = new LTI_Tool_Consumer($tool_guid, elgg_get_config('dbprefix')); $consumer->name = $name; $consumer->consumer_name = $consumer_name; $consumer->profile_url = $url; $consumer->enabled = $enable == 'yes' ? true : false; $consumer->updated = time(); $consumer->save(); // Create new consumer instance $consumerInstance = new LTI_Tool_Consumer_Instance($instance_guid, elgg_get_config('dbprefix')); $consumerInstance->secret = $secret; $consumerInstance->state = $state; $consumerInstance->save(); return; }
public function getNewShareKey($life, $auto_approve = FALSE, $length = NULL) { $expires = time() + $life * 60 * 60; if ($auto_approve) { $approve = 1; } else { $approve = 0; } if (empty($length) || !is_numeric($length)) { $length = self::MAX_SHARE_KEY_LENGTH; } else { $length = max(min($length, self::MAX_SHARE_KEY_LENGTH), self::MIN_SHARE_KEY_LENGTH); } $key = LTI_Tool_Consumer_Instance::getRandomString($length); $sql = sprintf("INSERT INTO {$this->consumer_instance->dbTableNamePrefix}" . BasicLTI_Tool_Provider::CONTEXT_SHARE_KEY_TABLE_NAME . ' (share_key, primary_consumer_instance_guid, primary_context_id, auto_approve, expires) ' . "VALUES (%s, %s, %s, {$approve}, {$expires})", BasicLTI_Tool_Provider::quoted($key), BasicLTI_Tool_Provider::quoted($this->consumer_instance->guid), BasicLTI_Tool_Provider::quoted($this->id)); $ok = mysql_query($sql); if (!$ok) { $key = ''; } return $key; }
<?php /*------------------------------------------------------------------- * Elgg LTI * * This is called when administrator delete a consumer ------------------------------------------------------------------*/ // Must be logged in as admin to use this page admin_gatekeeper(); // Sort out what is to go $consumer_instance = new LTI_Tool_Consumer_Instance(get_input('LTIconsumerguid'), elgg_get_config('dbprefix')); $consumer_tool = new LTI_Tool_Consumer($consumer_instance->consumer_guid, elgg_get_config('dbprefix')); // Check we have right sort of object if ($consumer_instance) { if ($consumer_instance->delete() && DeleteConsumerTool($consumer_tool)) { system_message(sprintf(elgg_echo('LTI:delete:success'), $consumer_tool->name)); } else { system_message(sprintf(elgg_echo('LTI:delete:fail'), $consumer_tool->name)); } } else { register_error(sprintf(elgg_echo('LTI:remove:fail'), $consumer_tool->name)); } forward($_SERVER['HTTP_REFERER']); /*------------------------------------------------------------------- * Delete the consumer tool. The instance will already be deleted * * Parameters * consumer_tool - Consumer to be deleted. Done via direct DB access * * return value - true, if row deleted *
<?php /*------------------------------------------------------------------- * Elgg LTI * * Enable/Disable consumer ------------------------------------------------------------------*/ // Must be logged in as admin to use this page admin_gatekeeper(); $consumer_instance = new LTI_Tool_Consumer_Instance(get_input('guid'), elgg_get_config('dbprefix')); $consumer_tool = new LTI_Tool_Consumer($consumer_instance->consumer_guid, elgg_get_config('dbprefix')); $consumer_tool->enabled = $consumer_instance->isEnabled() ? False : True; $consumer_tool->save(); forward(REFERRER);
<?php /*------------------------------------------------------------------- * Elgg LTI * * This is called when administrator removes a consumer ------------------------------------------------------------------*/ // Must be logged in as admin to use this page admin_gatekeeper(); // Sort out what is to go $consumer_instance = new LTI_Tool_Consumer_Instance(get_input('LTIconsumerguid'), elgg_get_config('dbprefix')); $consumer_tool = new LTI_Tool_Consumer($consumer_instance->consumer_guid, elgg_get_config('dbprefix')); // Check we have right sort of object if ($consumer_instance) { $consumer_instance->state = 'removed'; $consumer_instance->save(); if ($consumer_instance->state == 'removed') { system_message(sprintf(elgg_echo('LTI:remove:success'), $consumer_tool->name)); } else { system_message(sprintf(elgg_echo('LTI:restore:success'), $consumer_tool->name)); } } else { register_error(sprintf(elgg_echo('LTI:remove:fail'), $consumer_tool->name)); } forward($_SERVER['HTTP_REFERER']);
<?php /*------------------------------------------------------------------- * Elgg LTI * * Display the LTI object ------------------------------------------------------------------*/ $consumer_instance_guid = $vars['consumer_guid']; $consumer_instance = new LTI_Tool_Consumer_Instance($consumer_instance_guid, elgg_get_config('dbprefix')); $consumer_tool = new LTI_Tool_Consumer($consumer_instance->consumer_guid, elgg_get_config('dbprefix')); $url = elgg_get_site_entity()->url; if ($consumer_instance->isEnabled()) { $enabled = 'yes'; $info = '<div class="plugin_details active">'; } else { $enabled = 'no'; $info = '<div class="plugin_details not-active">'; } $icon = '<img src="' . GetImage($consumer_instance->guid, '.png') . '" title="Image of Consumer" />'; $info .= '<table>'; $info .= '<tr><th class = "column1"></th><th class = "column2"></th><th class = "column3">Name</th><th class = "column4">Consumer Name</th><th class = "column5"></th></tr>'; $info .= '<tr>'; $info .= '<td class = "column1">' . $icon . '</td>'; $info .= '<td class = "column2">'; $info .= '<a href="editconsumer?LTIconsumerguid=' . $consumer_instance->guid . '" alt="Edit consumer" title="Edit Consumer"><img src="' . elgg_get_config('wwwroot') . 'mod/blti/images/edit.gif' . '"></a>'; $info .= '<a href="' . $url . 'blti/delete/' . $consumer_instance->guid . '" alt="Delete consumer" title="Delete Consumer"><img src="' . elgg_get_config('wwwroot') . 'mod/blti/images/delete.gif' . '"></a>'; $info .= '</td>'; $info .= '<td class = "column3">' . $consumer_tool->name . '</td>'; $info .= '<td class = "column4">' . $consumer_tool->consumer_name . '</td>'; $url = elgg_add_action_tokens_to_url(elgg_get_config('wwwroot') . 'action/' . elgg_get_config('ltiname') . '/enable?guid=' . $consumer_instance->guid); $option = $consumer_instance->isEnabled() ? 'Disable' : 'Enable';
<?php /*------------------------------------------------------------------- * Elgg LTI * * This is called when administrator chooses to edit a consumer ------------------------------------------------------------------*/ // Have to be logged in to get to here at all admin_gatekeeper(); elgg_set_context('admin'); // Sort out which LTI provider we are editing $consumer_instance = new LTI_Tool_Consumer_Instance(get_input('LTIconsumerguid'), elgg_get_config('dbprefix')); $consumer_tool = new LTI_Tool_Consumer($consumer_instance->consumer_guid, elgg_get_config('dbprefix')); // Check we have LTI object if ($consumer_instance) { $isBasicLTI = $consumer_instance->state == 'BasicLTI' || $consumer_instance->consumer_guid == $consumer_instance->guid ? true : false; $tool_guid = elgg_view('input/hidden', array('name' => 'tool_guid', 'value' => $consumer_tool->guid)); // Tile //$area2 = elgg_view_title(elgg_echo('LTI:edit:consumer:title')); // Name $name = elgg_view('input/text', array('name' => 'name', 'value' => $consumer_tool->name)); // Enabled $option = $consumer_instance->isEnabled() ? 'yes' : 'no'; $enable = elgg_view('input/checkboxes', array('name' => 'enable', 'options' => array('' => 'yes'), 'value' => $option)); if (!$isBasicLTI) { // Profile UL $profile_url = '<a href="' . $consumer_tool->profile_url . '">' . $consumer_tool->profile_url . '</a>'; $url = elgg_view('input/hidden', array('name' => 'url', 'value' => $consumer_tool->profile_url)); // Version $version = elgg_view('input/text', array('name' => 'name', 'value' => $consumer_tool->consumer_version)); // System