@@ -2209,9 +2209,37 @@ function format_time($totalsecs, $str = null) {
2209
2209
* @return string the formatted date/time.
2210
2210
*/
2211
2211
function userdate ($ date , $ format = '' , $ timezone = 99 , $ fixday = true , $ fixhour = true ) {
2212
- $ calendartype = \core_calendar \type_factory::get_calendar_instance ();
2213
- return $ calendartype ->timestamp_to_date_string ($ date , $ format , $ timezone , $ fixday , $ fixhour );
2214
- }
2212
+ $ calendartype = \core_calendar \type_factory::get_calendar_instance ();
2213
+ return trocaMes ($ calendartype ->timestamp_to_date_string ($ date , $ format , $ timezone , $ fixday , $ fixhour ));
2214
+ }
2215
+
2216
+ function trocaMes ($ data ) {
2217
+ $ dataPt = $ data ;
2218
+ $ dataPt = str_replace ("January " , "Janeiro " , $ dataPt );
2219
+ $ dataPt = str_replace ("February " , "Fevereiro " , $ dataPt );
2220
+ $ dataPt = str_replace ("March " , "Março " , $ dataPt );
2221
+ $ dataPt = str_replace ("April " , "Abril " , $ dataPt );
2222
+ $ dataPt = str_replace ("May " , "Maio " , $ dataPt );
2223
+ $ dataPt = str_replace ("June " , "Junho " , $ dataPt );
2224
+ $ dataPt = str_replace ("July " , "Julho " , $ dataPt );
2225
+ $ dataPt = str_replace ("August " , "Agosto " , $ dataPt );
2226
+ $ dataPt = str_replace ("September " , "Setembro " , $ dataPt );
2227
+ $ dataPt = str_replace ("October " , "Outubro " , $ dataPt );
2228
+ $ dataPt = str_replace ("November " , "Novembro " , $ dataPt );
2229
+ $ dataPt = str_replace ("December " , "Dezembro " , $ dataPt );
2230
+
2231
+ $ dataPt = str_replace ("Sunday " , "Domingo " , $ dataPt );
2232
+ $ dataPt = str_replace ("Monday " , "Segunda-feira " , $ dataPt );
2233
+ $ dataPt = str_replace ("Tuesday " , "Terça-feira " , $ dataPt );
2234
+ $ dataPt = str_replace ("Thursday " , "Quinta-feira " , $ dataPt );
2235
+ $ dataPt = str_replace ("Friday " , "Sexta-feira " , $ dataPt );
2236
+ $ dataPt = str_replace ("Wednesday " , "Quarta-feira " , $ dataPt );
2237
+ $ dataPt = str_replace ("Saturday " , "Sábado " , $ dataPt );
2238
+
2239
+
2240
+ return $ dataPt ;
2241
+ }
2242
+
2215
2243
2216
2244
/**
2217
2245
* Returns a formatted date ensuring it is UTF-8.
@@ -2636,6 +2664,30 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $
2636
2664
}
2637
2665
}
2638
2666
2667
+
2668
+ // Verifica se o usuário tem que trocar o CPF.
2669
+ if (get_user_preferences ('auth_forcecpfchange ' ) && !\core \session \manager::is_loggedinas ()) {
2670
+ $ userauth = get_auth_plugin ($ USER ->auth );
2671
+ if (!$ preventredirect ) {
2672
+ if ($ setwantsurltome ) {
2673
+ $ SESSION ->wantsurl = qualified_me ();
2674
+ }
2675
+ if ($ changeurl = $ userauth ->change_password_url ()) {
2676
+ // Use plugin custom url.
2677
+ redirect ($ changeurl );
2678
+ } else {
2679
+ // Use moodle internal method.
2680
+ if (empty ($ CFG ->loginhttps )) {
2681
+ redirect ($ CFG ->wwwroot .'/login/change_cpf.php ' );
2682
+ } else {
2683
+ $ wwwroot = str_replace ('http: ' , 'https: ' , $ CFG ->wwwroot );
2684
+ redirect ($ wwwroot .'/login/change_cpf.php ' );
2685
+ }
2686
+ }
2687
+ }
2688
+ }
2689
+
2690
+
2639
2691
// Check whether the user should be changing password (but only if it is REALLY them).
2640
2692
if (get_user_preferences ('auth_forcepasswordchange ' ) && !\core \session \manager::is_loggedinas ()) {
2641
2693
$ userauth = get_auth_plugin ($ USER ->auth );
@@ -2862,8 +2914,8 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $
2862
2914
}
2863
2915
}
2864
2916
}
2865
-
2866
- if (!$ access ) {
2917
+ // MGBF: evita redirecionamento em caso de estar logado como outro usuário
2918
+ if (!$ access && !\ core \ session \manager:: is_loggedinas () ) {
2867
2919
if ($ preventredirect ) {
2868
2920
throw new require_login_exception ('Not enrolled ' );
2869
2921
}
@@ -4442,6 +4494,13 @@ function complete_user_login($user) {
4442
4494
// Select password change url.
4443
4495
$ userauth = get_auth_plugin ($ USER ->auth );
4444
4496
4497
+ // Verifica se o usuário tem que trocar o CPF.
4498
+ if (get_user_preferences ('auth_forcecpfchange ' , false )) {
4499
+ require_once ($ CFG ->dirroot . '/login/lib.php ' );
4500
+ $ SESSION ->wantsurl = core_login_get_return_url ();
4501
+ redirect ($ CFG ->httpswwwroot .'/login/change_cpf.php ' );
4502
+ }
4503
+
4445
4504
// Check whether the user should be changing password.
4446
4505
if (get_user_preferences ('auth_forcepasswordchange ' , false )) {
4447
4506
if ($ userauth ->can_change_password ()) {
@@ -4455,7 +4514,7 @@ function complete_user_login($user) {
4455
4514
} else {
4456
4515
print_error ('nopasswordchangeforced ' , 'auth ' );
4457
4516
}
4458
- }
4517
+ }
4459
4518
return $ USER ;
4460
4519
}
4461
4520
@@ -4634,6 +4693,30 @@ function update_internal_user_password($user, $password, $fasthash = false) {
4634
4693
* @param int $mnethostid
4635
4694
* @return mixed False, or A {@link $USER} object.
4636
4695
*/
4696
+
4697
+
4698
+ function update_internal_user_cpf ($ user , $ cpf ) {
4699
+ global $ CFG , $ DB ;
4700
+ // $DB->set_field('user_info_data', 'data', $cpf, array('userid' => $user->id, 'fieldid' => 8));
4701
+
4702
+ $ cpfdata = new stdClass ();
4703
+ $ cpfdata ->userid = $ user ->id ;
4704
+ $ cpfdata ->fieldid = 8 ;
4705
+ $ cpfdata ->data = $ cpf ;
4706
+ $ DB ->insert_record ('user_info_data ' , $ cpfdata );
4707
+
4708
+ $ cpfuser = new stdClass ();
4709
+ $ cpfuser ->id = $ user ->id ;
4710
+ $ cpfuser ->username = $ cpf ;
4711
+ $ DB ->update_record ('user ' , $ cpfuser );
4712
+
4713
+ return true ;
4714
+ }
4715
+
4716
+
4717
+
4718
+
4719
+
4637
4720
function get_complete_user_data ($ field , $ value , $ mnethostid = null ) {
4638
4721
global $ CFG , $ DB ;
4639
4722
0 commit comments