Line # Revision Author
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 sub class_name
42 {
43 return '������� ������������';
44 }
45
46 sub class_description
47 {
48 return '������� ������������';
49 }
50
51
52 sub class_table
53 {
54 return 'users::SQL::UserProfile';
55 }
56
57 sub contenido_status_style
58 {
59 my $self = shift;
60 if ( $self->status == 2 ) {
61 return 'color:green;';
62 } elsif ( $self->status == 3 ) {
63 return 'color:olive;';
64 } elsif ( $self->status == 4 ) {
65 return 'color:green;';
66 } elsif ( $self->status == 5 ) {
67 return 'color:red;';
68 }
69 }
70
71 sub pre_store
72 {
73 my $self = shift;
74
75 my $up = $keeper->get_document_by_id ( $self->id,
76 class => 'users::UserProfile'
77 );
78 if ( (ref $up && $self->passwd && $self->passwd ne $up->passwd) || (!ref $up && $self->passwd) ) {
79 warn "Pass = ".$self->passwd."\n" if $DEBUG;
80 my $pass = Digest::MD5::md5_hex($self->passwd);
81 warn "Pass_hex = $pass\n" if $DEBUG;
82 $self->passwd($pass);
83 } elsif ( ref $up && (!$self->passwd || $self->passwd eq $up->passwd ) ) {
84 $self->passwd($up->passwd);
85 }
86 $self->email(lc($self->email));
87 $self->login(lc($self->login));
88
89 my $default_section = $project->s_alias->{users} if ref $project->s_alias eq 'HASH' && exists $project->s_alias->{users};
90 if ( $default_section ) {
91 my $sections = $self->{sections};
92 if ( ref $sections eq 'ARRAY' && scalar @$sections ) {
93 my @new_sects = grep { $_ != $default_section } @$sections;
94 push @new_sects, $default_section;
95 $self->sections(@new_sects);
96 } elsif ( $sections && !ref $sections && $sections != $default_section ) {
97 my @new_sects = ($default_section, $sections);
98 $self->sections(@new_sects);
99 } else {
100 $self->sections($default_section);
101 }
102 }
103
104 return 1;
105 }
106 1;