1 |
package A3C::View; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use Jifty::View::Declare -base; |
7 |
use A3C::LDAP; |
8 |
use A3C::SQL; |
9 |
|
10 |
use Data::Dump qw/dump/; |
11 |
|
12 |
template '/' => page { |
13 |
|
14 |
h1 { _('Statistics') } |
15 |
|
16 |
my $orgs = A3C::Model::OrganizationCollection->new; |
17 |
$orgs->unlimit; |
18 |
|
19 |
dt { _('Number of schools in system') } |
20 |
dd { $orgs->count } |
21 |
|
22 |
my $people = A3C::Model::PersonCollection->new; |
23 |
$people->unlimit; |
24 |
|
25 |
dt { _('Number of persons in system') } |
26 |
dd { $people->count } |
27 |
|
28 |
my $by_towns = A3C::SQL->new({ query => qq{ |
29 |
select count(uid),l |
30 |
from organizations |
31 |
inner join towns on towns.name = l |
32 |
group by l |
33 |
order by count desc |
34 |
limit 25 |
35 |
}}); |
36 |
|
37 |
dt { _('Top %1 towns by schools', $by_towns->count) } |
38 |
dd { |
39 |
ul { |
40 |
while ( my $row = $by_towns->next ) { |
41 |
li { outs_raw( $row->count, ' ', $row->l ) } |
42 |
} |
43 |
} |
44 |
} |
45 |
|
46 |
my $by_county = A3C::SQL->new({ query => qq{ |
47 |
select |
48 |
count(uid) as schools, |
49 |
county, |
50 |
count(distinct municipality) as municipalities |
51 |
from organizations |
52 |
inner join towns on towns.name = l |
53 |
group by county |
54 |
order by schools desc |
55 |
}}); |
56 |
|
57 |
dt { _('Schools by counties') } |
58 |
dd { |
59 |
table { |
60 |
th { _('Schools') } |
61 |
th { _('County') } |
62 |
th { _('Municipalities') }; |
63 |
while ( my $row = $by_county->next ) { |
64 |
row { |
65 |
cell { $row->schools } |
66 |
cell { $row->county } |
67 |
cell { $row->municipalities } |
68 |
} |
69 |
} |
70 |
} |
71 |
} |
72 |
}; |
73 |
|
74 |
|
75 |
template 'ldap' => page { |
76 |
h1 { _('LDAP data about Schools in system') }; |
77 |
my $ldap = A3C::LDAP->new; |
78 |
div { |
79 |
$ldap->search( |
80 |
base => 'dc=skole,dc=hr', |
81 |
filter => '(objectClass=hrEduOrg)', |
82 |
sizelimit => 10, |
83 |
); |
84 |
while ( my $entry = $ldap->current_search->shift_entry ) { |
85 |
#warn $entry->dump; |
86 |
ul { |
87 |
foreach my $attr ( $entry->attributes ) { |
88 |
li { |
89 |
tt { $attr } |
90 |
span { dump( $entry->get_value( $attr ) ) } |
91 |
} |
92 |
} |
93 |
} |
94 |
} |
95 |
} |
96 |
}; |
97 |
|
98 |
template 'people' => page { |
99 |
|
100 |
h1 { _('Find people') } |
101 |
|
102 |
my $action = new_action( |
103 |
class => 'SearchPerson', |
104 |
moniker => 'search-users', |
105 |
sticky_on_success => 1, |
106 |
sticky_on_failure => 1, |
107 |
); |
108 |
|
109 |
|
110 |
form { |
111 |
render_action( $action => [ 'uid_contains', 'cn_contains' ] ); |
112 |
form_submit( label => _('Find someone') ); |
113 |
}; |
114 |
|
115 |
# warn dump( $action->result->content ); |
116 |
|
117 |
if ( my $search = $action->result->content('search') ) { |
118 |
div { sprintf(_('Found %d results'), $search->count ) } |
119 |
ol { |
120 |
while (my $user = $search->next) { |
121 |
li { |
122 |
span { $user->cn } |
123 |
tt { $user->uid } |
124 |
} |
125 |
} |
126 |
} |
127 |
} |
128 |
|
129 |
}; |
130 |
|
131 |
template 'sync' => page { |
132 |
|
133 |
h1 { _('Sync school from LDAP') } |
134 |
|
135 |
my $action = new_action( |
136 |
class => 'SyncOrganization', |
137 |
moniker => 'sync-organization' |
138 |
); |
139 |
|
140 |
form { |
141 |
render_action( $action => [ 'cn' ] ); |
142 |
form_submit( label => _('Sync Organization') ); |
143 |
}; |
144 |
|
145 |
if ( my $users = $action->result->content('synced-users') ) { |
146 |
ol { |
147 |
while (my $user = $users->next) { |
148 |
li { |
149 |
span { $user->cn } |
150 |
tt { { class is 'email' } '<' . $user->mail . '>' } |
151 |
} |
152 |
} |
153 |
} |
154 |
} |
155 |
|
156 |
}; |