Esempio n. 1
0
 public function get_url()
 {
     global $CFG;
     require_once "{$CFG->dirroot}/course/lib.php";
     $url = \make_log_url($this->other['module'], $this->other['url']);
     if (!$url) {
         return null;
     }
     return new \moodle_url($url);
 }
Esempio n. 2
0
function print_log($course, $user = 0, $date = 0, $order = "l.time ASC", $page = 0, $perpage = 100, $url = "", $modname = "", $modid = 0, $modaction = "", $groupid = 0)
{
    global $CFG, $DB, $OUTPUT;
    if (!($logs = build_logs_array($course, $user, $date, $order, $page * $perpage, $perpage, $modname, $modid, $modaction, $groupid))) {
        echo $OUTPUT->notification("No logs found!");
        echo $OUTPUT->footer();
        exit;
    }
    $courses = array();
    if ($course->id == SITEID) {
        $courses[0] = '';
        if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
            foreach ($ccc as $cc) {
                $courses[$cc->id] = $cc->shortname;
            }
        }
    } else {
        $courses[$course->id] = $course->shortname;
    }
    $totalcount = $logs['totalcount'];
    $count = 0;
    $ldcache = array();
    $tt = getdate(time());
    $today = mktime(0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
    $strftimedatetime = get_string("strftimedatetime");
    echo "<div class=\"info\">\n";
    print_string("displayingrecords", "", $totalcount);
    echo "</div>\n";
    echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "{$url}&perpage={$perpage}");
    $table = new html_table();
    $table->classes = array('logtable', 'generalbox');
    $table->align = array('right', 'left', 'left');
    $table->head = array(get_string('time'), get_string('ip_address'), get_string('fullnameuser'), get_string('action'), get_string('info'));
    $table->data = array();
    if ($course->id == SITEID) {
        array_unshift($table->align, 'left');
        array_unshift($table->head, get_string('course'));
    }
    // Make sure that the logs array is an array, even it is empty, to avoid warnings from the foreach.
    if (empty($logs['logs'])) {
        $logs['logs'] = array();
    }
    foreach ($logs['logs'] as $log) {
        if (isset($ldcache[$log->module][$log->action])) {
            $ld = $ldcache[$log->module][$log->action];
        } else {
            $ld = $DB->get_record('log_display', array('module' => $log->module, 'action' => $log->action));
            $ldcache[$log->module][$log->action] = $ld;
        }
        if ($ld && is_numeric($log->info)) {
            // ugly hack to make sure fullname is shown correctly
            if ($ld->mtable == 'user' && $ld->field == $DB->sql_concat('firstname', "' '", 'lastname')) {
                $log->info = fullname($DB->get_record($ld->mtable, array('id' => $log->info)), true);
            } else {
                $log->info = $DB->get_field($ld->mtable, $ld->field, array('id' => $log->info));
            }
        }
        //Filter log->info
        $log->info = format_string($log->info);
        // If $log->url has been trimmed short by the db size restriction
        // code in add_to_log, keep a note so we don't add a link to a broken url
        $brokenurl = textlib::strlen($log->url) == 100 && textlib::substr($log->url, 97) == '...';
        $row = array();
        if ($course->id == SITEID) {
            if (empty($log->course)) {
                $row[] = get_string('site');
            } else {
                $row[] = "<a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">" . format_string($courses[$log->course]) . "</a>";
            }
        }
        $row[] = userdate($log->time, '%a') . ' ' . userdate($log->time, $strftimedatetime);
        $link = new moodle_url("/iplookup/index.php?ip={$log->ip}&user={$log->userid}");
        $row[] = $OUTPUT->action_link($link, $log->ip, new popup_action('click', $link, 'iplookup', array('height' => 440, 'width' => 700)));
        $row[] = html_writer::link(new moodle_url("/user/view.php?id={$log->userid}&course={$log->course}"), fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
        $displayaction = "{$log->module} {$log->action}";
        if ($brokenurl) {
            $row[] = $displayaction;
        } else {
            $link = make_log_url($log->module, $log->url);
            $row[] = $OUTPUT->action_link($link, $displayaction, new popup_action('click', $link, 'fromloglive'), array('height' => 440, 'width' => 700));
        }
        $row[] = $log->info;
        $table->data[] = $row;
    }
    echo html_writer::table($table);
    echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "{$url}&perpage={$perpage}");
}
Esempio n. 3
0
function print_log_ods($course, $user, $date, $order = 'l.time DESC', $modname, $modid, $modaction, $groupid)
{
    global $CFG, $DB;
    require_once "{$CFG->libdir}/odslib.class.php";
    if (!($logs = build_logs_array($course, $user, $date, $order, '', '', $modname, $modid, $modaction, $groupid))) {
        return false;
    }
    $courses = array();
    if ($course->id == SITEID) {
        $courses[0] = '';
        if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
            foreach ($ccc as $cc) {
                $courses[$cc->id] = $cc->shortname;
            }
        }
    } else {
        $courses[$course->id] = $course->shortname;
    }
    $count = 0;
    $ldcache = array();
    $tt = getdate(time());
    $today = mktime(0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
    $strftimedatetime = get_string("strftimedatetime");
    $nroPages = ceil(count($logs) / (EXCELROWS - FIRSTUSEDEXCELROW + 1));
    $filename = 'logs_' . userdate(time(), get_string('backupnameformat', 'langconfig'), 99, false);
    $filename .= '.ods';
    $workbook = new MoodleODSWorkbook('-');
    $workbook->send($filename);
    $worksheet = array();
    $headers = array(get_string('course'), get_string('time'), get_string('ip_address'), get_string('fullnameuser'), get_string('action'), get_string('info'));
    // Creating worksheets
    for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
        $sheettitle = get_string('logs') . ' ' . $wsnumber . '-' . $nroPages;
        $worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
        $worksheet[$wsnumber]->set_column(1, 1, 30);
        $worksheet[$wsnumber]->write_string(0, 0, get_string('savedat') . userdate(time(), $strftimedatetime));
        $col = 0;
        foreach ($headers as $item) {
            $worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW - 1, $col, $item, '');
            $col++;
        }
    }
    if (empty($logs['logs'])) {
        $workbook->close();
        return true;
    }
    $formatDate =& $workbook->add_format();
    $formatDate->set_num_format(get_string('log_excel_date_format'));
    $row = FIRSTUSEDEXCELROW;
    $wsnumber = 1;
    $myxls =& $worksheet[$wsnumber];
    foreach ($logs['logs'] as $log) {
        if (isset($ldcache[$log->module][$log->action])) {
            $ld = $ldcache[$log->module][$log->action];
        } else {
            $ld = $DB->get_record('log_display', array('module' => $log->module, 'action' => $log->action));
            $ldcache[$log->module][$log->action] = $ld;
        }
        if ($ld && is_numeric($log->info)) {
            // ugly hack to make sure fullname is shown correctly
            if ($ld->mtable == 'user' and $ld->field == $DB->sql_concat('firstname', "' '", 'lastname')) {
                $log->info = fullname($DB->get_record($ld->mtable, array('id' => $log->info)), true);
            } else {
                $log->info = $DB->get_field($ld->mtable, $ld->field, array('id' => $log->info));
            }
        }
        // Filter log->info
        $log->info = format_string($log->info);
        $log->info = strip_tags(urldecode($log->info));
        // Some XSS protection
        if ($nroPages > 1) {
            if ($row > EXCELROWS) {
                $wsnumber++;
                $myxls =& $worksheet[$wsnumber];
                $row = FIRSTUSEDEXCELROW;
            }
        }
        $coursecontext = context_course::instance($course->id);
        $myxls->write_string($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)));
        $myxls->write_date($row, 1, $log->time);
        $myxls->write_string($row, 2, $log->ip);
        $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
        $myxls->write_string($row, 3, $fullname);
        $actionurl = $CFG->wwwroot . make_log_url($log->module, $log->url);
        $myxls->write_string($row, 4, $log->module . ' ' . $log->action . ' (' . $actionurl . ')');
        $myxls->write_string($row, 5, $log->info);
        $row++;
    }
    $workbook->close();
    return true;
}
Esempio n. 4
0
function print_log($course, $user = 0, $date = 0, $order = "l.time ASC", $page = 0, $perpage = 100, $url = "", $modname = "", $modid = 0, $modaction = "", $groupid = 0)
{
    global $CFG;
    if (!($logs = build_logs_array($course, $user, $date, $order, $page * $perpage, $perpage, $modname, $modid, $modaction, $groupid))) {
        notify("No logs found!");
        print_footer($course);
        exit;
    }
    $courses = array();
    if ($course->id == SITEID) {
        $courses[0] = '';
        if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
            foreach ($ccc as $cc) {
                $courses[$cc->id] = $cc->shortname;
            }
        }
    } else {
        $courses[$course->id] = $course->shortname;
    }
    $totalcount = $logs['totalcount'];
    $count = 0;
    $ldcache = array();
    $tt = getdate(time());
    $today = mktime(0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
    $strftimedatetime = get_string("strftimedatetime");
    echo "<div class=\"info\">\n";
    print_string("displayingrecords", "", $totalcount);
    echo "</div>\n";
    print_paging_bar($totalcount, $page, $perpage, "{$url}&amp;perpage={$perpage}&amp;");
    echo '<table class="logtable generalbox boxaligncenter" summary="">' . "\n";
    // echo "<table class=\"logtable\" cellpadding=\"3\" cellspacing=\"0\" summary=\"\">\n";
    echo "<tr>";
    if ($course->id == SITEID) {
        echo "<th class=\"c0 header\" scope=\"col\">" . get_string('course') . "</th>\n";
    }
    echo "<th class=\"c1 header\" scope=\"col\">" . get_string('time') . "</th>\n";
    echo "<th class=\"c2 header\" scope=\"col\">" . get_string('ip_address') . "</th>\n";
    echo "<th class=\"c3 header\" scope=\"col\">" . get_string('fullname') . "</th>\n";
    echo "<th class=\"c4 header\" scope=\"col\">" . get_string('action') . "</th>\n";
    echo "<th class=\"c5 header\" scope=\"col\">" . get_string('info') . "</th>\n";
    echo "</tr>\n";
    // Make sure that the logs array is an array, even it is empty, to avoid warnings from the foreach.
    if (empty($logs['logs'])) {
        $logs['logs'] = array();
    }
    $row = 1;
    foreach ($logs['logs'] as $log) {
        $row = ($row + 1) % 2;
        if (isset($ldcache[$log->module][$log->action])) {
            $ld = $ldcache[$log->module][$log->action];
        } else {
            $ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
            $ldcache[$log->module][$log->action] = $ld;
        }
        if ($ld && is_numeric($log->info)) {
            // ugly hack to make sure fullname is shown correctly
            if ($ld->mtable == 'user' and $ld->field == sql_concat('firstname', "' '", 'lastname')) {
                $log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
            } else {
                $log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
            }
        }
        //Filter log->info
        $log->info = format_string($log->info);
        // If $log->url has been trimmed short by the db size restriction
        // code in add_to_log, keep a note so we don't add a link to a broken url
        $tl = textlib_get_instance();
        $brokenurl = $tl->strlen($log->url) == 100 && $tl->substr($log->url, 97) == '...';
        echo '<tr class="r' . $row . '">';
        if ($course->id == SITEID) {
            echo "<td class=\"cell c0\">\n";
            if (empty($log->course)) {
                echo get_string('site') . "\n";
            } else {
                echo "    <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">" . format_string($courses[$log->course]) . "</a>\n";
            }
            echo "</td>\n";
        }
        echo "<td class=\"cell c1\" align=\"right\">" . userdate($log->time, '%a') . ' ' . userdate($log->time, $strftimedatetime) . "</td>\n";
        echo "<td class=\"cell c2\">\n";
        link_to_popup_window("/iplookup/index.php?ip={$log->ip}&amp;user={$log->userid}", 'iplookup', $log->ip, 440, 700);
        echo "</td>\n";
        $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
        echo "<td class=\"cell c3\">\n";
        echo "    <a href=\"{$CFG->wwwroot}/user/view.php?id={$log->userid}&amp;course={$log->course}\">{$fullname}</a>\n";
        echo "</td>\n";
        echo "<td class=\"cell c4\">\n";
        $displayaction = "{$log->module} {$log->action}";
        if ($brokenurl) {
            echo $displayaction;
        } else {
            link_to_popup_window(make_log_url($log->module, $log->url), 'fromloglive', $displayaction, 440, 700);
        }
        echo "</td>\n";
        echo "<td class=\"cell c5\">{$log->info}</td>\n";
        echo "</tr>\n";
    }
    echo "</table>\n";
    print_paging_bar($totalcount, $page, $perpage, "{$url}&amp;perpage={$perpage}&amp;");
}
    //$image=explode(" ", print_user_picture($log->userid, $log->course, false,true,true,true));
    //$image=explode("\"", $image[3]);
    //$file_xml=$file_xml."$fullname {$log->action}\" \nimage=\"$image[1]\">\n"; // User
    $file_xml = $file_xml . "{$fullname} {$log->action}\" \nimage=\"{$CFG->wwwroot}/user/pix.php/{$log->userid}/f2.jpg\">\n";
    // User
    // Link I.p.
    /*$ip_action=explode(" ", link_to_popup_window("/iplookup/index.php?ip=$log->ip&amp;user=$log->userid", 
      'iplookup',$log->ip, 400, 700, null, null, true));
      var_dump($ip_action);
      $link_to=$ip_action[0]." ".$ip_action[2]."".substr($ip_action[8], 4, strlen($ip_action[8]));
      $file_xml=$file_xml.correct_syntax($link_to."<br/>")."\n"; 
      */
    $ip_action = link_to_popup_window("/iplookup/index.php?ip={$log->ip}&amp;user={$log->userid}", 'iplookup', $log->ip, 400, 700, null, null, true);
    $file_xml = $file_xml . correct_syntax($ip_action) . '&lt;br/&gt;' . "\n";
    // User
    $file_xml = $file_xml . correct_syntax("<a href=\"{$CFG->wwwroot}/user/view.php?id={$log->userid}&amp;course={$log->course}\">{$fullname}</a><br/>\n");
    // Log Live Action
    /*$action=link_to_popup_window( make_log_url($log->module,$log->url), 'fromloglive',"$log->module $log->action", 
      400, 600, null , null, true);
      $ip_action=explode(" ",$action);
      $link_to=$ip_action[0]." ".$ip_action[2]."".substr($action, strpos($action, ">"), strlen($action));
      $file_xml=$file_xml.correct_syntax($link_to."<br/>")."\n"; */
    $ip_action = link_to_popup_window(make_log_url($log->module, $log->url), 'fromloglive', "{$log->module} {$log->action}", 400, 600, null, null, true);
    $file_xml = $file_xml . correct_syntax($ip_action) . '&lt;br/&gt;' . "\n";
    $file_xml = $file_xml . correct_syntax("<i>{$log->info}</i><br/>\n");
    //Info
    $file_xml = $file_xml . "</event>\n\n";
    echo $file_xml;
    $file_xml = "";
}
echo "\n</data>";