function get_content()
 {
     global $CFG, $USER, $COURSE;
     if (!empty($this->content)) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     $this->content->text = '';
     if (!($att = array_pop(get_all_instances_in_course('attforblock', $COURSE, NULL, true)))) {
         $this->content->text = get_string('needactivity', 'block_attendance');
         return $this->content;
     }
     $cmid = $att->coursemodule;
     require_once $CFG->dirroot . '/mod/attforblock/locallib.php';
     if (!($context = get_context_instance(CONTEXT_MODULE, $cmid))) {
         print_error('badcontext');
     }
     // link to attendance
     if (has_capability('mod/attforblock:takeattendances', $context) or has_capability('mod/attforblock:changeattendances', $context)) {
         $this->content->text .= '<a href="' . $CFG->wwwroot . '/mod/attforblock/manage.php?id=' . $cmid . '&amp;from=block">' . get_string('takeattendance', 'attforblock') . '</a><br />';
     }
     if (has_capability('mod/attforblock:manageattendances', $context)) {
         $this->content->text .= '<a href="' . $CFG->wwwroot . '/mod/attforblock/sessions.php?id=' . $cmid . '&amp;action=add">' . get_string('add', 'attforblock') . '</a><br />';
     }
     if (has_capability('mod/attforblock:viewreports', $context)) {
         $this->content->text .= '<a href="' . $CFG->wwwroot . '/mod/attforblock/report.php?id=' . $cmid . '&amp;view=weeks">' . get_string('report', 'attforblock') . '</a><br />';
     }
     if (has_capability('mod/attforblock:export', $context)) {
         $this->content->text .= '<a href="' . $CFG->wwwroot . '/mod/attforblock/export.php?id=' . $cmid . '">' . get_string('export', 'quiz') . '</a><br />';
     }
     if (has_capability('mod/attforblock:changepreferences', $context)) {
         $this->content->text .= '<a href="' . $CFG->wwwroot . '/mod/attforblock/attsettings.php?id=' . $cmid . '">' . get_string('settings', 'attforblock') . '</a><br />';
     }
     $context2 = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     if (has_capability('moodle/course:view', $context) && has_capability('mod/attforblock:view', $context)) {
         $complete = get_attendance($USER->id, $COURSE);
         if ($complete == 0) {
             //attendance not generated yet
             $this->content->text .= get_string('attendancenotstarted', 'attforblock');
         } else {
             //attendance taken
             $statuses = get_statuses($COURSE->id);
             foreach ($statuses as $st) {
                 $this->content->text .= $st->description . ':&nbsp;' . get_attendance($USER->id, $COURSE, $st->id) . '<br />';
             }
             $percent = get_percent($USER->id, $COURSE);
             $grade = get_grade($USER->id, $COURSE);
             $this->content->text .= get_string('attendancepercent', 'attforblock') . ':&nbsp;' . $percent . '&nbsp;%<br />';
             $this->content->text .= get_string('attendancegrade', 'attforblock') . ":&nbsp;{$grade}<br />";
             $this->content->text .= '<a href="' . $CFG->wwwroot . '/mod/attforblock/view.php?id=' . $cmid . '">' . get_string('indetail', 'attforblock') . '</a>';
         }
     }
     return $this->content;
 }
 $tnow += 60 * 60 * $config['raidattendance_timezone'];
 $tstamp = $tstamp > 0 ? $tstamp : $tnow;
 $now = strftime('%H:%M', $tnow);
 $today = strftime('%Y%m%d', $tnow);
 $raid_time = $config['raidattendance_raid_time'];
 $signoff_time = $config['raidattendance_raid_late'];
 $raids = get_raiding_days($tstamp, $raid_id);
 $raider_db = new raider_db();
 $raiders = array();
 $raider_db->get_raider_list($raiders, $raid_id, $sort_order);
 $action = request_var('u_action', '');
 if ($action) {
     handle_action($action, $raiders);
 }
 $day_names = get_raiding_day_names($raids);
 $attendance = get_attendance($raids, $raid_id);
 $static_attendance = get_static_attendance($raids);
 add_static_attendance($raids, $attendance, $static_attendance);
 $rowno = 0;
 $statusses = array(STATUS_ON => 'on', STATUS_OFF => 'off', STATUS_NOSHOW => 'noshow', STATUS_LATE => 'late', STATUS_SUBSTITUTE => 'substitute', 0 => 'future', -1 => 'past', -2 => 'unset', STATUS_LATE_SIGNOFF => 'late_signoff');
 $raid_sums = array();
 $raidData = array();
 // data used in the addon...
 $armory_link = $config['raidattendance_armory_link'];
 $realm = $config['raidattendance_realm_name'];
 $url_base = $armory_link . '/character-sheet.xml?r=' . urlencode($realm) . '&cn=';
 $date_array = getdate($tstamp);
 $last_week = mktime(0, 0, 0, $date_array['mon'], $date_array['mday'] - 7, $date_array['year']);
 $next_week = mktime(0, 0, 0, $date_array['mon'], $date_array['mday'] + 7, $date_array['year']);
 $dump_months = request_var('dump_months', 1);
 $dump_start = mktime(0, 0, 0, $date_array['mon'] - $dump_months, $date_array['mday'], $date_array['year']);
