Minor: Format code

pull/5010/head
Angel Fernando Quiroz Campos 2 years ago
parent a3e5a03599
commit b63d4271e6
  1. 2
      main/admin/user_update_import.php
  2. 4
      main/attendance/attendance_sheet.php
  3. 6
      main/attendance/index.php
  4. 2
      main/auth/profile.php
  5. 2
      main/auth/reset.php
  6. 1
      main/cron/update_ldap_users.php
  7. 8
      main/inc/lib/document.lib.php
  8. 3
      main/inc/lib/statistics.lib.php
  9. 110
      main/inc/lib/usermanager.lib.php

@ -90,7 +90,7 @@ function _updateUsers(
$resetPassword = false, $resetPassword = false,
$sendEmail = false, $sendEmail = false,
$askNewPassword = false $askNewPassword = false
){ ) {
$usergroup = new UserGroup(); $usergroup = new UserGroup();
$extraFieldValue = new ExtraFieldValue('user'); $extraFieldValue = new ExtraFieldValue('user');
if (is_array($users)) { if (is_array($users)) {

@ -522,8 +522,8 @@ if (api_is_allowed_to_edit(null, true) ||
// if calendar is blocked by admin is it not displayed here. // if calendar is blocked by admin is it not displayed here.
if ($isBlocked) { if ($isBlocked) {
continue; continue;
} }
if (!empty($_REQUEST['filter']) && is_numeric($_REQUEST['filter']) && $_REQUEST['filter'] != $presence['calendar_id']) { if (!empty($_REQUEST['filter']) && is_numeric($_REQUEST['filter']) && $_REQUEST['filter'] != $presence['calendar_id']) {
continue; continue;
} }
$signature = $attendance->getSignature($user_id, $presence['calendar_id']); $signature = $attendance->getSignature($user_id, $presence['calendar_id']);

@ -279,9 +279,9 @@ switch ($action) {
$renderer->setHeight(256); $renderer->setHeight(256);
$renderer->setWidth(256); $renderer->setWidth(256);
$writer = new \BaconQrCode\Writer($renderer); $writer = new \BaconQrCode\Writer($renderer);
$filter=""; $filter = "";
if (!empty($_REQUEST['filter'])) { if (!empty($_REQUEST['filter'])) {
$filter='&filter='.$_REQUEST['filter']; $filter = '&filter='.$_REQUEST['filter'];
} }
$attendanceSheetLink = api_get_path(WEB_CODE_PATH).'attendance/index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance_id.$filter; $attendanceSheetLink = api_get_path(WEB_CODE_PATH).'attendance/index.php?'.api_get_cidreq().'&action=attendance_sheet_list_no_edit&attendance_id='.$attendance_id.$filter;
$filename = "attendanceqrcode".uniqid().".png"; $filename = "attendanceqrcode".uniqid().".png";
@ -292,7 +292,7 @@ switch ($action) {
true true
); );
} }
$writer->writeFile($attendanceSheetLink,api_get_path(SYS_UPLOAD_PATH).'attendance/'.$filename); $writer->writeFile($attendanceSheetLink, api_get_path(SYS_UPLOAD_PATH).'attendance/'.$filename);
echo '<img src="'.api_get_path(WEB_UPLOAD_PATH).'attendance/'.$filename.'" alt="AttendanceQR">'; echo '<img src="'.api_get_path(WEB_UPLOAD_PATH).'attendance/'.$filename.'" alt="AttendanceQR">';
exit; exit;
case 'attendance_list': case 'attendance_list':

@ -690,7 +690,7 @@ if ($form->validate()) {
[ [
'item_id' => $user->getId(), 'item_id' => $user->getId(),
'variable' => 'password_updated_at', 'variable' => 'password_updated_at',
'value' => $date 'value' => $date,
] ]
); );
} }

@ -102,7 +102,7 @@ if ($form->validate()) {
[ [
'item_id' => $user->getId(), 'item_id' => $user->getId(),
'variable' => 'password_updated_at', 'variable' => 'password_updated_at',
'value' => $date 'value' => $date,
] ]
); );
} }

@ -29,6 +29,7 @@ if (api_get_configuration_value('ldap_encrypt_admin_password')) {
$ldapbind = @ldap_bind($ds, $extldap_config['admin_dn'], $ldap_pass); $ldapbind = @ldap_bind($ds, $extldap_config['admin_dn'], $ldap_pass);
if ($ldapbind === false) { if ($ldapbind === false) {
echo 'EXTLDAP ERROR : cannot connect with admin login/password'; echo 'EXTLDAP ERROR : cannot connect with admin login/password';
return false; return false;
} }

@ -5843,7 +5843,7 @@ class DocumentManager
} }
// Specific case to remove action icons for students on files in the Chat conversation history inside a group -refs BT#21165 // Specific case to remove action icons for students on files in the Chat conversation history inside a group -refs BT#21165
if (strpos($document_data['path'],'chat_files') !== false && $document_data['filetype'] === 'file' && api_is_student()) { if (strpos($document_data['path'], 'chat_files') !== false && $document_data['filetype'] === 'file' && api_is_student()) {
$modify_icons = []; $modify_icons = [];
} }
@ -7314,7 +7314,7 @@ class DocumentManager
return Display::url($iconEn, "edit_document.php?$courseParams&id=$document_id"); return Display::url($iconEn, "edit_document.php?$courseParams&id=$document_id");
} }
if (in_array($path, self::get_system_folders()) || $documentData['filetype'] === 'folder' && strpos($path,'chat_files') !== false) { if (in_array($path, self::get_system_folders()) || $documentData['filetype'] === 'folder' && strpos($path, 'chat_files') !== false) {
return $iconDis; return $iconDis;
} }
@ -7375,7 +7375,7 @@ class DocumentManager
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$courseParams = api_get_cidreq(); $courseParams = api_get_cidreq();
if ($isCertificateMode || in_array($path, self::get_system_folders()) || $documentData['filetype'] === 'folder' && strpos($path,'chat_files') !== false) { if ($isCertificateMode || in_array($path, self::get_system_folders()) || $documentData['filetype'] === 'folder' && strpos($path, 'chat_files') !== false) {
return $iconDis; return $iconDis;
} }
@ -7470,7 +7470,7 @@ class DocumentManager
return $iconDis; return $iconDis;
} }
if (in_array($path, self::get_system_folders()) || $documentData['filetype'] === 'folder' && strpos($path,'chat_files') !== false) { if (in_array($path, self::get_system_folders()) || $documentData['filetype'] === 'folder' && strpos($path, 'chat_files') !== false) {
return $iconDis; return $iconDis;
} }

