aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/message/user_form.php
blob: 007e57540774de94d88b420a1e5e1d8720cc12e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

namespace phpbb\message;

/**
* Class user_form
* Allows users to send emails to other users
*/
class user_form extends form
{
	/** @var int */
	protected $recipient_id;
	/** @var array */
	protected $recipient_row;
	/** @var string */
	protected $subject;

	/**
	* Get the data of the recipient
	*
	* @param int $user_id
	* @return	false|array		false if the user does not exist, array otherwise
	*/
	protected function get_user_row($user_id)
	{
		$sql = 'SELECT user_id, username, user_colour, user_email, user_allow_viewemail, user_lang, user_jabber, user_notify_type
			FROM ' . USERS_TABLE . '
			WHERE user_id = ' . (int) $user_id . '
				AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
		$result = $this->db->sql_query($sql);
		$row = $this->db->sql_fetchrow($result);
		$this->db->sql_freeresult($result);

		return $row;
	}

	/**
	* {inheritDoc}
	*/
	public function check_allow()
	{
		$error = parent::check_allow();
		if ($error)
		{
			return $error;
		}

		if (!$this->auth->acl_get('u_sendemail'))
		{
			return 'NO_EMAIL';
		}

		if ($this->recipient_id == ANONYMOUS || !$this->config['board_email_form'])
		{
			return 'NO_EMAIL';
		}

		if (!$this->recipient_row)
		{
			return 'NO_USER';
		}

		// Can we send email to this user?
		if (!$this->recipient_row['user_allow_viewemail'] && !$this->auth->acl_get('a_user'))
		{
			return 'NO_EMAIL';
		}

		return false;
	}

	/**
	* {inheritDoc}
	*/
	public function bind(\phpbb\request\request_interface $request)
	{
		parent::bind($request);

		$this->recipient_id = $request->variable('u', 0);
		$this->subject = $request->variable('subject', '', true);

		$this->recipient_row = $this->get_user_row($this->recipient_id);
	}

	/**
	* {inheritDoc}
	*/
	public function submit(\messenger $messenger)
	{
		if (!$this->subject)
		{
			$this->errors[] = $this->user->lang['EMPTY_SUBJECT_EMAIL'];
		}

		if (!$this->body)
		{
			$this->errors[] = $this->user->lang['EMPTY_MESSAGE_EMAIL'];
		}

		$this->message->set_template('profile_send_email');
		$this->message->set_subject($this->subject);
		$this->message->set_body($this->body);
		$this->message->add_recipient_from_user_row($this->recipient_row);

		parent::submit($messenger);
	}

	/**
	* {inheritDoc}
	*/
	public function render(\phpbb\template\template $template)
	{
		parent::render($template);

		$template->assign_vars(array(
			'S_SEND_USER'			=> true,
			'S_POST_ACTION'			=> append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=email&amp;u=' . $this->recipient_id),

			'L_SEND_EMAIL_USER'		=> $this->user->lang('SEND_EMAIL_USER', $this->recipient_row['username']),
			'USERNAME_FULL'			=> get_username_string('full', $this->recipient_row['user_id'], $this->recipient_row['username'], $this->recipient_row['user_colour']),
			'SUBJECT'				=> $this->subject,
			'MESSAGE'				=> $this->body,
		));
	}
}
ef='#n499'>499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
#*****************************************************************************
# 
#  Copyright (c) 2002 Guillaume Cottenceau
#  Copyright (c) 2002-2007 Thierry Vignaud <tvignaud@mandriva.com>
#  Copyright (c) 2003, 2004, 2005 MandrakeSoft SA
#  Copyright (c) 2005, 2007 Mandriva SA
# 
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License version 2, as
#  published by the Free Software Foundation.
# 
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
# 
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 
#*****************************************************************************
#
# $Id$

package rpmdrake;

use lib qw(/usr/lib/libDrakX);
use urpm::download ();
use urpm::prompt;
use urpm::media;

use MDK::Common;
use MDK::Common::System;
use urpm;
use urpm::cfg;
use URPM;
use URPM::Resolve;
use strict;
use c;
use POSIX qw(_exit);
use common;
use Locale::gettext;
use feature 'state';

