--- loncom/interface/loncreateuser.pm	2009/02/17 16:53:37	1.281
+++ loncom/interface/loncreateuser.pm	2009/04/22 17:19:10	1.291
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.281 2009/02/17 16:53:37 bisitz Exp $
+# $Id: loncreateuser.pm,v 1.291 2009/04/22 17:19:10 bisitz Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -337,7 +337,7 @@ sub print_username_entry_form {
                     'dom'  => "Domain",
                     'ecrp' => "Edit Custom Role Privileges",
                     'nr'   => "Name of Role",
-                    'cre'  => "Custom Role Editor",
+                    'cre'  => "Next",
 				       );
     $r->print($start_page."\n".$crumbs);
     if ($env{'form.action'} eq 'custom') {
@@ -347,7 +347,7 @@ sub print_username_entry_form {
 <input type="hidden" name="action" value="$env{'form.action'}" />
 <input type="hidden" name="phase" value="selected_custom_edit" />
 <h3>$lt{'ecrp'}</h3>
-$lt{'nr'}: $choice <input type="text" size="15" name="newrolename" /><br />
+$choice $lt{'nr'}: <input type="text" size="15" name="newrolename" /><br />
 <input name="customeditor" type="submit" value="$lt{'cre'}" />
 </form>
 ENDCUSTOM
@@ -901,7 +901,7 @@ ENDNOPORTPRIV
             if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
                 my %lt=&Apache::lonlocal::texthash(
                     'utav'  => "User Tools Availability",
-                    'yodo'  => "You do not have privileges to modify Portfolio, Blog or Home Page settings for this user.",
+                    'yodo'  => "You do not have privileges to modify Portfolio, Blog or Personal Information Page settings for this user.",
                     'ifch'  => "If a change is required, contact a domain coordinator for the domain",
                 );
                 $user_tools_text = <<ENDNOTOOLSPRIV;
@@ -1230,8 +1230,17 @@ sub display_existing_roles {
             }
         }
         if ($rolesdisplay == 1) {
+            my $contextrole='';
+            if ($env{'request.course.id'}) {
+                $contextrole = 'Existing Roles in this Course';
+            } elsif ($env{'request.role'} =~ /^au\./) {
+                $contextrole = 'Existing Co-Author Roles in your Construction Space';
+            } else {
+                $contextrole = 'Existing Roles in this Domain';
+            }
             $r->print('
 <h3>'.$lt{'rer'}.'</h3>'.
+'<div>'.&mt($contextrole).'</div>'.
 &Apache::loncommon::start_data_table("LC_createuser").
 &Apache::loncommon::start_data_table_header_row().
 '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.
@@ -1283,7 +1292,7 @@ sub new_coauthor_roles {
                   &Apache::loncommon::end_data_table_header_row()."\n".
                   &Apache::loncommon::start_data_table_row().'
            <td>
-            <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
+            <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
            </td>
            <td>'.$lt{'cau'}.'</td>
            <td>'.$cudom.'_'.$cuname.'</td>
@@ -1295,7 +1304,7 @@ sub new_coauthor_roles {
 "javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
               &Apache::loncommon::end_data_table_row()."\n".
               &Apache::loncommon::start_data_table_row()."\n".
-'<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
+'<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
 <td>'.$lt{'caa'}.'</td>
 <td>'.$cudom.'_'.$cuname.'</td>
 <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
@@ -1346,7 +1355,7 @@ sub new_domain_roles {
                $num_domain_level ++;
                $domaintext .=
 &Apache::loncommon::start_data_table_row().
-'<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
+'<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
 <td>'.$plrole.'</td>
 <td>'.$thisdomain.'</td>
 <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
@@ -1524,16 +1533,19 @@ sub modify_login_block {
 
 sub personal_data_display {
     my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
-    my ($output,$showforceid,%userenv,%canmodify);
+    my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
     my $rowcount = 0;
     my $editable = 0;
+    %canmodify_status = 
+        &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
+                                                   ['inststatus'],$rolesarray);
     if (!$newuser) {
         # Get the users information
         %userenv = &Apache::lonnet::get('environment',
                    ['firstname','middlename','lastname','generation',
-                    'permanentemail','id'],$ccdomain,$ccuname);
+                    'permanentemail','id','inststatus'],$ccdomain,$ccuname);
         %canmodify =
             &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
                                                        \@userinfo,$rolesarray);
@@ -1549,7 +1561,8 @@ sub personal_data_display {
                 'generation'     => "Generation",
                 'permanentemail' => "Permanent e-mail address",
                 'id'             => "Student/Employee ID",
-                'lg'             => "Login Data"
+                'lg'             => "Login Data",
+                'inststatus'     => "Affiliation",
     );
     my %textboxsize = (
                        firstname      => '15',
@@ -1587,11 +1600,15 @@ sub personal_data_display {
                 }
             } else {
                 if ($context eq 'selfcreate') {
-                    if ($canmodify{$item}) {
-                        $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
-                        $editable ++;
+                    if (($item eq 'permanentemail') && ($newuser eq 'email')) {
+                        $row .= $ccuname;
                     } else {
-                        $hiderow = 1;
+                        if ($canmodify{$item}) {
+                            $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                            $editable ++;
+                        } else {
+                            $hiderow = 1;
+                        }
                     }
                 } else {
                     $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
@@ -1613,6 +1630,30 @@ sub personal_data_display {
             $rowcount ++;
         }
     }
+    if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
+        my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
+        if (ref($types) eq 'ARRAY') {
+            if (@{$types} > 0) {
+                my ($hiderow,$shown);
+                if ($canmodify_status{'inststatus'}) {
+                    $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
+                } else {
+                    $shown .= $userenv{'inststatus'};
+                    if ($userenv{'inststatus'} eq '') {
+                        $hiderow = 1;
+                    }
+                }
+                if (!$hiderow) {
+                    my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
+                              $shown.&Apache::lonhtmlcommon::row_closure(1); 
+                    if ($context eq 'selfcreate') {
+                        $rowcount ++;
+                    }
+                    $output .= $row;
+                }
+            }
+        }
+    }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {
         if ($context eq 'selfcreate') {
@@ -1625,6 +1666,48 @@ sub personal_data_display {
     }
 }
 
+sub pick_inst_statuses {
+    my ($curr,$usertypes,$types) = @_;
+    my ($output,$rem,@currtypes);
+    if ($curr ne '') {
+        @currtypes = map { &unescape($_); } split(/:/,$curr);
+    }
+    my $numinrow = 2;
+    if (ref($types) eq 'ARRAY') {
+        $output = '<table>';
+        my $lastcolspan; 
+        for (my $i=0; $i<@{$types}; $i++) {
+            if (defined($usertypes->{$types->[$i]})) {
+                my $rem = $i%($numinrow);
+                if ($rem == 0) {
+                    if ($i<@{$types}-1) {
+                        if ($i > 0) { 
+                            $output .= '</tr>';
+                        }
+                        $output .= '<tr>';
+                    }
+                } elsif ($i==@{$types}-1) {
+                    my $colsleft = $numinrow - $rem;
+                    if ($colsleft > 1) {
+                        $lastcolspan = ' colspan="'.$colsleft.'"';
+                    }
+                }
+                my $check = ' ';
+                if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
+                    $check = ' checked="checked" ';
+                }
+                $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
+                           '<span class="LC_nobreak"><label>'.
+                           '<input type="checkbox" name="inststatus" '.
+                           'value="'.$types->[$i].'"'.$check.'/>'.
+                           $usertypes->{$types->[$i]}.'</label></span></td>';
+            }
+        }
+        $output .= '</tr></table>';
+    }
+    return $output;
+}
+
 sub selfcreate_canmodify {
     my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
     if (ref($inst_results) eq 'HASH') {
@@ -1774,6 +1857,8 @@ sub update_user_data {
     my (%alerts,%rulematch,%inst_results,%curr_rules);
     my @usertools = ('aboutme','blog','portfolio');
     my @requestcourses = ('official','unofficial');
+    my ($othertitle,$usertypes,$types) = 
+        &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
     if ($env{'form.makeuser'}) {
 	$r->print('<h3>'.&mt('Creating new account.').'</h3>');
         # Check for the authentication mode and password
@@ -1856,6 +1941,13 @@ sub update_user_data {
                 $changed{$item} = &tool_admin($item,$newcustom{$item},
                                               \%changeHash,'requestcourses');
             }
+            if (exists($env{'form.inststatus'})) {
+                my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
+                if (@inststatuses > 0) {
+                    $changeHash{'inststatus'} = join(',',@inststatuses);
+                    $changed{'inststatus'} = $changeHash{'inststatus'};
+                }
+            }
             if (keys(%changed)) {
                 $changeHash{'firstname'}  = $env{'form.cfirstname'};
                 $changeHash{'middlename'} = $env{'form.cmiddlename'};
@@ -2024,12 +2116,13 @@ sub update_user_data {
                 }
             }
         }
-        my ($quotachanged,$oldportfolioquota,$newportfolioquota,
-            $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
-            $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext);
+        my ($quotachanged,$oldportfolioquota,$newportfolioquota,$oldinststatus,
+            $inststatus,$newinststatus,$oldisdefault,$newisdefault,$olddefquotatext,
+            $newdefquotatext,%oldaccess,%oldaccesstext,%newaccess,%newaccesstext,
+            $oldinststatuses,$newinststatuses);
         my ($defquota,$settingstatus) = 
             &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
-        my ($showquota,$showtools,$showrequestcourses);
+        my ($showquota,$showtools,$showrequestcourses,$showinststatus);
         if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
             $showquota = 1;
         }
@@ -2039,7 +2132,46 @@ sub update_user_data {
         if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
             $showrequestcourses = 1;
         }
+        if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
+            $showinststatus = 1;
+        }
         my (%changeHash,%changed);
+        $oldinststatus = $userenv{'inststatus'};
+        if ($oldinststatus eq '') {
+            $oldinststatuses = $othertitle; 
+        } else {
+            if (ref($usertypes) eq 'HASH') {
+                $oldinststatuses = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
+            } else {
+                $oldinststatuses = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
+            }
+        }
+        $changeHash{'inststatus'} = $userenv{'inststatus'};
+        my %canmodify_inststatus = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},['inststatus'],\@userroles);
+        if ($canmodify_inststatus{'inststatus'}) {
+            if (exists($env{'form.inststatus'})) {
+                my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
+                if (@inststatuses > 0) {
+                    $newinststatus = join(':',map { &escape($_); } @inststatuses);
+                    $changeHash{'inststatus'} = $newinststatus;
+                    if ($newinststatus ne $oldinststatus) {
+                        $changed{'inststatus'} = $newinststatus;
+                    }
+                    if (ref($usertypes) eq 'HASH') {
+                        $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses)); 
+                    } else {
+                        $newinststatuses = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
+                    }
+                } else {
+                    $newinststatus = '';
+                    $changeHash{'inststatus'} = $newinststatus;
+                    $newinststatuses = $othertitle;
+                    if ($newinststatus ne $oldinststatus) {
+                        $changed{'inststatus'} = $changeHash{'inststatus'};
+                    }
+                }
+            }
+        }
         $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
         if ($userenv{'portfolioquota'} ne '') {
             $oldportfolioquota = $userenv{'portfolioquota'};
@@ -2056,7 +2188,7 @@ sub update_user_data {
             } else {
                 $changed{'quota'} = &quota_admin('',\%changeHash);
                 $newportfolioquota = $defquota;
-                $newisdefault = 1; 
+                $newisdefault = 1;
             }
         } else {
             $oldisdefault = 1;
@@ -2158,21 +2290,22 @@ sub update_user_data {
                 ((keys(%changed) > 0) && $chgresult eq 'ok')) {
             # Tell the user we changed the name
 		my %lt=&Apache::lonlocal::texthash(
-                             'uic'        => "User Information Changed",             
-                             'frst'       => "First",
-                             'mddl'       => "Middle",
-                             'lst'        => "Last",
-			     'gen'        => "Generation",
-                             'id'         => "Student/Employee ID",
-                             'mail'       => "Permanent E-mail",
-                             'disk'       => "Disk space allocated to portfolio files",
-                             'blog'       => "Blog Availability",
-                             'aboutme'    => "Home Page Availability",
-                             'portfolio'  => "Portfolio Availability",
-                             'official'   => "Can Request Official Courses",
-                             'unofficial' => "Can Request Unofficial Courses",
-                             'prvs'       => "Previous",
-                             'chto'       => "Changed To"
+                             'uic'        => 'User Information Changed',
+                             'frst'       => 'First Name',
+                             'mddl'       => 'Middle Name',
+                             'lst'        => 'Last Name',
+                             'gen'        => 'Generation',
+                             'id'         => 'Student/Employee ID',
+                             'mail'       => 'Permanent e-mail address',
+                             'disk'       => 'Disk space allocated to portfolio files',
+                             'blog'       => 'Blog Availability',
+                             'aboutme'    => 'Personal Information Page Availability',
+                             'portfolio'  => 'Portfolio Availability',
+                             'official'   => 'Can Request Official Courses',
+                             'unofficial' => 'Can Request Unofficial Courses',
+                             'inststatus' => "Affiliation",
+                             'prvs'       => 'Previous Value:',
+                             'chto'       => 'Changed To:'
 						   );
                 $r->print('<h4>'.$lt{'uic'}.'</h4>'.
                           &Apache::loncommon::start_data_table().
@@ -2186,6 +2319,10 @@ sub update_user_data {
     <th>$lt{'id'}</th>
     <th>$lt{'mail'}</th>
 END
+                if ($showinststatus) {
+                    $r->print("
+    <th>$lt{'inststatus'}</th>\n");
+                }
                 if ($showrequestcourses) {
                     foreach my $item (@requestcourses) {
                         $r->print("
@@ -2213,6 +2350,10 @@ END
     <td>$userenv{'id'}</td>
     <td>$userenv{'permanentemail'} </td>
 END
+                if ($showinststatus) {
+                    $r->print("
+    <td>$oldinststatuses</td>\n");
+                }  
                 if ($showrequestcourses) {
                     foreach my $item (@requestcourses) {
                         $r->print("
@@ -2240,6 +2381,10 @@ END
     <td>$env{'form.cid'} </td>
     <td>$env{'form.cpermanentemail'} </td>
 END
+                if ($showinststatus) {
+                    $r->print("
+    <td>$newinststatuses</td>\n");
+                }
                 if ($showrequestcourses) {
                     foreach my $item (@requestcourses) {
                         $r->print("
@@ -2289,13 +2434,14 @@ END
             # but we can still tell them what the name and quota and availabilities are  
 	    my %lt=&Apache::lonlocal::texthash(
                            'id'         => "Student/Employee ID",
-                           'mail'       => "Permanent e-mail",
+                           'mail'       => "Permanent e-mail address",
                            'disk'       => "Disk space allocated to user's portfolio files",
                            'blog'       => "Blog Availability",
-                           'aboutme'    => "Home Page Availability",
+                           'aboutme'    => "Personal Information Page Availability",
                            'portfolio'  => "Portfolio Availability",
                            'official'   => "Can Request Official Courses",
                            'unofficial' => "Can Request Unofficial Course",
+                           'inststatus' => "Affiliation",
 					       );
             $r->print(<<"END");
 <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
@@ -2304,6 +2450,9 @@ END
                 $r->print('<br />['.$lt{'mail'}.': '.
                           $userenv{'permanentemail'}.']');
             }
+            if ($showinststatus) {
+                $r->print('<br />['.$lt{'inststatus'}.': '.$oldinststatuses.']');
+            }
             if ($showrequestcourses) {
                 foreach my $item (@requestcourses) {
                     $r->print('<br />['.$lt{$item}.': '.$newaccess{$item}.' '.
@@ -3001,14 +3150,14 @@ ENDCCF
         my $privtext = &Apache::lonnet::plaintext($priv);
         $r->print(&Apache::loncommon::start_data_table_row().
 	          '<td>'.$privtext.'</td><td>'.
-    ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c" '.
-    ($courselevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').
+    ($courselevel{$priv}?'<input type="checkbox" name="'.$priv.'_c"'.
+    ($courselevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').
     '</td><td>'.
-    ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d" '.
-    ($domainlevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').
+    ($domainlevel{$priv}?'<input type="checkbox" name="'.$priv.'_d"'.
+    ($domainlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').
     '</td><td>'.
-    ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s" '.
-    ($systemlevelcurrent{$priv}?'checked="1"':'').' />':'&nbsp;').
+    ($systemlevel{$priv}?'<input type="checkbox" name="'.$priv.'_s"'.
+    ($systemlevelcurrent{$priv}?' checked="checked"':'').' />':'&nbsp;').
     '</td>'.
              &Apache::loncommon::end_data_table_row());
     }
@@ -3017,7 +3166,7 @@ ENDCCF
    '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
    '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".   
    '<input type="reset" value="'.&mt("Reset").'" />'."\n".
-   '<input type="submit" value="'.&mt('Define Role').'" /></form>'.
+   '<input type="submit" value="'.&mt('Save').'" /></form>'.
 	      &Apache::loncommon::end_page());
 }
 # --------------------------------------------------------
@@ -3200,8 +3349,11 @@ sub handler {
     if ($env{'form.action'} ne 'dateselect') {
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>"/adm/createuser",
-              text=>"User Management"});
+              text=>"User Management",
+              help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'});
     }
+    #SD Following files not added to help, because the corresponding .tex-files seem to
+    #be missing: Course_Approve_Selfenroll,Course_User_Logs,
     my ($permission,$allowed) = 
         &Apache::lonuserutils::get_permission($context);
     if (!$allowed) {
@@ -3839,9 +3991,10 @@ ENDSCRIPT
     my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
     if (ref($visactions) eq 'HASH') {
         if ($visible) {
-            $output .= '<p>'.$visactions->{'vis'}.'</p>';
+            $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
         } else {
-            $output .= $visactions->{'miss'}.'<br />'.$visactions->{'yous'}.
+            $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
+                      .$visactions->{'yous'}.
                        '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
             if (ref($vismsgs) eq 'ARRAY') {
                 $output .= '<br />'.$visactions->{'make'}.'<ul>';
@@ -4089,7 +4242,7 @@ ENDSCRIPT
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box().
                '<br /><input type="button" name="selfenrollconf" value="'
-               .&mt('Save changes').'" onclick="validate_types(this.form);" />'
+               .&mt('Save').'" onclick="validate_types(this.form);" />'
                .'<input type="hidden" name="action" value="selfenroll" /></form>';
     $r->print($output);
     return;
@@ -4378,7 +4531,7 @@ sub visible_in_cat {
                    miss => 'Your course does not currently appear in the Course Catalog for this domain.',
                    yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding your course.',
                    coca => 'Courses can be absent from the Catalog, because they do not have an institutional code, have no assigned category, or have been specifically excluded.',
-                   make => 'Make any changes to self-enrollment settings below, click "Save changes", then take action to include the course in the Catalog:',
+                   make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
                    take => 'Take the following action to ensure the course appears in the Catalog:',
                    dc_unhide  => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
                    dc_addinst => 'Ask a domain coordinator to enable display the catalog of "Official courses (with institutional codes)".',