Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions classes/ext_db/db_connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* DB connect class of the external database of logs.
*
* Defines the db connection used by fn_mentor
*
* @package block_fn_mentor
* @author Sheilla Rindahl <srindahl@erdc.k12.mn.us>
* @copyright 2016 cmERDC
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;


class Database {
/**
* Here is the Moodle external database connection functions
* using the built in tools in Moodle.
*/

private $dbtype = "mysqli";
private $dbhost = "localhost";
private $dbname = "DB_NAME";
private $dbuser = "DB_USER";
private $dbpass = "DB_PASSWORD";
private $tablesession = "TABLE_NAME";
private $dbencoding = "utf-8";
private $dbsetupsql = "SET NAMES 'utf8'";
private $dbdebug = false;
private $dbsybasequoting = false;
public $conn;

/**
* Tries to make connection to the external database.
*
* @return null|ADONewConnection
*/
protected function db_init() {
global $CFG;

require_once($CFG->libdir.'/adodb/adodb.inc.php');

// Connect to the external database (forcing new connection).
$extdb = ADONewConnection($this->dbtype);
if ($this->dbdebug) {
$extdb->debug = true;
ob_start(); // Start output buffer to allow later use of the page headers.
}

// The dbtype my contain the new connection URL, so make sure we are not connected yet.
if (!$extdb->IsConnected()) {
$result = $extdb->Connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, true);
if (!$result) {
return null;
}
}

$extdb->SetFetchMode(ADODB_FETCH_ASSOC);
if ($this->dbsetupsql) {
$extdb->Execute($this->dbsetupsql);
}
return $extdb;
}

protected function db_addslashes($text) {
// Use custom made function for now - it is better to not rely on adodb or php defaults.
if ($this->dbsybasequoting) {
$text = str_replace('\\', '\\\\', $text);
$text = str_replace(array('\'', '"', "\0"), array('\\\'', '\\"', '\\0'), $text);
} else {
$text = str_replace("'", "''", $text);
}
return $text;
}

protected function db_encode($text) {
$dbenc = $this->dbencoding;
if (empty($dbenc) or $dbenc == 'utf-8') {
return $text;
}
if (is_array($text)) {
foreach($text as $k=>$value) {
$text[$k] = $this->db_encode($value);
}
return $text;
} else {
return core_text::convert($text, 'utf-8', $dbenc);
}
}

protected function db_decode($text) {
$dbenc = $this->dbencoding;
if (empty($dbenc) or $dbenc == 'utf-8') {
return $text;
}
if (is_array($text)) {
foreach($text as $k=>$value) {
$text[$k] = $this->db_decode($value);
}
return $text;
} else {
return core_text::convert($text, $dbenc, 'utf-8');
}
}

function db_get_sql($table, array $conditions, array $fields, $distinct = false, $sort = "") {
$fields = $fields ? implode(',', $fields) : "*";
$where = array();
if ($conditions) {
foreach ($conditions as $key=>$value) {
$value = $this->db_encode($this->db_addslashes($value));

$where[] = "$key = '$value'";
}
}
$where = $where ? "WHERE ".implode(" AND ", $where) : "";
$sort = $sort ? "ORDER BY $sort" : "";
$distinct = $distinct ? "DISTINCT" : "";
$sql = "SELECT $distinct $fields
FROM $table
$where
$sort";

return $sql;
}

/* Add external database connection for
* displaying the session times for courses.
*/
function get_extdb_sessions($enrolledcourse) {
global $CFG, $OUTPUT;
// /classes/ext_db/db_connect.php needed.
$table = "session_times";
$conditions = array("course" => $enrolledcourse,);
$fields = array("meeting");
$adodb = $this->db_init();
if (!$adodb or !$adodb->IsConnected()) {
$this->config->debugdb = $olddebugdb;
$CFG->debug = $olddebug;
ini_set('display_errors', $olddisplay);
error_reporting($CFG->debug);
ob_end_flush();

echo $OUTPUT->notification('Cannot connect the database.', 'notifyproblem');
return;
}
$sql = $this->db_get_sql($table, $conditions, $fields);
if (!empty($enrolledcourse)) {
$rs = $adodb->Execute($sql);
if (!$rs) {
echo $OUTPUT->notification('Can not read external enrol table.', 'notifyproblem');

} else if ($rs->EOF) {
$session = false;
$rs->Close();

} else {
$session = $rs->FetchRow();
$rs->Close();
}
}
$adodb->Close();
return $session;
}

}
114 changes: 99 additions & 15 deletions course_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@
$courseid = optional_param('courseid', 0, PARAM_INT);
$groupid = optional_param('groupid', 0, PARAM_INT);

