- Hiding patron add toolbar when branches or categories are undefined
- Blocking patron entry form if branches or categories are undefined
- Removing nonfunctional template logic for displaying missing category
  error message.
---
 .../prog/en/includes/patron-toolbar.inc            |    2 +
 .../prog/en/modules/members/member.tmpl            |    5 +++
 .../prog/en/modules/members/memberentrygen.tmpl    |   12 ++++----
 members/memberentry.pl                             |   28 +++++++++++++++----
 members/members-home.pl                            |   26 +++++++++++++++---
 5 files changed, 56 insertions(+), 17 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc 
b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
index c508af0..bc4dbc4 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
@@ -1,3 +1,4 @@
+<!-- TMPL_UNLESS NAME="no_add" -->
 <div id="toolbar">
        <script type="text/javascript">
        //<![CDATA[
@@ -69,3 +70,4 @@
        </li>
 </ul>
 </div>
+<!-- /TMPL_UNLESS -->
\ No newline at end of file
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl 
b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl
index fef7b69..50a73da 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tmpl
@@ -17,6 +17,11 @@
 
                                <!-- TMPL_INCLUDE NAME="patron-toolbar.inc" -->
 
+       <!-- TMPL_IF NAME="no_add" --><div class="dialog alert"><h3>Cannot add 
patron</h3>
+               <!-- TMPL_IF NAME="no_branches" --><p>There are <strong>no 
libraries defined</strong>. <!-- TMPL_IF NAME="CAN_user_parameters" -->Please 
<a href="/cgi-bin/koha/admin/branches.pl">add a library</a>.<!-- TMPL_ELSE 
-->An administrator must define at least one library.<!-- /TMPL_IF --></p><!-- 
/TMPL_IF -->
+               <!-- TMPL_IF NAME="no_categories" --><p>There are <strong>no 
patron categories defined</strong>. <!-- TMPL_IF NAME="CAN_user_parameters" 
-->Please <a href="/cgi-bin/koha/admin/categorie.pl">add a patron 
category</a>.<!-- TMPL_ELSE -->An administrator must define at least one patron 
category.<!-- /TMPL_IF --></p><!-- /TMPL_IF --></div>
+       <!-- /TMPL_IF -->
+
                                                <div class="browse">
                                                        Browse by last name:
                                                        <!-- TMPL_LOOP 
name="letters" -->
diff --git 
a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl 
b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl
index b21d35a..18e7293 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl
@@ -1,6 +1,6 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 <title>Koha &rsaquo; Patrons &rsaquo; 
-<!-- TMPL_IF NAME="opadd" -->  Add<!-- TMPL_ELSE --> Modify<!--/TMPL_IF--> 
<!--TMPL_IF Name="categoryname"--> <!--TMPL_VAR Name="categoryname"--> 
patron<!-- TMPL_ELSE --><!--TMPL_IF Name="I"--> Organization patron<!--/TMPL_IF 
--><!--TMPL_IF Name="A"--> Adult patron<!--/TMPL_IF --><!--TMPL_IF Name="C"--> 
Child patron<!--/TMPL_IF --><!--TMPL_IF Name="P"--> Professional 
patron<!--/TMPL_IF --><!--TMPL_IF Name="S"--> Staff patron<!--/TMPL_IF 
--><!--/TMPL_IF --><!--TMPL_UNLESS Name="opadd"--> <!-- TMPL_VAR NAME="surname" 
-->, <!-- TMPL_VAR name="firstname" --><!--/TMPL_UNLESS--></title>
+<!-- TMPL_IF NAME="opadd" -->Add<!-- TMPL_ELSE --> Modify<!--/TMPL_IF--> 
<!--TMPL_IF Name="categoryname"--> <!--TMPL_VAR Name="categoryname"--> 
patron<!-- TMPL_ELSE --><!--TMPL_IF Name="I"--> Organization patron<!--/TMPL_IF 
--><!--TMPL_IF Name="A"--> Adult patron<!--/TMPL_IF --><!--TMPL_IF Name="C"--> 
Child patron<!--/TMPL_IF --><!--TMPL_IF Name="P"--> Professional 
patron<!--/TMPL_IF --><!--TMPL_IF Name="S"--> Staff patron<!--/TMPL_IF 
--><!--/TMPL_IF --><!--TMPL_UNLESS Name="opadd"--> <!-- TMPL_VAR NAME="surname" 
-->, <!-- TMPL_VAR name="firstname" --><!--/TMPL_UNLESS--></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 <script type="text/javascript" src="<!-- TMPL_VAR NAME='themelang' 
-->/js/members.js"></script>
 <!-- TMPL_INCLUDE NAME="calendar.inc" -->
