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; }
function lti_add_consumer() { global $wpdb; $options = get_site_option('lti_choices'); $editmode = $_REQUEST['action'] == 'edit'; if ($editmode) { $verb = 'Update'; } else { $verb = 'Add'; } ?> <script src="<?php echo plugins_url() . '/lti/js/GenKey.js'; ?> " language="javascript" type="text/javascript" > </script> <div id='form'> <h2><?php echo $verb . __(" Tool Consumer", 'lti-text'); ?> </h2> <p><?php echo $verb . __(' a tool consumer connecting to this site.', 'lti-text'); ?> </p> <form id="addlti" name="addlti" method="post" <?php if ($editmode) { ?> action="<?php echo plugins_url() . '/lti/includes/DoAddLTIConsumer.php?edit=true'; ?> " onsubmit="return verify()"> <?php } else { ?> action="" onsubmit="return createConsumer('<?php echo plugins_url(); ?> ')"> <?php } wp_nonce_field('add_lti', '_wpnonce_add_lti'); $button_text = __("{$verb} Tool Consumer", 'lti-text'); $type = "input"; if ($editmode) { $consumer = new LTI_Tool_Consumer($_REQUEST['lti'], array($wpdb->base_prefix)); } ?> <table class="form-table"> <tbody> <tr class="form-field form-required"> <th scope="row"> <label for="lti_name" id="lti_name_text"> <?php _e('Name', 'lti-text'); ?> <span id="req1" class="description"><?php _e('(required)', 'lti-text'); ?> </span> </label> </th> <td> <input id="lti_name" type="text" aria-required="true" value="<?php echo esc_attr($consumer->name); ?> " name="lti_name" class="regular-text"> </td> </tr> <tr class="form-field form-required"> <th scope="row"> <label for="lti_email_domain" id="lti_email_domain_text"> <?php _e('Primary Email Domain', 'lti-text'); ?> <span class="description"><?php _e('(The primary domain you expect your participant email addresses to originate from. If you expect student@example.edu, put example.edu in the field.)', 'lti-text'); ?> </span> </label> </th> <td> <input id="lti_email_domain" type="text" aria-required="true" value="<?php echo esc_attr($consumer->email_domain); ?> " name="lti_email_domain" class="regular-text"> </td> </tr> <?php if ($editmode) { ?> <tr class="form-field form-required"> <th scope="row"> <label for="lti_key" id="lti_key_text"> <?php _e('Key', 'lti-text'); ?> <span id="req2" class="description"><?php _e('(required)', 'lti-text'); ?> </span> </label> </th> <td> <?php echo esc_attr($consumer->getKey()); ?> <span class="description">(Consumer keys cannot be changed)</span> <input id="lti_key" type="hidden" aria-required="true" value="<?php echo esc_attr($consumer->getKey()); ?> " name="lti_key"> </td> </tr> <tr class="form-field form-required"> <th scope="row"> <label for="lti_secret" id="lti_secret_text"> <?php _e('Secret', 'lti-text'); ?> <span id="req3" class="description"><?php _e('(required)', 'lti-text'); ?> </span> </label> </th> <td> <input id="lti_secret" type="text" aria-required="true" value="<?php echo esc_attr($consumer->secret); ?> " name="lti_secret" class="regular-text"> </td> </tr> <?php } ?> <tr> <th scope="row"> <?php _e('Protected', 'lti-text'); ?> </th> <td> <fieldset> <legend class="screen-reader-text"> <span><?php _e('Protected', 'lti-text'); ?> </span> </legend> <label for="lti_protected"> <input name="lti_protected" type="checkbox" id="lti_protected" value="true" <?php checked(TRUE, $consumer->protected); ?> /> <?php _e('Restrict launch requests to the same tool consumer GUID parameter', 'lti-text'); ?> </label> </fieldset> </td> </tr> <tr> <th scope="row"> <?php _e('Enabled', 'lti-text'); ?> </th> <td> <fieldset> <legend class="screen-reader-text"> <span><?php _e('Enabled', 'lti-text'); ?> </span> </legend> <label for="lti_enabled"> <input name="lti_enabled" type="checkbox" id="lti_enabled" value="true" <?php checked(TRUE, $consumer->enabled); ?> /> <?php _e('Accept launch requests for this tool consumer', 'lti-text'); ?> </label> </fieldset> </td> </tr> <?php $from = $consumer->enable_from; if (is_null($from)) { $from = ''; } $until = $consumer->enable_until; if (is_null($until)) { $until = ''; } ?> <tr class="form-field"> <th scope="row"> <label for="lti_enable_form"> <?php _e('Enable From (e.g. 2013-01-26 12:34)', 'lti-text'); ?> </label> </th> <td> <input id="lti_enable_from" type="text" aria-required="true" value="<?php if (isset($from) && $from != "") { echo date('Y-m-d H:i', (int) $from); } ?> " name="lti_enable_from"> </td> <tr class="form-field"> <th scope="row"> <label for="lti_enable_until"> <?php _e('Enable Until (e.g. 2014-01-26 12:34)', 'lti-text'); ?> </label> </th> <td> <input id="lti_enable_until" type="text" aria-required="true" value="<?php if (isset($until) && $until != "") { echo date('Y-m-d H:i', (int) $until); } ?> " name="lti_enable_until"> </td> <tr> <?php if ($editmode) { ?> <tr> <th scope="row"> <?php _e('Username format', 'lti-text'); ?> </th> <td> <?php switch (lti_get_scope($consumer->getKey())) { case '4': _e('Global: Use email only', 'lti-text'); break; case '3': _e('Resource: Prefix the ID with the consumer key and resource link ID', 'lti-text'); break; case '2': _e('Context: Prefix the ID with the consumer key and context ID', 'lti-text'); break; case '1': _e('Consumer: Prefix the ID with the consumer key', 'lti-text'); break; case '0': _e('Global: Use ID value only', 'lti-text'); break; } ?> </td> <?php } else { ?> <th scope="row"> <?php _e('Username Format', 'lti-text'); ?> </th> <td> <fieldset> <legend class="screen-reader-text"> <span><?php _e('Resource: Prefix the ID with the consumer key and resource link ID', 'lti-text'); ?> </span> </legend> <!-- Swat Edit: Added lti_scope4 --> <label for="lti_scope4"> <input name="lti_scope" type="radio" id="lti_scope4" value="4" <?php checked('4', $options['scope']); ?> /> <?php _e('Global: Use Email Only', 'lti-text'); ?> </label><br /> <label for="lti_scope3"> <input name="lti_scope" type="radio" id="lti_scope3" value="3" <?php checked('3', $options['scope']); ?> /> <?php _e('Resource: Prefix the ID with the consumer key and resource link ID', 'lti-text'); ?> </label><br /> <legend class="screen-reader-text"> <span><?php _e('Context: Prefix the ID with the consumer key and context ID', 'lti-text'); ?> </span> </legend> <label for="lti_scope2"> <input name="lti_scope" type="radio" id="lti_scope2" value="2" <?php checked('2', $options['scope']); ?> /> <?php _e('Context: Prefix the ID with the consumer key and context ID', 'lti-text'); ?> </label><br /> <legend class="screen-reader-text"> <span><?php _e('Consumer: Prefix an ID with the consumer key', 'lti-text'); ?> </span> </legend> <label for="lti_scope1"> <input name="lti_scope" type="radio" id="lti_scope1" value="1" <?php checked('1', $options['scope']); ?> /> <?php _e('Consumer: Prefix the ID with the consumer key', 'lti-text'); ?> </label><br /> <legend class="screen-reader-text"> <span><?php _e('Global: Use ID value only', 'lti-text'); ?> </span> </legend> <label for="lti_scope0"> <input name="lti_scope" type="radio" id="lti_scope0" value="0" <?php checked('0', $options['scope']); ?> /> <?php _e('Global: Use ID value only', 'lti-text'); ?> </label> </fieldset> </td> </tr> <?php } ?> </tbody> </table> <p class="submit"> <input id="addltisub" class="button-primary" type="submit" value="<?php echo $button_text; ?> " name="addlti"> </p> </form> </div> <div id="keySecret" style="display:none"> <h2><?php _e('Details for LTI Tool Consumer: ', 'lti-text'); ?> <span id="lti_title" style="font-weight:bold"></span></h2> <table> <tr><td><?php echo __('Launch URL: ', 'lti-text') . '<b>' . get_option('siteurl') . '/?lti</b>'; ?> </td></tr> <tr><td><?php _e('Key: ', 'lti-text'); ?> <span id="key" style="font-weight:bold"></span></td></tr> <tr><td><?php _e('Secret: ', 'lti-text'); ?> <span id="secret" style="font-weight:bold"></span></td></tr> </table> <form action="<?php echo plugins_url() . '/lti/includes/XML.php'; ?> " name="download" id="download"> <input id="ltikey" type="hidden" value="" name="lti" /> <p class="submit"> <input id="xml" class="button-primary" type="submit" value="<?php _e('Download XML', 'lti-text'); ?> " name="xml" /> </p> </form> </div> <?php }
public function delete($deleteConsumer = FALSE) { // Delete any nonce values for this consumer instance $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . BasicLTI_Tool_Provider::NONCE_TABLE_NAME . " WHERE consumer_instance_guid = %s", BasicLTI_Tool_Provider::quoted($this->guid)); mysql_query($sql); // Update any contexts for which this is a primary context $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . BasicLTI_Tool_Provider::CONTEXT_TABLE_NAME . ' SET primary_consumer_instance_guid = NULL AND primary_context_id = NULL' . " WHERE primary_consumer_instance_guid = %s", BasicLTI_Tool_Provider::quoted($this->guid)); $ok = mysql_query($sql); // Delete any contexts for this consumer instance $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . BasicLTI_Tool_Provider::CONTEXT_TABLE_NAME . " WHERE consumer_instance_guid = %s", BasicLTI_Tool_Provider::quoted($this->guid)); mysql_query($sql); // Delete consumer instance $sql = sprintf("DELETE FROM {$this->dbTableNamePrefix}" . BasicLTI_Tool_Provider::CONSUMER_INSTANCE_TABLE_NAME . " WHERE consumer_instance_guid = %s", BasicLTI_Tool_Provider::quoted($this->guid)); $ok = mysql_query($sql); if ($ok) { $this->guid = NULL; if ($deleteConsumer) { $consumer = new LTI_Tool_Consumer($this->consumer_guid, $this->dbTableNamePrefix); $consumer->delete(); } } return $ok; }
if ($valid) { $consumer = new LTI_Tool_Consumer($_key, LTI_Data_Connector::getDataConnector($sql)); $consumer->name = $_name; $consumer->secret = $_REQUEST['secret']; $consumer->enabled = isset($_REQUEST['enabled']); if (!$consumer->save()) { $valid = false; $message = "<strong>Consumer could not be saved.</strong> {$sql->error}"; } } if (!$valid) { $smarty->addMessage('Required information missing', $message, NotificationMessage::ERROR); } /* look up consumer to edit, if requested */ } elseif (isset($_REQUEST['consumer_key'])) { $consumer = new LTI_Tool_Consumer($_REQUEST['consumer_key'], LTI_Data_Connector::getDataConnector($sql)); if (isset($_REQUEST['action'])) { switch ($_REQUEST['action']) { case 'delete': $consumer->delete(); break; case 'select': $name = $consumer->name; $key = $consumer->getKey(); $secret = $consumer->secret; $enabled = $consumer->enabled; break; case 'update': case 'insert': default: // leave default form values set
break; case 'info': return phpinfo(); break; default: echo "undefined function_type"; } } # mainline require_once 'LTI_Tool_Provider.php'; openlog('php', LOG_CONS | LOG_NDELAY | LOG_PID, LOG_USER | LOG_PERROR); //syslog(LOG_WARNING, 'starting TP'); $configs = (include 'config.php'); $db = new mysqli($configs['db_server'], $configs['db_user'], $configs['db_password'], $configs['db_schema']); $db_connector = LTI_Data_Connector::getDataConnector('', $db); $consumer = new LTI_Tool_Consumer('testing.edu', $db_connector); $consumer->name = '12345'; $consumer->secret = 'secret'; $consumer->save(); # enable tool consumer if (!is_null($consumer->created)) { $consumer->enabled = TRUE; $consumer->save(); } //var_dump($consumer); $full_path = $_SERVER['REQUEST_URI']; $paths = explode('/', $full_path); if (count($paths) >= 2) { $path = $paths[1]; } else { echo $full_path;
/** * Delete the tool consumer from the database * * @param LTI_Tool_Consumer $consumer * @return bool */ public function Tool_Consumer_delete($consumer) { $key = $consumer->getKey(); // Delete any nonce values for this consumer $sql = 'DELETE FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::NONCE_TABLE_NAME . ' WHERE consumer_key = :key'; $query = $this->db->prepare($sql); $query->bindValue('key', $key, PDO::PARAM_STR); $query->execute(); // Delete any outstanding share keys for resource links for this consumer $sql = 'DELETE FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' WHERE primary_consumer_key = :key'; $query = $this->db->prepare($sql); $query->bindValue('key', $key, PDO::PARAM_STR); $query->execute(); // Delete any users in resource links for this consumer $sql = 'DELETE FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::USER_TABLE_NAME . ' WHERE consumer_key = :key'; $query = $this->db->prepare($sql); $query->bindValue('key', $key, PDO::PARAM_STR); $query->execute(); // Update any resource links for which this consumer is acting as a primary resource link $sql = 'UPDATE ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' ' . 'SET primary_consumer_key = NULL AND primary_context_id = NULL ' . 'WHERE primary_consumer_key = :key'; $query = $this->db->prepare($sql); $query->bindValue('key', $key, PDO::PARAM_STR); $query->execute(); // Delete any resource links for this consumer $sql = 'DELETE FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::RESOURCE_LINK_TABLE_NAME . ' WHERE consumer_key = :key'; $query = $this->db->prepare($sql); $query->bindValue('key', $key, PDO::PARAM_STR); $query->execute(); // Delete consumer $sql = 'DELETE FROM ' . $this->dbTableNamePrefix . LTI_Data_Connector::CONSUMER_TABLE_NAME . ' WHERE consumer_key = :key'; $query = $this->db->prepare($sql); $query->bindValue('key', $key, PDO::PARAM_STR); $ok = $query->execute(); if ($ok) { $consumer->initialise(); } return $ok; }
/** * Demo function. Creates new LTI Consumer * @param string $key * @param string $name * @param string $secret * @param bool $enabled */ public function createConsumer($key = 'jisc.ac.uk', $name = 'ceLTIc', $secret = 'secret', $enabled = TRUE) { $consumer = new LTI_Tool_Consumer($key, $this->data_connector); if (is_null($consumer->created)) { $consumer->name = $name; $consumer->secret = $secret; $consumer->enabled = $enabled; return $consumer->save(); } return false; }
function lti_set_enable($key, $enable) { global $wpdb; $consumer = new LTI_Tool_Consumer($key, array($wpdb->prefix)); $consumer->enabled = $enable; $consumer->save(); }
<?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 require_once 'LTI_Tool_Provider.php'; openlog('php', LOG_CONS | LOG_NDELAY | LOG_PID, LOG_USER | LOG_PERROR); syslog(LOG_WARNING, 'starting TP'); $configs = (include 'config.php'); echo var_dump($configs); echo var_dump($configs['db_server']); $db = new mysqli($configs['db_server'], $configs['db_user'], $configs['db_password'], $configs['db_schema']); $db_connector = LTI_Data_Connector::getDataConnector('', $db); $consumer = new LTI_Tool_Consumer('testing.edu', $db_connector); $consumer->name = 'Testing'; $consumer->secret = 'ThisIsASecret!'; $consumer->save(); echo var_dump($consumer);
/** * execute * * @param \Form\Form $form */ public function update($form) { $object = new \LTI_Tool_Consumer($form->getFieldValue('key'), $this->getConfig()->getLtiDataConnector()); // Load object $object->name = $form->getFieldValue('name'); $object->secret = $form->getFieldValue('secret'); $object->enabled = $form->getFieldValue('enabled'); $object->protected = $form->getFieldValue('protected'); $object->css_path = $form->getFieldValue('css_path'); $object->updated = \Tk\Date::create()->getTimestamp(); // validate object if (!$object->name) { $form->addFieldError('name', 'Please supply a valid consumer name'); } if (!preg_match('/^[a-z0-9_-]{1,64}$/i', $object->getKey())) { $form->addFieldError('consumerKey', 'Invalid characters used in key field'); } if (!preg_match('/^[a-z0-9]{1,64}$/i', $object->secret)) { $form->addFieldError('secret', 'Invalid characters used in secret field'); } if ($form->hasErrors()) { if (!\Mod\Notice::hasMessages()) { \Mod\Notice::addError('The form contains errors.'); } return; } if (!$this->getConfig()->getLtiDataConnector()->Tool_Consumer_save($object)) { if (!\Mod\Notice::hasMessages()) { \Mod\Notice::addError('Error saving consumer to DB.'); } return; } //$this->getRedirectUrl()->set('key', $object->getKey())->redirect(); $this->getRedirectUrl()->redirect(); }