// Array of functions to call for grading purposes for modules.
$modgradesarray = array(
'assign' => 'assign.submissions.fn.php',
'quiz' => 'quiz.submissions.fn.php',
'assignment' => 'assignment.submissions.fn.php',
'forum' => 'forum.submissions.fn.php',
);
// Array of functions to call for grading purposes for modules. (- new function to add additional).
$modgradesarray = get_graded_mods();

require_login(null, false);

Expand All @@ -46,6 +41,7 @@
$ismentor = block_fn_mentor_has_system_role($USER->id, get_config('block_fn_mentor', 'mentor_role_system'));
$isteacher = block_fn_mentor_isteacherinanycourse($USER->id);
$isstudent = block_fn_mentor_isstudentinanycourse($USER->id);
$menteecanview = get_config('block_fn_mentor', 'menteecanview'); // Use the setting students can view for student views.

$allownotes = get_config('block_fn_mentor', 'allownotes');

Expand Down Expand Up @@ -77,8 +73,13 @@
}
// Pick a mentee if not selected.
if ((!$menteeid && $mentees) || (!in_array($menteeid, array_keys($mentees)))) {
// Account for student views
if($isstudent && $menteecanview) {
$menteeid = $USER->id;
} else {
$var = reset($mentees);
$menteeid = $var->studentid;
}
}

if (($USER->id <> $menteeid) && !$isadmin && !in_array($menteeid, array_keys($mentees))) {
Expand Down Expand Up @@ -119,8 +120,9 @@

$lastaccess = '';
if ($menteeuser->lastaccess) {
// Extra param for last access.
$lastaccess .= get_string('lastaccess').get_string('labelsep', 'langconfig').
block_fn_mentor_format_time(time() - $menteeuser->lastaccess);
block_fn_mentor_format_time(time(), $menteeuser->lastaccess);
} else {
$lastaccess .= get_string('lastaccess').get_string('labelsep', 'langconfig').get_string('never');
}
Expand All @@ -137,6 +139,9 @@
AND gm.userid = ?
ORDER BY g.name ASC";
$groups = $DB->get_records_sql($sql, array('M', $USER->id));
} else if ($isstudent) {
// Account for student views.
$groups = '';
}

$groupmenu = array();
Expand Down Expand Up @@ -217,10 +222,14 @@
'</div></div>';

