1 |
195 |
ahitrov |
package users::UserProfile; |
2 |
|
|
|
3 |
|
|
use base "Contenido::Document"; |
4 |
|
|
use Digest::MD5; |
5 |
|
|
use Contenido::Globals; |
6 |
|
|
|
7 |
|
|
sub extra_properties |
8 |
|
|
{ |
9 |
|
|
return ( |
10 |
|
|
{ 'attr' => 'status', 'type' => 'status', 'rusname' => '������ ������������', |
11 |
|
|
'cases' => [ |
12 |
|
|
[0, '������������� ������������'], |
13 |
|
|
[1, '���������� ������������'], |
14 |
|
|
[5, '��������� ���������'], |
15 |
|
|
], |
16 |
|
|
}, |
17 |
|
|
{ 'attr' => 'visibility', 'type' => 'status', 'rusname' => '������� ���������', |
18 |
|
|
'cases' => [ |
19 |
|
|
[0, '������ ����� �������� ����� ������ ���'], |
20 |
|
|
[1, '������ ����� �������� ����� ����'], |
21 |
|
|
[2, '������ ����� �������� ����� �������'], |
22 |
|
|
[3, '������ ����� �������� ����� ������� � ������ ������'], |
23 |
|
|
], |
24 |
|
|
}, |
25 |
|
|
{ 'attr' => 'country', 'type' => 'string', 'rusname' => '������' }, |
26 |
|
|
{ 'attr' => 'region', 'type' => 'string', 'rusname' => '������' }, |
27 |
|
|
{ 'attr' => 'passwd', 'type' => 'password', 'rusname' => '������', 'rem' => '(<font color="red">�� ������������. ��������� ��� �������� � ��� ���������</font>)' }, |
28 |
|
|
{ 'attr' => 'confirm', 'type' => 'string', 'rusname' => '��� �������������', hidden => 1 }, |
29 |
|
|
{ 'attr' => 'secmail', 'type' => 'string', 'rusname' => 'E-mail (secondary)' }, |
30 |
|
|
{ 'attr' => 'q1', 'type' => 'string', 'rusname' => '����������� ������ 1' }, |
31 |
|
|
{ 'attr' => 'a1', 'type' => 'string', 'rusname' => '����������� ����� 1' }, |
32 |
|
|
{ 'attr' => 'q2', 'type' => 'string', 'rusname' => '����������� ������ 2' }, |
33 |
|
|
{ 'attr' => 'a2', 'type' => 'string', 'rusname' => '����������� ����� 2' }, |
34 |
|
|
{ 'attr' => 'account', 'type' => 'string', 'rusname' => '����� �� �����' }, |
35 |
|
|
{ 'attr' => 'interests', 'type' => 'text', 'rusname' => '��������� ��������', rows => 10 }, |
36 |
|
|
{ 'attr' => 'origin', 'type' => 'text', 'rusname' => '�������', rows => 4 }, |
37 |
|
|
{ 'attr' => 'avatar', 'type' => 'image', 'rusname' => '������', preview => ['32x32','100x100','120x120','160x160'] }, |
38 |
|
|
) |
39 |
|
|
} |
40 |
|
|
|
41 |
466 |
ahitrov |
sub name_full |
42 |
|
|
{ |
43 |
|
|
my $self = shift; |
44 |
|
|
my $name = $self->name; |
45 |
|
|
if ( $name =~ /^(.*?),[\ \t]+(.*)$/ ) { |
46 |
|
|
$name = $2.' '.$1; |
47 |
|
|
} |
48 |
|
|
return $name; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
sub name_part |
52 |
|
|
{ |
53 |
|
|
my $self = shift; |
54 |
|
|
my $name = $self->name; |
55 |
|
|
if ( $name =~ /^(.*?),[\ \t]+(.*)$/ ) { |
56 |
|
|
$name = $2; |
57 |
|
|
} else { |
58 |
|
|
my @parts = split /\s+/, $name; |
59 |
|
|
if ( @parts > 1 ) { |
60 |
|
|
pop @parts; |
61 |
|
|
} |
62 |
|
|
$name = join ' ', @parts; |
63 |
|
|
} |
64 |
|
|
return $name; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
sub name_family |
68 |
|
|
{ |
69 |
|
|
my $self = shift; |
70 |
|
|
my $name = $self->name; |
71 |
|
|
if ( $name =~ /^(.*?),[\ \t]+(.*)$/ ) { |
72 |
|
|
$name = $1; |
73 |
|
|
} else { |
74 |
|
|
my @parts = split /\s+/, $name; |
75 |
|
|
if ( @parts > 1 ) { |
76 |
|
|
$name = pop @parts; |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
|
return $name; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
sub name_first |
83 |
|
|
{ |
84 |
|
|
my $self = shift; |
85 |
|
|
my @name = split /\s+/, $self->name_part; |
86 |
|
|
|
87 |
|
|
return $name[0]; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
sub name_middle |
91 |
|
|
{ |
92 |
|
|
my $self = shift; |
93 |
|
|
my @name = split /\s+/, $self->name_part; |
94 |
|
|
shift @name if @name; |
95 |
|
|
my $name = @name ? join (' ', @name) : ''; |
96 |
|
|
|
97 |
|
|
return $name; |
98 |
|
|
} |
99 |
|
|
|
100 |
195 |
ahitrov |
sub class_name |
101 |
|
|
{ |
102 |
|
|
return '������� ������������'; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
sub class_description |
106 |
|
|
{ |
107 |
|
|
return '������� ������������'; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
|
111 |
|
|
sub class_table |
112 |
|
|
{ |
113 |
|
|
return 'users::SQL::UserProfile'; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
sub contenido_status_style |
117 |
|
|
{ |
118 |
|
|
my $self = shift; |
119 |
|
|
if ( $self->status == 2 ) { |
120 |
|
|
return 'color:green;'; |
121 |
|
|
} elsif ( $self->status == 3 ) { |
122 |
|
|
return 'color:olive;'; |
123 |
|
|
} elsif ( $self->status == 4 ) { |
124 |
|
|
return 'color:green;'; |
125 |
|
|
} elsif ( $self->status == 5 ) { |
126 |
|
|
return 'color:red;'; |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
sub pre_store |
131 |
|
|
{ |
132 |
|
|
my $self = shift; |
133 |
|
|
|
134 |
|
|
my $up = $keeper->get_document_by_id ( $self->id, |
135 |
|
|
class => 'users::UserProfile' |
136 |
|
|
); |
137 |
|
|
if ( (ref $up && $self->passwd && $self->passwd ne $up->passwd) || (!ref $up && $self->passwd) ) { |
138 |
|
|
warn "Pass = ".$self->passwd."\n" if $DEBUG; |
139 |
|
|
my $pass = Digest::MD5::md5_hex($self->passwd); |
140 |
|
|
warn "Pass_hex = $pass\n" if $DEBUG; |
141 |
|
|
$self->passwd($pass); |
142 |
|
|
} elsif ( ref $up && (!$self->passwd || $self->passwd eq $up->passwd ) ) { |
143 |
|
|
$self->passwd($up->passwd); |
144 |
|
|
} |
145 |
|
|
$self->email(lc($self->email)); |
146 |
|
|
$self->login(lc($self->login)); |
147 |
|
|
|
148 |
|
|
my $default_section = $project->s_alias->{users} if ref $project->s_alias eq 'HASH' && exists $project->s_alias->{users}; |
149 |
|
|
if ( $default_section ) { |
150 |
|
|
my $sections = $self->{sections}; |
151 |
|
|
if ( ref $sections eq 'ARRAY' && scalar @$sections ) { |
152 |
|
|
my @new_sects = grep { $_ != $default_section } @$sections; |
153 |
|
|
push @new_sects, $default_section; |
154 |
|
|
$self->sections(@new_sects); |
155 |
|
|
} elsif ( $sections && !ref $sections && $sections != $default_section ) { |
156 |
|
|
my @new_sects = ($default_section, $sections); |
157 |
|
|
$self->sections(@new_sects); |
158 |
|
|
} else { |
159 |
|
|
$self->sections($default_section); |
160 |
|
|
} |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
return 1; |
164 |
|
|
} |
165 |
|
|
1; |