Exemplo n.º 1
0
 function get_student($post, $student_id)
 {
     require_once __DIR__ . "/../../API/Psr4AutoloaderClass.php";
     $loader = new Psr4AutoloaderClass();
     $loader->register();
     $loader->addNamespace('InstructureCanvasAPI', __DIR__ . "/../../API/InstructureCanvasAPI/src");
     $API = new InstructureCanvasAPI\InstructureCanvasAPI(array("site" => get_post_meta($post->ID, "courseURL", true), "token" => get_post_meta($post->ID, "courseToken", true), "webService" => "CURL"));
     $user = new InstructureCanvasAPI\Courses\Users\Users();
     $user->setAPI($API);
     $data = $user->getProfile($student_id);
     $loader->unregister();
     return $data;
 }
 function check_users()
 {
     if (wp_verify_nonce($_POST['nonce'], "molie_admin_check")) {
         require_once __DIR__ . "/../../API/Psr4AutoloaderClass.php";
         $loader = new Psr4AutoloaderClass();
         $loader->register();
         $loader->addNamespace('InstructureCanvasAPI', __DIR__ . "/../../API/InstructureCanvasAPI/src");
         $API = new InstructureCanvasAPI\InstructureCanvasAPI(array("site" => get_post_meta($_POST['course'], "courseURL", true), "token" => get_post_meta($_POST['course'], "courseToken", true), "webService" => "CURL"));
         $course_id = get_post_meta($_POST['course'], "courseID", true);
         $roster = new InstructureCanvasAPI\Courses\Users\Users();
         $roster->setAPI($API);
         $roster->setCourseID($course_id);
         $data = $roster->getUsers();
         $diff = false;
         $user_diff = array();
         foreach ($data->content as $item) {
             global $wpdb;
             $data = $wpdb->get_results("select post_id from " . $wpdb->prefix . "postmeta where meta_key ='CanvasUserID' and meta_value like '%" . $item->id . "%'");
             if (count($data) == 0) {
                 $diff = true;
                 array_push($user_diff, $item);
             }
         }
         if ($diff) {
             echo json_encode(array($diff, $user_diff));
         } else {
             echo json_encode(array($diff, $user_diff));
         }
     } else {
         echo "Nonce failed";
     }
     wp_die();
 }
Exemplo n.º 3
0
    function roster()
    {
        if (isset($_POST['molie-roster-nonce'])) {
            if (wp_verify_nonce($_POST['molie-roster-nonce'], "molie-roster-nonce")) {
                $course_id = get_post_meta($_POST['course_id'], "courseID", true);
                $course_token = get_post_meta($_POST['course_id'], "courseToken", true);
                $course_url = get_post_meta($_POST['course_id'], "courseURL", true);
                $categories = $this->create_categories(get_post($_POST['course_id']));
                if (get_post_meta($_POST['course_id'], "canvasRosterPage", true) == "") {
                    $roster_post = wp_insert_post(array("post_type" => 'post', "post_status" => 'publish', "post_title" => __("Course Roster"), "post_author" => get_current_user_id()));
                    wp_set_post_categories($roster_post, $categories);
                    update_post_meta($roster_post, "CanvasRoster", "true", true);
                    update_post_meta($roster_post, "CanvasCourse", $course_id, true);
                    update_post_meta($_POST['course_id'], "canvasRosterPage", $roster_post, true);
                }
                require_once __DIR__ . "/../../API/Psr4AutoloaderClass.php";
                $loader = new Psr4AutoloaderClass();
                $loader->register();
                $loader->addNamespace('InstructureCanvasAPI', __DIR__ . "/../../API/InstructureCanvasAPI/src");
                $API = new InstructureCanvasAPI\InstructureCanvasAPI(array("site" => $course_url, "token" => $course_token, "webService" => "CURL"));
                $roster = new InstructureCanvasAPI\Courses\Users\Users();
                $roster->setAPI($API);
                $roster->setCourseID($course_id);
                $data = $roster->getUsers();
                if ($data) {
                    if (count($data->content) != 0) {
                        echo "<div id='molie_choose'>";
                        echo "<h2>" . __("Course users") . "</h2>";
                        echo "<div id='importProgress'><p><strong>" . __("Import Progress") . " <span id='importTotal'></span></strong></p><div id='importProgressBar'></div></div>";
                        echo '<form id="molie_choose_form" action="javascript:function connect(){return false;};">';
                        echo "<input type='submit' id='molie_roster_submit' value='" . __("Add to roster") . "' />";
                        echo "<input type='submit' id='molie_roster_skip' value='" . __("Skip step") . "' />";
                        echo "<p><span><a href='javascript:molie_select_all()'>" . __("Select All") . "</a></span> <span><a href='javascript:molie_unselect_all()'>" . __("Unselect All") . "</a></span></p>";
                        echo "<ul>";
                        foreach ($data->content as $student) {
                            echo "<li>";
                            if (get_post_meta($_POST['course_id'], "canvasStudent_" . $student->id, true) != "") {
                                $link_checked = "";
                                $link_info = __("Student already linked");
                            } else {
                                $link_checked = "checked";
                                $link_info = "";
                            }
                            echo "<input type='checkbox' " . $link_checked . " id='" . $student->id . "' course_post='" . $_POST['course_id'] . "'>" . $student->short_name . "<span id='update" . $student->id . "'>" . $link_info . "</span></li>";
                        }
                        echo "</ul>";
                        echo "<input type='submit' id='molie_roster_submit' value='" . __("Add to roster") . "' />";
                        echo "</form>";
                        echo "</div>";
                        echo "<div id='molie_calendar' style='display:none'>";
                        echo '<form method="post" action="' . admin_url("admin.php?page=molie_calendar") . '">';
                        echo "<input name='course_id' type='hidden' value='" . $_POST['course_id'] . "' />";
                        echo wp_nonce_field("molie-calendar-nonce", "molie-calendar-nonce");
                        echo "<input type='submit' value='" . __("Link Calendar") . "' />";
                        echo "</form>";
                        echo "</div>";
                    }
                }
                $loader->unregister();
            } else {
                print_r($_POST);
            }
        } else {
            $args = array("post_type" => "linkedcanvascourse", "post_status" => "publish");
            $courses = get_posts($args);
            if (count($courses) != 0) {
                echo "<h2>" . __("Choose a course") . "</h2>";
                $nonce = wp_create_nonce("molie-roster-nonce");
                foreach ($courses as $course) {
                    ?>
						<form method="post" action='<?php 
                    echo admin_url("admin.php?page=molie_roster");
                    ?>
'>
							<p><?php 
                    echo $course->post_title;
                    ?>
</p>
							<input type="hidden" name="molie-roster-nonce" value="<?php 
                    echo $nonce;
                    ?>
"/>
							<input type="hidden" name="url" value="<?php 
                    echo get_post_meta($course->ID, "courseURL", true);
                    ?>
" />
							<input type="hidden" name="token" value="<?php 
                    echo get_post_meta($course->ID, "courseToken", true);
                    ?>
" />
							<input name="course_id" type="hidden" value="<?php 
                    echo $course->ID;
                    ?>
" />
							<input type="submit" value="<?php 
                    echo __("Get Roster");
                    ?>
" />
						</form>
					<?php 
                }
            }
        }
    }