// COURSES.
if (!$enrolledcourses = enrol_get_all_users_courses($menteeid, false, 'id,fullname,shortname', 'fullname ASC')) {
if($enrollmenttypeconfig = get_config('block_fn_mentor', 'includecurrentenrollments')) {
$enrollmenttype = true;
} else {
$enrollmenttype = false;
}
if (!$enrolledcourses = enrol_get_all_users_courses($menteeid, $enrollmenttype, 'id,fullname,shortname', 'fullname ASC')) {
$enrolledcourses = array();
}

$filtercourses = array();

if ($configcategory = get_config('block_fn_mentor', 'category')) {
Expand Down Expand Up @@ -303,6 +312,57 @@
</div>
</div>';

// Add LEARNING PLANS.
// Requires mentor to have moodle/competency:planview set to allow in role.
if(get_config('core_competency', 'enabled')) {
$userid = optional_param('userid', $menteeuser->id, PARAM_INT);
$view = \core_competency\plan::can_read_user($userid);
$lp_url = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
$plans = \core_competency\api::list_user_plans($userid);
$tooltip = 'View complete report for all learning plans.';
$reports = core_component::get_plugin_list('report');
$lpmonitoring= false;
if ($reports['lpmonitoring']) {
$lp_url = new moodle_url('/report/lpmonitoring/userreport.php', array('userid' => $menteeuser->id));

}
if ($view) {
echo '<div class="mentee-course-overview-block">
<div class="mentee-course-overview-block-title">
Learning Plans
</div>
<div class="fz_popup_wrapper">
<a href="'.$lp_url.'" data-toggle="tooltip" title="'.$tooltip.'"
onclick="window.open(\''.$lp_url.'\', \'\', \'width=800,height=600,toolbar=no,location=no,menubar=no,copyhistory=no,'.
'status=no,directories=no,scrollbars=yes,resizable=yes\'); return false;"
class="" ><img src="'.$CFG->wwwroot.'/blocks/fn_mentor/pix/popup_icon.gif"></a>
</div>
<div class="mentee-course-overview-block-content">';

// Learning plan.
$lp_count = count($plans);
foreach($plans as $plan) {
$exporter = new \core_competency\external\plan_exporter($plan, array('template' => $plan->get_template()));
$record = $exporter->export($OUTPUT);
$plan_record = '<div class="courselist"><img class="mentees-course-bullet" src="'.$CFG->wwwroot.'/blocks/fn_mentor/pix/b.gif"> <a href="' . $CFG->wwwroot .
'/admin/tool/lp/plan.php?id=' . $record->id . '">' . $record->name . '</a>';
if($record->duedate) {
$due_date = $record->duedateformatted;
$plan_record .= ' (Due: '.$due_date.')';
}
if($record->iscompleted) {
$plan_record .= ' <em>- Completed</em> ';
}
$plan_record .= '</div>';

echo $plan_record;

}

echo '</div>
</div>';
}
}
// NOTES.
if ($view = has_capability('block/fn_mentor:viewcoursenotes', context_system::instance()) && $allownotes) {
echo '<div class="mentee-course-overview-block">
Expand Down Expand Up @@ -389,6 +449,8 @@ class="" ><img src="'.$CFG->wwwroot.'/blocks/fn_mentor/pix/popup_icon.gif"></a>
$progresshtml .= '<div class="overview-progress-list">' . $progressdata->content->icons[$key] .
$progressdata->content->items[$key] . '</div>';
}
// Add enrollment dates.
$enroldata = get_enrollment_dates($menteeid, $enrolledcourse->id);

echo '<table class="mentee-course-overview-center_table block">';
echo '<tr>';
Expand All @@ -399,7 +461,21 @@ class="" ><img src="'.$CFG->wwwroot.'/blocks/fn_mentor/pix/popup_icon.gif"></a>
$enrolledcourse->id . '\', \'\', \'width=800,height=600,toolbar=no,location=no,menubar=no,'.
'copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes\'); return false;" class="" >' .
$course_fullname . '</a></div>';

// Enrollment dates.
if ($enroldata->enrolstart && $enroldata->enrolend){
echo '<div style="text-align:center"><small><b>'.get_string('enroldates', 'block_fn_mentor').':</b><br>'.date('n/j/Y', $enroldata->enrolstart).' - '.date('n/j/Y', $enroldata->enrolend).'</small></div>';
} else {
echo '<div style="text-align:center"><small><b>'.get_string('enroldates', 'block_fn_mentor').':</b><br>'.get_string('enroldatesnone', 'block_fn_mentor').'</small></div>';
}
// Add Session times.

$session = get_session_times($enrolledcourse->id);

if ($session){
echo '<div style="text-align:center"><small><b>'.get_string('sessions', 'block_fn_mentor').':</b><br>'.$session['meeting'].'</small></div>';
} else {
echo '<div style="text-align:center"><small><b>'.get_string('sessions', 'block_fn_mentor').':</b><br>'.get_string('sessionsnone', 'block_fn_mentor').'</small></div>';
}
echo '<div class="overview-teacher">';
echo '<table class="mentee-teacher-table">';
// Course teachers.
Expand All @@ -421,8 +497,9 @@ class="" ><img src="'.$CFG->wwwroot.'/blocks/fn_mentor/pix/popup_icon.gif"></a>
$teacherlist = '';
$teacherlabel = get_string('teacher', 'block_fn_mentor');
foreach ($teachers as $teacher) {
// Extra param for last access.
$lastaccess = get_string('lastaccess') . get_string('labelsep', 'langconfig') .
block_fn_mentor_format_time(time() - $teacher->lastaccess);
block_fn_mentor_format_time(time(), $teacher->lastaccess);
$teacherlist .= block_fn_mentor_teacher_link ($teacher->id, $lastaccess);
}
if ($numofteachers > 1) {
Expand Down Expand Up @@ -455,8 +532,9 @@ class="" ><img src="'.$CFG->wwwroot.'/blocks/fn_mentor/pix/popup_icon.gif"></a>
'blockname') : get_string('mentor', 'block_fn_mentor');

foreach ($mentors as $mentor) {
// Extra param for last access.
$lastaccess = get_string('lastaccess') . get_string('labelsep', 'langconfig') .
block_fn_mentor_format_time(time() - $mentor->lastaccess);
block_fn_mentor_format_time(time(), $mentor->lastaccess);
$mentorlist .= block_fn_mentor_teacher_link($mentor->mentorid, $lastaccess);
}
echo '<tr><td class="mentee-teacher-table-label" valign="top"><span>';
Expand Down Expand Up @@ -506,9 +584,15 @@ class="" ><img src="'.$CFG->wwwroot.'/blocks/fn_mentor/pix/popup_icon.gif"></a>
}
echo '</td>';
echo '</tr>';

// Add Progress bar.
echo '<tr>';
echo '<td>';
$progressbar = block_fn_mentor_print_activity_progress ($course , $menteeuser->id);
echo $progressbar;
echo '</td>';
echo '</tr>';
// End
echo '</table>';

echo '</td>';
// Grade.
echo '<td valign="top" style="height: 100%;" class="mentee-blue-border '.$completedcourseclass.'">';
Expand Down
Loading