$update_args = array();
         foreach ($_pcpin_slave_userdata as $key => $val) {
             if (!is_null($val) && isset($current_userdata_set[$key]) && $current_userdata_set[$key] != $val) {
                 $update_args[$key] = $val;
             }
         }
         if (!empty($update_args)) {
             $current_userdata->_db_updateRow($current_user_set['id'], 'user_id', $update_args);
         }
         // Avatar
         $avatar->deleteAvatar($current_user_set['id']);
         if (!empty($_pcpin_slave_userdata['avatar'])) {
             $new_avatar_data = null;
             if (PCPIN_IMAGE_CHECK_OK === PCPIN_Image::checkImage($new_avatar_data, $_pcpin_slave_userdata['avatar'], $session->_conf_all['avatar_image_types'], 0, 0, 0, true)) {
                 if ($binaryfile->newBinaryFile(file_get_contents($_pcpin_slave_userdata['avatar']), $new_avatar_data['mime'], $new_avatar_data['width'], $new_avatar_data['height'], 'log')) {
                     $avatar->addAvatar($binaryfile->id, $current_user_set['id']);
                 }
             }
         }
     }
 } else {
     // User not exists yet
     $login = $_pcpin_slave_userdata['login'];
     // Create new user
     $current_user->newUser($_pcpin_slave_userdata['login'], PCPIN_Common::randomString(32), $_pcpin_slave_userdata['email'], $_pcpin_slave_userdata['hide_email'], 'n', '');
     $current_user->password = $_pcpin_slave_userdata['password'];
     $_pcpin_slave_userdata_md5_password = $_pcpin_slave_userdata['password'];
     $current_user->_db_updateObj($current_user->id);
     // Userdata
     $current_userdata->_db_getList('user_id = ' . $current_user->id, 1);
     $current_userdata_set = $current_userdata->_db_list[0];
             case PCPIN_IMAGE_CHECK_ERROR_FILESIZE:
                 // Image file size larger than allowed
                 $upload_status = array('code' => 400, 'message' => str_replace('[SIZE]', $session->_conf_all['avatar_max_filesize'], $l->g('file_too_large')));
                 break;
         }
     }
     if ($upload_status['code'] === 0) {
         // Image OK
         $width = $img_data['width'];
         $height = $img_data['height'];
         _pcpin_loadClass('binaryfile');
         $binaryfile = new PCPIN_BinaryFile($session);
         if ($binaryfile->newBinaryFile(file_get_contents($f_data['tmp_name']), $img_data['mime'], $width, $height, 'log')) {
             if (!empty($binaryfile->id)) {
                 $binaryfile_id = $binaryfile->id;
                 $avatar->addAvatar($binaryfile->id, $profile_user_id);
             }
         }
         $msg->addMessage(1010, 'n', 0, '', $session->_s_room_id, 0, $profile_user_id);
     }
     break;
 case 'avatar_gallery_image':
     // New Avatar for Gallery
     if ($current_user->is_admin !== 'y') {
         break;
     }
     // Check image data
     $img_data = null;
     switch (PCPIN_Image::checkImage($img_data, $f_data['tmp_name'], $session->_conf_all['avatar_image_types'], $session->_conf_all['avatar_max_width'], $session->_conf_all['avatar_max_height'], $session->_conf_all['avatar_max_filesize'], false)) {
         case PCPIN_IMAGE_CHECK_OK:
             // Image OK
$avatar = new PCPIN_Avatar($session);
_pcpin_loadClass('tmpdata');
$tmpdata = new PCPIN_TmpData($session);
_pcpin_loadClass('binaryfile');
$binaryfile = new PCPIN_BinaryFile($session);
$errortext = array();
if (!empty($current_user->id) && $current_user->is_admin === 'y') {
    $tmpdata->_db_getList('id, binaryfile_id', 'user_id = ' . $current_user->id, 'type = 4', 1);
    if (empty($tmpdata->_db_list)) {
        $errortext[] = $l->g('smilie_image_empty_error');
    } else {
        $tmpdata_id = $tmpdata->_db_list[0]['id'];
        $binaryfile_id = $tmpdata->_db_list[0]['binaryfile_id'];
        $tmpdata->_db_freeList();
    }
    if (empty($errortext)) {
        // Save avatar
        if ($avatar->addAvatar($binaryfile_id, 0)) {
            // Delete temporary data
            $tmpdata->_db_freeList();
            $tmpdata->deleteUserRecords($session->_s_user_id, 4, 0, true);
            $xmlwriter->setHeaderStatus(0);
            $xmlwriter->setHeaderMessage($l->g('avatar_uploaded'));
        } else {
            $xmlwriter->setHeaderStatus(1);
            $xmlwriter->setHeaderMessage($l->g('error'));
        }
    } else {
        $xmlwriter->setHeaderMessage(implode("\n", $errortext));
    }
}