ispman/ispman-web/cgi-bin/tmpl/vhosts edit_acls.tmpl,1.6,1.7

Joerg Delker <[email protected]>
Newsgroups gmane.comp.isp.ispman.cvs
Message-ID <[email protected]>
Update of /cvsroot/ispman/ispman/ispman-web/cgi-bin/tmpl/vhosts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12469/ispman-web/cgi-bin/tmpl/vhosts

Modified Files:
	edit_acls.tmpl 
Log Message:
big time recoding
cleaner, smoother, nicer ;)

Index: edit_acls.tmpl
===================================================================
RCS file: /cvsroot/ispman/ispman/ispman-web/cgi-bin/tmpl/vhosts/edit_acls.tmpl,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- edit_acls.tmpl	11 Jun 2004 18:30:47 -0000	1.6
+++ edit_acls.tmpl	12 Jun 2004 00:06:13 -0000	1.7
@@ -1,158 +1,177 @@
-<table>
-<tr>
-    <td valign=top>
-        <perl>_("Website  Access control")</perl>  <br>
-        
-        </td>
-    <td>
-        <font  color=white><i>
-        </font>
-        </td>
-</tr>
-<tr>
-<td colspan=2>                        
+<script type="text/javascript" language="JavaScript">
+<!--
+    function checkACL(f){
+        if (f.newIspmanVhostAclLocation.value == ""){
+            alert("Location must not be empty!")
+            return false
+        }
+        if (f.newIspmanVhostAclAllowUser.value == ""){
+            alert("Users must not be empty!")
+            return false
+        }
+        return true
+    }
+
+    function editACL(f){
+        location=cgiurl+"?mode=editVhost&section=acls&"+cgidata+"&ispmanVhostAclLocation="+f.ispmanVhostAclLocation.value+"&form="+f.name;
+    }
+
+    function deleteACL(f){
+        location=cgiurl+"?mode=deleteVhostAcl&"+cgidata+"&ispmanVhostAclLocation="+f.ispmanVhostAclLocation.value;
+    }
+
+//-->
+</script>
+
+
+Add new ACI
 <table border=1>
