Problema con imagenes de usuarios

Re: Problema con imagenes de usuarios

de Manuel Q -
Número de respuestas: 0

Buenos dias de nuevo, te comento, tal y como esta el codigo que se ve completo funciona tirando del username de la tabla user para obtener el nombre de la foto del servidor, ahora bien el username ha cambiado y ahora necesita el campo idnumber de la tabla user y he modificado:

//$idnumber1 = $user->idnumber;

y en todos los

$src = 'http://imageserver.****.int/FOTOS/'.$numberid.'.jpg'; los he sustituido por:

$src = 'http://imageserver****.int/FOTOS/'.$idnumber1.'.jpg';

pero solo me muestra la foto cuando ves el perfil es decir en la llamada a print_user_picture de view.php, pero el resto como por ejemplo segun se loguea el usuario que deberia aparecer la foto aparece la imagen gris por defecto, asi que mi duda es como hacer para que funcione para mostrarla en otros sitios y por qué solo funciona la llamada desde view.php. es posible que se llame otra funcion ademas de esta para msotrar la foto?. Muchas gracias por dedicarme vuestro tiempo para ayudarme

Te adjunto el codigo que si funciona y muestra la foto en todas partes, sin las modificaciones que te comentaba.

/**
 * Print the specified user's avatar.
 *
 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname
 *      If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
 *      if at all possible, particularly for reports. It is very bad for performance.
 * @param int $courseid The course id. Used when constructing the link to the user's profile.
 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatability
 * @param boolean $return If false print picture to current page, otherwise return the output as string
 * @param boolean $link enclose printed image in a link the user's profile (default true).
 * @param string $target link target attribute. Makes the profile open in a popup window.
 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
 *      decorative images, or where the username will be printed anyway.)
 * @return string or nothing, depending on $return.
 */
function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
    global $CFG;
 //$idnumber1 = $user->idnumber;
    $needrec = false;
   
    //modificación
    //miguel v1.3
 if (!is_object($user)) {
     if (! $useraux = get_record("user", "id",  $user) ) {
         error("No se encuentra el usuario");
     }
     
    }else{
     if (empty($user->idnumber)){
      if (! $useraux = get_record("user", "id",  $user->id) ) {
          error("No se encuentra el usuario");
      }
     }else{
      $useraux = $user->username;
 }
     
    }
    if (!is_object($useraux)){
     $numberid = $useraux;
    }else{
     $numberid = $useraux->username;
    }
    //------------------------------
   
   
    // only touch the DB if we are missing data...
    if (is_object($user)) {
        // Note - both picture and imagealt _can_ be empty
        // what we are trying to see here is if they have been fetched
        // from the DB. We should use isset() _except_ that some installs
        // have those fields as nullable, and isset() will return false
        // on null. The only safe thing is to ask array_key_exists()
        // which works on objects. property_exists() isn't quite
        // what we want here...
        if (! (array_key_exists('picture', $user)
               && ($alttext && array_key_exists('imagealt', $user)
                   || (isset($user->firstname) && isset($user->lastname)))) ) {
            $needrec = true;
            $user = $user->id;
        }
    } else {
        if ($alttext) {
            // we need firstname, lastname, imagealt, can't escape...
            $needrec = true;
        } else {
            $userobj = new StdClass; // fake it to save DB traffic
            $userobj->id = $user;
            $userobj->picture = $picture;
            $user = clone($userobj);
            unset($userobj);
        }
    }
    if ($needrec) {
        $user = get_record('user','id',$user, '', '', '', '', 'id,firstname,lastname,imagealt');
    }

    if ($link) {
        $url = '/user/view.php?id='. $user->id .'&course='. $courseid ;
        if ($target) {
            $target='onclick="return openpopup(\''.$url.'\');"';
        }
        $output = '<a '.$target.' href="'. $CFG->wwwroot . $url .'">';
    } else {
        $output = '';
    }
    if (empty($size)) {
        $file = 'f2';
        $size = 35;
    } else if ($size === true or $size == 1) {
        $file = 'f1';
        $size = 100;
    } else if ($size >= 50) {
        $file = 'f1';
    } else {
        $file = 'f2';
    }
    $class = "userpicture";

    if (is_null($picture) and !empty($user->picture)) {
        $picture = $user->picture;
    }

    if ($picture) {  // Print custom user picture
        require_once($CFG->libdir.'/filelib.php');
       
        //modificación
        //$src = get_file_url($user->id.'/'.$file.'.jpg', null, 'user');
       
        $src = 'http://imageserver.****.int/FOTOS/'.$numberid.'.jpg';
         $fileUrl = $src;
   $AgetHeaders = @get_headers($fileUrl);
         if (preg_match("|200|", $AgetHeaders[0])) {
    // file exists
    $src = 'http://imageserver.****.int/FOTOS/'.$numberid.'.jpg';
   } else {
    // file doesn't exists
    $src = $CFG->pixpath .'/no_profile2.jpg"';
   }
         
       
    } else {         // Print default user pictures (use theme version if available)
        $class .= " defaultuserpic";
       
        //modificacion
        $src = 'http://imageserver.****.int/FOTOS/'.$numberid.'.jpg';
        $fileUrl = $src;
   $AgetHeaders = @get_headers($fileUrl);
         if (preg_match("|200|", $AgetHeaders[0])) {
    // file exists
    $src = 'http://imageserver.****.int/FOTOS/'.$numberid.'.jpg';
   } else {
    // file doesn't exists
    $src = $CFG->pixpath .'/no_profile2.jpg"';
   }
         //modificacion
        //$src =  "$CFG->pixpath/u/$file.png";
    }
    $imagealt = '';
    if ($alttext) {
        if (!empty($user->imagealt)) {
            $imagealt = $user->imagealt;
        } else {
            $imagealt = get_string('pictureof','',fullname($user));
        }
    }

    $output .= "<img class=\"$class\" src=\"$src\" height=\"$size\" width=\"$size\" alt=\"".s($imagealt).'"  />';
    if ($link) {
        $output .= '</a>';
    }

    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}