コード例 #1
0
 $header = "";
 $description = "";
 $regService = $ScormService->getRegistrationService();
 $query = $wpdb->prepare('SELECT r.reg_id, r.invite_id FROM ' . ScormCloudDatabase::get_invitations_table() . ' i
                          JOIN ' . ScormCloudDatabase::get_registrations_table() . ' r ON i.invite_id = r.invite_id
                          WHERE r.user_email = %s AND i.course_id = %s AND i.app_id', array($user_email, $courseId, ScormCloudPlugin::get_wp_option('scormcloud_appid')));
 $inviteReg = $wpdb->get_row($query, OBJECT);
 if ($inviteReg != null) {
     $regid = (string) $inviteReg->reg_id;
     $inviteId = (string) $inviteReg->invite_id;
 } else {
     $inviteId = uniqid();
     $regid = $inviteId . "-" . uniqid();
     $require_login = 0;
     $show_course_info = 0;
     $wpdb->insert(ScormCloudDatabase::get_invitations_table(), array('invite_id' => $inviteId, 'blog_id' => $GLOBALS['blog_id'], 'app_id' => ScormCloudPlugin::get_wp_option('scormcloud_appid'), 'post_id' => $postId, 'course_id' => $courseId, 'course_title' => $courseTitle, 'header' => $header, 'description' => $description, 'require_login' => $require_login, 'show_course_info' => $show_course_info), array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d'));
     //create the cloud registration
     $regService->CreateRegistration($regid, $courseId, $user_email, $user_first_name, $user_last_name, $user_email);
     $wpdb->insert(ScormCloudDatabase::get_registrations_table(), array('invite_id' => $inviteId, 'reg_id' => $regid, 'user_email' => $user_email), array('%s', '%s', '%s'));
 }
 $courseTags = 'catalog_widget';
 $regTags = $GLOBALS['blog_id'] . ',' . $inviteId . ',' . $courseTags;
 $learnerTags = isset($current_user->roles[0]) ? $current_user->roles[0] : "anonymous";
 if (function_exists("bp_activity_add")) {
     global $bp;
     $actionStr = sprintf('%s launched course "%s" from the Catalog Widget', $user_first_name . ' ' . $user_last_name, $courseTitle);
     //error_log('logged in user: '******'action' => $actionStr, 'content' => '', 'component' => 'scormcloud', 'type' => 'training_launch', 'primary_link' => '', 'user_id' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => gmdate("Y-m-d H:i:s"), 'hide_sitewide' => false);
     $bpActivityId = bp_activity_add($activityArgs);
     error_log('Logging action: ' . $actionStr . ' Activity ID: ' . $bpActivityId);
 }
コード例 #2
0
<?php

require_once SCORMCLOUD_BASE . 'scormcloudplugin.php';
require_once SCORMCLOUD_BASE . 'db/scormclouddatabase.php';
$inviteId = $_GET['inviteid'];
$invTable = ScormCloudDatabase::get_invitations_table();
$regTable = ScormCloudDatabase::get_registrations_table();
$query = $wpdb->prepare('SELECT inv.*, count(reg.reg_id) as reg_count FROM ' . $invTable . ' inv
                         LEFT OUTER JOIN ' . $regTable . ' reg ON inv.invite_id = reg.invite_id
                         WHERE inv.invite_id = %s AND inv.app_id = %s GROUP BY inv.invite_id', array($inviteId, ScormCloudPlugin::get_wp_option('scormcloud_appid')));
$invite = $wpdb->get_row($query, OBJECT);
?>
<div class="scormcloud-admin-page trainingDetail"><a class='backLink'
	href='<?php 
echo get_option('siteurl') . "/wp-admin/admin.php?page=scormcloud/manage_training";
?>
'><?php 
_e("Go back to all trainings", "scormcloud");
?>
</a>

<h2><?php 
echo __("Training Details for", "scormcloud") . ' "' . $invite->course_title;
?>
"</h2>
<div class="invitationStatus"><?php 
echo __("This training is currently", "scormcloud") . " <span class='activeText' key='" . $inviteId . "'>" . ($invite->active == 1 ? __("Active", "scormcloud") : __("Inactive", "scormcloud")) . "</span>";
if ($invite->active != 2) {
    echo "(<a href='#' key='" . $inviteId . "' class='activateLink' active='" . $invite->active . "' >" . ($invite->active == 1 ? __("click to deactivate", "scormcloud") : __("click to activate", "scormcloud")) . "</a>)";
}
?>
 /**
  * Displays the Widget
  *
  */
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title']);
     $requireLogin = isset($instance['requirelogin']) ? (bool) $instance['requirelogin'] : true;
     $regsRemaining = ScormCloudPlugin::remaining_registrations();
     # Before the widget
     echo $before_widget;
     # The title
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     # Make the widget
     echo '<link rel="stylesheet" type="text/css" href="' . get_option('siteurl') . '/wp-content/plugins/scormcloud/css/scormcloud.widget.css" />';
     //echo '<h2>SCORM Cloud Courses</h2>';
     global $current_user;
     global $wpdb;
     get_currentuserinfo();
     $coursesFilter = ScormCloudPlugin::is_network_managed() && get_site_option('scormcloud_sharecourses') !== '1' ? $GLOBALS['blog_id'] . "-.*" : null;
     $ScormService = ScormCloudPlugin::get_cloud_service();
     $courseService = $ScormService->getCourseService();
     $courseObjArray = $courseService->GetCourseList($coursesFilter);
     if ($requireLogin && !is_user_logged_in()) {
         echo '<a href="wp-login.php">Log in</a> to see the course catalog.';
     } else {
         $regService = $ScormService->getRegistrationService();
         //echo count($regs);
         echo '<div class="courselistDiv">';
         echo "<div class='helpMsg'>" . __("Click course title to launch.", "scormcloud") . " <br/><a class='catalogMoreInfo toggleButton' href='javascript:void(0);' toggleobject='.courselistDiv .catalog.moreInfo' onText='" . __("hide info", "scormcloud") . "' offText='" . __("more info", "scormcloud") . "'>" . __("more info", "scormcloud") . "</a></div>";
         echo "<div class='catalog moreInfo'>";
         if ($current_user->user_login != '') {
             echo "<p>" . __("If you have taken a course before, your most recent results will display by clicking 'show details' and your most recent training will launch by clicking the course title.", "scormcloud") . "</p>";
         } else {
             echo "<p>" . __("To launch a course, you must provide a name and email address.  This will allow your training results to be tracked.", "scormcloud") . "</p>";
             echo "<p>" . __("By registering or logging in, your results will be associated with your user identity and you will be able to see your training results in this widget.", "scormcloud") . "</p>";
         }
         echo "</div>";
         foreach ($courseObjArray as $course) {
             $courseId = $course->getCourseId();
             $courseTitle = $course->getTitle();
             if (isset($current_user->user_login) && $current_user->user_login != '') {
                 $invTable = ScormCloudDatabase::get_invitations_table();
                 $regTable = ScormCloudDatabase::get_registrations_table();
                 $query = $wpdb->prepare('SELECT reg.reg_id, inv.course_title, inv.course_id, inv.active, reg.update_date FROM ' . $regTable . ' reg
                                              JOIN ' . $invTable . ' inv ON reg.invite_id = inv.invite_id
                                              WHERE reg.user_id = %s AND inv.course_id = %s ORDER BY reg.update_date DESC', array($current_user->ID, $courseId));
                 $reg = $wpdb->get_row($query, OBJECT);
                 if ($reg != null) {
                     $regId = $reg->reg_id;
                     $regResultsXmlStr = $regService->GetRegistrationResult($regId, 0, 0);
                     $resXml = simplexml_load_string($regResultsXmlStr);
                     $completion = $resXml->registrationreport->complete;
                     $success = $resXml->registrationreport->success;
                     $seconds = $resXml->registrationreport->totaltime;
                     $score = $resXml->registrationreport->score;
                     echo "<div class='usercourseblock'>";
                     if ($reg->active == 1) {
                         echo "<a class='courseTitle' href='javascript:void(0);' key='{$regId}' onclick='ScormCloud.Widget.getLaunchURL(\"{$regId}\",\"Catalog\");' url='" . get_option('siteurl') . "/wp-content/plugins/scormcloud/ajax.php' title='" . __("Click to launch course ", "scormcloud") . "{$courseTitle}'>{$courseTitle}</a>";
                     } else {
                         echo "<span class='courseTitle' title='" . __("This course is currently inactive.", "scormcloud") . "'>{$courseTitle}</span>";
                     }
                     echo "<br/><a href='javascript:void(0);' class='toggleButton showDetails' toggleobject='.courselistDiv .catalog.courseDetails.{$regId}' onText='" . __("hide details", "scormcloud") . "' offText='" . __("show details", "scormcloud") . "'>" . __("show details", "scormcloud") . "</a>";
                     echo "<div class='catalog courseDetails {$regId}' >";
                     if ($seconds > 0) {
                         echo "<div class=''>" . __("Completion", "scormcloud") . ": <span class='{$completion}'>" . __($completion) . "</span></div>";
                         echo "<div class=''>" . __("Success", "scormcloud") . ": <span class='{$success}'>" . __($success) . "</span></div>";
                         echo "<div class=''>" . __("Score", "scormcloud") . ": " . ($score == "unknown" ? "-" : $score . "%") . "</div>";
                         echo '<div class="time">' . floor($seconds / 60) . "min " . $seconds % 60 . __("sec spent in course", "scormcloud") . '</div>';
                     } else {
                         echo '<div class="">' . __("Not Started", "scormcloud") . '</div>';
                     }
                     echo "</div>";
                 } else {
                     echo "<div class='usercourseblock'>";
                     if ($regsRemaining > 0) {
                         echo "<a class='courseTitle' href='javascript:void(0);' coursetitle='{$courseTitle}' key='{$courseId}' onclick='ScormCloud.Widget.getCatalogLaunchURL(\"{$courseId}\");' url='" . get_option('siteurl') . "/wp-content/plugins/scormcloud/ajax.php' title='" . __("Click to launch course ", "scormcloud") . "{$courseTitle}'>{$courseTitle}</a>";
                     } else {
                         echo "<span class='courseTitle' title='" . __("This course is currently inactive.", "scormcloud") . "'>{$courseTitle}</span>";
                     }
                 }
             } else {
                 echo "<div class='usercourseblock'>";
                 if ($regsRemaining > 0) {
                     echo "<a class='courseTitle anonLaunch' href='javascript:void(0);' key='{$courseId}' title='" . __("Click to launch course", "scormcloud") . " {$courseTitle}'>{$courseTitle}</a>";
                     echo "<div class='anonlaunchdiv' key='{$courseId}'>" . __("First Name", "scormcloud") . ":<br/><input name='scormcloudfname' type='text' key='{$courseId}'/><br/>";
                     echo __("Last Name", "scormcloud") . ":<br/><input name='scormcloudlname' type='text' key='{$courseId}'/><br/>";
                     echo __("Email", "scormcloud") . ":<br/><input name='scormcloudemail' type='text' key='{$courseId}'/>";
                     echo "<input name='launch' type='button' class='catalogLaunchBtn' key='{$courseId}' coursetitle='{$courseTitle}' onclick='ScormCloud.Widget.getAnonCatalogLaunchURL(\"{$courseId}\");' url='" . get_option('siteurl') . "/wp-content/plugins/scormcloud/ajax.php' value='" . __("Start Training", "scormcloud") . "'/>";
                     echo "<div class='launchMessage'>message</div></div>";
                 } else {
                     echo "<span class='courseTitle' title='" . __("This course is currently inactive.", "scormcloud") . "'>{$courseTitle}</span>";
                 }
             }
             echo "</div>";
         }
         echo '</div>';
         //echo '<script language="javascript">'.$widgetscript.'</script>';
         echo '<script language="javascript" src="' . get_option('siteurl') . '/wp-content/plugins/scormcloud/scripts/scormcloud.widget.js" >' . '</script>';
     }
     # After the widget
     echo $after_widget;
 }
 /**
  * Displays the Widget
  *
  */
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title']);
     $limitregs = isset($instance['limitregs']) ? (bool) $instance['limitregs'] : false;
     # Before the widget
     echo $before_widget;
     # The title
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     # Make the widget
     echo '<link rel="stylesheet" type="text/css" href="' . get_option('siteurl') . '/wp-content/plugins/scormcloud/css/scormcloud.widget.css" />';
     //echo '<h2>SCORM Course Registrations</h2>';
     global $current_user;
     global $wpdb;
     get_currentuserinfo();
     if (!is_user_logged_in()) {
         echo '<a href="wp-login.php">' . __("Log in", "scormcloud") . '</a> ' . __("to see your training history", "scormcloud") . '.';
     } else {
         $ScormService = ScormCloudPlugin::get_cloud_service();
         $regService = $ScormService->getRegistrationService();
         $invTable = ScormCloudDatabase::get_invitations_table();
         $regTable = ScormCloudDatabase::get_registrations_table();
         $query = $wpdb->prepare('SELECT reg.reg_id, inv.course_title, inv.course_id, inv.active, reg.update_date FROM ' . $regTable . ' reg
                                      JOIN ' . $invTable . ' inv ON reg.invite_id = inv.invite_id
                                      WHERE user_id = %s AND inv.blog_id = %s ORDER BY reg.update_date DESC', array($current_user->ID, $GLOBALS['blog_id']));
         $regs = $wpdb->get_results($query, OBJECT);
         //echo count($regs);
         echo '<div class="courselistDiv">';
         if (count($regs) > 0) {
             echo "<div class='helpMsg'>" . __("Click course title to launch.", "scormcloud") . "</div>";
         } else {
             echo "<div class='helpMsg'>" . __("You have not taken any training.", "scormcloud") . "</div>";
         }
         $coursesDisplayed = array();
         foreach ($regs as $reg) {
             try {
                 $regId = $reg->reg_id;
                 if ($limitregs && in_array($reg->course_id, $coursesDisplayed) || !$regService->Exists($regId)) {
                     continue;
                 } else {
                     $coursesDisplayed[] = $reg->course_id;
                     $regResultsXmlStr = $regService->GetRegistrationResult($regId, 0, 0);
                     $resXml = simplexml_load_string($regResultsXmlStr);
                     $completion = $resXml->registrationreport->complete;
                     $success = $resXml->registrationreport->success;
                     $seconds = $resXml->registrationreport->totaltime;
                     $score = $resXml->registrationreport->score;
                     $courseTitle = $reg->course_title;
                     echo "<div class='usercourseblock'>";
                     if ($reg->active == 1) {
                         echo "<a class='courseTitle' href='javascript:void(0);' key='{$regId}' onclick='ScormCloud.Widget.getLaunchURL(\"{$regId}\",\"Training\");' url='" . get_option('siteurl') . "/wp-content/plugins/scormcloud/ajax.php' title='Click to launch course {$courseTitle}'>{$courseTitle}</a>";
                     } else {
                         echo "<span class='courseTitle' title='" . __("This course is currently inactive.", "scormcloud") . "'>{$courseTitle}</span>";
                     }
                     echo "<br/><a href='javascript:void(0);' class='toggleButton showDetails' toggleobject='.courselistDiv .regs.courseDetails.{$regId}' onText='hide details' offText='show details'>" . __("show details", "scormcloud") . "</a>";
                     echo "<div class='regs courseDetails {$regId}' >";
                     if ($seconds > 0) {
                         echo "<div class=''>" . __("Completion", "scormcloud") . ": <span class='{$completion}'>{$completion}</span></div>";
                         echo "<div class=''>" . __("Success", "scormcloud") . ": <span class='{$success}'>{$success}</span></div>";
                         echo "<div class=''>" . __("Score", "scormcloud") . ": " . ($score == "unknown" ? "-" : $score . "%") . "</div>";
                         echo '<div class="time">' . floor($seconds / 60) . "min " . $seconds % 60 . __('sec spent in course', "scormcloud") . '</div>';
                     } else {
                         echo '<div class="">' . __("Not Started", "scormcloud") . '</div>';
                     }
                     echo "</div>";
                     //$widgetscript .= 'jQuery("#title_'.$reg->package_id.'").click(function(){jQuery("#details_'.$reg->package_id.'").toggle();});';
                     //$widgetscript .= 'jQuery("#title_'.$reg->package_id.'").hover(function(){jQuery(this).addClass("widgetTitleHover");},function(){jQuery(this).removeClass("widgetTitleHover");});';
                     echo '</div>';
                 }
             } catch (Exception $e) {
                 echo '<span>' . $e->getMessage() . '</span>';
             }
         }
         echo '</div>';
         //echo '<script language="javascript">'.$widgetscript.'</script>';
         echo '<script language="javascript" src="' . get_option('siteurl') . '/wp-content/plugins/scormcloud/scripts/scormcloud.widget.js" >' . '</script>';
     }
     # After the widget
     echo $after_widget;
 }
 public static function update_post_invite($postId)
 {
     global $wpdb;
     $post = get_post($postId);
     $content = $post->post_content;
     if ($parent_id = wp_is_post_revision($postId)) {
         $postId = $parent_id;
     }
     preg_match_all('/\\[scormcloud.training:.*\\]/', $content, $cloudTagArray);
     $cloudTags = $cloudTagArray[0];
     foreach ($cloudTags as $tagString) {
         $inviteId = substr($tagString, 21, strlen($tagString) - 22);
         $wpdb->update(ScormCloudDatabase::get_invitations_table(), array('post_id' => $postId), array('invite_id' => $inviteId));
     }
 }