-	<tr class=header>
-			<td><perl>_("Protected area")</perl></td>
-			<td><perl>_("Allowed users")</perl></td>
-			<td colspan=2>&nbsp;</td>                               
-	</tr>
-	<perl>
-		my $ACLs=$ispman->getAcls($r->param("ispmanDomain"), $r->param('ispmanVhostName'));
-		my $text="";
-		if ($ACLs){
-			$text.="<tr><td colspan=4 class=control>";
-			$text.=_("The following rules are defined ");
-			$text.="</td></tr>";
-			
-			my $vhost = join '.', ($r->param("ispmanVhostName"), $r->param('ispmanDomain'));
-			$text.= $vhost;
-			$text.="<br><br>";
-                
-                
-			for (sort {length($b) <=> length($a)} keys %$ACLs){ 
-				$text.="<tr>";
-				if ($r->param("ispmanVhostAclLocation") && $r->param("ispmanVhostAclLocation") eq $ACLs->{$_}{'ispmanVhostAclLocation'}){
-					$text.=qq|\n<form name=ACLEditForm>\n
-					<td valign=top>
-					$ACLs->{$_}{'ispmanVhostAclLocation'}
-					</td>
-						<td valign=top> <select name=ispmanVhostAclAllowUser multiple size=5>|;
-					my $allowedUsers={};
-					for my $allowedUser ($ispman->as_array($ACLs->{$_}{'ispmanVhostAclAllowUser'})){
-						$allowedUsers->{$allowedUser}++;
-					}
-                                   
-					my $webusers=$ispman->getWebusers($r->param('ispmanDomain'));
-					for $webuser(keys %$webusers){
-						$text.="<option value='$webusers->{$webuser}{'ispmanUserId'}'";
-						if ($allowedUsers->{$webusers->{$webuser}{'ispmanUserId'}}) {
-							$text.=" selected ";
-						}
-						$text.=">webuser: $webusers->{$webuser}{'ispmanUserId'}</option>\n";
-					}
-					my $domainusers=$ispman->getDomainUsersForDomain($r->param('ispmanDomain'));
-					for $domainuser(keys %$domainusers){
-						my $exploded_dn=$ispman->explodeDN($domainusers->{$domainuser});
-						my $uid=$exploded_dn->{'uid'};
+  <tr>
+    <th><perl>_("Protected area")</perl></th>
+    <th><perl>_("Allowed users")</perl></th>
+    <th>&nbsp;</th>
+  </tr>
 
-                                                # FIXME!!!
-                                                # Really dirty hack to fake the ispmanUserId which can not easily retrieved here.
-                                                # This will get fixed with new ISPMan Core Libs
-                                                my $domain = $r->param("ispmanDomain");
-                                                $domain =~ s/\./_/;
-                                                $uid =~ s/_$domain//;
+  <tr class=control>
+    <form name="NewVhostACLForm" onSubmit="return checkACL(this)">
+    <td valign=top class=control><input type=text name=newIspmanVhostAclLocation value=""></td>
+    <td valign=top class=control>
+    <select MULTIPLE size=5 name=newIspmanVhostAclAllowUser>
 
-						$text.="<option value='$uid'";
-						if ($allowedUsers->{$uid}) {
-							$text.=" selected ";
-						}
-						$text.=">domainuser: $uid</option>\n";
-					}
-					$text.=qq|
-					</select>
-					</td>
-					<td><input type=submit value='@{[_("update")]}'></td>
-					<input type=hidden name=ispmanVhostAclLocation value="$ACLs->{$_}{'ispmanVhostAclLocation'}">
-					<input type=hidden name=ispmanDomain value="@{[$r->param('ispmanDomain')]}">
-					<input type=hidden name=ispmanVhostName value="@{[$r->param('ispmanVhostName')]}">
-					<input type=hidden name=mode value="updateVhostAcl">
-					</form>
-					<td><a href="@{[$r->url]}?mode=deleteVhostAcl&section=acls&ispmanDomain=@{[$r->param("ispmanDomain")]}&ispmanVhostName=@{[$r->param("ispmanVhostName")]}&ispmanVhostAclLocation=$ACLs->{$_}{'ispmanVhostAclLocation'}">@{[_('Delete')]}</a></td>
-					|;
-				} else {
-					$text.=qq|
-						<td><font color=blue>$ACLs->{$_}{'ispmanVhostAclLocation'}</font></td>
-						<td> <font color=green>|;
-					if (ref $ACLs->{$_}{'ispmanVhostAclAllowUser'} eq "ARRAY") {
-						$text.= join ', ', @{$ACLs->{$_}{'ispmanVhostAclAllowUser'}};
-					} else {
-						$text.=$ACLs->{$_}{'ispmanVhostAclAllowUser'};
-					}
-                                
-					$text.=qq|
-						</font></td>
-						<td><a href="@{[$r->url]}?mode=editVhost&section=acls&ispmanVhostName=@{[$r->param("ispmanVhostName")]}&ispmanDomain=@{[$r->param("ispmanDomain")]}&ispmanVhostAclLocation=$ACLs->{$_}{'ispmanVhostAclLocation'}">@{[_('Edit')]}</a></td>
-						<td><a href="@{[$r->url]}?mode=deleteVhostAcl&ispmanDomain=@{[$r->param("ispmanDomain")]}&section=acls&ispmanVhostName=@{[$r->param("ispmanVhostName")]}&ispmanVhostAclLocation=$ACLs->{$_}{'ispmanVhostAclLocation'}">@{[_('Delete')]}</a></td>
-						|;
-				}
-                        
-				$text.="<tr>";
-			}
-		} else {
-			$text.="<tr><td colspan=4 class=control>";
-			$text.=_("No Website ACL defined ");
-			$text.="</td></tr>";
-		}                                        
-		$text
-	</perl>
-                
-	<tr class=control>
-		<form name=NewVhostACLForm>
-		<td valign=top class=control><input type=text name=newIspmanVhostAclLocation value=""></td>
-		<td valign=top class=control>
-		<select MULTIPLE size=5 name=newIspmanVhostAclAllowUser>
-		<perl>
-			$text='';
-			my $webusers=$ispman->getWebusers($r->param('ispmanDomain'));
-			for $webuser(keys %$webusers){
-				$text.="\n<option value='$webusers->{$webuser}{'ispmanUserId'}'>webuser: $webusers->{$webuser}{'ispmanUserId'}</option>";
-			}
-			$text
-		</perl>
-                        
-		<perl>
-			$text="";
-			my $users=$ispman->getDomainUsersForDomain($r->param('ispmanDomain'));
-			for my $user(keys %$users) {
-				my $exploded_dn=$ispman->explodeDN($users->{$user});
-				my $uid=$exploded_dn->{'uid'};
+<perl>
+# gather users for selection
+my $_wusers=$ispman->getWebusers($r->param('ispmanDomain'));
[email protected]=();
+for (keys %$_wusers){ push @webusers, $_wusers->{$_}{'ispmanUserId'} };
+    
+my $_dusers=$ispman->getDomainUsersForDomain($r->param('ispmanDomain'));
[email protected]=();
+for (keys %$_dusers){
+    my $exploded_dn=$ispman->explodeDN($_dusers->{$_});
+    my $uid=$exploded_dn->{'uid'};
+    
+    # FIXME!!!
+    # Really dirty hack to fake the ispmanUserId which can not easily retrieved here.
+    # This will get fixed with new ISPMan Core Libs
+    my $domain = $r->param("ispmanDomain");
+    $domain =~ s/\./_/;
+    $uid =~ s/_$domain//;
+    push @domainusers, $uid;
+}
 
-                                # FIXME!!!
-                                # Really dirty hack to fake the ispmanUserId which can not easily retrieved here.
-                                # This will get fixed with new ISPMan Core Libs
-                                my $domain = $r->param("ispmanDomain");
-                                $domain =~ s/\./_/;
-                                $uid =~ s/_$domain//;
+$text='';
+foreach (@webusers){
+    $text.="<option value='$_'>webuser: $_</option>";
+}
 
-				$text.="<option value='$uid'>domainuser: $uid</option>\n";
-			}
-			$text
-		</perl>
-		</select>
-		</td>
-		<input type=hidden name=mode value="addVhostAcl">
-		<input type=hidden name=ispmanVhostName value="<perl>$r->param("ispmanVhostName")</perl>">
-		<input type=hidden name=ispmanDomain value="<perl>$r->param("ispmanDomain")</perl>">
-		<td colspan=2><input type=submit value="<perl>_('Add  new protected area')</perl>"></td>
-		</form>
-	</tr>
+my $users=$ispman->getDomainUsersForDomain($r->param('ispmanDomain'));
+foreach (@domainusers){
+    $text.="<option value='$_'>domainuser: $_</option>\n";
+}
+$text
+</perl>
+
+    </select>
+  </td>
+  <input type=hidden name=mode value="addVhostAcl">
+  <input type=hidden name=ispmanVhostName value="<perl>$r->param("ispmanVhostName")</perl>">
+  <input type=hidden name=ispmanDomain value="<perl>$r->param("ispmanDomain")</perl>">
+  <td><input type=submit value="<perl>_('Add')</perl>"></td>
+  </form>
+</tr>
 </table>                
 