@@ -70,7 +70,11 @@
        <div id="yui-main">
        <div class="yui-b">
 
+       <!-- TMPL_IF NAME="no_add" --><div class="dialog alert"><h3>Cannot add 
patron</h3>
+               <!-- TMPL_IF NAME="no_branches" --><p>There are <strong>no 
libraries defined</strong>. <!-- TMPL_IF NAME="CAN_user_parameters" -->Please 
<a href="/cgi-bin/koha/admin/branches.pl">add a library</a>.<!-- TMPL_ELSE 
-->An administrator must define at least one library.<!-- /TMPL_IF --></p><!-- 
/TMPL_IF -->
+               <!-- TMPL_IF NAME="no_categories" --><p>There are <strong>no 
patron categories defined</strong>. <!-- TMPL_IF NAME="CAN_user_parameters" 
-->Please <a href="/cgi-bin/koha/admin/categorie.pl">add a patron 
category</a>.<!-- TMPL_ELSE -->An administrator must define at least one patron 
category.</p><!-- /TMPL_IF --><!-- /TMPL_IF --></div><!-- /TMPL_IF -->
 
+       <!-- TMPL_UNLESS NAME="no_add" -->
        <!-- TMPL_IF NAME="opadd" -->
        <h1>
                Add<!--TMPL_IF Name="categoryname"--> <!--TMPL_VAR 
Name="categoryname"--> patron<!-- TMPL_ELSE --><!--TMPL_IF Name="I"--> 
Organization patron<!--/TMPL_IF --><!--TMPL_IF Name="A"--> Adult 
patron<!--/TMPL_IF --><!--TMPL_IF Name="C"--> Child patron<!--/TMPL_IF 
--><!--TMPL_IF Name="P"--> Professional patron<!--/TMPL_IF --><!--TMPL_IF 
Name="S"--> Staff patron<!--/TMPL_IF --><!--/TMPL_IF --> <!-- TMPL_VAR 
name="firstname" --> <!-- TMPL_VAR NAME="surname" --> 
@@ -728,7 +732,6 @@
          <!-- TMPL_IF NAME="mandatorybranchcode" --><span 
class="required">Required</span><!-- /TMPL_IF -->
     </li>
     <li>
-    <!-- TMPL_IF NAME="typeloop" -->
         <label for="categorycode">Category: </label>
         <select id="categorycode" name="categorycode">
         <!-- TMPL_LOOP NAME="typeloop" -->
@@ -748,10 +751,6 @@
         </optgroup>
         <!-- /TMPL_LOOP -->
                </select>
-    <!-- TMPL_ELSE -->
-        <span class="problem">There is no category type to add <!--TMPL_IF 
Name="A"-->an Adult<!--/TMPL_IF--><!--TMPL_IF Name="C"-->a 
Child<!--/TMPL_IF--><!--TMPL_IF Name="I"-->an 
Institution<!--/TMPL_IF--><!--TMPL_IF Name="P"-->a 
professionnal<!--/TMPL_IF--><!--TMPL_IF Name="S"-->a Staff 
Member<!--/TMPL_IF-->.</span>
-              <a href="/cgi-bin/koha/admin/categorie.pl">Please create one</a>
-    <!-- /TMPL_IF -->
     </li>
     <li>
       <!-- TMPL_IF NAME="mandatorysort1" -->
@@ -1063,5 +1062,6 @@
 <!-- TMPL_UNLESS NAME="opadd" --><div class="yui-b">
 <!-- TMPL_INCLUDE NAME="members-menu.inc" -->
 </div><!-- /TMPL_UNLESS -->
+<!-- /TMPL_UNLESS -->
 </div>
 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
diff --git a/members/memberentry.pl b/members/memberentry.pl
index 6ec6d8e..2228fa3 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -415,9 +415,12 @@ if ($ethnicitycategoriescount>=0) {
 }
 
 my @typeloop;