our @ISA = qw(Exporter);
our $VERSION = '2.27';
our @EXPORT = qw(
    $changelog_first_config
    $filter
    $dont_show_selections
    $ignore_debug_media
    $mandrakeupdate_wanted_categories
    $mandrivaupdate_height
    $mandrivaupdate_width
    $max_info_in_descr
    $mode
    $offered_to_add_sources
    $rpmdrake_height
    $rpmdrake_width
    $tree_flat
    $tree_mode
    $typical_width
    add_distrib_update_media
    add_medium_and_check
    but
    but_
    check_update_media_version
    choose_mirror
    distro_type
    fatal_msg
    getbanner
    interactive_list
    interactive_list_
    interactive_msg
    interactive_packtable
    myexit
    readconf
    remove_wait_msg
    run_as_user
    run_drakbug
    show_urpm_progress
    slow_func
    slow_func_statusbar
    statusbar_msg
    statusbar_msg_remove
    strip_first_underscore
    update_sources
    update_sources_check
    update_sources_interactive
    update_sources_noninteractive
    wait_msg
    warn_for_network_need
    writeconf
);
our $typical_width = 280;

our $dont_show_selections;

# i18n: IMPORTANT: to get correct namespace (rpmdrake instead of libDrakX)
BEGIN { unshift @::textdomains, qw(rpmdrake urpmi rpm-summary-main rpm-summary-contrib rpm-summary-devel rpm-summary-non-free) }

use mygtk2 qw(gtknew);
use ugtk2 qw(:all);
ugtk2::add_icon_path('/usr/share/rpmdrake/icons');

Locale::gettext::bind_textdomain_codeset('rpmdrake', 'UTF8');

our $mandrake_release = cat_(
    -e '/etc/mandrakelinux-release' ? '/etc/mandrakelinux-release' : '/etc/release'
) || '';
chomp $mandrake_release;
our ($mdk_version) = $mandrake_release =~ /(\d+\.\d+)/;
our ($branded, %distrib);
$branded = -f '/etc/sysconfig/oem'
    and %distrib = MDK::Common::System::distrib();
our $myname_update = $branded ? N("Software Update") : N("Mandriva Linux Update");

@rpmdrake::prompt::ISA = 'urpm::prompt';

sub rpmdrake::prompt::prompt {
    my ($self) = @_;
    my @answers;
    my $d = ugtk2->new("", grab => 1, if_($::main_window, transient => $::main_window));
    $d->{rwindow}->set_position('center_on_parent');
    gtkadd(
	$d->{window},
	gtkpack(
	    Gtk2::VBox->new(0, 5),
	    Gtk2::WrappedLabel->new($self->{title}),
	    (map { gtkpack(
		Gtk2::HBox->new(0, 5),
		Gtk2::Label->new($self->{prompts}[$_]),
		$answers[$_] = gtkset_visibility(gtkentry(), !$self->{hidden}[$_]),
	    ) } 0 .. $#{$self->{prompts}}),
	    gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub { Gtk2->main_quit }),
	),
    );
    $d->main;
    map { $_->get_text } @answers;
}

$urpm::download::PROMPT_PROXY = new rpmdrake::prompt(
    N("Please enter your credentials for accessing proxy\n"),
    [ N("User name:"), N("Password:") ],
    undef,
    [ 0, 1 ],
);

sub myexit {
    writeconf();
    ugtk2::exit(undef, @_);
}

my ($root) = grep { $_->[2] == 0 } list_passwd();
$ENV{HOME} = $> == 0 ? $root->[7] : $ENV{HOME} || '/root';
$ENV{HOME} = $::env if $::env = $Rpmdrake::init::rpmdrake_options{env}[0];

