+=item getnbpages
+
+Returns the number of pages to display in a pagination bar, given the number
+of items and the number of items per page.
+
+=cut
+
+sub getnbpages {
+ my ($nb_items, $nb_items_per_page) = @_;
+
+ return int(($nb_items - 1) / $nb_items_per_page) + 1;
+}
+
+
+=head2 getcities (OUEST-PROVENCE)
+
+ ($id_cityarrayref, $city_hashref) = &getcities();
+
+Looks up the different city and zip in the database. Returns two
+elements: a reference-to-array, which lists the zip city
+codes, and a reference-to-hash, which maps the name of the city.
+WHERE =>OUEST PROVENCE OR EXTERIEUR
+
+=cut
+sub getcities {
+ #my ($type_city) = @_;
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare("Select cityid,city_name from cities order by cityid ");
+ #$sth->execute($type_city);
+ $sth->execute();
+ my %city;
+ my @id;
+# insert empty value to create a empty choice in cgi popup
+
+while (my $data=$sth->fetchrow_hashref){
+
+ push @id,$data->{'cityid'};
+ $city{$data->{'cityid'}}=$data->{'city_name'};
+ }
+
+ #test to know if the table contain some records if no the function return nothing
+ my $id=@id;
+ $sth->finish;
+ if ($id eq 0)
+ {
+ return();
+ }
+ else{
+ unshift (@id ,"");
+ return(\@id,\%city);
+ }
+}
+
+
+=head2 getroadtypes (OUEST-PROVENCE)
+
+ ($idroadtypearrayref, $roadttype_hashref) = &getroadtypes();
+
+Looks up the different road type . Returns two
+elements: a reference-to-array, which lists the id_roadtype
+codes, and a reference-to-hash, which maps the road type of the road .
+
+
+=cut
+sub getroadtypes {
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare("Select roadtypeid,road_type from roadtype order by road_type ");
+ $sth->execute();
+ my %roadtype;
+ my @id;
+# insert empty value to create a empty choice in cgi popup
+while (my $data=$sth->fetchrow_hashref){
+ push @id,$data->{'roadtypeid'};
+ $roadtype{$data->{'roadtypeid'}}=$data->{'road_type'};
+ }
+ #test to know if the table contain some records if no the function return nothing
+ my $id=@id;
+ $sth->finish;
+ if ($id eq 0)
+ {
+ return();
+ }
+ else{
+ unshift (@id ,"");
+ return(\@id,\%roadtype);
+ }
+}
+
+=head2 get_branchinfos_of
+
+ my $branchinfos_of = get_branchinfos_of(@branchcodes);
+
+Associates a list of branchcodes to the information of the branch, taken in
+branches table.
+
+Returns a href where keys are branchcodes and values are href where keys are
+branch information key.
+
+ print 'branchname is ', $branchinfos_of->{$code}->{branchname};
+
+=cut
+sub get_branchinfos_of {
+ my @branchcodes = @_;
+
+ my $query = '
+SELECT branchcode,
+ branchname
+ FROM branches
+ WHERE branchcode IN ('.join(',', map({"'".$_."'"} @branchcodes)).')
+';
+ return get_infos_of($query, 'branchcode');
+}
+
+=head2 get_notforloan_label_of
+
+ my $notforloan_label_of = get_notforloan_label_of();
+
+Each authorised value of notforloan (information available in items and
+itemtypes) is link to a single label.
+
+Returns a href where keys are authorised values and values are corresponding
+labels.
+
+ foreach my $authorised_value (keys %{$notforloan_label_of}) {
+ printf(
+ "authorised_value: %s => %s\n",
+ $authorised_value,
+ $notforloan_label_of->{$authorised_value}
+ );
+ }
+
+=cut
+sub get_notforloan_label_of {
+ my $dbh = C4::Context->dbh;
+
+ my $query = '
+SELECT authorised_value
+ FROM marc_subfield_structure
+ WHERE kohafield = \'items.notforloan\'
+ LIMIT 0, 1
+';
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+ my ($statuscode) = $sth->fetchrow_array();
+
+ $query = '
+SELECT lib,
+ authorised_value
+ FROM authorised_values
+ WHERE category = ?
+';
+ $sth = $dbh->prepare($query);
+ $sth->execute($statuscode);
+ my %notforloan_label_of;
+ while (my $row = $sth->fetchrow_hashref) {
+ $notforloan_label_of{ $row->{authorised_value} } = $row->{lib};
+ }
+ $sth->finish;
+
+ return \%notforloan_label_of;
+}
+
+=head2 get_infos_of
+
+Return a href where a key is associated to a href. You give a query, the
+name of the key among the fields returned by the query. If you also give as
+third argument the name of the value, the function returns a href of scalar.
+
+ my $query = '
+SELECT itemnumber,
+ notforloan,
+ barcode
+ FROM items
+';
+
+ # generic href of any information on the item, href of href.
+ my $iteminfos_of = get_infos_of($query, 'itemnumber');
+ print $iteminfos_of->{$itemnumber}{barcode};
+
+ # specific information, href of scalar
+ my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode');
+ print $barcode_of_item->{$itemnumber};
+
+=cut
+sub get_infos_of {
+ my ($query, $key_name, $value_name) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute();
+
+ my %infos_of;
+ while (my $row = $sth->fetchrow_hashref) {
+ if (defined $value_name) {
+ $infos_of{ $row->{$key_name} } = $row->{$value_name};
+ }
+ else {
+ $infos_of{ $row->{$key_name} } = $row;
+ }
+ }
+ $sth->finish;
+
+ return \%infos_of;
+}