[LON-CAPA-cvs] cvs: modules /raeburn/register registrations.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sat, 19 Apr 2008 16:05:51 -0000


This is a MIME encoded message

--raeburn1208621151
Content-Type: text/plain

raeburn		Sat Apr 19 12:05:51 2008 EDT

  Modified files:              
    /modules/raeburn/register	registrations.pm 
  Log:
  - Administrative interface to set/modify fees and fee conditions.
  
  
--raeburn1208621151
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080419120551.txt"

Index: modules/raeburn/register/registrations.pm
diff -u modules/raeburn/register/registrations.pm:1.7 modules/raeburn/register/registrations.pm:1.8
--- modules/raeburn/register/registrations.pm:1.7	Mon Apr 14 16:48:17 2008
+++ modules/raeburn/register/registrations.pm	Sat Apr 19 12:05:49 2008
@@ -6,7 +6,7 @@
 # privilege for an event can edit the contents of the registration 
 # form. 
 #
-# $Id: registrations.pm,v 1.7 2008/04/14 20:48:17 raeburn Exp $
+# $Id: registrations.pm,v 1.8 2008/04/19 16:05:49 raeburn Exp $
 #
 # Stuart P Raeburn
 #
@@ -238,18 +238,19 @@
                 &process_config_changes($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,
                                         $portal,\%params,\@sponsors,\%sponsorinfo);
             }