function attforblock_user_outline($course, $user, $mod, $attforblock)
{
    /// Return a small object with summary information about what a
    /// user has done with a given particular instance of this module
    /// Used for user activity reports.
    /// $return->time = the time they did it
    /// $return->info = a short text description
    require_once 'locallib.php';
    $result = false;
    // this line was added as per Juan Carlos Rodr&#237;guez-del-Pino advice
    if (isstudent($course->id, $user->id)) {
        if ($sescount = get_attendance($user->id, $course)) {
            $strgrade = get_string('grade');
            $maxgrade = get_maxgrade($user->id, $course);
            $usergrade = get_grade($user->id, $course);
            $percent = get_percent($user->id, $course);
            $result->info = "{$strgrade}: {$usergrade} / {$maxgrade} ({$percent}%)";
        }
    }
    return $result;
}
$A_perm = get_events_attended($facebook_id, $conn);
$N_perm = get_events_not_attended($facebook_id, $conn);
$user_ids = get_user_ids($facebook_id, $conn);
//echo "count : ", count($user_ids), "<br>";
$similarity_indices = array();
foreach ($user_ids as $id) {
    $A_2 = get_events_attended($id, $conn);
    $N_2 = get_events_attended($id, $conn);
    $similarity_indices["{$id}"] = calculate_similarity_index($A_perm, $N_perm, $A_2, $N_2);
    //echo $id, " ------ ", $similarity_indices["$id"], "<br>";
}
$event_ids = get_events($conn);
$event_probablity = array();
foreach ($event_ids as $event_id) {
    //echo $event_id, " : ";
    $users_attending = get_attendance($event_id, $facebook_id, $conn);
    $sum_similarity;
    settype($sum_similarity, "float");
    $sum_similarity = 0.0;
    foreach ($users_attending as $user) {
        //echo "sim of user_index(" , $user, ") is ---", $similarity_indices["$user"], "<br>";
        $sum_similarity += $similarity_indices["{$user}"];
    }
    if (count($users_attending) != 0) {
        $event_probablity["{$event_id}"] = floatval($sum_similarity / count($users_attending));
    } else {
        $event_probablity["{$event_id}"] = 0.0;
    }
    //echo "sum sim ", $sum_similarity, "count : ", count($users_attending), "<br>";
    //echo $event_probablity["$event_id"], "<br>";
}
 function attendance_form_html($formid = '', $extraclass = '', $rows = '2', $cols = '40')
 {
     $index = !empty($formid) ? '[' . $formid . ']' : '';
     $formid_suffix = !empty($formid) ? '_' . $formid : '';
     $output = '';
     //        if (!$atn = cm_get_attendance($this->classid, $this->userid)) {
     if (!($atn = get_attendance($this->classid, $this->userid))) {
         $atn = new attendance();
     }
     $output .= '<style>' . $this->_editstyle . '</style>';
     $output .= '<fieldset id="cmclasseditform' . $formid . '" class="cmclasseditform ' . $extraclass . '">' . "\n";
     $output .= '<legend>' . get_string('edit_student_attendance', 'block_curr_admin') . '</legend>' . "\n";
     $output .= '<label for="timestart' . $formid . '" id="ltimestart' . $formid . '">Start Date:<br />';
     $output .= cm_print_date_selector('startday', 'startmonth', 'startyear', $atn->timestart, true);
     $output .= '</label><br /><br />';
     $output .= '<label for="timeend' . $formid . '" id="ltimeend' . $formid . '">End Date:<br />';
     $output .= cm_print_date_selector('endday', 'endmonth', 'endyear', $atn->timeend, true);
     $output .= '</label><br /><br />';
     $output .= '<label for="note' . $formid . '" id="lnote' . $formid . '">Note:<br />';
     $output .= '<textarea name="note' . $index . '" cols="' . $cols . '" rows="' . $rows . '" ' . 'id="note' . $formid . '" class="attendanceeditform ' . $extraclass . '">' . $atn->note . '</textarea>' . "\n";
     $output .= '</label>';
     $output .= '<input type="hidden" name="id' . $index . '" value="' . $this->id . '" />' . "\n";
     $output .= '<input type="hidden" name="class" value="' . $this->classid . '" />';
     $output .= '<input type="hidden" name="userid" value="' . $this->userid . '" />';
     $output .= '<input type="hidden" name="atnid' . $index . '" value="' . $atn->id . '" />' . "\n";
     $output .= '</fieldset>';
     return $output;
 }
