* @param type description
*
*/
-function count_records_select($table, $select="") {
+function count_records_select($table, $select="", $countitem="COUNT(*)") {
global $CFG;
$select = "WHERE $select";
}
- return count_records_sql("SELECT COUNT(*) FROM $CFG->prefix$table $select");
+ return count_records_sql("SELECT $countitem FROM $CFG->prefix$table $select");
}
}
return false;
}
-
+
if ( $rs->RecordCount() > 0 ) {
if ($records = $rs->GetAssoc(true)) {
foreach ($records as $key => $record) {
}
}
+
+/**
+* Get a single field from a database record
+*
+* longdesc
+*
+* @param type description
+*/
+function get_field_sql($sql) {
+
+ global $db, $CFG;
+
+ $rs = $db->Execute($sql);
+ if (!$rs) {
+ if (isset($CFG->debug) and $CFG->debug > 7) {
+ notify($db->ErrorMsg()."<br /><br />$sql");
+ }
+ return false;
+ }
+
+ if ( $rs->RecordCount() == 1 ) {
+ return $rs->fields[0];
+ } else {
+ return false;
+ }
+}
+
/**
* Set a single field in a database record
*
if (isset($USER->realuser)) { // Don't log
return;
}
- $userid = empty($USER->id) ? "" : $USER->id;
+ $userid = empty($USER->id) ? "0" : $USER->id;
}
$timenow = time();
$order = "ORDER BY $order";
}
- $selectsql = "{$CFG->prefix}log l, {$CFG->prefix}user u WHERE $select";
-
+ $selectsql = "{$CFG->prefix}log l LEFT JOIN {$CFG->prefix}user u ON l.userid = u.id ".((strlen($select) > 0) ? "WHERE $select" : "");
$totalcount = count_records_sql("SELECT COUNT(*) FROM $selectsql");
return get_records_sql("SELECT l.*, u.firstname, u.lastname, u.picture
GROUP BY hour ");
}
+/**
+ * Returns an object with counts of failed login attempts
+ *
+ * Returns information about failed login attempts. If the current user is
+ * an admin, then two numbers are returned: the number of attempts and the
+ * number of accounts. For non-admins, only the attempts on the given user
+ * are shown.
+ *
+ * @param mode - admin, teacher or everybody
+ * @param username - the username we are searching for
+ * @param lastlogin - the date from which we are searching
+ */
+
+function count_login_failures($mode, $username, $lastlogin) {
+
+ $select = "module='login' AND action='error' AND time > $lastlogin";
+
+ if (isadmin()) { // Return information about all accounts
+ if ($count->attempts = count_records_select('log', $select)) {
+ $count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
+ return $count;
+ }
+ } else if ($mode == 'everybody' or ($mode == 'teacher' and isteacher())) {
+ if ($count->attempts = count_records_select('log', "$select AND info = '$username'")) {
+ return $count;
+ }
+ }
+ return NULL;
+}
+
+
/// GENERAL HELPFUL THINGS ///////////////////////////////////
/**
$menu = "<font size=\"2\"><a target=\"$CFG->framename\" href=\"$wwwroot/login/index.php\">".get_string("login")."</a></font>";
}
}
+
+ if (isset($SESSION->justloggedin)) {
+ unset($SESSION->justloggedin);
+ if (!empty($CFG->displayloginfailures)) {
+ if (!empty($USER->username) and !isguest()) {
+ if ($count = count_login_failures($CFG->displayloginfailures, $USER->username, $USER->lastlogin)) {
+ $menu .= ' <font size="1">';
+ if (empty($count->accounts)) {
+ $menu .= get_string('failedloginattempts', '', $count);
+ } else {
+ $menu .= get_string('failedloginattemptsall', '', $count);
+ }
+ if (isadmin()) {
+ $menu .= ' (<a href="'.$CFG->wwwroot.'/course/log.php'.
+ '?chooselog=1&id=1&modid=site_errors">'.get_string('logs').'</a>)';
+ }
+ $menu .= '</font>';
+ }
+ }
+ }
+ }
// Add a stylesheet for the HTML editor
$meta = "<style type=\"text/css\">@import url($CFG->wwwroot/lib/editor/htmlarea.css);</style>\n$meta\n";
return $text;
}
+
+
+
// ================================================
// THREE FUNCTIONS MOVED HERE FROM course/lib.php
// ================================================
echo '<tbody style="background-color: '.$THEME->cellcontent2.';"><tr><td class="sideblockmain">';
}
+
+
function print_side_block_end() {
echo '</td></tr></tbody></table><br />';
echo "\n";