mail.sh: avoid sendmail errors when "no email generated"
[girocco.git] / cgi / editproj.cgi
blobcaecf62b8a62712839f81e678cbfd02494db80d6
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
14 my $script = <<'EOT';
15 <script type="text/javascript">
16 // <![CDATA[
17 function adduseritem(elem)
19 var inp = document.createElement('input');
20 inp.type = 'text';
21 inp.name = 'user';
22 var li = document.createElement('li');
23 li.appendChild(document.createTextNode('Add user: '));
24 li.appendChild(inp);
25 elem.parentNode.insertBefore(li, elem);
27 // ]]>
28 </script>
29 EOT
30 my $gcgi = Girocco::CGI->new('Project Settings', undef, $script);
31 my $cgi = $gcgi->cgi;
33 my $name = $cgi->param('name');
34 $name =~ s#\.git$## if $name; #
36 unless (defined $name) {
37 print "<p>I need the project name as an argument now.</p>\n";
38 exit;
41 if (!Girocco::Project::valid_name($name)) {
42 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
43 exit;
46 if (!Girocco::Project::does_exist($name)) {
47 print "<p>Sorry but the project $name does not exist. Now, how did you <em>get</em> here?!</p>\n";
48 exit;
51 my $proj = Girocco::Project->load($name);
52 $proj or die "not found project $name, that's really weird!";
54 if ($cgi->param('y0')) {
55 # submitted, let's see
56 if ($proj->cgi_fill($gcgi) and $proj->authenticate($gcgi) and $proj->update) {
57 print "<p>Project successfully updated.</p>\n";
58 if ($proj->{clone_failed}) {
59 print "<p>Please <a href=\"mirrorproj.cgi?name=$name\">pass onwards</a>.</p>\n";
60 print "<script language=\"javascript\">document.location='mirrorproj.cgi?name=$name'</script>\n";
61 exit;
66 # $proj may be insane now but that's actually good for us since we'll let the
67 # user fix the invalid values she entered
68 my %h = $proj->form_defaults;
70 print <<EOT;
71 <p>Here you can adjust the settings of project $h{name}. Go wild.
72 EOT
73 if ($proj->{mirror}) {
74 print <<EOT;
75 Since this is a mirrored project, you can opt to remove it from the site as well.
76 Just <a href="delproj.cgi?name=$h{name}">delete it</a>.</p>
77 EOT
78 } else {
79 if ($proj->is_empty) {
80 print <<EOT;
81 Since this is an empty project, you can opt to remove it from the site as well.
82 Just <a href="delproj.cgi?name=$h{name}">delete it</a>.</p>
83 EOT
85 print <<EOT;
86 Use the <b>+</b> button to enable access for more than a single user at a time.</p>
87 EOT
90 my $button_label = $proj->{clone_failed} ? 'Restart Mirroring' : 'Update';
92 print <<EOT;
93 <form method="post">
94 <table class="form">
95 <tr><td class="formlabel">Project name:</td><td class="formdata"><a href="$Girocco::Config::gitweburl/$h{name}.git">$h{name}</a>.git
96 <input type="hidden" name="name" value="$h{name}" /></td></tr>
97 EOT
98 if ($Girocco::Config::project_passwords) {
99 print <<EOT;
100 <tr><td class="formlabel"><strong>Admin password:</strong></td><td>
101 <input type="password" name="cpwd" /> <sup><a href="pwproj.cgi?name=$name" class="ctxaction">(forgot password?)</a></sup></td></tr>
102 <tr><td class="formlabel">New admin password (twice):<br />
103 <em>(leave empty to keep it the same)</em></td><td>
104 <input type="password" name="pwd" /><br /><input type="password" name="pwd2" /><br />
105 </td></tr>
108 if ($Girocco::Config::project_owners eq 'email') {
109 print <<EOT;
110 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" value="$h{email}" /></td></tr>
114 if ($proj->{mirror}) {
115 print "<tr><td class=\"formlabel\">Repository URL:</td><td><input type=\"text\" name=\"url\" value=\"$h{url}\" /></td></tr>\n";
116 } else {
117 print <<EOT;
118 <tr><td class="formlabel" style="vertical-align:middle">Users:</td><td>
119 <ul>
121 $Girocco::Config::manage_users and print "<p>Only <a href=\"reguser.cgi\">registered users</a> can push.</p>";
122 if ($Girocco::Config::mob and not grep { $_ eq $Girocco::Config::mob } @{$h{users}}) {
123 print "<p><em>(Please consider adding the <tt>$Girocco::Config::mob</tt> user.\n";
124 print "<sup><a href=\"$Girocco::Config::htmlurl/mob.html\">(learn more)</a></sup>)\n";
125 print "</em></p>\n";
127 foreach my $user (@{$h{users}}) {
128 my $mlm = '';
129 $mlm = " <sup><a href=\"$Girocco::Config::htmlurl/mob.html\">(learn more)</a></sup>"
130 if $Girocco::Config::mob && $user eq $Girocco::Config::mob;
131 print "<li><input type=\"checkbox\" name=\"user\" value=\"$user\" checked=\"1\" /> $user$mlm</li>\n";
133 print <<EOT;
134 <li>Add user: <input type="text" name="user" /></li>
135 <button type="button" onclick="adduseritem(this)"><b>+</b></button>
136 </ul>
137 </td></tr>
141 print '<tr><td class="formlabel">Default branch:</td><td><select size="1" name="HEAD">';
142 for ($proj->get_heads) {
143 my $selected = $proj->{HEAD} eq $_ ? ' selected="selected"' : '';
144 print "<option$selected>".Girocco::CGI::html_esc($_)."</option>";
146 print '</select></td></tr>
149 print '<tr><td class="formlabel">Tags (select to delete):</td><td>';
150 print '<select size="6" name="tags" multiple="multiple">';
151 for ($proj->get_ctag_names) {
152 print '<option>'.Girocco::CGI::html_esc($_).'</option>';
154 print '</select></td></tr>
158 $gcgi->print_form_fields($Girocco::Project::metadata_fields, \%h, @Girocco::Config::project_fields);
160 print <<EOT;
161 <tr><td></td><td><input type="submit" name="y0" value="$button_label" /></td></tr>
162 </table>
163 </form>