body<= " if $remote && $remote->{journaltype} ne 'P'; return $LJ::MSG_READONLY_USER if LJ::get_cap($remote, "readonly"); my ($ret, $saved); my %errors; my $error_msg = sub { my $key = shift; my $msg = $errors{$key}; return unless $msg; return ""; }; my %formats = ( 'ogg', 'Ogg Vorbis', 'wav', 'Wav (GSM encoded)' ); $formats{'mp3'} = 'Mp3' if $LJ::PHONEPOST_MP3; POST: while ($remote && LJ::did_post()) { my $phone = $POST{phone}; my $trans = $POST{trans}; my $format = $POST{format}; my $pin = $POST{pin}; if ($POST{delete}) { my $dbh = LJ::get_db_writer(); $dbh->do("DELETE FROM phonepostlogin WHERE userid=?", undef, $remote->{userid}); return ""; } $phone =~ s/\D//g; $errors{'.phone'} = $ML{'.error.phone.length'} unless length $phone >= 10; $errors{'.pin'} = $ML{'.error.pin'} if $pin =~ /\D/ or length $pin < 1; my $dbh = LJ::get_db_writer(); my $prevuserid = $dbh->selectrow_array("SELECT userid FROM phonepostlogin ". "WHERE phone=? AND pin=?", undef, $phone, $pin); $errors{'.pin'} = $ML{'.error.inuse'} if $prevuserid && $prevuserid != $remote->{userid}; my $grouplist = LJ::get_friend_group($remote); $errors{'.transcribers'} = $ML{'.error.transcription'} unless $trans == -1 || $trans == 0 || defined $grouplist->{$trans}; $errors{'.format'} = "Bad format selected." unless $formats{$format}; last POST if %errors; $dbh->do("REPLACE INTO phonepostlogin ". "(phone, pin, userid) VALUES (?, ?, ?)", undef, $phone, $pin, $remote->{userid}); LJ::set_userprop($remote, 'pp_transallow', $trans); LJ::set_userprop($remote, 'pp_format', $format); $saved .= ""; $saved .= ""; $saved .= ""; last; } my $grouplist = LJ::get_friend_group($remote); my $tableline = sub { my ($mlcaption, $content) = @_; my $err = $error_msg->($mlcaption); return "$ML{$mlcaption}$content\n$err"; }; my $dbr = LJ::get_db_reader(); my ($phone, $pin); if ($remote) { ($phone, $pin) = $dbr->selectrow_array( "SELECT phone, pin FROM phonepostlogin ". "WHERE userid=?", undef, $remote->{userid}); LJ::load_user_props($remote, qw/ pp_transallow pp_format /); $ret .= $ML{'.intro.loggedin'}; } else { $ret .= ""; } $phone = $POST{'phone'} ? $POST{'phone'} : $phone; $pin = $POST{'pin'} ? $POST{'pin'} : $pin; $ret .= "
\n"; $ret .= ""; $ret .= $tableline->('.phone', LJ::html_text({name => 'phone', value => $phone, maxlength => 25, disabled => !$remote})); $ret .= $tableline->('.pin', LJ::html_text({name => 'pin', value => $pin, type => 'password', maxlength => 8, disabled => !$remote})); my $default_format = $remote->{pp_format} || ($LJ::PHONEPOST_MP3 ? 'mp3' : 'ogg'); $ret .= $tableline->('.format', LJ::html_select({ name => 'format', selected => $default_format }, %formats)); $ret .= $tableline->('.transcribers', LJ::html_select({ name=>'trans', selected=>$remote->{pp_transallow} }, 0,'All friends',-1,'No one but you', map { $_, $grouplist->{$_}->{groupname} } sort {$grouplist->{$a}->{groupname} cmp $grouplist->{$b}->{groupname}} keys %$grouplist)); $ret .= '
 ' . LJ::html_submit('save', $ML{'.save'}, { disabled => !$remote }) . ''; $ret .= LJ::html_submit('delete', $ML{'.delete'}, { disabled => !$remote}) . '

'; $ret .= "
"; $ret .= $saved if $saved; return $ret; } _code?> <=body page?>