function print_user_attendaces($user, $cm, $course = 0, $printing = null)
{
    global $CFG, $COURSE, $DB, $OUTPUT, $mode;
    echo '<table class="userinfobox">';
    if (!$printing) {
        echo '<tr>';
        echo '<td colspan="2" class="generalboxcontent"><div align="right">';
        echo $OUTPUT->help_icon('studentview', 'attforblock', get_string('attendancereport', 'attforblock'));
        //helpbutton(, , , true, false, '', true).
        //"<a href=\"view.php?id={$cm->id}&amp;student={$user->id}&amp;mode=$mode&amp;printing=yes\" target=\"_blank\">[".get_string('versionforprinting','attforblock').']</a></div></td>';
        echo '</tr>';
    }
    //    echo '<tr>';
    //    echo '<th colspan="2"><h2 class="main help"><center>'.get_string('attendancereport','attforblock').helpbutton('studentview', get_string('attendancereport','attforblock'), 'attforblock', true, false, '', true).'</center></h1></th>';
    //    echo '</tr>';
    echo '<tr>';
    echo '<td class="left side">';
    echo $OUTPUT->user_picture($user, array($COURSE->id));
    echo '</td>';
    echo '<td class="generalboxcontent">';
    echo '<font size="+1"><b>' . fullname($user) . '</b></font>';
    if ($course) {
        echo '<hr />';
        $complete = get_attendance($user->id, $course);
        if ($complete) {
            print_attendance_table($user, $course);
        } else {
            echo get_string('attendancenotstarted', 'attforblock');
        }
    } else {
        $stqry = "SELECT ats.courseid \n\t\t\t\t\tFROM {attendance_log} al \n\t\t\t\t\tJOIN {attendance_sessions} ats \n\t\t\t\t\t  ON al.sessionid = ats.id\n\t\t\t\t   WHERE al.studentid = ?\n\t\t\t\tGROUP BY ats.courseid\n\t\t\t\tORDER BY ats.courseid asc";
        $recs = $DB->get_records_sql_menu($stqry, array($user->id));
        foreach ($recs as $courseid => $value) {
            echo '<hr />';
            echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="list1">';
            $nextcourse = $DB->get_record('course', array('id' => $courseid));
            echo '<tr><td valign="top"><strong>' . $nextcourse->fullname . '</strong></td>';
            echo '<td align="right">';
            $complete = get_attendance($user->id, $nextcourse);
            if ($complete) {
                print_attendance_table($user, $nextcourse);
            } else {
                echo get_string('attendancenotstarted', 'attforblock');
            }
            echo '</td></tr>';
            echo '</table>';
        }
    }
    if ($course) {
        $stqry = "SELECT ats.sessdate,ats.description,al.statusid,al.remarks \n\t\t\t\t\tFROM {attendance_log} al \n\t\t\t\t\tJOIN {attendance_sessions} ats \n\t\t\t\t\t  ON al.sessionid = ats.id\n\t\t\t\t   WHERE ats.courseid = ? AND al.studentid = ? \n\t\t\t\tORDER BY ats.sessdate asc";
        if ($sessions = $DB->get_records_sql($stqry, array($course->id, $user->id))) {
            $statuses = get_statuses($course->id);
            ?>
			<div id="mod-assignment-submissions">
			<table align="left" cellpadding="3" cellspacing="0" class="submissions">
			  <tr>
				<th>#</th>
				<th align="center"><?php 
            print_string('date');
            ?>
</th>
				<th align="center"><?php 
            print_string('time');
            ?>
</th>
				<th align="center"><?php 
            print_string('description', 'attforblock');
            ?>
</th>
				<th align="center"><?php 
            print_string('status', 'attforblock');
            ?>
</th>
				<th align="center"><?php 
            print_string('remarks', 'attforblock');
            ?>
</th>
			  </tr>
			  <?php 
            $i = 1;
            foreach ($sessions as $key => $session) {
                ?>
			  <tr>
				<td align="center"><?php 
                echo $i++;
                ?>
</td>
				<td><?php 
                echo userdate($session->sessdate, get_string('str_ftimedmyw', 'attforblock'));
                //userdate($students->sessdate,'%d.%m.%y&nbsp;(%a)', 99, false);
                ?>
</td>
				<td><?php 
                echo userdate($session->sessdate, get_string('str_ftimehm', 'attforblock'));
                ?>
</td>
				<td><?php 
                echo empty($session->description) ? get_string('nodescription', 'attforblock') : $session->description;
                ?>
</td>
				<td><?php 
                echo $statuses[$session->statusid]->description;
                ?>
</td>
				<td><?php 
                echo $session->remarks;
                ?>
</td>
			  </tr>
			  <?php 
            }
            echo '</table>';
        } else {
            echo $OUTPUT->heading(get_string('noattforuser', 'attforblock'));
        }
    }
    echo '</td></tr><tr><td>&nbsp;</td></tr></table></div>';
}
        foreach ($students as $student) {
            $table->data[$student->id][] = print_user_picture($student->id, $course->id, $student->picture, 20, true, true);
            $table->data[$student->id][] = "<a href=\"view.php?id={$id}&amp;student={$student->id}\">" . fullname($student) . '</a>';
            foreach ($course_sess as $sessdata) {
                if ($att = get_record('attendance_log', 'sessionid', $sessdata->id, 'studentid', $student->id)) {
                    if (isset($statuses[$att->statusid])) {
                        $table->data[$student->id][] = $statuses[$att->statusid]->acronym;
                    } else {
                        $table->data[$student->id][] = '<font color="red"><b>' . $allstatuses[$att->statusid]->acronym . '</b></font>';
                    }
                } else {
                    $table->data[$student->id][] = '-';
                }
            }
            foreach ($statuses as $st) {
                $table->data[$student->id][] = get_attendance($student->id, $course, $st->id);
            }
            $table->data[$student->id][] = get_grade($student->id, $course) . '&nbsp;/&nbsp;' . get_maxgrade($student->id, $course);
            $table->data[$student->id][] = get_percent($student->id, $course) . '%';
        }
        echo '<br />';
        print_table($table);
    } else {
        print_heading(get_string('nothingtodisplay'), 'center');
    }
    echo get_string('status', 'attforblock') . ':<br />';
    foreach ($statuses as $st) {
        echo $st->acronym . ' - ' . $st->description . '<br />';
    }
}
print_footer($course);
                     echo '<th id="tshowstudent" name="tshowstudent">' . get_string('student', 'attforblock') . '</th>';
                     echo '<th id="tshowcourse" name="tshowcourse">' . get_string('course') . '</th>';
                     $statuses = get_statuses($course->id);
                     foreach ($statuses as $st) {
                         echo '<th>' . $st->description . '</th>';
                     }
                     echo '<th>' . get_string('grade') . '</th>';
                     echo '<th>%</th></tr><tr><td></td>';
                     echo '</tr></thead>';
                     echo '<tbody><tr>';
                     echo '<td id="tshowstudent" name="tshowstudent">';
                     echo "<a href=\"view.php?id={$id}&amp;student={$student->id}\">" . fullname($student);
                     echo '</a></td><td id="tshowcourse" name="tshowcourse">';
                     echo "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . $course->fullname . '</a></td>';
                     foreach ($statuses as $st) {
                         echo '<td>' . get_attendance($student->id, $course, $st->id) . '</td>';
                     }
                     echo '<td>' . get_grade($studentselected, $course) . '&nbsp;/&nbsp;' . get_maxgrade($student->id, $course) . '</td>';
                     echo '<td>' . get_percent($studentselected, $course) . '%' . '</td>';
                     echo '</tr></tbody></table>';
                 }
                 if ($reportselected === 'all' or $reportselected === 'detailed') {
                     echo '<h3>' . "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . $course->fullname . '</a></h3>';
                     print_detailed_report($studentselected, $cm, $course->id);
                 }
             }
         }
     }
 }
 if ($reportselected === 'detailed') {
     echo '</table>';
function attforblock_user_outline($course, $user, $mod, $attforblock)
{
    /// Return a small object with summary information about what a
    /// user has done with a given particular instance of this module
    /// Used for user activity reports.
    /// $return->time = the time they did it
    /// $return->info = a short text description
    require_once 'locallib.php';
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    if (has_capability('moodle/course:view', $context)) {
        //if (isstudent($course->id, $user->id)) {
        if ($sescount = get_attendance($user->id, $course)) {
            $strgrade = get_string('grade');
            $maxgrade = get_maxgrade($user->id, $course);
            $usergrade = get_grade($user->id, $course);
            $percent = get_percent($user->id, $course);
            $result->info = "{$strgrade}: {$usergrade} / {$maxgrade} ({$percent}%)";
        }
    }
    return $result;
}
function print_cleared_items($user, $cm, $course = 0, $printing = null)
{
    global $CFG, $COURSE, $mode;
    echo '<table class="userinfobox">';
    if (!$printing) {
        echo '<tr>';
        echo '<td colspan="2">' . helpbutton('studentview', get_string('attendancereport', 'attforblock'), 'attforblock', true, false, '', true) . "<a href=\"view.php?id={$cm->id}&amp;student={$user->id}&amp;mode={$mode}&amp;printing=yes\" >[" . get_string('versionforprinting', 'attforblock') . ']</a></td>';
        echo '</tr>';
    }
    echo '<tr>';
    echo '<td class="left side">';
    print_user_picture($user->id, $COURSE->id, $user->picture, true);
    echo '</td>';
    echo '<td class="generalboxcontent">';
    echo '<h1><b>' . fullname($user) . '</b></h1>';
    if ($course) {
        echo '<hr />';
        $complete = get_attendance($user->id, $course);
        if ($complete) {
            print_attendance_table($user, $course);
        } else {
            echo get_string('nocleareditems', 'attforblock');
        }
    } else {
        $stqry = "\n            SELECT ats.id,ats.courseid\n            FROM {$CFG->prefix}attendance_log al\n            JOIN {$CFG->prefix}attendance_sessions ats\n            ON al.sessionid = ats.id\n            WHERE al.studentid = {$user->id}\n            GROUP BY ats.courseid\n            ORDER BY ats.courseid asc";
        $recs = get_records_sql_menu($stqry);
        foreach ($recs as $id => $courseid) {
            echo '<hr />';
            echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="list1">';
            $nextcourse = get_record('course', 'id', $courseid);
            echo '<tr><td valign="top"><strong>' . $nextcourse->fullname . '</strong></td>';
            echo '<td align="right">';
            $complete = get_attendance($user->id, $nextcourse);
            if ($complete) {
                print_attendance_table($user, $nextcourse);
            } else {
                echo get_string('nocleareditems', 'attforblock');
            }
            echo '</td></tr>';
            echo '</table>';
        }
    }
    if ($course) {
        $stqry = "\n            SELECT ats.sessdate,ats.sessiontitle,ats.subject,ats.teacher,ats.description,al.statusid,al.remarks,al.makeupnotes,al.sicknote\n            FROM {$CFG->prefix}attendance_log al\n            JOIN {$CFG->prefix}attendance_sessions ats\n            ON al.sessionid = ats.id\n            WHERE al.studentid = {$user->id} AND al.makeupnotes = 'cleared' AND (al.sicknote = 'cleared' OR al.sicknote = 'notrequired')\n            ORDER BY ats.sessdate asc";
        if ($sessions = get_records_sql($stqry)) {
            $statuses = get_statuses($course->id);
            ?>
            <div id="mod-assignment-submissions">
            <table
                align="left"
                cellpadding="3"
                cellspacing="0"
                class="submissions"
            >
                <tr>
                    <th>#</th>
                    <th align="center"><?php 
            print_string('date');
            ?>
</th>
                    <th align="center"><?php 
            print_string('time');
            ?>
</th>
                    <th align="center"><?php 
            print_string('status', 'attforblock');
            ?>
</th>
                    <th align="center"><?php 
            print_string('sessiontitle', 'attforblock');
            ?>
</th>
                    <th align="center"><?php 
            print_string('subject', 'attforblock');
            ?>
</th>
                    <th align="center"><?php 
            print_string('teacher', 'attforblock');
            ?>
</th>
                    <th align="center"><?php 
            print_string('description', 'attforblock');
            ?>
</th>
                    <th align="center"><?php 
            print_string('makeupnotes', 'attforblock');
            ?>
</th>
                    <th align="center"><?php 
            print_string('sicknote', 'attforblock');
            ?>
</th>
                    <th align="center"><?php 
            print_string('remarks', 'attforblock');
            ?>
</th>
                </tr>
                <?php 
            $i = 1;
            foreach ($sessions as $key => $session) {
                ?>
                <tr>
                    <td align="center"><?php 
                echo $i++;
                ?>
</td>
                    <td><?php 
                echo userdate($session->sessdate, get_string('strftimedmyw', 'attforblock'));
                //userdate($students->sessdate,'%d.%m.%y&nbsp;(%a)', 99, false);
                ?>
</td>
                    <td><?php 
                echo userdate($session->sessdate, get_string('strftimehm', 'attforblock'));
                ?>
</td>
                    <td><?php 
                echo $statuses($session->statusid)->description;
                ?>
</td>
                    <td><?php 
                echo empty($session->sessiontitle) ? get_string('notitle', 'attforblock') : $session->sessiontitle;
                ?>
</td>
                    <td><?php 
                echo empty($session->subject) ? get_string('nosubject', 'attforblock') : $session->subject;
                ?>
</td>
                    <td><?php 
                echo empty($session->teacher) ? get_string('noteacher', 'attforblock') : $session->teacher;
                ?>
</td>
                    <td><?php 
                echo empty($session->description) ? get_string('nodescription', 'attforblock') : $session->description;
                ?>
</td>
                    <td><?php 
                echo get_string($session->makeupnotes, 'attforblock');
                ?>
</td>
                    <td><?php 
                echo get_string($session->sicknote, 'attforblock');
                ?>
</td>
                    <td><?php 
                echo $session->remarks;
                ?>
</td>
                </tr>
                <?php 
            }
            echo '</table>';
        } else {
            print_heading(get_string('nocleareditems', 'attforblock'));
        }
    }
    echo '</td></tr><tr><td>&nbsp;</td></tr></table></div>';
}