+my $no_categories = 1;
+my $no_add;
 foreach (qw(C A S P I X)) {
     my $action="WHERE category_type=?";
        ($categories,$labels)=GetborCatFromCatType($_,$action);
+    if(scalar(@$categories) > 0){ $no_categories = 0; }
        my @categoryloop;
        foreach my $cat (@$categories){
                push @categoryloop,{'categorycode' => $cat,
@@ -432,9 +435,10 @@ foreach (qw(C A S P I X)) {
        $typehash{'categoryloop'}...@categoryloop;
        push @typeloop,{'typename' => $_,
          'categoryloop' => \...@categoryloop};
-}  
-$template->param('typeloop' => \...@typeloop);
-
+}
+$template->param('typeloop' => \...@typeloop,
+        no_categories => $no_categories);
+if($no_categories){ $no_add = 1; }
 # test in city
 $select_city=getidcity($data{'city'}) if defined $guarantorid and 
($guarantorid ne '0');
 ($default_city=$select_city) if ($step eq 0);
@@ -525,17 +529,18 @@ my 
$onlymine=(C4::Context->preference('IndependantBranches') &&
               
 my $branches=GetBranches($onlymine);
 my $default;
-
+my $CGIbranch;
 for my $branch (sort { $branches->{$a}->{branchname} cmp 
$branches->{$b}->{branchname} } keys %$branches) {
     push @select_branch,$branch;
     $select_branches{$branch} = $branches->{$branch}->{'branchname'};
     $default = C4::Context->userenv->{'branch'} if (C4::Context->userenv && 
C4::Context->userenv->{'branch'});
 }
+if(scalar(@select_branch) > 0){
 # 
--------------------------------------------------------------------------------------------------------
   #in modify mod :default value from $CGIbranch comes from borrowers table
   #in add mod: default value come from branches table (ip correspendence)
 $default=$data{'branchcode'}  if ($op eq 'modify' || ($op eq 'add' && 
$category_type eq 'C'));
-my $CGIbranch = CGI::scrolling_list(-id    => 'branchcode',
+$CGIbranch = CGI::scrolling_list(-id    => 'branchcode',
             -name   => 'branchcode',
             -values => \...@select_branch,
             -labels => \%select_branches,
@@ -544,6 +549,17 @@ my $CGIbranch = CGI::scrolling_list(-id    => 'branchcode',
             -multiple =>0,
             -default => $default,
         );
+}
+
+if(!$CGIbranch){
+    $no_add = 1;
+    $template->param(no_branches => 1);
+}
+if($no_categories){
+    $no_add = 1;
+    $template->param(no_categories => 1);
+}
+$template->param(no_add => $no_add);
 my $CGIorganisations;
 my $member_of_institution;
 if (C4::Context->preference("memberofinstitution")){
@@ -634,6 +650,7 @@ $template->param(
   check_member    => $check_member,#to know if the borrower already exist(=>1) 
or not (=>0) 
   "op$op"   => 1);
 
+$template->param(CGIbranch=>$CGIbranch) if ($CGIbranch);
 $template->param(
   nodouble  => $nodouble,
   borrowernumber  => $borrowernumber, #register number
@@ -650,7 +667,6 @@ $template->param(
   check_categorytype =>$check_categorytype,#to recover the category type with 
checkcategorytype function
   modify          => $modify,
   nok     => $nok,#flag to konw if an error 
-  CGIbranch => $CGIbranch,
   memberofinstution => $member_of_institution,
   CGIorganisations => $CGIorganisations,
   NoUpdateLogin =>  $NoUpdateLogin
diff --git a/members/members-home.pl b/members/members-home.pl
index 04fc557..e6468c1 100755
--- a/members/members-home.pl
+++ b/members/members-home.pl
@@ -51,13 +51,29 @@ if($quicksearch){
                  debug => 1,
                  });
 }
-my @categories=C4::Category->all;
-$template->param(
-    branchloop=>(defined $branch?GetBranchesLoop($branch):GetBranchesLoop()),
-       categories=>\...@categories,
-);
+my @categories;
+my $no_categories;
+my $no_add = 0;
+my $branchloop = (defined $branch?GetBranchesLoop($branch):GetBranchesLoop());
+if(scalar(@$branchloop) < 1){
+    $no_add = 1;
+    $template->param(no_branches => 1);
+} else {
+    $template->param(branchloop=>\...@$branchloop);
+}
+
+...@categories=c4::Category->all;
+if(scalar(@categories) < 1){ $no_categories = 1; }
+if($no_categories && C4::Context->preference("AddPatronLists")=~/code/){
+    $no_add = 1;
+    $template->param(no_categories => 1);
+} else {
+    $template->param(categories=>\...@categories);
+}
+
 $template->param( 
         "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
+        no_add => $no_add,
             );
 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
 $template->param( letters => \...@letters );
-- 
1.7.0.4

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-patches

Reply via email to