id, true); if(!isadmin() && !$isteacher) { throw new Exception(get_string('error_rol_required', 'block_clickedu'), 3); } $id = required_param('blockid', PARAM_INT); $block = getClickeduBlock( $id ); $oauth = loadOAuthClient( $block->config->url.'/ws/moodle_clickedu_query.php' ); switch ($action) { case 'savedIdnumberUsername': if($_POST['ckedu_users']) { $idm_idnumber = $_POST['ckedu_users']; $idm_idnumber = substr(substr($idm_idnumber,1),0,-1); $r = explode('][', $idm_idnumber); if($r) { foreach($r as $idnumber) { if(isset($_POST['chk_col_'.$idnumber])) { $userid = $_POST['chk_col_'.$idnumber]; $sql = "UPDATE {$CFG->prefix}user SET idnumber = ".$idnumber." WHERE id = ".$userid; execute_sql($sql, false); } } } } echo ""; exit; break; case 'syncIdnumberUsername': if( !isset($date) ) $date = NULL; $ws_users = json_decode($oauth->getUsers()); $html_result = ''; $si_accio = 0; $class_tr = ' class="odd"'; $ckedu_users = array(); foreach($ws_users as $usr) { $ckedu_users[] = $usr->id; $r_relacio = ''; if ( empty($usr->id) || empty($usr->username) || empty( $usr->name) ) { $r_relacio = "params_required"; } else { $sql = "SELECT id, username, password, idnumber, firstname, lastname FROM {$CFG->prefix}user WHERE idnumber = '".$usr->id."'"; $r = get_record_sql($sql); if($r) { $r_relacio = "idnumber_found"; } else { $sql = "SELECT id, username, password, idnumber, firstname, lastname FROM {$CFG->prefix}user WHERE username = '".$usr->username."'"; $r = get_record_sql($sql); if($r) { if($r->idnumber == '') { $r_relacio = "username_found"; } else { $r_relacio = "username_found_notnull_idnumber"; } } } } $html_action = ''; switch($r_relacio) { case 'username_found': // Hem trobat el username i no esta relacionat, idnumber null ++$si_accio; $html_action = '
'.get_string('update').'
'; break; case 'username_found_notnull_idnumber': // Hem trobat el username, pero el idnumber no es null $html_action = "idnumber NOT NULL"; break; case 'idnumber_found': // Per defecte el usuari esta sincronizat default: $html_action = ""; } $class_tr = (($class_tr==' class="odd"')?'':' class="odd"'); $str_id = ""; $str_firstname = ""; $str_lastname= ""; if( is_object( $r ) ) { $str_id = $r->id; $str_firstname = $r->firstname; $str_lastname= $r->lastname; } $html_result .= " ".$usr->id." ".$usr->username." ".$usr->name." ".$usr->surname." ".$str_id." ".$str_firstname." ".$str_lastname." ".$html_action." "; } $html_btn_mdl = ''; if($si_accio > 0) { $html_btn_mdl = '
'.get_string('select'). ' '.get_string('all').'
'.get_string('select'). ' '.get_string('none').'
'; } $html_result = '
'.get_string('back').'
'.$html_btn_mdl.'
'.$html_result.'
idNumber '.get_string('username').' '.get_string('firstname').' '.get_string('lastname').' idUser '.get_string('firstname').' '.get_string('lastname').' '.utf8_decode(get_string('action')).'
'; break; } } catch(Exception $e) { add_to_log_click($action, "Line:".$e->getLine()." Message:".$e->getMessage()); echo $e->getMessage(); } ?>