+<br>
+Current ACL
+<table border=1>
+  <tr>
+    <th><perl>_("Protected area")</perl></th>
+    <th><perl>_("Allowed users")</perl></th>
+    <th>&nbsp;</th>
+  </tr>
+	
+<perl>
+my $ACLs=$ispman->getAcls($r->param("ispmanDomain"), $r->param('ispmanVhostName'));
+my $text="";
+if ($ACLs){
+    my $i=0;    
+    for (sort {length($b) <=> length($a)} keys %$ACLs){ 
+        $text.="<tr>";
+        $i++;
+        $isedited=($r->param("form") && $r->param("form") eq "aci$i")?1:0;
+        
+        $text.=qq|
+<form name=aci$i>
+<td valign=top>
+  <input type=hidden name=ispmanVhostAclLocation value="$ACLs->{$_}{'ispmanVhostAclLocation'}">
+  $ACLs->{$_}{'ispmanVhostAclLocation'}
+</td>
+<td valign=top>|;
+        
+        if ($isedited){
+            # is edited
+            $text.="<select name=ispmanVhostAclAllowUser multiple size=5>";
 
+            my $allowedUsers={};
+            for my $allowedUser ($ispman->as_array($ACLs->{$_}{'ispmanVhostAclAllowUser'})){
+                $allowedUsers->{$allowedUser}++;
+            }
+                                   
+            foreach (@webusers){
+                $text.="<option value='$_'";
+                if ($allowedUsers->{$_}) {
+                    $text.=" selected ";
+                }
+                $text.=">webuser: $_</option>\n";
+            }
+
+            foreach (@domainusers){
+                $text.="<option value='$_'";
+                if ($allowedUsers->{$_}) {
+                    $text.=" selected ";
+                }
+                $text.=">domainuser: $_</option>\n";
+            }
+            $text.=qq|
+</select>
+</td>
+<input type=hidden name=ispmanDomain value="@{[$r->param('ispmanDomain')]}">
+<input type=hidden name=ispmanVhostName value="@{[$r->param('ispmanVhostName')]}">
+<input type=hidden name=mode value="updateVhostAcl">
+<td><a href="javascript: document.aci$i.submit()" alt="@{[_("Apply")]}" title="@{[_("Apply")]}">
+<img src="/gfx/apply.gif" border="0"></a>
+|;
+        } else {
+            # not edited
+            if (ref $ACLs->{$_}{'ispmanVhostAclAllowUser'} eq "ARRAY") {
+                $text.= join ', ', @{$ACLs->{$_}{'ispmanVhostAclAllowUser'}};
+            } else {
+                $text.=$ACLs->{$_}{'ispmanVhostAclAllowUser'};
+            }
+            $text.=qq|
+</td>
+<td>
+<a href="javascript: editACL(document.aci$i)" alt="@{[_("Edit")]}" title="@{[_("Edit")]}">
+<img src="/gfx/modify.gif" border="0"></a>
+|;
+        }
 
+        $text.=qq|
+<a href="javascript: deleteACL(document.aci$i)" alt="@{[_("Delete")]}" title="@{[_("Delete")]}">
+<img src="/gfx/delete.gif" border="0"></a>
 </td>
+</form>
 </tr>
+|;
+    }
+} else {
+    $text.="<tr><td colspan=3 class=control>";
+    $text.=_("No Website ACL defined ");
+    $text.="</td></tr>";
+}                                        
+$text
+</perl>
+    
 </table>
 
 



-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
From Windows to Linux, servers to mobile, InstallShield X is the
one installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.