function update_pano_user_progress() { // Get the user id and hotspot id $user_id = get_current_user_id(); $points = 0; $points_allowed = false; // Make sure a numeric id is supplied if (is_numeric($_POST['hotspot'])) { $hotspot_id = $_POST['hotspot']; } else { $hotspot_id = 0; } if (is_numeric($_POST['domain_id'])) { $domain_id = $_POST['domain_id']; } else { $domain_id = 0; } // Update the user progress if ($user_id == 0) { // maybe do session stuff? } else { // Check if the user is allowed to get points $points_allowed = check_points($user_id, $hotspot_id); // If yes, give them points if ($points_allowed) { $points = add_user_progress($user_id, $hotspot_id, $domain_id); } } // Return the points associated to flash on the screen echo $points; die; // this is required to terminate immediately and return a proper response }
} // Process setting all if (isset($_POST["values"]) && isset($_POST["save"])) { $write_mode = TRUE; if (!$course->is_admin($user)) { throw new Exception("No course admin!", E_ACCESS); } $values = $_POST["values"]; $points = $values["points"]; $maxpoints = $values["maxpoints"]; if (!is_array($points)) { $points = array(); } $error = FALSE; foreach ($points as $key => $p) { if (!check_points(array($key => $p), $maxpoints)) { $error = TRUE; break; // end the excecution } } if ($error) { $problems .= gettext("Invalid values"); $hints .= gettext("Please correct the invalid values and save again"); } if (empty($problems)) { $proxy = $unit->get_attribute("UNIT_POINTLIST_PROXY"); //$proxy->set_attribute("UNIT_POINTLIST_POINTS", $points); foreach ($points as $key => $p) { $akey = "UNIT_POINTLIST_POINTS_" . $key; $proxy->set_attribute($akey, $p, TRUE);
// X value = 0.00 : 100.00 for ($j = 0; $j < $n_points_per_row; $j++) { $row[] = mt_rand(-1000, 1000) / 100.0; // Y value -10.00 - 10.00 } $data[] = $row; } # This will hold the generated map points: $points = array(); $plot = new PHPlot(800, 600); $plot->SetFailureImage(False); // No error images $plot->SetPrintImage(False); // No automatic output $plot->SetDataValues($data); $plot->SetDataType('data-data'); $plot->SetPlotType('points'); $plot->SetCallback('data_points', 'store_map', $data); $plot->DrawGraph(); // For validation of error checks: // $points[] = array(100,100); // Add a point // unset($points[1][2]); // Delete a point // $points[3][2][0]++; // Corrupt an X // $points[1][0][1] = 0; // Corrupt a Y $errors = check_points($plot, $data, $n_rows, $n_points_per_row, $points); $name = 'points plot image map unit test'; if ($errors > 0) { fwrite(STDERR, "Failed: {$errors} error(s) in {$name}\n"); exit(1); } echo "Passed: no errors in {$name}\n";
} elseif ($data_type == 'data-data') { $data = array(array('', 0, 5, 6, 10), array('', 1, 4, 8, 2), array('', 2, 1, 0, 15), array('', 3, 9, 8, 0)); $n_segments = count($data[0]) - 2; } elseif ($data_type == 'text-data') { $data = array(array('', 5, 6, 10, 8, 5), array('', 1, 2, 1, 2, 6)); $n_segments = count($data[0]) - 1; } else { die("Invalid data type: {$data_type}"); } # This will hold the generated map points: $points = array(); $plot = new PHPlot(800, 600); $plot->SetFailureImage(False); // No error images $plot->SetPrintImage(False); // No automatic output $plot->SetDataValues($data); $plot->SetDataType($data_type); $plot->SetPlotType('pie'); $plot->SetCallback('data_points', 'store_map', $data); $plot->DrawGraph(); // For validation of error checks: // $points[] = array(1,2,3,4,5,6); // Add a point // unset($points[2]); // Delete a point $errors = check_points($data, $n_segments, $points); $name = "pie chart image map unit test ({$data_type}, {$n_segments} segments)"; if ($errors > 0) { fwrite(STDERR, "Failed: {$errors} error(s) in {$name}\n"); exit(1); } echo "Passed: no errors in {$name}\n";