our $configfile = "$ENV{HOME}/.rpmdrake";
our ($changelog_first_config, $filter, $max_info_in_descr, $mode, $tree_flat, $tree_mode);
our ($mandrakeupdate_wanted_categories, $ignore_debug_media, $offered_to_add_sources, $no_confirmation);
our ($rpmdrake_height, $rpmdrake_width, $mandrivaupdate_height, $mandrivaupdate_width);
our %config = (
    mandrakeupdate_wanted_categories => { var => \$mandrakeupdate_wanted_categories, default => [ qw(security) ] },
    dont_show_selections => { var => \$dont_show_selections, default => [ $> ? 1 : 0 ] },
    mandrivaupdate_width => { var => \$mandrivaupdate_width, default => [ 0 ] },
    mandrivaupdate_height => { var => \$mandrivaupdate_height, default => [ 0 ] },
    max_info_in_descr => { var => \$max_info_in_descr, default => [] },
    ignore_debug_media => { var => \$ignore_debug_media, default => [ 0 ] },
    offered_to_add_sources => { var => \$offered_to_add_sources, default => [ 0 ] },
    tree_mode => { var => \$tree_mode, default => [ qw(gui_pkgs) ] },
    tree_flat => { var => \$tree_flat, default => [ 0 ] },
    changelog_first_config => { var => \$changelog_first_config, default => [ 0 ] },
    'no-confirmation' => { var => \$no_confirmation, default => [ 0 ] },
    filter => { var => \$filter, default => [ 'all' ] },
    mode => { var => \$mode, default => [ 'by_group' ] },
    rpmdrake_width => { var => \$rpmdrake_width, default => [ 0 ] },
    rpmdrake_height => { var => \$rpmdrake_height, default => [ 0 ] },
);

sub readconf() {
    ${$config{$_}{var}} = $config{$_}{default} foreach keys %config;
    foreach my $l (cat_($configfile)) {
	$l =~ /^\Q$_\E (.*)/ and ${$config{$_}{var}} = [ split ' ', $1 ] foreach keys %config;
       foreach (keys %config) {
           $l =~ /^\Q$_\E (.*)/ and $1 and ${$config{$_}{var}} = [ split ' ', $1 ];
       }
    }
    # special cases:
    $::rpmdrake_options{'no-confirmation'} = $no_confirmation->[0] if !defined $::rpmdrake_options{'no-confirmation'};
    $Rpmdrake::init::default_list_mode = $tree_mode->[0] if ref $tree_mode && !$Rpmdrake::init::overriding_config;
}

sub writeconf() {
    return if $::env;
    unlink $configfile;

    # special case:
    $no_confirmation->[0] = $::rpmdrake_options{'no-confirmation'};

    output $configfile, map { "$_ " . (ref ${$config{$_}{var}} ? join(' ', @${$config{$_}{var}}) : ()) . "\n" } keys %config;
}

sub getbanner() {
    $::MODE or return undef;
    if (0) {
	+{
	remove  => N("Software Packages Removal"),
	update  => N("Software Packages Update"),
	install => N("Software Packages Installation"),
	};
    }
    Gtk2::Banner->new('title-update', $::MODE eq 'update' ? N("Software Packages Update") : N("Software Management"));
}

sub interactive_msg {
    my ($title, $contents, %options) = @_;
    $options{transient} ||= $::main_window if $::main_window;
    local $::isEmbedded;
    my $d = ugtk2->new($title, grab => 1, if_(exists $options{transient}, transient => $options{transient}));
    $d->{rwindow}->set_position($options{transient} ? 'center_on_parent' : 'center_always');
    if ($options{scroll}) {
        $contents = ugtk2::markup_to_TextView_format($contents) if !ref $contents;
    } else { #- because we'll use a WrappedLabel
        $contents = formatAlaTeX($contents) if !ref $contents;
    }
    my $text_w;
    my $button_yes;
    gtkadd(
	$d->{window},
	gtkpack_(
	    Gtk2::VBox->new(0, 5),
	    1,
	    (
		$options{scroll} ?
            ($text_w = create_scrolled_window(gtktext_insert(Gtk2::TextView->new, $contents)))
              : ($text_w = gtknew('WrappedLabel', text_markup => $contents))
	    ),
         if_($options{widget}, 0, $options{widget}),
	    0,
	    gtkpack(
		create_hbox(),
		(
		    ref($options{yesno}) eq 'ARRAY' ? map {
			my $label = $_;
			gtksignal_connect(
			    $button_yes = Gtk2::Button->new($label),
			    clicked => sub { $d->{retval} = $label; Gtk2->main_quit }
			);
		    } @{$options{yesno}}
		    : (
			$options{yesno} ? (
			    gtksignal_connect( 
				Gtk2::Button->new($options{text}{no} || N("No")),