<%doc> People % <%attr> title => 'People' % % %####################################################################### %# %# Args section %# %####################################################################### <%args> $search => undef $search_people => undef $user => $ui->get_current_user($r); $submit_person => undef $submit_insert => undef $show_tasks => undef $showheader => 1 $_action => undef $view => 'search' % % % %####################################################################### %# %# INIT section %# %####################################################################### % <%init> my $DEBUG = 0; print '%ARGS is

    ', Dumper(%ARGS), '

' if $DEBUG; $show_tasks = $show_tasks || $user->getAttribute("SHOW_TASKS"); if ( $show_tasks eq "" ) { $user->setAttribute($r, "SHOW_TASKS", "show"); $show_tasks = "show"; } *print_showtaskslink = $m->comp('SELF:.sub_print_showtaskslink'); my $hideheader = 'style="display:none"' if ( !$showheader ); my @list; my $personid = -1; my $manager = $ui->get_permission_manager($r);
>
Contacts Tasks
% if ( $manager && $manager->can($user, 'access_admin_section', 'people:new') ){ % if ( $view eq 'search' ){ [new] % }elsif ( $view eq 'new' ){ [search] % } % } % print_showtaskslink($show_tasks);
">

% if ( $view eq 'search' ){ Search Person: % }elsif ( $view eq 'new' ){ Add a New Person First Name*: % print $ui->form_field(table=>"Person", column=>"firstname", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); Last Name*: % print $ui->form_field(table=>"Person", column=>"lastname", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); User Name*: % print $ui->form_field(table=>"Person", column=>"username", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); Employer*: % print $ui->form_field(table=>"Person", column=>"entity", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); Site: % print $ui->form_field(table=>"Person", column=>"location", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); Email: % print $ui->form_field(table=>"Person", column=>"email", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); Work Phone: % print $ui->form_field(table=>"Person", column=>"office", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); Work Phone Extension: % print $ui->form_field(table=>"Person", column=>"extension", edit=>1, htmlExtra=>'class="txt"', returnValOnly=>1, no_help=>1); (*) Field is required % }

<%perl> ####################################################################################### # Search # ####################################################################################### # Remove trailing and leading spaces if ( $submit_person && $search_people ){ $search = $ui->rem_lt_sp($search_people); my %idx1; my %idx2; my %resultidx; my $firstpass = 1; #support searches with more than 1 keywords (we do an intersection on results) for my $keyword (split(/\s+/, $search)) { if ($firstpass) { map { $resultidx{$_->id} = $_ } Person->search_like(firstname => $keyword); map { $resultidx{$_->id} = $_ } Person->search_like(lastname => $keyword); map { $resultidx{$_->id} = $_ } Person->search_like(aliases => $keyword); map { $resultidx{$_->id} = $_ } Person->search_like(username => $keyword); $firstpass = 0; } else { for my $r (keys %resultidx) { $idx1{$r} = $resultidx{$r}; } %resultidx = (); map { $idx2{$_->id} = $_ } Person->search_like(firstname => $keyword); map { $idx2{$_->id} = $_ } Person->search_like(lastname => $keyword); map { $idx2{$_->id} = $_ } Person->search_like(aliases => $keyword); map { $idx2{$_->id} = $_ } Person->search_like(username => $keyword); for my $key (keys %idx1) { if (exists $idx2{$key}) { $resultidx{$key} = $idx1{$key}; } } } %idx1 = (); %idx2 = (); } @list = values %resultidx; }elsif ( $submit_person ) { $m->comp('/generic/no_search_criteria.html'); } ####################################################################################### # Add Person # ####################################################################################### if ( $submit_insert ){ my %ret; eval { %ret = $ui->form_to_db(%ARGS); print 'form_to_db returned:

    ', Dumper(%ret), '

' if $DEBUG; }; if ( my $e = $@ ) { $m->comp('/generic/error.mhtml', error=>$e); } if ( %ret ){ $personid = (keys %{$ret{'Person'}{id}})[0]; $_action = "VIEW"; } } % if ( $search ){ % if ( scalar @list > 1 ){
Query <% $search %> returned: <% scalar(@list) %> matches
<& /generic/sortresults.mhtml, object=>\@list, page=>'view.html', withedit=>0 &>
% }elsif ( scalar @list == 1 ){ % my $viewid = $list[0]->id; % $m->comp('/generic/view.html', table=>'Person', id=>$viewid); % }else{ % $m->comp('/generic/no_search_results.html', search=>$search); % } % } % if ( $_action eq "VIEW" && defined $personid && $personid != -1 ){ % $m->comp('/generic/view.html', table=>"Person", id=>$personid); % }