本文整理汇总了PHP中sql_ilike函数的典型用法代码示例。如果您正苦于以下问题:PHP sql_ilike函数的具体用法?PHP sql_ilike怎么用?PHP sql_ilike使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sql_ilike函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
function execute($data, $user, $courseid)
{
$data->value = addslashes($data->value);
$ilike = sql_ilike();
switch ($data->operator) {
case 'LIKE % %':
$sql = "{$data->field} {$ilike} '%{$data->value}%'";
break;
default:
$sql = "{$data->field} {$data->operator} '{$data->value}'";
}
$courses = get_records_select('course', $sql);
if ($courses) {
return array_keys($courses);
}
return array();
}
示例2: get_sql_filter
/**
* Returns the condition to be used with SQL where
* @param array $data filter settings
* @return string the filtering condition or null if the filter is disabled
*/
function get_sql_filter($data)
{
$operator = $data['operator'];
$value = addslashes($data['value']);
$field = $this->_field;
if ($operator != 5 and $value === '') {
return '';
}
$ilike = sql_ilike();
switch ($operator) {
case 0:
// contains
$res = "{$ilike} '%{$value}%'";
break;
case 1:
// does not contain
$res = "NOT {$ilike} '%{$value}%'";
break;
case 2:
// equal to
$res = "{$ilike} '{$value}'";
break;
case 3:
// starts with
$res = "{$ilike} '{$value}%'";
break;
case 4:
// ends with
$res = "{$ilike} '%{$value}'";
break;
case 5:
// empty
$res = "=''";
break;
default:
return '';
}
return $field . ' ' . $res;
}
示例3: xmldb_block_php_report_upgrade
/**
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package elis
* @subpackage php_reports
* @author Remote-Learner.net Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
*
*/
function xmldb_block_php_report_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
if ($result && $oldversion < 2011040600) {
/// Define table php_report_schedule to be created
$table = new XMLDBTable('php_report_schedule');
/// Adding fields to table php_report_schedule
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('report', XMLDB_TYPE_CHAR, '63', null, XMLDB_NOTNULL, null, null, null, null);
$table->addFieldInfo('config', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null, null, null);
/// Adding keys to table php_report_schedule
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table php_report_schedule
$table->addIndexInfo('report_idx', XMLDB_INDEX_NOTUNIQUE, array('report'));
/// Launch create table for php_report_schedule
$result = $result && create_table($table);
/// Define field userid to be added to php_report_schedule
$table = new XMLDBTable('php_report_schedule');
$field = new XMLDBField('userid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'id');
/// Launch add field userid
$result = $result && add_field($table, $field);
/// Define index userid_idx (not unique) to be added to php_report_schedule
$table = new XMLDBTable('php_report_schedule');
$index = new XMLDBIndex('userid_idx');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('userid'));
/// Launch add index userid_idx
$result = $result && add_index($table, $index);
}
if ($result && $oldversion < 2011042900) {
$query = "name " . sql_ilike() . " 'php_report%'";
$result = $result && delete_records_select('user_preferences', $query);
}
return $result;
}
示例4: message_search
function message_search($searchterms, $fromme = true, $tome = true, $courseid = 'none', $userid = 0)
{
/// Returns a list of posts found using an array of search terms
/// eg word +word -word
///
global $CFG, $USER;
/// If no userid sent then assume current user
if ($userid == 0) {
$userid = $USER->id;
}
/// Some differences in SQL syntax
$LIKE = sql_ilike();
$NOTLIKE = 'NOT ' . $LIKE;
if ($CFG->dbfamily == "postgres") {
$REGEXP = "~*";
$NOTREGEXP = "!~*";
} else {
$REGEXP = "REGEXP";
$NOTREGEXP = "NOT REGEXP";
}
$messagesearch = "";
foreach ($searchterms as $searchterm) {
if (strlen($searchterm) < 2) {
continue;
}
/// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE search
if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
$searchterm = trim($searchterm, '+-');
}
if ($messagesearch) {
$messagesearch .= " AND ";
}
if (substr($searchterm, 0, 1) == "+") {
$searchterm = substr($searchterm, 1);
$messagesearch .= " m.message {$REGEXP} '(^|[^a-zA-Z0-9]){$searchterm}([^a-zA-Z0-9]|\$)' ";
} else {
if (substr($searchterm, 0, 1) == "-") {
$searchterm = substr($searchterm, 1);
$messagesearch .= " m.message {$NOTREGEXP} '(^|[^a-zA-Z0-9]){$searchterm}([^a-zA-Z0-9]|\$)' ";
} else {
$messagesearch .= " m.message {$LIKE} '%{$searchterm}%' ";
}
}
}
if ($messagesearch == '') {
// if only 1 letter words searched
return false;
}
$messagesearch = "({$messagesearch}) ";
/// There are several possibilities
/// 1. courseid = SITEID : The admin is searching messages by all users
/// 2. courseid = ?? : A teacher is searching messages by users in
/// one of their courses - currently disabled
/// 3. courseid = none : User is searching their own messages;
/// a. Messages from user
/// b. Messages to user
/// c. Messages to and from user
if ($courseid == SITEID) {
/// admin is searching all messages
$m_read = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated\n FROM {$CFG->prefix}message_read m\n WHERE {$messagesearch}");
$m_unread = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated\n FROM {$CFG->prefix}message m\n WHERE {$messagesearch}");
if ($m_read === false) {
$m_read = array();
}
if ($m_unread === false) {
$m_unread = array();
}
} elseif ($courseid !== 'none') {
/// This has not been implemented due to security concerns
} else {
if ($fromme and $tome) {
$messagesearch .= "AND (m.useridfrom='{$userid}' OR m.useridto='{$userid}') ";
} elseif ($fromme) {
$messagesearch .= "AND m.useridfrom='{$userid}' ";
} elseif ($tome) {
$messagesearch .= "AND m.useridto='{$userid}' ";
}
$m_read = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated\n FROM {$CFG->prefix}message_read m\n WHERE {$messagesearch}");
$m_unread = get_records_sql("SELECT m.id, m.useridto, m.useridfrom, m.message, m.timecreated\n FROM {$CFG->prefix}message m\n WHERE {$messagesearch}");
if ($m_read === false) {
$m_read = array();
}
if ($m_unread === false) {
$m_unread = array();
}
}
/// The keys may be duplicated in $m_read and $m_unread so we can't
/// do a simple concatenation
$message = array();
foreach ($m_read as $m) {
$messages[] = $m;
}
foreach ($m_unread as $m) {
$messages[] = $m;
}
return empty($messages) ? false : $messages;
}
示例5: get_course_students
/**
* Returns array of userinfo of all students in this course
* or on this site if courseid is id of site
*
* @uses $CFG
* @uses SITEID
* @param int $courseid The course in question.
* @param string $sort ?
* @param string $dir ?
* @param int $page ?
* @param int $recordsperpage ?
* @param string $firstinitial ?
* @param string $lastinitial ?
* @param ? $group ?
* @param string $search ?
* @param string $fields A comma separated list of fields to be returned from the chosen table.
* @param string $exceptions ?
* @return object
* @todo Finish documenting this function
*/
function get_course_students($courseid, $sort = 'ul.timeaccess', $dir = '', $page = '', $recordsperpage = '', $firstinitial = '', $lastinitial = '', $group = NULL, $search = '', $fields = '', $exceptions = '')
{
global $CFG;
if ($courseid == SITEID and $CFG->allusersaresitestudents) {
// return users with confirmed, undeleted accounts who are not site teachers
// the following is a mess because of different conventions in the different user functions
$sort = str_replace('s.timeaccess', 'lastaccess', $sort);
// site users can't be sorted by timeaccess
$sort = str_replace('timeaccess', 'lastaccess', $sort);
// site users can't be sorted by timeaccess
$sort = str_replace('u.', '', $sort);
// the get_user function doesn't use the u. prefix to fields
$fields = str_replace('u.', '', $fields);
if ($sort) {
$sort = $sort . ' ' . $dir;
}
// Now we have to make sure site teachers are excluded
if ($teachers = get_course_teachers(SITEID)) {
foreach ($teachers as $teacher) {
$exceptions .= ',' . $teacher->userid;
}
$exceptions = ltrim($exceptions, ',');
}
return get_users(true, $search, true, $exceptions, $sort, $firstinitial, $lastinitial, $page, $recordsperpage, $fields ? $fields : '*');
}
$LIKE = sql_ilike();
$fullname = sql_fullname('u.firstname', 'u.lastname');
$groupmembers = '';
// make sure it works on the site course
$context = get_context_instance(CONTEXT_COURSE, $courseid);
$select = "c.contextlevel=" . CONTEXT_COURSE . " AND ";
// Must be on a course
if ($courseid != SITEID) {
// If not site, require specific course
$select .= "c.instanceid={$courseid} AND ";
}
$select .= "rc.capability='moodle/legacy:student' AND rc.permission=" . CAP_ALLOW . " AND ";
$select .= ' u.deleted = \'0\' ';
if (!$fields) {
$fields = 'u.id, u.confirmed, u.username, u.firstname, u.lastname, ' . 'u.maildisplay, u.mailformat, u.maildigest, u.email, u.city, ' . 'u.country, u.picture, u.idnumber, u.department, u.institution, ' . 'u.emailstop, u.lang, u.timezone, ul.timeaccess as lastaccess';
}
if ($search) {
$search = ' AND (' . $fullname . ' ' . $LIKE . '\'%' . $search . '%\' OR email ' . $LIKE . '\'%' . $search . '%\') ';
}
if ($firstinitial) {
$select .= ' AND u.firstname ' . $LIKE . '\'' . $firstinitial . '%\' ';
}
if ($lastinitial) {
$select .= ' AND u.lastname ' . $LIKE . '\'' . $lastinitial . '%\' ';
}
if ($group === 0) {
/// Need something here to get all students not in a group
return array();
} else {
if ($group !== NULL) {
$groupmembers = "INNER JOIN {$CFG->prefix}groups_members gm on u.id=gm.userid";
$select .= ' AND gm.groupid = \'' . $group . '\'';
}
}
if (!empty($exceptions)) {
$select .= ' AND u.id NOT IN (' . $exceptions . ')';
}
if ($sort) {
$sort = ' ORDER BY ' . $sort . ' ';
}
$students = get_records_sql("SELECT {$fields}\n FROM {$CFG->prefix}user u INNER JOIN\n {$CFG->prefix}role_assignments ra on u.id=ra.userid INNER JOIN\n {$CFG->prefix}role_capabilities rc ON ra.roleid=rc.roleid INNER JOIN\n {$CFG->prefix}context c ON c.id=ra.contextid LEFT OUTER JOIN\n {$CFG->prefix}user_lastaccess ul on ul.userid=ra.userid\n {$groupmembers}\n WHERE {$select} {$search} {$sort} {$dir}", $page, $recordsperpage);
return $students;
}
示例6: render
//.........这里部分代码省略.........
$deletemsg .= '<input type="hidden" name="_type" value="user" />';
if ($allentries) {
$deletemsg .= '<input type="hidden" name="id" value="all" />';
} else {
if ($searchentries) {
$deletemsg .= '<input type="hidden" name="id" value="search" /><input type="hidden" name="search" value="' . $this->searchstr . '" />';
} else {
$deletemsg .= '<input type="hidden" name="id" value="' . $this->moodleuserid . '" />';
}
}
if (!is_null($this->courseid)) {
$deletemsg .= '<input type="hidden" name="course" value="' . $this->courseid . '" />';
}
$deletemsg .= '<input type="hidden" name="delete" value="' . $this->deletesloodleentry . '" />';
$deletemsg .= '<input type="hidden" name="start" value="' . $this->start . '" />';
$deletemsg .= '<input style="color:green;" type="submit" value="' . $form_yes . '" name="confirm" /> ';
$deletemsg .= '<input style="color:red;" type="submit" value="' . $form_no . '" name="confirm" />';
$deletemsg .= '</form><br/>';
} else {
$deletemsg = get_string('deletecancelled', 'sloodle');
}
}
}
// Are we getting all entries, searching, or just viewing one?
if ($allentries) {
// All entries
$moodleuserdata = null;
// Fetch a list of all Sloodle user entries
$sloodleentries = get_records('sloodle_users');
} else {
if ($searchentries && !empty($this->searchstr)) {
// Search entries
$moodleuserdata = null;
$LIKE = sql_ilike();
$fullsloodleentries = get_records_select('sloodle_users', "avname {$LIKE} '%{$this->searchstr}%' OR uuid {$LIKE} '%{$this->searchstr}%'", 'avname');
if (!$fullsloodleentries) {
$fullsloodleentries = array();
}
$sloodleentries = array();
// Eliminate entries belonging to avatars who are not in the current course
foreach ($fullsloodleentries as $fse) {
// Does the Moodle user have permission?
if (has_capability('moodle/course:view', $this->course_context, $fse->userid)) {
// Copy it to our filtered list
$sloodleentries[] = $fse;
}
}
} else {
// Attempt to fetch the Moodle user data
$moodleuserdata = get_record('user', 'id', $this->moodleuserid);
// Fetch a list of all Sloodle user entries associated with this Moodle account
$sloodleentries = get_records('sloodle_users', 'userid', $this->moodleuserid);
}
}
// Post-process the query results
if ($sloodleentries === FALSE) {
$sloodleentries = array();
}
$numsloodleentries = count($sloodleentries);
// Get the localization strings
$strsloodle = get_string('modulename', 'sloodle');
$strsloodles = get_string('modulenameplural', 'sloodle');
$strunknown = get_string('unknown', 'sloodle');
// Construct the breadcrumb links
$navigation = "";
if ($this->courseid != 1) {
示例7: forum_search_posts
/**
* Returns a list of posts found using an array of search terms.
* @param $searchterms - array of search terms, e.g. word +word -word
* @param $courseid - if 0, we search through the whole site
* @param $page
* @param $recordsperpage=50
* @param &$totalcount
* @param $extrasql
* @return array of posts found
*/
function forum_search_posts($searchterms, $courseid = 0, $limitfrom = 0, $limitnum = 50, &$totalcount, $extrasql = '')
{
global $CFG, $USER;
require_once $CFG->libdir . '/searchlib.php';
$forums = forum_get_readable_forums($USER->id, $courseid);
if (count($forums) == 0) {
$totalcount = 0;
return false;
}
$now = round(time(), -2);
// db friendly
$fullaccess = array();
$where = array();
foreach ($forums as $forumid => $forum) {
$select = array();
if (!$forum->viewhiddentimedposts) {
$select[] = "(d.userid = {$USER->id} OR (d.timestart < {$now} AND (d.timeend = 0 OR d.timeend > {$now})))";
}
if ($forum->type == 'qanda') {
if (!empty($forum->onlydiscussions)) {
$discussionsids = implode(',', $forum->onlydiscussions);
$select[] = "(d.id IN ({$discussionsids}) OR p.parent = 0)";
} else {
$select[] = "p.parent = 0";
}
}
if (!empty($forum->onlygroups)) {
$groupids = implode(',', $forum->onlygroups);
$select[] = "d.groupid IN ({$groupids})";
}
if ($select) {
$selects = implode(" AND ", $select);
$where[] = "(d.forum = {$forumid} AND {$selects})";
} else {
$fullaccess[] = $forumid;
}
}
if ($fullaccess) {
$fullids = implode(',', $fullaccess);
$where[] = "(d.forum IN ({$fullids}))";
}
$selectdiscussion = "(" . implode(" OR ", $where) . ")";
// Some differences SQL
$LIKE = sql_ilike();
$NOTLIKE = 'NOT ' . $LIKE;
if ($CFG->dbfamily == 'postgres') {
$REGEXP = '~*';
$NOTREGEXP = '!~*';
} else {
$REGEXP = 'REGEXP';
$NOTREGEXP = 'NOT REGEXP';
}
$messagesearch = '';
$searchstring = '';
// Need to concat these back together for parser to work.
foreach ($searchterms as $searchterm) {
if ($searchstring != '') {
$searchstring .= ' ';
}
$searchstring .= $searchterm;
}
// We need to allow quoted strings for the search. The quotes *should* be stripped
// by the parser, but this should be examined carefully for security implications.
$searchstring = str_replace("\\\"", "\"", $searchstring);
$parser = new search_parser();
$lexer = new search_lexer($parser);
if ($lexer->parse($searchstring)) {
$parsearray = $parser->get_parsed_array();
// Experimental feature under 1.8! MDL-8830
// Use alternative text searches if defined
// This feature only works under mysql until properly implemented for other DBs
// Requires manual creation of text index for forum_posts before enabling it:
// CREATE FULLTEXT INDEX foru_post_tix ON [prefix]forum_posts (subject, message)
// Experimental feature under 1.8! MDL-8830
if (!empty($CFG->forum_usetextsearches)) {
$messagesearch = search_generate_text_SQL($parsearray, 'p.message', 'p.subject', 'p.userid', 'u.id', 'u.firstname', 'u.lastname', 'p.modified', 'd.forum');
} else {
$messagesearch = search_generate_SQL($parsearray, 'p.message', 'p.subject', 'p.userid', 'u.id', 'u.firstname', 'u.lastname', 'p.modified', 'd.forum');
}
}
$fromsql = "{$CFG->prefix}forum_posts p,\n {$CFG->prefix}forum_discussions d,\n {$CFG->prefix}user u";
$selectsql = " {$messagesearch}\n AND p.discussion = d.id\n AND p.userid = u.id\n AND {$selectdiscussion}\n {$extrasql}";
$countsql = "SELECT COUNT(*)\n FROM {$fromsql}\n WHERE {$selectsql}";
$searchsql = "SELECT p.*,\n d.forum,\n u.firstname,\n u.lastname,\n u.email,\n u.picture,\n u.imagealt\n FROM {$fromsql}\n WHERE {$selectsql}\n ORDER BY p.modified DESC";
$totalcount = count_records_sql($countsql);
return get_records_sql($searchsql, $limitfrom, $limitnum);
}
示例8: internalmail_get_users_by_capability
/**
* who has this capability in this context
* does not handling user level resolving!!!
* i.e 1 person has 2 roles 1 allow, 1 prevent, this will not work properly
* @param $context - object
* @param $capability - string capability
* @param $fields - fields to be pulled
* @param $sort - the sort order
* @param $limitfrom - number of records to skip (offset)
* @param $limitnum - number of records to fetch
* @param $groups - single group or array of groups - group(s) user is in
* @param $exceptions - list of users to exclude
*/
function internalmail_get_users_by_capability($context, $capability, $fields = '', $sort = 'u.firstname', $limitfrom = '', $limitnum = '', $groups = '', $exceptions = '', $doanything = true, $search = '', $firstinitial = '', $lastinitial = '')
{
global $CFG, $USER, $COURSE;
/// Sorting out groups
if ($groups !== '') {
$groupjoin = 'INNER JOIN ' . $CFG->prefix . 'groups_members gm ON gm.userid = ra.userid';
if (is_array($groups)) {
$groupsql = 'AND gm.groupid IN (' . implode(',', $groups) . ')';
} else {
if ($groups == 0) {
if (!has_capability('block/email_list:viewallgroups', $context) && $COURSE->groupmode == 1) {
$groupids = groups_get_groups_for_user($USER->id, $COURSE->id);
$groupsql = 'AND gm.groupid IN (' . implode(',', $groupids) . ')';
} else {
$groupsql = '';
}
} else {
$groupsql = 'AND gm.groupid = ' . $groups;
}
}
} else {
$groupjoin = '';
$groupsql = '';
}
/// Sorting out exceptions
$exceptionsql = $exceptions ? "AND u.id NOT IN ({$exceptions})" : '';
/// Set up default fields
if (empty($fields)) {
$fields = 'u.*, ul.timeaccess as lastaccess, ra.hidden';
}
/// Set up default sort
if (empty($sort)) {
$sortby = 'ul.timeaccess';
}
$sortby = $sort ? " ORDER BY {$sort} " : '';
/// If context is a course, then construct sql for ul
if ($context->contextlevel == CONTEXT_COURSE) {
$courseid = $context->instanceid;
$coursesql = "AND (ul.courseid = {$courseid} OR ul.courseid IS NULL)";
} else {
$coursesql = '';
}
$LIKE = sql_ilike();
$fullname = sql_fullname();
$search_sql = '';
if (!empty($search)) {
$search = trim($search);
$search_sql .= " AND ({$fullname} {$LIKE} '%{$search}%' OR email {$LIKE} '%{$search}%' OR username {$LIKE} '%{$search}%' OR idnumber {$LIKE} '%{$search}%') ";
}
if ($firstinitial) {
$search_sql .= ' AND firstname ' . $LIKE . ' \'' . $firstinitial . '%\'';
}
if ($lastinitial) {
$search_sql .= ' AND lastname ' . $LIKE . ' \'' . $lastinitial . '%\'';
}
/// Sorting out roles with this capability set
if ($possibleroles = get_roles_with_capability($capability, CAP_ALLOW, $context)) {
if (!$doanything) {
if (!($sitecontext = get_context_instance(CONTEXT_SYSTEM))) {
return false;
// Something is seriously wrong
}
$doanythingroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext);
}
$validroleids = array();
foreach ($possibleroles as $possiblerole) {
if (!$doanything) {
if (isset($doanythingroles[$possiblerole->id])) {
// We don't want these included
continue;
}
}
if ($caps = role_context_capabilities($possiblerole->id, $context, $capability)) {
// resolved list
if (isset($caps[$capability]) && $caps[$capability] > 0) {
// resolved capability > 0
$validroleids[] = $possiblerole->id;
}
}
}
if (empty($validroleids)) {
return false;
}
$roleids = '(' . implode(',', $validroleids) . ')';
} else {
return false;
// No need to continue, since no roles have this capability set
//.........这里部分代码省略.........
示例9: get_string
$strfeedback = get_string("modulename", "feedback");
$buttontext = update_module_button($cm->id, $course->id, $strfeedback);
$navlinks = array();
$navlinks[] = array('name' => $strfeedbacks, 'link' => "index.php?id={$course->id}", 'type' => 'activity');
$navlinks[] = array('name' => format_string($feedback->name), 'link' => "", 'type' => 'activityinstance');
$navigation = build_navigation($navlinks);
print_header_simple(format_string($feedback->name), "", $navigation, "", "", true, $buttontext, navmenu($course, $cm));
include 'tabs.php';
// print_simple_box(get_string('mapcourseinfo', 'feedback'), 'center', '80%');
print_box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide');
// print_simple_box_start('center', '70%');
print_box_start('generalbox boxaligncenter boxwidthwide');
echo '<form method="post">';
echo '<input type="hidden" name="id" value="' . $id . '" />';
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
$sql = "select c.id, c.shortname from {$CFG->prefix}course c\n where\n c.shortname " . sql_ilike() . " '%{$searchcourse}%'\n OR c.fullname " . sql_ilike() . " '%{$searchcourse}%'";
if (($courses = get_records_sql_menu($sql)) && !empty($searchcourse)) {
echo ' ' . get_string('courses') . ': ';
choose_from_menu($courses, 'coursefilter', $coursefilter, 'choose');
echo '<input type="submit" value="' . get_string('mapcourse', 'feedback') . '"/>';
helpbutton('mapcourses', '', 'feedback', true, true);
echo '<input type="button" value="' . get_string('searchagain') . '" onclick="document.location=\'mapcourse.php?id=' . $id . '\'"/>';
echo '<input type="hidden" name="searchcourse" value="' . $searchcourse . '"/>';
echo '<input type="hidden" name="feedbackid" value="' . $feedback->id . '"/>';
helpbutton('searchcourses', '', 'feedback', true, true);
} else {
echo '<input type="text" name="searchcourse" value="' . $searchcourse . '"/> <input type="submit" value="' . get_string('searchcourses') . '"/>';
helpbutton('searchcourses', '', 'feedback', true, true);
}
echo '</form>';
if ($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) {
示例10: get_allowed_clusters
/**
* Returns an array of cluster ids that are children of the supplied cluster and
* the current user has access to enrol users into
*
* @param int $clusterid The cluster whose children we care about
* @return int array The array of accessible cluster ids
*/
public static function get_allowed_clusters($clusterid)
{
global $USER, $CURMAN;
$context = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster:enrol_cluster_user', $USER->id);
$allowed_clusters = array();
//get the clusters and check the context against them
$cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin');
$cluster_context_instance = get_context_instance($cluster_context_level, $clusterid);
$path = sql_concat('ctxt.path', "'/%'");
$like = sql_ilike();
//query to get sub-cluster contexts
$cluster_permissions_sql = "SELECT clst.* FROM\n {$CURMAN->db->prefix_table(CLSTTABLE)} clst\n JOIN {$CURMAN->db->prefix_table('context')} ctxt\n ON clst.id = ctxt.instanceid\n AND ctxt.contextlevel = {$cluster_context_level}\n AND '{$cluster_context_instance->path}' {$like} {$path}";
if ($records = get_records_sql($cluster_permissions_sql)) {
//filter the records based on what contexts have the cluster:enrol_cluster_user capability
$allowed_clusters = $context->get_allowed_instances($records, 'cluster', 'id');
}
return $allowed_clusters;
}
示例11: forum_upgrade
//.........这里部分代码省略.........
modify_database('', 'CREATE INDEX prefix_forum_user_forum_idx ON prefix_forum_read (userid, forumid);');
modify_database('', 'CREATE INDEX prefix_forum_user_discussion_idx ON prefix_forum_read (userid, discussionid);');
modify_database('', 'CREATE INDEX prefix_forum_user_post_idx ON prefix_forum_read (userid, postid);');
set_config('upgrade', 'forumread');
// The upgrade of this table will be done later by admin/upgradeforumread.php
}
if ($oldversion < 2005032900) {
modify_database('', 'CREATE INDEX prefix_forum_posts_created_idx ON prefix_forum_posts (created);');
modify_database('', 'CREATE INDEX prefix_forum_posts_mailed_idx ON prefix_forum_posts (mailed);');
}
if ($oldversion < 2005041100) {
// replace wiki-like with markdown
include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
$wtm = new WikiToMarkdown();
$sql = "select course from {$CFG->prefix}forum_discussions, {$CFG->prefix}forum_posts ";
$sql .= "where {$CFG->prefix}forum_posts.discussion = {$CFG->prefix}forum_discussions.id ";
$sql .= "and {$CFG->prefix}forum_posts.id = ";
$wtm->update('forum_posts', 'message', 'format', $sql);
}
if ($oldversion < 2005042300) {
// Add tracking prefs table
modify_database('', 'CREATE TABLE prefix_forum_track_prefs (
id SERIAL PRIMARY KEY,
userid integer default 0 NOT NULL,
forumid integer default 0 NOT NULL
);');
}
if ($oldversion < 2005042600) {
table_column('forum', '', 'trackingtype', 'integer', '2', 'unsigned', '1', '', 'forcesubscribe');
modify_database('', 'CREATE INDEX prefix_forum_track_user_forum_idx ON prefix_forum_track_prefs (userid, forumid);');
}
if ($oldversion < 2005042601) {
// Mass cleanup of bad postgres upgrade scripts
modify_database('', 'ALTER TABLE prefix_forum ALTER trackingtype SET NOT NULL');
}
if ($oldversion < 2005111100) {
table_column('forum_discussions', '', 'timestart', 'integer');
table_column('forum_discussions', '', 'timeend', 'integer');
}
if ($oldversion < 2006011600) {
notify('forum_type does not exists, you can ignore and this will properly removed');
execute_sql("ALTER TABLE {$CFG->prefix}forum DROP CONSTRAINT {$CFG->prefix}forum_type");
execute_sql("ALTER TABLE {$CFG->prefix}forum ADD CONSTRAINT {$CFG->prefix}forum_type CHECK (type IN ('single','news','general','social','eachuser','teacher','qanda')) ");
}
if ($oldversion < 2006011601) {
table_column('forum', '', 'warnafter');
table_column('forum', '', 'blockafter');
table_column('forum', '', 'blockperiod');
}
if ($oldversion < 2006011700) {
table_column('forum_posts', '', 'mailnow', 'integer');
}
if ($oldversion < 2006011701) {
execute_sql("ALTER TABLE {$CFG->prefix}forum DROP CONSTRAINT {$CFG->prefix}forum_type_check");
}
if ($oldversion < 2006011702) {
execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('forum', 'user report', 'user', 'firstname||\\' \\'||lastname')");
}
if ($oldversion < 2006081800) {
// Upgrades for new roles and capabilities support.
require_once $CFG->dirroot . '/mod/forum/lib.php';
$forummod = get_record('modules', 'name', 'forum');
if ($forums = get_records('forum')) {
if (!($teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW))) {
notify('Default teacher role was not found. Roles and permissions ' . 'for all your forums will have to be manually set after ' . 'this upgrade.');
}
if (!($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW))) {
notify('Default student role was not found. Roles and permissions ' . 'for all your forums will have to be manually set after ' . 'this upgrade.');
}
if (!($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW))) {
notify('Default guest role was not found. Roles and permissions ' . 'for teacher forums will have to be manually set after ' . 'this upgrade.');
}
foreach ($forums as $forum) {
if (!forum_convert_to_roles($forum, $forummod->id, $teacherroles, $studentroles, $guestroles)) {
notify('Forum with id ' . $forum->id . ' was not upgraded');
}
}
// We need to rebuild all the course caches to refresh the state of
// the forum modules.
rebuild_course_cache();
}
// End if.
// Drop column forum.open.
modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN open;');
// Drop column forum.assesspublic.
modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN assesspublic;');
}
if ($oldversion < 2006082700) {
$sql = "UPDATE {$CFG->prefix}forum_posts SET message = REPLACE(message, '" . TRUSTTEXT . "', '');";
$likecond = sql_ilike() . " '%" . TRUSTTEXT . "%'";
while (true) {
if (!count_records_select('forum_posts', "message {$likecond}")) {
break;
}
execute_sql($sql);
}
}
////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
return true;
}
示例12: glossary_upgrade
//.........这里部分代码省略.........
table_column("glossary", "", "editalways", "integer", "2", "unsigned", "0", "", "entbypage");
}
//Activate editalways in old secondary glossaries (old behaviour)
if ($oldversion < 2004080900) {
set_field('glossary', 'editalways', '1', 'mainglossary', '0');
}
if ($oldversion < 2004111200) {
execute_sql("DROP INDEX {$CFG->prefix}glossary_course_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_alias_entryid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_categories_glossaryid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_comments_entryid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_comments_userid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_glossaryid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_userid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_concept_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_categories_category_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_entries_categories_entryid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_ratings_userid_idx;", false);
execute_sql("DROP INDEX {$CFG->prefix}glossary_ratings_entryid_idx;", false);
modify_database('', 'CREATE INDEX prefix_glossary_course_idx ON prefix_glossary (course);');
modify_database('', 'CREATE INDEX prefix_glossary_alias_entryid_idx ON prefix_glossary_alias (entryid);');
modify_database('', 'CREATE INDEX prefix_glossary_categories_glossaryid_idx ON prefix_glossary_categories (glossaryid);');
modify_database('', 'CREATE INDEX prefix_glossary_comments_entryid_idx ON prefix_glossary_comments (entryid);');
modify_database('', 'CREATE INDEX prefix_glossary_comments_userid_idx ON prefix_glossary_comments (userid);');
modify_database('', 'CREATE INDEX prefix_glossary_entries_glossaryid_idx ON prefix_glossary_entries (glossaryid);');
modify_database('', 'CREATE INDEX prefix_glossary_entries_userid_idx ON prefix_glossary_entries (userid);');
modify_database('', 'CREATE INDEX prefix_glossary_entries_concept_idx ON prefix_glossary_entries (concept);');
modify_database('', 'CREATE INDEX prefix_glossary_entries_categories_category_idx ON prefix_glossary_entries_categories (categoryid);');
modify_database('', 'CREATE INDEX prefix_glossary_entries_categories_entryid_idx ON prefix_glossary_entries_categories (entryid);');
modify_database('', 'CREATE INDEX prefix_glossary_ratings_userid_idx ON prefix_glossary_ratings (userid);');
modify_database('', 'CREATE INDEX prefix_glossary_ratings_entryid_idx ON prefix_glossary_ratings (entryid);');
}
//Delete orphaned categories (bug 2140)
if ($oldversion < 2005011100) {
$categories = get_records('glossary_categories', '', '', '', 'id, glossaryid');
if ($categories) {
foreach ($categories as $category) {
$glossary = get_record('glossary', 'id', "{$category->glossaryid}");
if (!$glossary) {
delete_records('glossary_categories', 'id', "{$category->id}");
}
}
}
}
//Allowprintview flag
if ($oldversion < 2005011200) {
table_column('glossary', '', 'allowprintview', 'integer', '2', 'unsigned', '1', '', 'allowcomments');
$glossaries = get_records('glossary', '', '', '', 'id, name');
if ($glossaries) {
foreach ($glossaries as $glossary) {
set_field('glossary', 'allowprintview', '1', 'id', "{$glossary->id}");
}
}
}
if ($oldversion < 2005031001) {
modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('glossary', 'view entry', 'glossary_entries', 'concept');");
}
if ($oldversion < 2005041100) {
// replace wiki-like with markdown
include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php";
$wtm = new WikiToMarkdown();
// update glossary_entries->definition
$sql = "select course from {$CFG->prefix}glossary,{$CFG->prefix}glossary_entries ";
$sql .= "where {$CFG->prefix}glossary.id = {$CFG->prefix}glossary_entries.glossaryid ";
$sql .= "and {$CFG->prefix}glossary_entries.id = ";
$wtm->update('glossary_entries', 'definition', 'format');
// update glossary_comments->text
$sql = "select course from {$CFG->prefix}glossary,{$CFG->prefix}glossary_entries,{$CFG->prefix}glossary_comments ";
$sql .= "where {$CFG->prefix}glossary.id = {$CFG->prefix}glossary_entries.glossaryid ";
$sql .= "and {$CFG->prefix}glossary_entries.id = {$CFG->prefix}glossary_comments.entryid ";
$sql .= "and {$CFG->prefix}glossary_comments.id = ";
$wtm->update('glossary_comments', 'text', 'format', $sql);
}
if ($oldversion < 2005041901) {
// Mass cleanup of bad postgres upgrade scripts
table_column('glossary', 'allowprintview', 'allowprintview', 'smallint', '4', 'unsigned', '1');
}
if ($oldversion < 2006082600) {
$sql1 = "UPDATE {$CFG->prefix}glossary_entries SET definition = REPLACE(definition, '" . TRUSTTEXT . "', '');";
$sql2 = "UPDATE {$CFG->prefix}glossary_comments SET comment = REPLACE(comment, '" . TRUSTTEXT . "', '');";
$likecond = sql_ilike() . " '%" . TRUSTTEXT . "%'";
while (true) {
if (!count_records_select('glossary_entries', "definition {$likecond}")) {
break;
}
execute_sql($sql1);
}
while (true) {
if (!count_records_select('glossary_comments', "comment {$likecond}")) {
break;
}
execute_sql($sql2);
}
}
if ($oldversion < 2006090400) {
table_column('glossary_comments', 'comment', 'entrycomment', 'text', '', '', '');
}
////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
return true;
}
示例13: print_form
function print_form()
{
global $THEME, $CFG;
// get the search string, if it exists
$searchtext = optional_param('searchtext', '', PARAM_RAW);
$previoussearch = optional_param('previoussearch', 0, PARAM_BOOL);
$showall = optional_param('showall', 0, PARAM_BOOL);
$strshowall = get_string('showall');
$strsearchresults = get_string('searchresults');
$previoussearch = $searchtext != '' or $previoussearch ? 1 : 0;
// Showing all means that we need to clear out the search string
if ($showall) {
$searchtext = '';
$previoussearch = 0;
}
$searchtext = trim($searchtext);
if ($searchtext !== '') {
$LIKE = sql_ilike();
$selectsql = " AND (CONCAT(u.firstname, ' ', u.lastname) \n {$LIKE} '%{$searchtext}%' OR email {$LIKE} '%{$searchtext}%') ";
} else {
$selectsql = '';
$previoussearch = 0;
}
define('MAX_USERS_PER_PAGE', 5000);
define('MAX_USERS_TO_LIST_PER_ROLE', 20);
//Find all the users that are assigned this role
$sql = $this->get_sql();
$sub_sql = $this->get_context_user_sql();
$everyone = $this->get_everyone_sql();
$excsql = $this->get_exclusive_sql($sub_sql);
// These are the people who are assigned
$contextusers = get_records_sql($sql . $sub_sql);
if (!$contextusers) {
$contextusers = array();
}
// These are people who can be potentially assigned
$availableusers = get_recordset_sql($sql . $everyone . $selectsql . $excsql);
$usercount = $availableusers->_numOfRows;
$strsearch = get_string('search');
print_box_start();
include 'assign.html';
print_box_end();
}
示例14: block_php_report_get_copy_label
/**
* Calculates a new label for a copy of an existing PHP report schedule
* based on the existing schedule's name
*
* @param string $parent_label The label from the original schedule instance
*
* @return string The label for the new schedule instance
*/
function block_php_report_get_copy_label($parent_label)
{
//first guess at to our copy number
$i = 1;
$done = false;
while (!$done) {
//get the proposed label
$a = new stdClass();
$a->label = $parent_label;
$a->index = $i;
$label = get_string('task_copy_label', 'block_php_report', $a);
//look for records containing the proposed namy anywhere in their config data
//(may include false-positives but very unlikely)
if ($records = get_recordset_select('php_report_schedule', 'config ' . sql_ilike() . " '%{$label}%'")) {
//track whether an exact match was found
$found = false;
//go through all possible matches
while ($record = rs_fetch_next_record($records)) {
//perform an exact comparison
$config = unserialize($record->config);
if ($config['label'] == $label) {
//exact match
$found = true;
break;
}
}
if (!$found) {
//all cases were false, positive, so accept
$done = true;
} else {
//exact match, so increment and try again
$i++;
}
} else {
//no config contained the proposed label, so accept
$done = true;
}
}
return $label;
}
示例15: COUNT
$searchselect = ' ';
}
} else {
if ($search) {
$what = ' DISTINCT r.id, r.approved, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(DISTINCT c.recordid) ';
$tables = $CFG->prefix . 'data_content c,' . $CFG->prefix . 'data_records r, ' . $CFG->prefix . 'user u ';
$where = 'WHERE c.recordid = r.id
AND r.userid = u.id
AND r.dataid = ' . $data->id;
$sortorder = ' ORDER BY r.id ASC ';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
$searchselect = ' AND (c.content ' . sql_ilike() . " '%{$search}%') ";
//Be case-insensitive
} else {
$what = ' DISTINCT r.id, r.approved, r.timecreated, r.userid, u.firstname, u.lastname ';
$count = ' COUNT(r.id) ';
$tables = $CFG->prefix . 'data_records r, ' . $CFG->prefix . 'user u ';
$where = 'WHERE r.dataid = ' . $data->id . ' AND r.userid = u.id ';
$sortorder = ' ORDER BY r.timecreated ' . $order . ' ';
$searchselect = ' ';
// If requiredentries is not reached, only show current user's entries
if (!$requiredentries_allowed) {
$where .= ' AND u.id = ' . $USER->id;
}
}
}
/// To actually fetch the records