-        } elsif ($choice eq 'sponsors') {
-            if ($editaction eq '') {
-                &sponsors_menu($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,
-                             $portal,\%params,\@sponsors,\%sponsorinfo);
-            } else {
-                &process_sponsors_changes($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,
-                                         $portal,\%params,\@sponsors,\%sponsorinfo);
-            }
         } elsif ($choice eq 'fees') {
             if ($editaction eq '') {
                 &fees_menu($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,
                              $portal,\%params,\@sponsors,\%sponsorinfo);
+            } elsif ($editaction eq 'conditions') {
+                if ($phase eq 'process') {
+                    &process_condfee_changes($r,$dbh,$event_id,$event,$year,
+                                             $returnpage,$exitpage,$portal,\%params,
+                                             \@sponsors,\%sponsorinfo);
+                } else {
+                    &feeconditions_menu($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,
+                                        $portal,\%params,\@sponsors,\%sponsorinfo);
+                }
             } else {
                 &process_fees_changes($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,
                                         $portal,\%params,\@sponsors,\%sponsorinfo);
@@ -1977,6 +1978,7 @@
         if (confirm("Please confirm you wish to delete row "+rownum+" ("+rowname+").")) {
             changePage(form,'edit','formfields','modify','process'); 
         } else {
+            caller.checked = false;
             return; 
         }
     }
@@ -2711,6 +2713,14 @@
     my ($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,$portal,$params,
         $sponsors,$sponsorinfo) = @_;
     my $jspage = &javascript_page_flip();
+    my $eventid_quoted = $dbh->quote( $event_id );
+    my @allprods;
+    my $sth = $dbh->prepare("SELECT iid FROM products WHERE event_id = $eventid_quoted ORDER BY iid");
+    $sth->execute();
+    while (my $iid = $sth->fetchrow_array) {
+        push(@allprods,$iid);
+    }
+    my $allprods_str = join("','",@allprods); 
     my $formname = 'feesForm';
     $r->print(<<"END_OF_BLOCK");
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
@@ -2721,6 +2731,65 @@
 </head>
 <script type="text/javascript">
 $jspage
+
+function orderFees(form,iid,maxh) {
+    var changedVal;
+    var current = new Array;
+    var newitemVal = form.elements['newitem_displayorder'].options[form.elements['newitem_displayorder'].selectedIndex].value;
+    if (iid == 'newitem') {
+        changedVal = newitemVal;
+    } else {
+        changedVal = form.elements['change_'+iid+'_displayorder'].options[form.elements['change_'+iid+'_displayorder'].selectedIndex].value;
+        current[newitemVal-1] = 'newitem_displayorder';
+    }
+    var allprods = new Array('$allprods_str');
+    for (var i=0; i<allprods.length; i++) {
+        if (allprods[i] != iid) {
+            var elementName = 'change_'+allprods[i]+'_displayorder';
+            if (form.elements[elementName]) {
+                var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
+                current[currVal-1] = elementName;
+            }
+        }
+    }
+    var oldVal;
+    for (var j=0; j<maxh; j++) {
+        if (current[j] == undefined) {
+            oldVal = j+1;
+        }
+    }
+    if (oldVal < changedVal) {
+        for (var k=oldVal+1; k<=changedVal ; k++) {
+           var elementName = current[k-1];
+           form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
+        }
+    } else {
+        for (var k=changedVal; k<oldVal; k++) {
+            var elementName = current[k-1];
+            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
+        }
+    }
+    return;
+}
+
+
+function setFeeCondition(caller) {
+    document.$formname.editcondfee.value = caller;
+    changePage(document.$formname,'edit','fees','conditions','');
+}
+
+function checkDelete(form,caller,feename) {
+    if (caller.checked) {
+        var rownum = caller.value
+        if (confirm("Please confirm you wish to delete the "+feename+" fee.")) {
+            changePage(form,'edit','fees','modify','');
+        } else {
+            caller.checked = false;
+            return;
+        }
+    }
+}
+
 </script>
 <body>
 <form name="$formname" method ="post" action="/registrations">
@@ -2750,13 +2819,406 @@
      </tr>
     </table>
 END_OF_B
- r->print(<<"END_OF_BLOCK");
-<br />No interface currently available
+    my $fees = $dbh->selectrow_array("SELECT fees FROM event_config WHERE event_id = $eventid_quoted");
+    if ($fees) {
+        my (%products,%products_by_order);
+        my @settings = ('iid','description','cost','required','longdesc','type','waiver','registration','infotext','displayorder','dependency');
+        my $itemstr = join(',',@settings);
+        my $sth = $dbh->prepare("SELECT $itemstr FROM products WHERE event_id = $eventid_quoted ORDER BY iid");
+        $sth->execute();
+        while (my @current = $sth->fetchrow_array) {
+            my $iid = $current[0];
+            my $displayorder = $current[9];
+            for (my $j=1; $j<@settings; $j++) {
+                $products{$iid}{$settings[$j]} = $current[$j];
+                $products_by_order{$displayorder} = $iid;
+            }
+        }
+        $sth->finish;
+        $r->print('<span class="rowheader1">Modify existing fee definition</span><br />');
+        if (keys(%products) > 0) {
+            $r->print('<input type="hidden" name="editcondfee" value="" />');
+            foreach my $item (sort {$a <=> $b} (keys(%products_by_order))) {
+                my $iid = $products_by_order{$item};
+                $r->print('<div class="rowtitle"><table><tr><td><span class="rowheader2">'.$products{$iid}{'longdesc'}.'</span></td><td>&nbsp;</td><td valign="top"><span class="rowtitlechange"><label><input type="checkbox" name="deletefee" value="'.$iid.'" onclick="javascript:checkDelete(this.form,this,'."'$products{$iid}{'longdesc'}'".')" />Delete</label></span></td></tr></table></div>'."\n");
+                $r->print(&build_fees_table($dbh,$iid,\@settings,\%products,'modify',$eventid_quoted,$formname).'<br />');
+            }
+        } else {
+            $r->print('There are currently no fees defined for this event.<br />');
+        }
+        $r->print('<hr noshade />');
+        $r->print('<div class="rowtitle"><table><tr><td><span class="rowheader2">New fee definition</span></td><td>&nbsp;</td><td valign="top"><span class="rowtitlechange"><label><input type="checkbox" name="addfee" value="Y" />Add?</label></span></td></tr></table></div>'."\n");
+        $r->print(&build_fees_table($dbh,'newitem',\@settings,\%products,'new',$eventid_quoted,$formname).'<br /><hr noshade />');
+        $r->print('<br /><input type="button" name="processfeebutton" value="Save changes" onclick="javascript:changePage('."document.$formname,'edit','fees','modify','process'".')"><br />');
+    } else {
+        $r->print('Fee collection is not enabled for this event.<br />'
+                  .'Please go to "Modify Overall Configuration" and indicate there are registration fees for the event.');  
+    }
+    &main_footer($r,$year,$event,$returnpage,$sponsors,$sponsorinfo);
+    return;
+}
+
+sub feeconditions_menu {
+    my ($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,$portal,$params,
+        $sponsors,$sponsorinfo,$msg) = @_;
+    my $output;
+    my $jspage = &javascript_page_flip();
+    my $formname = 'feeconditionsForm';
+    $r->print(<<"END_OF_BLOCK");
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head><title>Configure LON-CAPA Registration Form</title>
+<meta http-equiv="pragma" content="no-cache">
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<link type="text/css" rel="stylesheet" href="/css/registration.css">
+</head>
+<script type="text/javascript">
+$jspage
+
+function checkDelete(form,caller,num) {
+    if (caller.checked) {
+        if (confirm("Please confirm you wish to delete sub-condition "+num+".")) {
+            changePage(form,'edit','fees','conditions','process');
+        } else {
+            caller.checked = false;
+            return;
+        }
+    }
+}
+
+</script>
+<body>
+<form name="$formname" method ="post" action="/registrations">
 END_OF_BLOCK
+    &main_box($r,$year,$event);
+    if ($portal eq '') {
+        $portal = $exitpage;
+    }
+    my $logoutportal = $portal;
+    if ($logoutportal  =~ /^\/update/) {
+        $logoutportal = '/registrations';
+    }
+    $r->print(<<"END_OF_B");
+    <table class="LC_breadcrumb">
+     <tr>
+      <td>
+       <span class="nobreak"><a href="http://loncapa.org/">Home</a>&nbsp;--&gt;&nbsp;<a href="$exitpage">Support</a>&nbsp;--&gt;&nbsp;<a href="/registrations">Choose an event</a>&nbsp;--&gt;&nbsp;<a href="javascript:changePage(document.$formname,'edit','','','')">Choose edit action</a>&nbsp;--&gt;&nbsp;<a href="javascript:changePage(document.$formname,'edit','fees','','')">Configure Fees</a>&nbsp;--&gt;&nbsp;<b>Display/Set conditions</b></span></td>
+      <td>&nbsp;</td>
+      <td align="right" valign="top">
+       <img border="0" src="/images/login/logout_red.gif" width="90" height="23" align="right" usemap="#event_header">
+        <map name = "event_header">
+         <area shape='rect' coords=10,2,80,18' href="/logout?portal=$logoutportal">         <area shape = 'default' nohref>
+        </map>
+      </td>
+     </tr>
+    </table>
+END_OF_B
+    my $iid;
+    if (ref($params) eq 'HASH') {
+        $iid = $params->{'editcondfee'};
+    }
+    if (!$iid) {
+        $r->print('No fee definition specified');
+        &main_footer($r,$year,$event,$returnpage,$sponsors,$sponsorinfo);
+        return;
+    }
+    my $eventid_quoted = $dbh->quote( $event_id );
+    my $iid_quoted = $dbh->quote( $iid );
+    my ($longdesc,$type) = $dbh->selectrow_array("SELECT longdesc,type FROM products WHERE iid = $iid_quoted");
+    if ($type ne 'conditional') {
+        $r->print('<br />The fee type for the "'.$longdesc.'" fee definition is not set to "conditional".</br />Once you have set conditions here you should return to <a href="javascript:changePage('."document.$formname,'edit','fees','',''".');">Configure Fees</a> to set the appropriate fee type.');
+    }
+    my ($maxnum,%condfee,%conditions_by_num);
+    $maxnum = 0;
+    my @conditions = ('did','name','tablename','value','condition','num');
+    my $conditionstr = join(',',@conditions);
+    my $statement = "SELECT $conditionstr from product_dependencies WHERE (event_id = $eventid_quoted AND iid = $iid_quoted) ORDER BY did";
+    my $sth = $dbh->prepare($statement); 
+    $sth->execute();
+    while (my @current = $sth->fetchrow_array) {
+        my $did = $current[0];
+        for (my $i=1; $i<@conditions; $i++) {
+            $condfee{$did}{$conditions[$i]} = $current[$i];
+        }
+        my $num = $condfee{$did}{'num'};
+        if (ref($conditions_by_num{$num}) eq 'ARRAY') {
+            push(@{$conditions_by_num{$num}},$did); 
+        } else {
+            @{$conditions_by_num{$num}} = ($did);
+            $maxnum ++;
+        }
+    }
+    $maxnum ++;
+    $sth->finish;
+    $r->print('<h3>Modify existing fee condition definition for "'.$longdesc.'"</h3>'."\n".
+'  <ul>
+    <li>Each condition definition contains one or more sub-conditions.</li>
+    <li>Each sub-condition contains one or more components.</li>
+    <li>All sub-conditions must be met for the fee to apply to the registrant.</li>
+    <li>A sub-condition is met if at least one component within it is met, and zero "False" components are <b>not</b> met.</li>
+    <li>Component evaluates as "True" for the registrant:<ul>
+      <li>For "attendancedays" table - if item is present in the table for registrant (no expected value).</li>
+      <li>For "event_registration" table - if the item is set to the expected value for registrant.</li>
+     </ul></li>  
+   </ul><hr noshade />');         
+    if (keys(%condfee) > 0) {
+        foreach my $num (sort {$a <=> $b} (keys(%conditions_by_num))) {
+            if (ref($conditions_by_num{$num}) eq 'ARRAY') {
+                $r->print('<table><tr><td><span class="itemtitle">Sub-condition: '.$num.'</span></td><td>&nbsp;</td><td>&nbsp;</td><td><span class="rowtitlechange"><label><input type="checkbox" name="deletecond" value="'.$num.'" onclick="javascript:checkDelete('."this.form,this,'$num'".');" />Delete all components</label></span></td></tr></table>'."\n");
+                my $component = 1;
+                foreach my $did (@{$conditions_by_num{$num}}) {
+                    $r->print('<p>Component: '.$component.'&nbsp;&nbsp;<labl><input type="checkbox" name="deletecomponent" value="'.$did.'" />Delete?</label><br />'.&build_condfees_table($dbh,$did,\@conditions,\%condfee,'modify',$eventid_quoted,$formname,$maxnum).'</p>');
+                    $component ++;
+                }
+                $r->print('<div class="rowtitle"><table><tr><td>New component</td><td>&nbsp;</td><td valign="top"><span class="rowtitlechange"><label><input type="checkbox" name="addcomponent" value="'.$num.'" />Add?</label></span></td></tr></table></div>'."\n");
+                $r->print(&build_condfees_table($dbh,'newcond_'.$num,\@conditions,\%condfee,'new',$eventid_quoted,$formname,$maxnum).'<br /><hr noshade />');
+            }
+        }
+    } else {
+        $r->print('There are currently no fee conditions defined for "'.$longdesc.'".<br />');
+    }
+    $r->print('<div class="rowtitle"><table><tr><td><span class="rowheader2">Add new sub-condition</span></td><td>&nbsp;</td><td valign="top"><span class="rowtitlechange"><label><input type="checkbox" name="addsubcondition" value="'.$maxnum.'" />Add?</label></span></td></tr></table></div>'."\n");
+    $r->print('Component: 1<br />'.&build_condfees_table($dbh,'newcond',\@conditions,\%condfee,'new',$eventid_quoted,$formname,$maxnum).'<br /><hr noshade />');
+    $r->print('<br /><input type="button" name="processcondfeebutton" value="Save changes" onclick="javascript:changePage('."document.$formname,'edit','fees','conditions','process'".')"><input type="hidden" name="editcondfee" value="'.$iid.'" /><br />');
     &main_footer($r,$year,$event,$returnpage,$sponsors,$sponsorinfo);
     return;
 }
 
+sub build_fees_table {
+    my ($dbh,$iid,$settings,$products,$context,$eventid_quoted,$formname) = @_;
+    my $output;
+    my %attributes = &get_fee_attributes();
+    if (ref($settings) eq 'ARRAY') {
+        my @params = @{$settings};
+        shift(@params);
+        my $rowcount = 0;
+        my $css = $rowcount%2?' class="LC_oddrow"':' class="LC_evenrow"';
+        $output = '<table class="LC_adminform"><tr '.$css.'>';
+        my $numparams = @params;
+        foreach (my $i=0; $i<$numparams; $i++) {
+            if (($i > 0) && ($i%4 ==0)) {
+                $rowcount ++;
+                $output .= '</tr>';
+                my $css = $rowcount%2?' class="LC_oddrow"':' class="LC_evenrow"';
+                $output .= '<tr '.$css.'>';
+            }
+            $output .= '<td valign="top"><span class="nobreak">'.$attributes{$params[$i]}.'</span><br />';
+            my ($feeitem,$current);
+            my $prodmax = scalar(keys(%{$products})) + 1; 
+            if ($context eq 'modify') {
+                $current = $products->{$iid}{$params[$i]};
+                $feeitem = &fee_row($dbh,'change_'.$iid,$params[$i],$current,$iid,$prodmax,$eventid_quoted,$formname);
+            } else {
+                if ($params[$i] eq 'displayorder') {
+                    $current = $prodmax;
+                }
+                $feeitem = &fee_row($dbh,$iid,$params[$i],$current,$iid,$prodmax,$eventid_quoted,$formname);
+            }
+            $output .= '<span class="nobreak">'.$feeitem.'</span></td>';
+        }
+        my $rem = $numparams%4;
+        if ($rem>0) {
+            for (my $j=$rem; $j<4; $j++) {
+                $output .= '<td>&nbsp;</td>';
+            }
+        }
+        $output .= '</tr></table><br />';
+    }
+    return $output;
+}
+
+sub fee_row {
+    my ($dbh,$name,$item,$current,$iid,$prodmax,$eventid_quoted,$formname) = @_;
+    my $output;
+    if ($item eq 'description') {
+        my @descs;
+        my $sth = $dbh->prepare("SELECT DISTINCT(description) FROM products");
+        $sth->execute();
+        while (my $desc = $sth->fetchrow_array) {
+            push(@descs,$desc);
+        }
+        $sth->finish;
+        @descs = sort(@descs);
+        $output = '<select name="'.$name.'_'.$item.'">'."\n";
+        foreach my $desc (@descs) {
+            if ($desc eq $current) {
+                $output.='<option value="'.$desc.'" selected="selected">'.$desc.'</option>';
+            } else {
+                $output.='<option value="'.$desc.'">'.$desc.'</option>';
+            }
+        }
+        $output .= '</select>';
+    } elsif ($item eq 'cost') {
+        $output='<span class="nobreak"><input type="textbox" name="'.$name.'_'.$item.'" size="10" value="'.$current.'" /></span>';
+    } elsif ($item eq 'required') {
+        $output='<label><input name="'.$name.'_'.$item.'" type="radio" value="N"';
+        if ($current eq 'N' || $current eq '') {
+            $output.=' checked="checked"';
+        }
+        $output.='/>&nbsp;No</label>&nbsp;&nbsp;<label><input name="'.$name.'_'.$item.'" type="radio" value="Y"';
+        if ($current eq 'Y') {
+            $output.=' checked="checked"';
+        }
+        $output.=' />&nbsp;Yes</label>'."\n";
+    } elsif ($item eq 'required') {
+        $output='<label><input name="'.$name.'_'.$item.'" type="radio" value="N"';
+        if ($current eq 'N' || $current eq '') {
+            $output.=' checked="checked"';
+        }
+        $output.= '/>&nbsp;No</label>&nbsp;&nbsp;<label><input name="'.$item.'" type="radio" value="Y"';
+        if ($current eq 'Y') {
+            $output.=' checked="checked"';
+        }
+        $output.=' />&nbsp;Yes</label>'."\n";
+    } elsif ($item eq 'longdesc') {
+        $output='<textarea rows="5" cols="40" name="'.$name.'_'.$item.'">'.$current.'</textarea>'."\n";
+    } elsif ($item eq 'type') {
+        my @types = ('reg','accom','conditional');
+        $output = '<span class="nobreak"><select name="'.$name.'_'.$item.'">'."\n";
+        foreach my $type (@types) {
+            if ($type eq $current) {
+                $output.='<option value="'.$type.'" selected="selected">'.$type.'</option>';
+            } else {
+                $output.='<option value="'.$type.'">'.$type.'</option>';
+            }
+        }
+        $output .= '</select>&nbsp;&nbsp;<a href="javascript:setFeeCondition('."'$iid'".');">Display/Set Conditions</a></span>';
+    } elsif ($item eq 'waiver') {
+        $output='<label><input name="'.$name.'_'.$item.'" type="radio" value="N"';
+        if ($current eq 'N' || $current eq '') {
+            $output.=' checked="checked"';
+        }
+        $output.='/>&nbsp;No</label>&nbsp;&nbsp;<label><input name="'.$name.'_'.$item.'" type="radio" value="Y"';
+        if ($current eq 'Y') {
+            $output.=' checked="checked"';
+        }
+        $output.=' />&nbsp;Yes</label>'."\n";
+    } elsif ($item eq 'registration') {
+        $output='<label><input name="'.$name.'_'.$item.'" type="radio" value="N"';
+        if ($current eq 'N' || $current eq '') {
+            $output.=' checked="checked"';
+        }
+        $output.='/>&nbsp;No</label>&nbsp;&nbsp;<label><input name="'.$name.'_'.$item.'" type="radio" value="Y"';
+        if ($current eq 'Y') {
+            $output.=' checked="checked"';
+        }
+        $output.=' />&nbsp;Yes</label>'."\n";
+    } elsif ($item eq 'infotext') {
+        $output='<textarea name="'.$name.'_'.$item.'" rows="3" cols="40">'.$current.'</textarea>'."\n";
+    } elsif ($item eq 'displayorder') {
+        $output='<select name="'.$name.'_'.$item.'" onchange="javascript:orderFees('."this.form,'$iid','$prodmax'".')">'."\n";
+        for (my $i=1; $i<=$prodmax; $i++) {
+            if ($i == $current) {
+                $output.='<option value="'.$i.'" selected="selected">'.$i.'</option>';
+            } else {
+                $output.='<option value="'.$i.'">'.$i.'</option>';
+            }
+        }
+        $output.='</select>'."\n";
+    } elsif ($item eq 'dependency') {
+        my (@fields,%order_by_title);
+        my $sth = $dbh->prepare("SELECT name,title FROM event_formfields WHERE event_id = $eventid_quoted ORDER BY name");
+        $sth->execute();
+        while (my ($name,$title) = $sth->fetchrow_array) {
+            if (ref($order_by_title{$title}) eq 'ARRAY') {
+                push(@{$order_by_title{$title}},$name);
+            } else {
+                @{$order_by_title{$title}} = ($name);
+            }
+        }
+        $sth->finish;
+        $output = '<select name="'.$name.'_'.$item.'">'."\n"
+                  .'<option value="">None</option>'."\n";
+        foreach my $title (sort(keys(%order_by_title))) {
+            if (ref($order_by_title{$title}) eq 'ARRAY') {
+                foreach my $field (@{$order_by_title{$title}}) { 
+                    if ($field eq $current) {
+                        $output.='<option value="'.$field.'" selected="selected">'.$title.'</option>';
+                    } else {
+                        $output.='<option value="'.$field.'">'.$title.'</option>';
+                    }
+                }
+            }
+        }
+        $output.='</select>'."\n";
+    }
+    return $output;
+}
+
+sub build_condfees_table {
+    my ($dbh,$did,$conditions,$condfee,$context,$eventid_quoted,$formname,$maxnum) = @_;
+    my $output;
+    my %condtitle = &get_condtitles();
+    if (ref($conditions) eq 'ARRAY') {
+        my @params = @{$conditions};
+        shift(@params);
+        pop(@params);
+        my $rowcount = 0;
+        my $css = $rowcount%2?' class="LC_oddrow"':' class="LC_evenrow"';
+        $output = '<table class="LC_adminform"><tr '.$css.'>';
+        my $numparams = @params;
+        foreach (my $i=0; $i<$numparams; $i++) {
+            if (($i > 0) && ($i%4 ==0)) {
+                $rowcount ++;
+                $output .= '</tr>';
+                my $css = $rowcount%2?' class="LC_oddrow"':' class="LC_evenrow"';
+                $output .= '<tr '.$css.'>';
+            }
+            $output .= '<td valign="top"><span class="nobreak">'.$condtitle{$params[$i]}.'</span><br />';
+            my ($condfeeitem,$current);
+            if ($context eq 'modify') {
+                $current = $condfee->{$did}{$params[$i]};
+                $condfeeitem = &condfee_row($dbh,'change_'.$did,$params[$i],$current,$did,$maxnum,$eventid_quoted,$formname);
+            } else {
+                if ($params[$i] eq 'num') {
+                    $current = $maxnum;
+                }
+                $condfeeitem = &condfee_row($dbh,$did,$params[$i],$current,$did,$maxnum,$eventid_quoted,$formname);
+            }
+            $output .= '<span class="nobreak">'.$condfeeitem.'</span></td>';
+        }
+        my $rem = $numparams%4;
+        if ($rem>0) {
+            for (my $j=$rem; $j<4; $j++) {
+                $output .= '<td>&nbsp;</td>';
+            }
+        }
+        $output .= '</tr></table><br />';
+    }
+    return $output;
+}
+
+sub condfee_row {
+    my ($dbh,$name,$item,$current,$did,$maxnum,$eventid_quoted,$formname) = @_;
+    my $output;
+    if ($item eq 'tablename') {
+        my @tables = ('attendancedays','event_registration','workshop_registration','event_accommodation');
+        $output = '<select name="'.$name.'_'.$item.'">'."\n";
+        foreach my $table (@tables) {
+            if ($table eq $current) {
+                $output.='<option value="'.$table.'" selected="selected">'.$table.'</option>';
+            } else {
+                $output.='<option value="'.$table.'">'.$table.'</option>';
+            }
+        }
+        $output .= '</select>';
+    } elsif ($item eq 'condition') {
+        $output='<label><input name="'.$name.'_'.$item.'" type="radio" value="on"';
+        if ($current eq 'on' || $current eq '') {
+            $output.=' checked="checked"';
+        }
+        $output.= '/>&nbsp;True</label>&nbsp;&nbsp;<label><input name="'.$name.'_'.$item.'" type="radio" value="off"';
+        if ($current eq 'off') {
+            $output.=' checked="checked"';
+        }
+        $output.=' />&nbsp;False</label>'."\n";
+    } elsif ($item eq 'name') {
+        $output='<input type="textbox" name="'.$name.'_'.$item.'" size="15" value="'.$current.'" />';
+    } elsif ($item eq 'value') {
+        $output='<input type="textbox" name="'.$name.'_'.$item.'" size="30" value="'.$current.'" />';
+    }
+    return $output; 
+}
+
 sub emails_menu {
     my ($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,$portal,$params,
         $sponsors,$sponsorinfo) = @_;
@@ -2912,7 +3374,225 @@
 sub process_fees_changes {
     my ($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,$portal,$params,
         $sponsors,$sponsorinfo) = @_;
+    if (ref($params) eq 'HASH') {
+        my $eventid_quoted = $dbh->quote( $event_id );
+        my @deletes;
+        if (ref($params->{'deletefee'}) eq 'ARRAY') {
+            @deletes = @{$params->{'deletefee'}};
+        } elsif ($params->{'deletefee'} ne '') {
+           @deletes = ($params->{'deletefee'});  
+        }
+        if (@deletes > 0) {
+            foreach my $iid (@deletes) {
+                my $iid_quoted = $dbh->quote( $iid );
+                my $delete = "DELETE FROM products WHERE (event_id = $eventid_quoted AND iid = $iid_quoted)";
+                $dbh->do($delete);
+            }
+        } else {
+            my %changes;
+            my @settings = ('iid','description','cost','required','longdesc','type','waiver','registration','infotext','displayorder','dependency');
+            my $itemstr = join(',',@settings);
+            my $sth = $dbh->prepare("SELECT $itemstr FROM products WHERE event_id = $eventid_quoted ORDER BY iid");
+            $sth->execute();
+            while (my @current = $sth->fetchrow_array) {
+                my $iid = $current[0];
+                next if ((@deletes > 0) && (grep(/^\Q$iid\E$/,@deletes)));
+                for (my $j=1; $j<@settings; $j++) {
+                    my $parm = 'change_'.$iid.'_'.$settings[$j];
+                    if (grep(/^\Q$parm\E$/,keys(%{$params}))) {
+                        $params->{$parm} =~ s#\(\$\)#\$#g;
+                        if ($params->{$parm} ne $current[$j]) {
+                            $changes{$iid}{$settings[$j]} = $params->{$parm};
+                        }
+                    }
+                }
+            }
+            $sth->finish;
+            if (keys(%changes) > 0) {
+                foreach my $iid (keys(%changes)) {
+                    my $iid_quoted = $dbh->quote( $iid );
+                    if (ref($changes{$iid}) eq 'HASH') {
+                        foreach my $setting (keys(%{$changes{$iid}})) {
+                            my $value_quoted = $dbh->quote( $changes{$iid}{$setting} );
+                            my $update = "UPDATE products SET $setting = $value_quoted WHERE (event_id = $eventid_quoted AND iid = $iid_quoted)";
+                            $dbh->do($update);
+                        }
+                    }
+                }
+            }
+            if ($params->{'addfee'} eq 'Y') {
+                my @params = @settings;
+                shift(@params);
+                my @newfee;
+                for (my $j=0; $j<@params; $j++) {
+                    if ($params->{'newitem_'.$params[$j]} eq '') {
+                        $newfee[$j] = 'NULL';
+                    } else {
+                        $params->{'newitem_'.$params[$j]} =~ s#\(\$\)#\$#g;
+                        $newfee[$j] = $dbh->quote( $params->{'newitem_'.$params[$j]} );
+                    }
+                }
+                unshift(@params,'eventid');
+                unshift(@newfee,$eventid_quoted);
+                my $itemstr = join(',',@params);
+                my $newfeestr = join(',',@newfee);
+                my $insert = "INSERT INTO products ($itemstr) VALUES ($newfeestr)";
+                $dbh->do($insert);
+            }
+        }
+    }
+    &fees_menu($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,
+               $portal,$params,$sponsors,$sponsorinfo);
+    return;
+}
 
+sub process_condfee_changes {
+    my ($r,$dbh,$event_id,$event,$year,$returnpage,$exitpage,$portal,$params,
+        $sponsors,$sponsorinfo) = @_;
+    my ($msg,$iid);
+    if (ref($params) eq 'HASH') {
+        $iid = $params->{'editcondfee'};
+        if ($iid eq '') {
+            &feeconditions_menu($r,$dbh,$event_id,$event,$year,$returnpage,
+                                $exitpage,$portal,$params,$sponsors,$sponsorinfo);
+        }
+        my $eventid_quoted = $dbh->quote( $event_id );
+        my $iid_quoted = $dbh->quote( $iid );
+        my ($longdesc,$type) = $dbh->selectrow_array("SELECT longdesc,type FROM products WHERE iid = $iid_quoted");
+        if ($type ne 'conditional') {
+            $msg = '<br />The fee type for the "'.$longdesc.'" fee definition is not set to "conditional".</br />Once you have set conditions here you should return to <a href="javascript:changePage('."document.feesForm,'edit','fees','',''".');">Configure Fees</a> to set the appropriate fee type.';
+        }
+        my @deletes;
+        if (ref($params->{'deletecond'}) eq 'ARRAY') {
+            @deletes = @{$params->{'deletecond'}};
+        } elsif ($params->{'deletecond'} ne '') {
+           @deletes = ($params->{'deletecond'});
+        }
+        if (@deletes > 0) {
+            foreach my $num (@deletes) {
+                my $num_quoted = $dbh->quote( $num );
+                my $delete = "DELETE FROM product_dependencies WHERE (event_id = $eventid_quoted AND iid = $iid_quoted AND num = $num_quoted)";
+                $dbh->do($delete);
+            }
+        } else {
+            my @deletecomponents;
+            if (ref($params->{'deletecomponent'}) eq 'ARRAY') {
+                @deletecomponents = @{$params->{'deletecomponent'}};
+            } elsif ($params->{'deletecomponent'} ne '') {
+                @deletecomponents = ($params->{'deletecomponent'});
+            }
+            if (@deletecomponents > 0) {
+                foreach my $did (@deletecomponents) {
+                    my $did_quoted = $dbh->quote( $did );
+                    my $num = $dbh->selectrow_array("SELECT num FROM product_dependencies WHERE did = $did_quoted");
+                    my $deletecpt = "DELETE FROM product_dependencies WHERE (event_id = $eventid_quoted AND iid = $iid_quoted AND did = $did_quoted)";
+                    $dbh->do($deletecpt);
+                }
+            }
+            my %changes;
+            my @conditions = ('did','name','tablename','value','condition','num');
+            my $conditionstr = join(',',@conditions);
+            my $statement = "SELECT $conditionstr from product_dependencies WHERE (event_id = $eventid_quoted AND iid = $iid_quoted) ORDER BY did";
+            my $sth = $dbh->prepare($statement);
+            $sth->execute();
+            while (my @current = $sth->fetchrow_array) {
+                my $did = $current[0];
+                my $num = $current[5];
+                if ((@deletecomponents ==  0) || (!grep(/^\Q$did\E$/,@deletecomponents))) {
+                    for (my $i=1; $i<@conditions-1; $i++) {
+                        if ($current[$i] ne $params->{'change_'.$did.'_'.$conditions[$i]}) {
+                            $changes{$did}{$conditions[$i]} = $params->{'change_'.$did.'_'.$conditions[$i]};     
+                        }
+                    }
+                }
+            }
+            $sth->finish;
+            if (keys(%changes) > 0) {
+                foreach my $did (keys(%changes)) {
+                    my $did_quoted = $dbh->quote( $did );
+                    if (ref($changes{$did}) eq 'HASH') {
+                        foreach my $condition (keys(%{$changes{$did}})) {
+                            my $value_quoted = $dbh->quote( $changes{$did}{$condition} );
+                            my $update = "UPDATE product_dependencies SET $condition = $value_quoted WHERE (event_id = $eventid_quoted AND iid = $iid_quoted AND did = $did_quoted)";
+                            $dbh->do($update);
+                        }
+                    }
+                }
+            }
+            my @addcomponents;
+            if (ref($params->{'addcomponent'}) eq 'ARRAY') {
+                @addcomponents = @{$params->{'addcomponent'}};
+            } elsif ($params->{'addcomponent'} ne '') {
+                @addcomponents = ($params->{'addcomponent'});
+            }
+            foreach my $newcpt (@addcomponents) {
+                my @params = @conditions;
+                shift(@params);
+                my @newcondfee;
+                my $numparam = @params; 
+                for (my $j=0; $j<$numparam-1; $j++) {
+                    if ($params->{'newcond_'.$newcpt.'_'.$params[$j]} eq '') {
+                        $newcondfee[$j] = 'NULL';
+                    } else {
+                        $newcondfee[$j] = $dbh->quote( $params->{'newcond_'.$newcpt.'_'.$params[$j]} );
+                    }
+                }
+                $newcondfee[$numparam-1] = $newcpt;
+                unshift(@params,('iid','eventid'));
+                unshift(@newcondfee,($iid_quoted,$eventid_quoted));
+                my $condstr = join(',',@params);
+                my $newcondfeestr = join(',',@newcondfee);
+                my $insert = "INSERT INTO product_dependencies ($condstr) VALUES ($newcondfeestr)";
+                $dbh->do($insert);
+            }
+            if ($params->{'addsubcondition'}) {
+                my @params = @conditions;
+                shift(@params);
+                my @newcondfee;
+                my $numparam = @params;
+                for (my $j=0; $j<$numparam-1; $j++) {
+                    if ($params->{'newcond_'.$params[$j]} eq '') {
+                        $newcondfee[$j] = 'NULL';
+                    } else {
+                        $newcondfee[$j] = $dbh->quote( $params->{'newcond_'.$params[$j]} );
+                    }
+                }
+                $newcondfee[$numparam-1] = $params->{'addsubcondition'};
+                unshift(@params,('iid','eventid'));
+                unshift(@newcondfee,($iid_quoted,$eventid_quoted));
+                my $condstr = join(',',@params);
+                my $newcondfeestr = join(',',@newcondfee);
+                my $insert = "INSERT INTO product_dependencies ($condstr) VALUES ($newcondfeestr)";
+                $dbh->do($insert);
+            }
+            my (@allnums,%renumber);
+            $statement = "SELECT DISTINCT(num) from product_dependencies WHERE (event_id = $eventid_quoted AND iid = $iid_quoted) ORDER BY num";
+            my $sth = $dbh->prepare($statement);
+            $sth->execute();
+            while (my $num = $sth->fetchrow_array) {
+                push(@allnums,$num);
+            }
+            $sth->finish;
+            my $cptcount = 0;
+            for (my $i=0; $i<@allnums; $i++) {
+                $cptcount ++;
+                if ($allnums[$i] != $cptcount) {
+                    $renumber{$allnums[$i]} = $cptcount;
+                }
+            }
+            if (keys(%renumber) > 0) {
+                foreach my $oldnum (sort { $a <=> $b } (keys(%renumber))) {
+                    my $oldnum_quoted = $dbh->quote( $oldnum );
+                    my $newnum = $renumber{$oldnum};
+                    my $newnum_quoted = $dbh->quote( $newnum );   
+                    my $update = "UPDATE product_dependencies SET num = $newnum_quoted WHERE (event_id = $eventid_quoted AND iid = $iid_quoted AND num = $oldnum_quoted";
+                    $dbh->do($update);  
+                } 
+            }
+        }
+    }
+    &feeconditions_menu($r,$dbh,$event_id,$event,$year,$returnpage,
+                        $exitpage,$portal,$params,$sponsors,$sponsorinfo,$msg);
     return;
 }
 
@@ -2947,6 +3627,33 @@
     return %configitems;
 }
 
+sub get_fee_attributes {
+    my %attributes = (
+                      'description'  => 'Type',
+                      'cost'         => 'Fee (US$)',
+                      'required'     => 'Required?',
+                      'longdesc'     => 'Name',
+                      'type'         => 'Category',
+                      'waiver'       => 'Consortium waiver applies?',
+                      'registration' => 'Registration indicated',
+                      'infotext'     => 'Description on registration form', 
+                      'displayorder' => 'Order in fees listing',
+                      'dependency'   => 'Dependency on form field',
+                     ); 
+    return %attributes;
+}
+
+sub get_condtitles {
+    my %condtitles = (
+                       name      => 'Item name',
+                       tablename => 'Database table',
+                       value     => 'Expected value',
+                       condition => 'True/False',
+                       num       => 'Condition number',
+                     );
+    return %condtitles;
+}
+
 sub current_config {
     my ($dbh,$eventid_quoted) = @_; 
     my @cols = ('eventstart','eventend','location','webpath','directlogin','registeropen',

--raeburn1208621151--