-my $dbh = C4::Context->dbh;
-my $query="Select itemtype,description from itemtypes order by description";
-my $sth=$dbh->prepare($query);
-$sth->execute;
-my @itemtype;
-my %itemtypes;
-while (my ($value,$lib) = $sth->fetchrow_array) {
- push @itemtype, $value;
- $itemtypes{$value}=$lib;
+my $dbh = C4::Context->dbh;
+
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+ {
+ template_name => "opac-main.tmpl",
+ type => "opac",
+ query => $input,
+ authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
+ flagsrequired => { borrow => 1 },
+ }
+);
+
+my $casAuthentication = C4::Context->preference('casAuthentication');
+$template->param(
+ casAuthentication => $casAuthentication,
+);
+
+
+my $borrower = GetMember( borrowernumber=>$borrowernumber );
+$template->param(
+ textmessaging => $borrower->{textmessaging},
+) if (ref($borrower) eq "HASH");
+
+# display news
+# use cookie setting for language, bug default to syspref if it's not set
+(my $theme) = themelanguage(C4::Context->config('opachtdocs'),'opac-main.tmpl','opac',$input);
+
+my $translations = getTranslatedLanguages('opac',$theme);
+my @languages = ();
+foreach my $trans (@$translations)
+{
+ push(@languages, $trans->{rfc4646_subtag});