[Bio] / FigWebServices / assignments.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/assignments.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Wed Jan 14 20:20:32 2004 UTC revision 1.2, Fri Jan 16 14:59:48 2004 UTC
# Line 1  Line 1 
   
1  use FIG;  use FIG;
2  my $fig = new FIG;  my $fig = new FIG;
3    
# Line 22  Line 21 
21    
22  my $html = [];  my $html = [];
23    
24    my $user = $cgi->param('user');
25    if (! $user)
26    {
27        push(@$html,$cgi->h1("Sorry, you need to specify a user to process assignment sets"));
28    }
29    else
30    {
31  my $request = $cgi->param("request");  my $request = $cgi->param("request");
32  $request = defined($request) ? $request : "";  $request = defined($request) ? $request : "";
33    
# Line 46  Line 52 
52  {  {
53      &show_initial($fig,$cgi,$html);      &show_initial($fig,$cgi,$html);
54  }  }
55    }
56    
57  &HTML::show_page($cgi,$html);  &HTML::show_page($cgi,$html);
58    
59  sub show_initial {  sub show_initial {
60      my($fig,$cgi,$html) = @_;      my($fig,$cgi,$html) = @_;
61        my($set,$when,$comment);
62    
63      my @sets = &assignment_sets;      my $user = $cgi->param('user');
64        my @sets = &assignment_sets($user);
65      if (@sets == 0)      if (@sets == 0)
66      {      {
67          push(@$html,$cgi->h1("No Assignment Sets Defined"));          push(@$html,$cgi->h1("No Assignment Sets Defined"));
# Line 60  Line 69 
69      }      }
70    
71      my $target = "window$$";      my $target = "window$$";
     my $user = $cgi->param('user');  
72      push(@$html, $cgi->h1('Assignment Sets'),      push(@$html, $cgi->h1('Assignment Sets'),
73                   $cgi->start_form(-action => "assignments.cgi",                   $cgi->start_form(-action => "assignments.cgi",
74                                    -target => $target,                                    -target => $target,
# Line 71  Line 79 
79      my $col_hdrs = ["Edit/Examine","Delete","Accept All","Set Date","Comment"];      my $col_hdrs = ["Edit/Examine","Delete","Accept All","Set Date","Comment"];
80      my $tab      = [];      my $tab      = [];
81      my $title    = "Existing Assignment Sets";      my $title    = "Existing Assignment Sets";
82    
83      foreach $set (sort { &compare_set_names($a,$b) } @sets)      foreach $set (sort { &compare_set_names($a,$b) } @sets)
84      {      {
85          $set =~ /(\d+-\d+-\d+:\d+:\d+:\d+)(:(.*))?/;          $set =~ /(\d+-\d+-\d+:\d+:\d+:\d+)(:(.*))?/;
# Line 91  Line 100 
100  sub edit_link {  sub edit_link {
101      my($cgi,$set) = @_;      my($cgi,$set) = @_;
102    
103      return $cgi->self_url() . "&request=edit_set&set=$set";      return "<a href=" . $cgi->self_url() . "&request=edit_set&set=$set>edit</a>";
104  }  }
105    
106  sub delete_link {  sub delete_link {
107      my($cgi,$set) = @_;      my($cgi,$set) = @_;
108    
109      return $cgi->self_url() . "&request=delete_set&set=$set";      return "<a href=" . $cgi->self_url() . "&request=delete_set&set=$set>delete</a>";
110  }  }
111    
112  sub accept_link {  sub accept_link {
113      my($cgi,$set) = @_;      my($cgi,$set) = @_;
114    
115      return $cgi->self_url() . "&request=accept_set&set=$set";      return "<a href=" . $cgi->self_url() . "&request=accept_set&set=$set>accept</a>";
116  }  }
117    
118  sub assignment_sets {  sub assignment_sets {
119        my($user) = @_;
120    
121        my $userR = $user;
122        $userR =~ s/^master://;
123      my @sets = ();      my @sets = ();
124      if (opendir(SETS,"$FIG_Config::data/Assignments"))      if (opendir(SETS,"$FIG_Config::data/Assignments/$userR"))
125      {      {
126          @sets = grep { $_ =~ /^\d+-\d+-\d+:\d+:\d+:\d+/ } readdir(SETS);          @sets = grep { $_ =~ /^\d+-\d+-\d+:\d+:\d+:\d+/ } readdir(SETS);
127          closedir(SETS);          closedir(SETS);
# Line 147  Line 159 
159          push(@$html,$cgi->h1("Sorry, but you need to specify a user to edit assignments"));          push(@$html,$cgi->h1("Sorry, but you need to specify a user to edit assignments"));
160          return;          return;
161      }      }
     elsif ($user =~ /^master:/)  
     {  
         $userR = "master";  
     }  
162      else      else
163      {      {
164          $userR = $user;          $userR = $user;
165            $userR =~ s/^master://;
166      }      }
167    
168      my $set  = $cgi->param('set');      my $set  = $cgi->param('set');
# Line 166  Line 175 
175      my $target = "window$$";      my $target = "window$$";
176      if (-s "$FIG_Config::data/Assignments/$userR/$set")      if (-s "$FIG_Config::data/Assignments/$userR/$set")
177      {      {
178          push(@$html, $cgi->h1('Edit Set $set'),          if (open(SET,"<$FIG_Config::data/Assignments/$userR/$set"))
179            {
180                push(@$html, $cgi->h1("Edit Set $set"),
181                       $cgi->start_form(-method => 'post',                       $cgi->start_form(-method => 'post',
182                                        -target => $target,                                        -target => $target,
183                                        -action => 'edit_checked.cgi'                                            -action => 'assignments.cgi'
184                                        ),                                        ),
185                       $cgi->hidden(-name => 'user', -value => $user),                       $cgi->hidden(-name => 'user', -value => $user),
186                       $cgi->hidden(-name => 'set', -value => $set)                       $cgi->hidden(-name => 'set', -value => $set)
# Line 177  Line 188 
188    
189          $col_hdrs = ["delete","PEG","Functions"];          $col_hdrs = ["delete","PEG","Functions"];
190          $tab      = [];          $tab      = [];
         if (open(SET,"<$FIG_Config::data/Assignments/$userR/$set"))  
         {  
191              while (defined($line = <SET>))              while (defined($line = <SET>))
192              {              {
193                  chop $line;                  chop $line;
# Line 196  Line 205 
205                  }                  }
206              }              }
207              close(SET);              close(SET);
208          }              if (@$tab > 0)
209                {
210          push(@$html,&HTML::make_table($col_hdrs,$tab,"",["nowrap"]));          push(@$html,&HTML::make_table($col_hdrs,$tab,"",["nowrap"]));
211          push(@$html,$cgi->submit("delete checked entries"));          push(@$html,$cgi->submit("delete checked entries"));
212      }      }
213                else
214                {
215                    push(@$html,$cgi->h2("No new assignments"));
216                }
217            }
218            else
219            {
220                push(@$html,$cgi->h1("Sorry, could not open $FIG_Config::data/Assignments/$userR/$set; sounds like a permissions problem"));
221            }
222        }
223        else
224        {
225            push(@$html,$cgi->h1("Sorry, $set does not exist for user $user"));
226        }
227  }  }
228    
229  sub delete_set {  sub delete_set {
# Line 229  Line 253 
253      {      {
254          my $userR = $user;          my $userR = $user;
255          $userR =~ s/^master://;          $userR =~ s/^master://;
256          if (system("fig assign_functionF $user $FIG_Config::data/Assignments/$userR/$set > /dev/null") == 0)          if (system("$FIG_Config::bin/fig assign_functionF $user $FIG_Config::data/Assignments/$userR/$set > /dev/null") == 0)
257          {          {
258              push(@$html,$cgi->h1("Made Assignments from $set"));              push(@$html,$cgi->h1("Made Assignments from $set"));
259          }          }
260          else          else
261          {          {
262              push(@$html,$cgi->h1("Call Support: some error occurred"));              push(@$html,$cgi->h1("Call Support: some error occurred in accepting assignments from $FIG_Config::data/Assignments/$userR/$set"));
263          }          }
264      }      }
265      else      else
# Line 261  Line 285 
285    
286  sub delete_checked {  sub delete_checked {
287      my($fig,$cgi,$html) = @_;      my($fig,$cgi,$html) = @_;
288        my($line);
289    
290      my $user = $cgi->param('user');      my $user = $cgi->param('user');
291      my $set  = $cgi->param('set');      my $set  = $cgi->param('set');
292        my @checked = $cgi->param('checked');
293        my %checked = map { $_ => 1 } @checked;
294    
295      if ($user)      if ($user)
296      {      {
297          my $userR = $user;          my $userR = $user;
298          $userR =~ s/^master://;          $userR =~ s/^master://;
299          if (-s "$FIG_Config::data/Assignments/$userR/$set")          if (-s "$FIG_Config::data/Assignments/$userR/$set")
300          {          {
301              @entries = `cat $FIG_Config::data/Assignments/$userR/$set`;              if (rename("$FIG_Config::data/Assignments/$userR/$set","$FIG_Config::data/Assignments/$userR/$set~"))
302                {
303                    if (open(IN,"<$FIG_Config::data/Assignments/$userR/$set~") &&
304                        open(OUT,"<$FIG_Config::data/Assignments/$userR/$set"))
305                    {
306                        while (defined($line = <IN>))
307                        {
308                            if (($line =~ /^(\S+)/) && (! $checked{$1}))
309                            {
310                                print OUT $line;
311                            }
312                        }
313                        close(IN);
314                        close(OUT);
315    
316                        if (chmod(0777,"$FIG_Config::data/Assignments/$userR/$set"))
317                        {
318                            unlink("$FIG_Config::data/Assignments/$userR/$set~");
319                            push(@$html,$cgi->h1("ok"));
320                        }
321                        else
322                        {
323                            push(@$html,$cgi->h1("chmod failure: permissions problem"));
324                        }
325                    }
326                    else
327                    {
328                        push(@$html,$cgi->h1("could not open $FIG_Config::data/Assignments/$userR/$set; maybe a permissions problem"));
329                    }
330                }
331                else
332                {
333                    push(@$html,$cgi->h1("Could not rename $FIG_Config::data/Assignments/$userR/$set"));
334                }
335            }
336        }
337        else
338        {
339            push(@$html,$cgi->h1("invalid user"));
340        }
341  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3