本文整理汇总了PHP中record_exists_sql函数的典型用法代码示例。如果您正苦于以下问题:PHP record_exists_sql函数的具体用法?PHP record_exists_sql怎么用?PHP record_exists_sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了record_exists_sql函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_record_exists_sql
function test_record_exists_sql()
{
global $CFG;
$this->assertTrue(record_exists_sql("SELECT * FROM {$CFG->prefix}{$this->table} WHERE numberfield = 101 AND id = 1"));
$this->assertFalse(record_exists_sql("SELECT * FROM {$CFG->prefix}{$this->table} WHERE numberfield = 102 AND id = 1"));
$this->assertTrue(record_exists_sql("SELECT * FROM {$CFG->prefix}{$this->table} WHERE numberfield IS NULL"));
}
示例2: forgotpass_validate
function forgotpass_validate(Pieform $form, $values)
{
// See if the user input an email address or a username. We favour email addresses
if (!$form->get_error('emailusername')) {
// Check if the user who associates to username or email address is using the external authentication
if (record_exists_sql('SELECT u.authinstance
FROM {usr} u INNER JOIN {auth_instance} ai ON (u.authinstance = ai.id)
WHERE (LOWER(u.email) = ? OR LOWER(u.username) = ?)
AND ((ai.authname != \'internal\') AND (ai.authname != \'none\'))', array_fill(0, 2, strtolower($values['emailusername'])))) {
$form->set_error('emailusername', get_string('forgotpassuserusingexternalauthentication', 'mahara', get_config('wwwroot') . 'contact.php'));
} else {
if (!($authinstance = get_field_sql('SELECT u.authinstance
FROM {usr} u INNER JOIN {auth_instance} ai ON (u.authinstance = ai.id)
WHERE (LOWER(u.email) = ? OR LOWER(u.username) = ?)
AND ai.authname = \'internal\'', array_fill(0, 2, strtolower($values['emailusername']))))) {
$form->set_error('emailusername', get_string('forgotpassnosuchemailaddressorusername'));
}
}
}
if ($form->get_error('emailusername')) {
return;
}
$authobj = AuthFactory::create($authinstance);
if (!method_exists($authobj, 'change_password')) {
die_info(get_string('cantchangepassword'));
}
}
示例3: isAttemptLeftOpen
function isAttemptLeftOpen($cmid, $userid)
{
$result = false;
$cm = get_record('course_modules', 'id', $cmid);
$sql = 'select * from mdl_quiz_attempts where userid = ' . $userid . ' and quiz =' . $cm->instance . ' and timefinish = 0';
if (record_exists_sql($sql)) {
$result = true;
}
return $result;
}
示例4: artefact_in_view
function artefact_in_view($artefact, $view)
{
$sql = 'SELECT a.id
FROM {view_artefact} a WHERE "view" = ? AND artefact = ?
UNION
SELECT c.parent
FROM {view_artefact} top JOIN {artefact_parent_cache} c
ON c.parent = top.artefact
WHERE top.view = ? AND c.artefact = ?
UNION
SELECT s.id
FROM {view} v INNER JOIN {skin} s ON v.skin = s.id
WHERE v.id = ? AND ? in (s.bodybgimg, s.viewbgimg)
';
return record_exists_sql($sql, array($view, $artefact, $view, $artefact, $view, $artefact));
}
示例5: can_do_viewreport
/**
* Dummy can_do method for viewing a curriculum report (needed for the
* cluster tree parameter for reports)
*/
function can_do_viewreport()
{
global $CFG, $CURMAN;
$id = $this->required_param('id', PARAM_INT);
//needed for execution mode constants
require_once $CFG->dirroot . '/blocks/php_report/php_report_base.php';
//check if we're scheduling or viewing
$execution_mode = $this->optional_param('execution_mode', php_report::EXECUTION_MODE_SCHEDULED, PARAM_INT);
//check the correct capability
$capability = $execution_mode == php_report::EXECUTION_MODE_SCHEDULED ? 'block/php_report:schedule' : 'block/php_report:view';
if ($this->_has_capability($capability)) {
return true;
}
/*
* Start of cluster hierarchy extension
*/
$viewable_clusters = cluster::get_viewable_clusters($capability);
$cluster_context_level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin');
$like = sql_ilike();
$parent_path = sql_concat('parent_context.path', "'/%'");
//if the user has no additional access through parent clusters, then they can't view this cluster
if (empty($viewable_clusters)) {
return false;
}
$cluster_filter = implode(',', $viewable_clusters);
//determine if this cluster is the parent of some accessible child cluster
$sql = "SELECT parent_context.instanceid\n FROM {$CURMAN->db->prefix_table('context')} parent_context\n JOIN {$CURMAN->db->prefix_table('context')} child_context\n ON child_context.path {$like} {$parent_path}\n AND parent_context.contextlevel = {$cluster_context_level}\n AND child_context.contextlevel = {$cluster_context_level}\n AND child_context.instanceid IN ({$cluster_filter})\n AND parent_context.instanceid = {$id}";
return record_exists_sql($sql);
/*
* End of cluster hierarchy extension
*/
}
示例6: backup_general_info
function backup_general_info($bf, $preferences)
{
global $CFG;
fwrite($bf, start_tag("INFO", 1, true));
//The name of the backup
fwrite($bf, full_tag("NAME", 2, false, $preferences->backup_name));
//The moodle_version
fwrite($bf, full_tag("MOODLE_VERSION", 2, false, $preferences->moodle_version));
fwrite($bf, full_tag("MOODLE_RELEASE", 2, false, $preferences->moodle_release));
//The backup_version
fwrite($bf, full_tag("BACKUP_VERSION", 2, false, $preferences->backup_version));
fwrite($bf, full_tag("BACKUP_RELEASE", 2, false, $preferences->backup_release));
//The date
fwrite($bf, full_tag("DATE", 2, false, $preferences->backup_unique_code));
//The original site wwwroot
fwrite($bf, full_tag("ORIGINAL_WWWROOT", 2, false, $CFG->wwwroot));
//The original site identifier. MD5 hashed for security.
fwrite($bf, full_tag("ORIGINAL_SITE_IDENTIFIER_HASH", 2, false, md5(get_site_identifier())));
//The zip method used
if (!empty($CFG->zip)) {
$zipmethod = 'external';
} else {
$zipmethod = 'internal';
}
//Indicate if it includes external MNET users
$sql = "SELECT b.old_id\n FROM {$CFG->prefix}backup_ids b\n JOIN {$CFG->prefix}user u ON b.old_id=u.id\n WHERE b.backup_code = '{$preferences->backup_unique_code}'\n AND b.table_name = 'user' AND u.mnethostid != '{$CFG->mnet_localhost_id}'";
if (record_exists_sql($sql)) {
fwrite($bf, full_tag("MNET_REMOTEUSERS", 2, false, 'true'));
}
fwrite($bf, full_tag("ZIP_METHOD", 2, false, $zipmethod));
//Te includes tag
fwrite($bf, start_tag("DETAILS", 2, true));
//Now, go to mod element of preferences to print its status
foreach ($preferences->mods as $element) {
//Calculate info
$included = "false";
$userinfo = "false";
if ($element->backup) {
$included = "true";
if ($element->userinfo) {
$userinfo = "true";
}
}
//Prints the mod start
fwrite($bf, start_tag("MOD", 3, true));
fwrite($bf, full_tag("NAME", 4, false, $element->name));
fwrite($bf, full_tag("INCLUDED", 4, false, $included));
fwrite($bf, full_tag("USERINFO", 4, false, $userinfo));
if (isset($preferences->mods[$element->name]->instances) && is_array($preferences->mods[$element->name]->instances) && count($preferences->mods[$element->name]->instances)) {
fwrite($bf, start_tag("INSTANCES", 4, true));
foreach ($preferences->mods[$element->name]->instances as $id => $object) {
if (!empty($object->backup)) {
//Calculate info
$included = "false";
$userinfo = "false";
if ($object->backup) {
$included = "true";
if ($object->userinfo) {
$userinfo = "true";
}
}
fwrite($bf, start_tag("INSTANCE", 5, true));
fwrite($bf, full_tag("ID", 5, false, $id));
fwrite($bf, full_tag("NAME", 5, false, $object->name));
fwrite($bf, full_tag("INCLUDED", 5, false, $included));
fwrite($bf, full_tag("USERINFO", 5, false, $userinfo));
fwrite($bf, end_tag("INSTANCE", 5, true));
}
}
fwrite($bf, end_tag("INSTANCES", 4, true));
}
//Print the end
fwrite($bf, end_tag("MOD", 3, true));
}
//The metacourse in backup
if ($preferences->backup_metacourse == 1) {
fwrite($bf, full_tag("METACOURSE", 3, false, "true"));
} else {
fwrite($bf, full_tag("METACOURSE", 3, false, "false"));
}
//The user in backup
if ($preferences->backup_users == 1) {
fwrite($bf, full_tag("USERS", 3, false, "course"));
} else {
if ($preferences->backup_users == 0) {
fwrite($bf, full_tag("USERS", 3, false, "all"));
} else {
fwrite($bf, full_tag("USERS", 3, false, "none"));
}
}
//The logs in backup
if ($preferences->backup_logs == 1) {
fwrite($bf, full_tag("LOGS", 3, false, "true"));
} else {
fwrite($bf, full_tag("LOGS", 3, false, "false"));
}
//The user files
if ($preferences->backup_user_files == 1) {
fwrite($bf, full_tag("USERFILES", 3, false, "true"));
} else {
//.........这里部分代码省略.........
示例7: send
/**
* Send the request to the server - decode and return the response
*
* @param object $mnet_peer A mnet_peer object with details of the
* remote host we're connecting to
* @return mixed A PHP variable, as returned by the
* remote function
*/
function send($mnet_peer)
{
global $CFG, $MNET;
$this->uri = $mnet_peer->wwwroot . $mnet_peer->application->xmlrpc_server_url;
// Initialize with the target URL
$ch = curl_init($this->uri);
$system_methods = array('system/listMethods', 'system/methodSignature', 'system/methodHelp', 'system/listServices');
if (in_array($this->method, $system_methods)) {
// Executing any system method is permitted.
} else {
$id_list = $mnet_peer->id;
if (!empty($CFG->mnet_all_hosts_id)) {
$id_list .= ', ' . $CFG->mnet_all_hosts_id;
}
// At this point, we don't care if the remote host implements the
// method we're trying to call. We just want to know that:
// 1. The method belongs to some service, as far as OUR host knows
// 2. We are allowed to subscribe to that service on this mnet_peer
// Find methods that we subscribe to on this host
$sql = "\n SELECT\n r.id\n FROM\n {$CFG->prefix}mnet_rpc r,\n {$CFG->prefix}mnet_service2rpc s2r,\n {$CFG->prefix}mnet_host2service h2s\n WHERE\n r.xmlrpc_path = '{$this->method}' AND\n s2r.rpcid = r.id AND\n s2r.serviceid = h2s.serviceid AND\n h2s.subscribe = '1' AND\n h2s.hostid in ({$id_list})";
if (!record_exists_sql($sql)) {
global $USER;
$this->error[] = '7:User with ID ' . $USER->id . ' attempted to call unauthorised method ' . $this->method . ' on host ' . $mnet_peer->wwwroot;
return false;
}
}
$this->requesttext = xmlrpc_encode_request($this->method, $this->params, array("encoding" => "utf-8", "escaping" => "markup"));
$rq = $this->requesttext;
$rq = mnet_sign_message($this->requesttext);
$this->signedrequest = $rq;
$rq = mnet_encrypt_message($rq, $mnet_peer->public_key);
$this->encryptedrequest = $rq;
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Moodle');
curl_setopt($ch, CURLOPT_POSTFIELDS, $rq);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml charset=UTF-8"));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$timestamp_send = time();
$this->rawresponse = curl_exec($ch);
$timestamp_receive = time();
if ($this->rawresponse === false) {
$this->error[] = curl_errno($ch) . ':' . curl_error($ch);
return false;
}
$this->rawresponse = trim($this->rawresponse);
$mnet_peer->touch();
$crypt_parser = new mnet_encxml_parser();
$crypt_parser->parse($this->rawresponse);
if ($crypt_parser->payload_encrypted) {
$key = array_pop($crypt_parser->cipher);
$data = array_pop($crypt_parser->cipher);
$crypt_parser->free_resource();
// Initialize payload var
$payload = '';
// &$payload
$isOpen = openssl_open(base64_decode($data), $payload, base64_decode($key), $MNET->get_private_key());
if (!$isOpen) {
// Decryption failed... let's try our archived keys
$openssl_history = get_config('mnet', 'openssl_history');
if (empty($openssl_history)) {
$openssl_history = array();
set_config('openssl_history', serialize($openssl_history), 'mnet');
} else {
$openssl_history = unserialize($openssl_history);
}
foreach ($openssl_history as $keyset) {
$keyresource = openssl_pkey_get_private($keyset['keypair_PEM']);
$isOpen = openssl_open(base64_decode($data), $payload, base64_decode($key), $keyresource);
if ($isOpen) {
// It's an older code, sir, but it checks out
break;
}
}
}
if (!$isOpen) {
trigger_error("None of our keys could open the payload from host {$mnet_peer->wwwroot} with id {$mnet_peer->id}.");
$this->error[] = '3:No key match';
return false;
}
if (strpos(substr($payload, 0, 100), '<signedMessage>')) {
$sig_parser = new mnet_encxml_parser();
$sig_parser->parse($payload);
} else {
$this->error[] = '2:Payload not signed: ' . $payload;
return false;
}
} else {
if (!empty($crypt_parser->remoteerror)) {
$this->error[] = '4: remote server error: ' . $crypt_parser->remoteerror;
//.........这里部分代码省略.........
示例8: edituser_site_validate
function edituser_site_validate(Pieform $form, $values)
{
global $USER, $SESSION;
if (!($user = get_record('usr', 'id', $values['id']))) {
return false;
}
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
$maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
$maxquota = get_config_plugin('artefact', 'file', 'maxquota');
if ($maxquotaenabled && $values['quota'] > $maxquota) {
$form->set_error('quota', get_string('maxquotaexceededform', 'artefact.file', display_size($maxquota)));
$SESSION->add_error_msg(get_string('maxquotaexceeded', 'artefact.file', display_size($maxquota)));
}
}
$userobj = new User();
$userobj = $userobj->find_by_id($user->id);
if (isset($values['username']) && !empty($values['username']) && $values['username'] != $userobj->username) {
if (!isset($values['authinstance'])) {
$authobj = AuthFactory::create($userobj->authinstance);
} else {
$authobj = AuthFactory::create($values['authinstance']);
}
if (method_exists($authobj, 'change_username')) {
if (method_exists($authobj, 'is_username_valid_admin')) {
if (!$authobj->is_username_valid_admin($values['username'])) {
$form->set_error('username', get_string('usernameinvalidadminform', 'auth.internal'));
}
} else {
if (method_exists($authobj, 'is_username_valid')) {
if (!$authobj->is_username_valid($values['username'])) {
$form->set_error('username', get_string('usernameinvalidform', 'auth.internal'));
}
}
}
if (!$form->get_error('username') && record_exists_select('usr', 'LOWER(username) = ?', array(strtolower($values['username'])))) {
$form->set_error('username', get_string('usernamealreadytaken', 'auth.internal'));
}
} else {
$form->set_error('username', get_string('usernamechangenotallowed', 'admin'));
}
}
// Check that the external username isn't already in use by someone else
if (isset($values['authinstance']) && isset($values['remoteusername'])) {
// there are 4 cases for changes on the page
// 1) ai and remoteuser have changed
// 2) just ai has changed
// 3) just remoteuser has changed
// 4) the ai changes and the remoteuser is wiped - this is a delete of the old ai-remoteuser
// determine the current remoteuser
$current_remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id);
if (!$current_remotename) {
$current_remotename = $user->username;
}
// what should the new remoteuser be
$new_remoteuser = get_field('auth_remote_user', 'remoteusername', 'authinstance', $values['authinstance'], 'localusr', $user->id);
if (!$new_remoteuser) {
$new_remoteuser = $user->username;
}
if (strlen(trim($values['remoteusername'])) > 0) {
// value changed on page - use it
if ($values['remoteusername'] != $current_remotename) {
$new_remoteuser = $values['remoteusername'];
}
}
// what really counts is who owns the target remoteuser slot
$target_owner = get_field('auth_remote_user', 'localusr', 'authinstance', $values['authinstance'], 'remoteusername', $new_remoteuser);
// target remoteuser is owned by someone else
if ($target_owner && $target_owner != $user->id) {
$usedbyuser = get_field('usr', 'username', 'id', $target_owner);
$SESSION->add_error_msg(get_string('duplicateremoteusername', 'auth', $usedbyuser));
$form->set_error('remoteusername', get_string('duplicateremoteusernameformerror', 'auth'));
}
}
// Check if the new primary email address is valid
if (isset($values['email']) && $values['email'] !== $user->email) {
$email = sanitize_email($values['email']);
if (!$form->get_error('email')) {
if (!$form->get_error('email') && empty($email)) {
$form->set_error('email', get_string('invalidemailaddress', 'artefact.internal'));
}
if (record_exists_sql('
SELECT id
FROM {usr}
WHERE deleted != 1 AND email = ? AND id != ?', array($email, $user->id)) || record_exists_sql('
SELECT owner
FROM {artefact_internal_profile_email}
WHERE email = ? AND owner != ?', array($email, $user->id))) {
$form->set_error('email', get_string('emailalreadytakenbyothers', 'auth.internal'));
}
}
}
}
示例9: record_exists
/**
* Test whether a record exists in a table where all the given fields match the given values.
*
* The record to test is specified by giving up to three fields that must
* equal the corresponding values.
*
* @uses $CFG
* @param string $table The table to check.
* @param string $field1 the first field to check (optional).
* @param string $value1 the value field1 must have (requred if field1 is given, else optional).
* @param string $field2 the second field to check (optional).
* @param string $value2 the value field2 must have (requred if field2 is given, else optional).
* @param string $field3 the third field to check (optional).
* @param string $value3 the value field3 must have (requred if field3 is given, else optional).
* @return bool true if a matching record exists, else false.
*/
function record_exists($table, $field1 = null, $value1 = null, $field2 = null, $value2 = null, $field3 = null, $value3 = null)
{
global $CFG;
$select = where_clause_prepared($field1, $field2, $field3);
$values = where_values_prepared($value1, $value2, $value3);
return record_exists_sql('SELECT * FROM ' . $CFG->prefix . $table . ' ' . $select . ' LIMIT 1', $values);
}
示例10: online_assignment_cleanup
function online_assignment_cleanup($output = false)
{
global $CFG;
if ($output) {
print_heading('Online Assignment Cleanup');
echo '<center>';
}
/// We don't want to run this code if we are doing an upgrade from an assignment
/// version earlier than 2005041400
/// because the assignment type field will not exist
$amv = get_field('modules', 'version', 'name', 'assignment');
if ((int) $amv < 2005041400) {
if ($output) {
echo '</center>';
}
return;
}
/// get the module id for assignments from db
$arecord = get_record('modules', 'name', 'assignment');
$aid = $arecord->id;
/// get a list of all courses on this site
$courses = get_records('course');
/// cycle through each course
foreach ($courses as $course) {
$fullname = empty($course->fullname) ? 'Course: ' . $course->id : $course->fullname;
if ($output) {
print_heading($fullname);
}
/// retrieve a list of sections beyond what is currently being shown
$sql = 'SELECT * FROM ' . $CFG->prefix . 'course_sections WHERE course=' . $course->id . ' AND section>' . $course->numsections . ' ORDER BY section ASC';
if (!($xsections = get_records_sql($sql))) {
if ($output) {
echo 'No extra sections<br />';
}
continue;
}
/// cycle through each of the xtra sections
foreach ($xsections as $xsection) {
if ($output) {
echo 'Checking Section: ' . $xsection->section . '<br />';
}
/// grab any module instances from the sequence field
if (!empty($xsection->sequence)) {
$instances = explode(',', $xsection->sequence);
/// cycle through the instances
foreach ($instances as $instance) {
/// is this an instance of an online assignment
$sql = "SELECT a.id\n FROM {$CFG->prefix}course_modules cm,\n {$CFG->prefix}assignment a\n WHERE cm.id = '{$instance}' AND\n cm.module = '{$aid}' AND\n cm.instance = a.id AND\n a.assignmenttype = 'online'";
/// if record exists then we need to move instance to it's correct section
if (record_exists_sql($sql)) {
/// check the new section id
/// the journal update erroneously stored it in course_sections->section
$newsection = $xsection->section;
/// double check the new section
if ($newsection > $course->numsections) {
/// get the record for section 0 for this course
if (!($zerosection = get_record('course_sections', 'course', $course->id, 'section', '0'))) {
continue;
}
$newsection = $zerosection->id;
}
/// grab the section record
if (!($section = get_record('course_sections', 'id', $newsection))) {
if ($output) {
echo 'Serious error: Cannot retrieve section: ' . $newsection . ' for course: ' . format_string($course->fullname) . '<br />';
}
continue;
}
/// explode the sequence
if (($sequence = explode(',', $section->sequence)) === false) {
$sequence = array();
}
/// add instance to correct section
array_push($sequence, $instance);
/// implode the sequence
$section->sequence = implode(',', $sequence);
set_field('course_sections', 'sequence', $section->sequence, 'id', $section->id);
/// now we need to remove the instance from the old sequence
/// grab the old section record
if (!($section = get_record('course_sections', 'id', $xsection->id))) {
if ($output) {
echo 'Serious error: Cannot retrieve old section: ' . $xsection->id . ' for course: ' . $course->fullname . '<br />';
}
continue;
}
/// explode the sequence
if (($sequence = explode(',', $section->sequence)) === false) {
$sequence = array();
}
/// remove the old value from the array
$key = array_search($instance, $sequence);
unset($sequence[$key]);
/// implode the sequence
$section->sequence = implode(',', $sequence);
set_field('course_sections', 'sequence', $section->sequence, 'id', $section->id);
if ($output) {
echo 'Online Assignment (instance ' . $instance . ') moved from section ' . $section->id . ': to section ' . $newsection . '<br />';
}
}
}
//.........这里部分代码省略.........
示例11: record_exists_select
/**
* Test whether any records exists in a table which match a particular WHERE clause.
*
* This function returns true if at least one record is returned
*
* @param string $table The database table to be checked against.
* @param string $select A fragment of SQL to be used in a WHERE clause in the SQL call.
* @param array $values When using prepared statements, this is the value array (optional).
* @return bool true if a matching record exists, else false.
* @throws SQLException
*/
function record_exists_select($table, $select = '', $values = null)
{
global $CFG;
if ($select) {
$select = 'WHERE ' . $select;
}
return record_exists_sql('SELECT * FROM ' . db_table_name($table) . ' ' . $select, $values);
}
示例12: data_preprocessing
function data_preprocessing(&$default_values)
{
global $CFG;
if (array_key_exists('update', $default_values)) {
$sql = "SELECT id FROM {$CFG->prefix}adobeconnect_meeting_groups WHERE " . "instanceid = " . $default_values['id'];
if (record_exists_sql($sql)) {
$default_values['tempenable'] = 0;
}
}
}
示例13: elseif
} elseif (intval($days2expire) < 0) {
print_header("{$site->fullname}: {$loginsite}", "{$site->fullname}", $navigation, '', '', true, "<div class=\"langmenu\">{$langmenu}</div>");
notice_yesno(get_string('auth_passwordisexpired', 'auth'), $passwordchangeurl, $urltogo);
print_footer();
exit;
}
}
reset_login_count();
redirect($urltogo);
exit;
} else {
if (empty($errormsg)) {
$errormsg = get_string("invalidlogin");
$errorcode = 3;
}
if (!empty($CFG->mnet_dispatcher_mode) && $CFG->mnet_dispatcher_mode === 'strict' && is_enabled_auth('mnet') && record_exists_sql("SELECT h.id FROM {$CFG->prefix}mnet_host h\n INNER JOIN {$CFG->prefix}mnet_host2service m ON h.id=m.hostid\n INNER JOIN {$CFG->prefix}mnet_service s ON s.id=m.serviceid\n WHERE s.name='sso_sp' AND h.deleted=0 AND m.publish = 1") && record_exists_select('user', "username = '{$frm->username}' AND mnethostid != {$CFG->mnet_localhost_id}")) {
$errormsg .= get_string('loginlinkmnetuser', 'mnet', "mnet_email.php?u={$frm->username}");
}
}
}
}
/// Detect problems with timedout sessions
if ($session_has_timed_out and !data_submitted()) {
$errormsg = get_string('sessionerroruser', 'error');
$errorcode = 4;
}
/// First, let's remember where the user was trying to get to before they got here
if (empty($SESSION->wantsurl)) {
$SESSION->wantsurl = array_key_exists('HTTP_REFERER', $_SERVER) && $_SERVER["HTTP_REFERER"] != $CFG->wwwroot && $_SERVER["HTTP_REFERER"] != $CFG->wwwroot . '/' && $_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot . '/login/' && $_SERVER["HTTP_REFERER"] != $CFG->httpswwwroot . '/login/index.php' ? $_SERVER["HTTP_REFERER"] : NULL;
}
/// Redirect to alternative login URL if needed
示例14: update_favorites
/**
* Update or create a favourites list for a user
*
* @param $owner integer owner of the favorites list
* @param $shortname string name for the favorites list
* @param $institution string institution with permission to update the favorites list
* @param $userlist array array of userids to add to the list
*/
function update_favorites($owner, $shortname, $institution, $userlist)
{
global $USER;
if (empty($institution)) {
// User-editable favorites lists are not implemented yet.
return;
}
if (!$USER->can_edit_institution($institution)) {
throw new AccessDeniedException("update_favorites: access denied");
}
$owner = (int) $owner;
if ($institution == 'mahara') {
if (!record_exists('usr', 'id', $owner, 'deleted', 0)) {
throw new NotFoundException("update_favorites: user {$owner} not found");
}
} else {
$sql = '
SELECT u.id
FROM {usr} u JOIN {usr_institution} ui ON u.id = ui.usr AND ui.institution = ?
WHERE u.id = ? AND u.deleted = 0';
if (!record_exists_sql($sql, array($institution, $owner))) {
throw new NotFoundException("update_favorites: user {$owner} not found in institution {$institution}");
}
}
$listdata = get_record('favorite', 'owner', $owner, 'shortname', $shortname);
if ($listdata && $listdata->institution != $institution) {
throw new AccessDeniedException("update_favorites: user {$owner} already has a favorites list called {$shortname} which is updated by another institution");
}
if (!is_array($userlist)) {
throw new SystemException("update_favorites: userlist is not an array");
}
if (!empty($userlist)) {
$userids = get_column_sql('
SELECT id FROM {usr} WHERE id IN (' . join(',', array_fill(0, count($userlist), '?')) . ') AND deleted = 0', array_map('intval', $userlist));
}
if (empty($userids)) {
$userids = array();
}
db_begin();
$now = db_format_timestamp(time());
if ($listdata) {
delete_records('favorite_usr', 'favorite', $listdata->id);
$listdata->mtime = $now;
update_record('favorite', $listdata, 'id');
} else {
$listdata = (object) array('owner' => $owner, 'shortname' => $shortname, 'institution' => $institution, 'ctime' => $now, 'mtime' => $now);
$listdata->id = insert_record('favorite', $listdata, 'id', true);
}
foreach ($userids as $userid) {
insert_record('favorite_usr', (object) array('favorite' => $listdata->id, 'usr' => $userid));
}
db_commit();
}
示例15: artefact_in_view
/**
* Checks if artefact or at least one of its ancestors is in view
*
* @param int|object $artefact ID of an artefact or object itself.
* Will load object if ID is supplied.
* @param int $view ID of a page that contains artefact.
*
* @return boolean True if artefact is in view, False otherwise.
*/
function artefact_in_view($artefact, $view)
{
if (!is_object($artefact)) {
$artefact = artefact_instance_from_id($artefact);
}
$ancestors = $artefact->get_item_ancestors();
$params = array($view, $artefact->get('id'), $artefact->get('id'));
$extrasql = '';
if ($ancestors) {
$extrasql = "SELECT a.parent\n FROM {view_artefact} top JOIN {artefact} a\n ON a.parent = top.artefact\n WHERE top.view = ? AND top.artefact IN (" . implode(',', $ancestors) . ")\n UNION";
$params[] = $view;
}
$sql = "SELECT a.id\n FROM {view_artefact} a WHERE \"view\" = ? AND artefact = ?\n UNION\n SELECT aa.artefact\n FROM {artefact} a INNER JOIN {artefact_attachment} aa\n ON a.id = aa.artefact\n WHERE aa.attachment = ?\n UNION\n {$extrasql}\n SELECT s.id\n FROM {view} v INNER JOIN {skin} s\n ON v.skin = s.id\n WHERE v.id = ? AND ? in (s.bodybgimg, s.viewbgimg)\n ";
$params = array_merge($params, array($view, $artefact->get('id')));
return record_exists_sql($sql, $params);
}