@ -1085,13 +1085,12 @@ class Statistics
$table->set_header(6, get_lang('IPAddress')); $table->set_header(6, get_lang('IPAddress'));
$table->set_header(7, get_lang('Date')); $table->set_header(7, get_lang('Date'));
$content .= $table->return_table(); $content .= $table->return_table();
} }
$content .= '<div class="alert alert-info">'.get_lang('ImportantActivities').' : '.'<br>'; $content .= '<div class="alert alert-info">'.get_lang('ImportantActivities').' : '.'<br>';
$prefix = 'LOG_'; $prefix = 'LOG_';
$userDefinedConstants = get_defined_constants(true)['user']; $userDefinedConstants = get_defined_constants(true)['user'];
$filteredConstants = array_filter($userDefinedConstants, function($constantName) use ($prefix) { $filteredConstants = array_filter($userDefinedConstants, function ($constantName) use ($prefix) {
return strpos($constantName, $prefix) === 0; return strpos($constantName, $prefix) === 0;
}, ARRAY_FILTER_USE_KEY); }, ARRAY_FILTER_USE_KEY);
$constantNames = array_keys($filteredConstants); $constantNames = array_keys($filteredConstants);

@ -1675,7 +1675,7 @@ class UserManager
[ [
'item_id' => $user->getId(), 'item_id' => $user->getId(),
'variable' => 'password_updated_at', 'variable' => 'password_updated_at',
'value' => $date 'value' => $date,
] ]
); );
} }
@ -1803,8 +1803,6 @@ class UserManager
null, null,
$creatorEmail $creatorEmail
); );
} else { } else {
$layoutContent = $tplContent->get_template('mail/user_edit_content.tpl'); $layoutContent = $tplContent->get_template('mail/user_edit_content.tpl');
$emailBody = $tplContent->fetch($layoutContent); $emailBody = $tplContent->fetch($layoutContent);
@ -7709,7 +7707,7 @@ SQL;
); );
if (!empty($askPassword) && isset($askPassword['ask_new_password']) && if (!empty($askPassword) && isset($askPassword['ask_new_password']) &&
1 === (int)$askPassword['ask_new_password'] 1 === (int) $askPassword['ask_new_password']
) { ) {
$uniqueId = api_get_unique_id(); $uniqueId = api_get_unique_id();
$userObj = api_get_user_entity($userId); $userObj = api_get_user_entity($userId);
@ -8044,6 +8042,59 @@ SQL;
}'; }';
} }
/**
* Get a list of users with the given e-mail address + their "active" field value (0 or 1).
*
* @param string $mail User id
*
* @return array List of users e-mails + active field
*/
public static function getUsersByMail(string $mail): array
{
$resultData = Database::select(
'id, active',
Database::get_main_table(TABLE_MAIN_USER),
[
'where' => ['email = ?' => $mail],
],
'all',
null
);
if ($resultData === false) {
return [];
}
return $resultData;
}
/**
* Get whether we can send an e-mail or not.
* If the e-mail is not in the database, send the mail.
* If the e-mail is in the database but none of its occurences is active, don't send.
*
* @param string $mail The e-mail address to check
*
* @return bool Whether we can send an e-mail or not
*/
public function isEmailingAllowed(string $mail): bool
{
$list = self::getUsersByMail($mail);
if (empty($list)) {
// No e-mail matches, send the mail
return true;
}
$send = false;
foreach ($list as $id => $user) {
if ($user['active'] == 1) {
// as soon as we find at least one active user, send the mail
return true;
}
}
return false;
}
/** /**
* @return EncoderFactory * @return EncoderFactory
*/ */
@ -8137,55 +8188,4 @@ SQL;
return $url; return $url;
} }
/**
* Get a list of users with the given e-mail address + their "active" field value (0 or 1)
*
* @param string $mail User id
*
* @return array List of users e-mails + active field
*/
public static function getUsersByMail(string $mail): array
{
$resultData = Database::select(
'id, active',
Database::get_main_table(TABLE_MAIN_USER),
[
'where' => ['email = ?' => $mail],
],
'all',
null
);
if ($resultData === false) {
return [];
}
return $resultData;
}
/**
* Get whether we can send an e-mail or not.
* If the e-mail is not in the database, send the mail.
* If the e-mail is in the database but none of its occurences is active, don't send.
* @param string $mail The e-mail address to check
* @return bool Whether we can send an e-mail or not
*/
public function isEmailingAllowed(string $mail): bool
{
$list = self::getUsersByMail($mail);
if (empty($list)) {
// No e-mail matches, send the mail
return true;
}
$send = false;
foreach ($list as $id => $user) {
if ($user['active'] == 1) {
// as soon as we find at least one active user, send the mail
return true;
}
}
return false;
}
} }

Loading…
Cancel
Save