require_once("util/fns.inc");
require_once("html/study.inc");
$show_pay_info = true;
//if visiting old_reading, ok. otherwise still limited_access.
//limited_access(5);2 steps.
//used to show all bookmarked subjects. Simplified.
pre_check();//limited_access: step 1 - session, db connect.
$dbo = db_connect_dbo();
$exam_guide_id = get_user_exam_guide_id();
if(isset($_REQUEST['id'])) {
$id = $_REQUEST['id'];
}
else if (isset($_REQUEST['module_link'])) {
$rid_clause = get_module_id_clause();//rid range
$query = "select rid as id from reading where link = ? " . $rid_clause;
$id = get_study_id_by_link_dbo($query, $_REQUEST['module_link']);
if($id == 0 && is_guest()) {
$query = "select rid as id from reading where link = ?";
$id = get_study_id_by_link_dbo($query, $_REQUEST['module_link']);
}
if($id == 0) {
$query = "select rid as id from old_reading where link = ?";
$id = get_study_id_by_link_dbo($query, $_REQUEST['module_link']);
}
}
if(!is_numeric($id)) {
show_user_error();
exit;
}
$id = intval($id);
if($id > 500) {
show_old_reading($id);
exit;
}
//limited_access: step 2
if(!can_access_member_page(5)) {
exit;
}
//restricted access:
if(!validate_id($id) || !cross_level_check(2, $id)) {
$msg = "";
if(is_logged_on()) {
$msg = "User cannot access module $id. Exam Guide ID: " . $_SESSION['user']['exam_guide_id'];
}
show_user_error("", $msg);
exit;
}
$custom_js = get_learning_module_jquery_js($id);
if(is_guest()) {
$exam_guide_id = get_exam_guide_id_by_reading_id($id);
set_up_exam_guide_id_for_guest($exam_guide_id);
}
$query = "select ss.ssid as ssid, ss.number as ssnumber, ss.value as ssvalue, r.rid as rid,
r.ssid as rssid, r.number as rnumber, r.value as rvalue, r.status as rstatus " .
"from study_session ss, reading r where r.rid= $id and ss.ssid = r.ssid";
$result = do_mysqli_query($query);
if(mysqli_num_rows($result) == 0) {
show_restricted_access("no module for rid " . $id);
exit;
}
$rrow = mysqli_fetch_array($result);
$reading_status = $rrow['rstatus'];
//Consistent with session.inc
//unless the user manipulate the url param, it should not get here.
//don't show the module link to: the module is 'not ready' (status = 3), and the user is paid.
//for other users, show all subjects to lure them.
if($reading_status == 3 && is_paid_user()) {
show_restricted_access("module not ready yet: $id");
exit;
}
//get complete and bookmarked subjects: one query instead of one subject per query!
$completeids = array();
$bookmarkids = array();
$my_reading_status = 0;
if(is_logged_on()) {
$my_reading_status = get_notes_status($id, 2);
$query = "select sua.subid, sua.status, bookmark from sub_user_assgnmt sua, subject sub where sua.subid = sub.subid " .
"and sub.rid = " . $id . " and (sua.status != 0 or sua.bookmark != 0) and sua.userId = " . $_SESSION['user']['id'];
$result = do_mysqli_query($query);
$count = mysqli_num_rows($result);
$completecount = 0; $bookmarkcount = 0;
//the real complete:bookmark ratio = 25:1. focus on complete.
for($i=0; $i<$count; $i++) {
$rowsua = mysqli_fetch_array($result);
if($rowsua['status'] == 1) {
$completeids[$completecount++] = $rowsua['subid'];
}
if($rowsua['bookmark'] == 1) {
$bookmarkids[$bookmarkcount++] = $rowsua['subid'];
}
}
}
$exam_name = get_exam_name_for_user();
$link_study_all = build_study_all_link();
$link_topic = build_topic_link_title($rrow['ssid']);
$link_module = build_module_link_title($id);
$private_note = get_private_note($id, 1);
$breadcrumb = array(array($link_study_all, "$exam_name"),
array($link_topic, "Topic " . $rrow['ssnumber'] . ". " . $rrow['ssvalue']),
array("", "Learning Module " . $rrow['rnumber'] . ". " . $rrow['rvalue']));
print_page_header("Topic " . $rrow['ssnumber'] . ". " . $rrow['ssvalue'] . " - Learning Module " . $rrow['rnumber'] . ". " . $rrow['rvalue'], $link_module);
print_breadcrumb($breadcrumb);
print_container_start();
print_main_section_start();
print_subject_list_card();
print_section_end();
//side
print_side_section_start();
print_rotating_image();
print_testimonial();
print_flashcard_box(1);
print_reading_action_links();
print_side_section_end();
print_container_end();
print_footer();
//the underlying link is the same. just the list shown is sujects, not los.
function print_subject_list_card() {
global $rrow, $show_pay_info;
$rssid = $rrow['rssid'];
$id = $rrow['rid'];
if(!validate_id($id)) {
return;
}
$subids = array();
//special: ethics readings (don't show los repeatly) or CFAI visits.
$show_los = show_los_for_reading($id) && can_show_los();
print_card_start();
?>
if($rrow['rstatus'] == 3) {
show_los_list_for_not_ready_reading($rrow['rid']);
print_card_end();
return $subids;
}
print_study_table_start();
$query = "select subid, number, value, status from subject where rid = ". $id . " order by number";
$result = do_mysqli_query($query);
$count = mysqli_num_rows($result);
for($i=0; $i<$count; $i++) {
$row = mysqli_fetch_array($result);
$subids[$i] = $row['subid'];
print_value_per_status($show_los, $row);
}
print_study_table_end();
print_card_end();
return $subids;
}
function print_reading_action_links() {
global $rrow, $my_reading_status, $private_note;
$id = $rrow['rid'];
$title_flashcard = "Add my flashcard";
if($private_note) {
$title_flashcard = "Edit my flashcard";
}
print_card_start_with_header("Actions");
?>
if(is_guest()) {
print_study_button_for_modal("pdf", "download", "PDF Download");
print_study_button_for_modal("print", "print", "Print module notes");
print_study_button_link("", "Mark this module complete once you log in.", "check", "Mark as complete");
print_study_button_link("", "Log in to make my own flashcard for this module.", "film", $title_flashcard);
print_study_button_for_modal("print", "print", "Print quiz questions");
}
else {
//removed is_cellphone. show the links. simply don't let unpaid users to print the entire module.
if(is_paid_user_full()) {//unpaid user can print a few pages here, as long as there's still room.
$printable = "JavaScript:scrollingPopupBig('print.php?id=$id&type=1')";
$printableBasics = "JavaScript:scrollingPopupBig('print.php?id=$id&type=3')";
print_study_button_link($printable, "Print out study notes for module " . $rrow['rnumber'], "print", "Print module notes");
print_study_button_link($printableBasics, "Print out all basic questions for module " . $rrow['rnumber'], "print", "Print Questions");
}
else {
print_study_button_for_modal("pdf", "download", "PDF Download");
print_study_button_for_modal("print", "print", "Print module notes");
print_study_button_for_modal("print", "print", "Print quiz questions");
}
//to mark it incomplete, need to go the session level, or unmark a los.
//Simplify: don't bother to add a unmark button. or mark all subjects.
if($my_reading_status == 0) {//"Module marked complete",
print_study_button_js_id("complete_button", "Mark this module as complete", "check", "Mark as complete");
print_study_button_js_id("incomplete_button", "Remove this module from complete list", "times", "Mark as incomplete", false);
}
else {
print_study_button_js_id("complete_button", "Mark this subject as complete", "check", "Mark as complete", false);
print_study_button_js_id("incomplete_button", "Remove this subject from complete list", "times", "Mark as incomplete");
}
print_study_button_for_modal("modal-add-note", "film", $title_flashcard);
}
?>
print_module_action_msgs();
print_card_end();
//don't show this to paid users before pdf is implemented. ask them to print and save pdf.
if(!is_paid_user()) {
$msg_pdf = "Download study notes in a PDF file immediately.";
print_modal_for_payment("pdf", $msg_pdf);
}
if(!can_user_print()) {
print_modal_for_payment("print", get_disabled_print_msg());
}
print_private_note_modal($id, 11, $private_note);
}
function print_value_per_status($can_show_los, $row) {
global $completeids, $bookmarkids;
$value = $row['number'] . ". " . cleanup_notes_html($row['value']);
if(!validate_id($row['subid'])) {
return;
}
$blocked = (is_restricted_user() && $row['status'] != 2);
$available = $row['status'] != 3;
$link_subject = build_subject_link_title_from_subid($row['subid']);
echo "";
if(is_logged_on()) {
if($blocked) {
echo " ";
}
else if($available) {
if(in_array($row['subid'], $completeids)) {
$desc = 'Mark this LOS as incomplete';
$image = 'checked.gif';
}
else {
$desc = 'Mark this LOS as complete';
$image = 'unchecked.gif';
}
echo " ";
}
else {//not available for paid or logged on trial users.
echo " ";
}
}
else {//guest
echo "";
}
echo " | ";
if(!$blocked && $available) {
echo "$value";
if(in_array($row['subid'], $bookmarkids)) {
echo " ";
}
}
else if ($blocked) {
echo "$value";
}
else {//not available
echo "$value";
}
if($can_show_los) {
$query = "select * from los_main where id in (select losid from los_subject where subid = " . $row['subid'] . ")";
$result_lm = do_mysqli_query($query);
echo " ";
while($row_lm = mysqli_fetch_array($result_lm)) {
echo "" . $row_lm['value'] . "";
}
}
echo " |
";
}
function get_module_id_clause() {
$exam_guide_id = get_user_exam_guide_id();
$min_rid = ($exam_guide_id -1) * 100;
return " and rid > $min_rid and rid < " . ($min_rid + 100);
}
function show_los_list_for_not_ready_reading($rid) {
if(!validate_id($rid)) {
return;
}
$query = "select * from los_main where rid = ". $rid . " order by id";
$result = do_mysqli_query($query);
print_study_table_start();
while($row = mysqli_fetch_array($result)) {
echo " | " .
$row['value'] . " |
";
}
print_study_table_end();
}
function show_old_reading($id) {
//query the same table again but ok: no need to complicate by simplifying.
$result = do_mysqli_query("select * from old_reading where rid = " . $id);
//should not be possible as id exists, and redundent, but check anyway.
if(mysqli_num_rows($result) == 0) {
show_user_error();
return;
}
$row = mysqli_fetch_array($result);
do_mysqli_query("update old_reading set visit = visit + 1 where rid = $id");
$breadcrumb = array();
print_page_header("Learning Outcome Statements", $row['link']);
print_breadcrumb($breadcrumb);
print_container_start();
//main:
print_main_section_start_with_card_header("Learning Outcome Statements", "bars");
$thead = "| " . $row['title'] . " |
";
print_study_table_start($thead);
$query = "select * from old_subject where rid = $id order by subid";
$result = do_mysqli_query($query);
while($row = mysqli_fetch_array($result)) {
echo "| ";
echo "" .
cleanup_notes_html($row['title']) . " ";
echo " |
";
}
print_study_table_end();
print_card_section_end();
//side_column
print_side_section_start();
print_rotating_image();
print_side_study_title_only("Learning Outcome Statements from a previous year's CFA study guide.");
print_side_section_end();
print_container_end();
print_footer();
}
function get_learning_module_jquery_js($id) {
if(is_guest()) {
return "";
}
$js = "";
return $js;
}
function print_module_action_msgs() {
?>
Module marked as complete.
Module marked as incomplete.
}
?>