[Affelio-cvs 752] CVS update: affelio/lib/Affelio/App/Admin

Back to archive index

Tadashi Okoshi slash****@users*****
2005年 11月 8日 (火) 14:16:29 JST


Index: affelio/lib/Affelio/App/Admin/ManageApplication.pm
diff -u affelio/lib/Affelio/App/Admin/ManageApplication.pm:1.4 affelio/lib/Affelio/App/Admin/ManageApplication.pm:1.5
--- affelio/lib/Affelio/App/Admin/ManageApplication.pm:1.4	Thu Oct 27 20:15:01 2005
+++ affelio/lib/Affelio/App/Admin/ManageApplication.pm	Tue Nov  8 14:16:28 2005
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
-# $Id: ManageApplication.pm,v 1.4 2005/10/27 11:15:01 slash5234 Exp $
+# $Id: ManageApplication.pm,v 1.5 2005/11/08 05:16:28 slash5234 Exp $
 
 package Affelio::App::Admin::ManageApplication;
 {
@@ -35,43 +35,94 @@
     #save_permission
     #####################################################################
     sub save_permission{
-    	my $af = shift;                 #arg(1) AF
+	my $af = shift;                 #arg(1) AF
 	my $q  = shift;                 #arg(2) CGI
-	my $app_name = shift;           #arg(e) app_name
+	my $app_name = shift;           #arg(3) app_name
+	my $am = $af->getAM;
 
-	#formhead_num_action_types
-	#formdata_pid(\n)_(n)
-	my $num_action_types = $q->param("formhead_num_action_types");
-	my $pid_list = $q->param("formhead_pid_list");
-	my @pids = split('[\s]+', $pid_list);
-	
-	my @type_array = 
-	    @{$af->getAM->{apps}->{$app_name}->{action_types}};
-	unshift(@type_array, "DF_access");
-	unshift(@type_array, "DF_visibility");
-
-	foreach my $pid (@pids){
-	    my $type_count=0;
-	    for($type_count=0; $type_count<$num_action_types; $type_count++){
-		
-		my $param_name = "formdata_pid" . $pid . "_" . $type_count;
-		my $param_value = $q->param($param_name);
-		if($param_value ne ""){
-		    $param_value = 1;
-		}else{
-		    $param_value = 0;
+	#######################
+	#debug
+	#######################
+	my @params = $q->param;
+	foreach my  $i (@params){
+	    debug_print("save_permission: [$i] =". $q->param($i));
+	}
+
+	my @type_array = @{$am->{apps}->{$app_name}->{action_types}};
+	my $num_action_types = @type_array;
+	my %val_hash=();
+
+	#######################
+	# Save values for F1, F2, and PB
+	#######################
+	{
+	    my @gids = ("f1", "f2", "pb");
+	    my @option_pids = (1,2,3);
+
+	    for(my $i=0; $i<3; $i++){
+		%val_hash=();
+
+		my $gid = $gids[$i];
+		my $option_pid = $option_pids[$i];
+		debug_print("save_permission: For group[$gid]...");
+
+		#Set values
+		my $count=0;
+		for($count=0; $count < $num_action_types; $count++){
+
+		    my $param_name 
+			= "formdata__f__" . $gid . "__" . $type_array[$count];
+
+		    if($q->param($param_name) eq "on"){
+			$val_hash{$type_array[$count]} = 1;
+		    }else{
+			$val_hash{$type_array[$count]} = 0;
+		    }
 		}
-		debug_print("ManageApp:save: [$pid]:[$type_array[$type_count]]  = [$param_value]");
+		debug_print("save_permission: group_permission=[%val_hash]");
+		$am->update_permission($app_name,
+				       $gid,
+				       $option_pid, 
+				       \%val_hash);
+	    }#for
+	}#part
+    
+	#######################
+	# Save values for registered groups
+	#######################
+        {
+	    my $groups_SQL = $af->getGM->get_all_group_list();
+	    #For each group returned...
+	    while( (my ($gid, $group_name, $members, $option_pid) 
+		    = $groups_SQL->fetchrow_array)){
+
+		%val_hash=();
+
+		#Set values
+		my $count=0;
+		for($count=0; $count < $num_action_types; $count++){
+
+		    my $param_name 
+			= "formdata__g__" . $gid . "__" . $type_array[$count];
+
+		    if($q->param($param_name) eq "on"){
+			$val_hash{$type_array[$count]} = 1;
+		    }else{
+			$val_hash{$type_array[$count]} = 0;
+		    }
+		}
+		debug_print("save_permission: group_permission=[%val_hash]");
+		$am->update_permission($app_name,
+				       $gid,
+				       $option_pid, 
+				       \%val_hash);
 
-		$af->getAM->update_permission($app_name,
-					     $pid,
-					     $type_array[$type_count],
-					     $param_value);
-	    }
+	    }#while
+
+	}#part
+    }#sub		
 
-	} #for each
 
-    }
     #####################################################################
     #show_app
     #####################################################################
@@ -81,10 +132,20 @@
 	my $output_ref = shift;         #arg(3) ref of %output_data; 
 
 	debug_print("ManageApp::show_app: start.");
+
+	#######################
+	#Prep
+	#######################
+	my $am = $af->getAM;
 	
 	$output_ref->{"install_name"} = $app_name;
 	$output_ref->{"install_title"} 
-	= $af->getAM->{apps}->{$app_name}->{install_title};
+	= $am->{apps}->{$app_name}->{install_title};
+
+	my @type_desc_array = 
+	    @{$am->{apps}->{$app_name}->{action_types_desc}};
+	my @type_array = 
+	    @{$am->{apps}->{$app_name}->{action_types}};
 
 	#######################
 	#Headers
@@ -92,80 +153,111 @@
 	my @headers=();
 	$output_ref->{"headers"} = \@headers;
 
-	push(@headers, {header => '<AF_M text="DF_visibility">'});
-	push(@headers, {header => '<AF_M text="DF_access">'});
-
-	my $type_desc_array = 
-	    $af->getAM->{apps}->{$app_name}->{action_types_desc};
-
 	my $count=0;
-	foreach my $desc (@{$type_desc_array}){
+	foreach my $desc (@type_desc_array){
 	    debug_print("ManageApp::show_app: header=[$desc]");
 	    push(@headers, {header => "$desc"});
 	    $count++;
 	}
-	$output_ref->{"num_action_types"} = $count + 2; #gotta inlude DF 2s.
+	$output_ref->{"num_action_types"} = $count;
 
-	#######################
-	#Permission data
-	#######################
 	my @groups=();
 	$output_ref->{"groups"} = \@groups;
 
-	#prepare application permission table
-	$af->getAM->prepare_app_perm_table($app_name);
+	#######################
+	# F1, F2, and PB
+	#######################
+	{
+	    my @gids = ("f1", "f2", "pb");
+	    my @group_names = ($af->{lh}->maketext("_VISITOR_TYPE_F1"),
+			       $af->{lh}->maketext("_VISITOR_TYPE_F2"),
+			       $af->{lh}->maketext("_VISITOR_TYPE_PB"));
+	    my @option_pids = (1,2,3);
+
+	    for(my $i=0; $i<3; $i++){
+
+		my $gid = $gids[$i];
+		my $group_name = $group_names[$i];
+		my $option_pid = $option_pids[$i];
+		debug_print("ManApp::show_app: For group[$gid]...");
+
+		#set group_name
+		my %this_group =();
+		$this_group{"group_name"} = $group_name;
+
+		#For each group, get the permission list.
+		my $g_perm_result = $am->get_permission("f", $gid, $app_name);
+		my @g_perm = $g_perm_result->fetchrow_array;
+		debug_print("ManApp::show_app: group_permission=[@g_perm]");
+
+		#Set values
+		my @data_array=();
+		$this_group{data_array} = \@data_array;
+		my $count=0;
+		my $count2=-3;
+		foreach my $val (@g_perm){
+		    if($count2 >= 0){ 
+			my $chk_name = "formdata__f__" 
+			    . $gid . "__" .  $type_array[$count2];
+
+			push(@data_array, {value => $val,
+					   checkbox_name => $chk_name});
+		    }
+		    $count++;
+		    $count2++;
+		}
+		push(@groups, \%this_group);
+	    } #while
 
-	#Retrieve table
-	my $result= $af->getAM->get_all_permission($app_name);
+	}#part
 
-	##################
-	#For each group...
-	##################
-	my $pid_list="";
-	while( (my ($pid, $type, $target_id, @perms) 
-		= $result->fetchrow_array)){
-	    
-	    debug_print("ManageApp::show_app: data[$pid] $type, $target_id, @perms");
-	    my %this_group=();
-	    push(@groups, \%this_group);
+	#######################
+	# Registered Groups
+	#######################
+	my $groups_SQL = $af->getGM->get_all_group_list();
 
-	    #######################
-	    #Group name
-	    if($pid==1){
-		$this_group{group_name} = "<B><I>" . 
-		    $af->{lh}->maketext("_VISITOR_TYPE_F1") . "</I></B>";
-	    }elsif($pid==2){
-		$this_group{group_name} = "<B><I>" . 
-		    $af->{lh}->maketext("_VISITOR_TYPE_F2") . "</I></B>";
-	    }elsif($pid==3){
-		$this_group{group_name} = "<B><I>" . 
-		    $af->{lh}->maketext("_VISITOR_TYPE_PB") . "</I></B>";
-	    }elsif($type eq "g"){
-		my $query = "select group_name from AFuser_CORE_group where gid=$target_id";
-		my $sth = $af->getDB->prepare($query) or die $af->getDB->errstr;
-		$sth->execute() or die $af->getDB->errstr;
-		my @tmp_array = $sth->fetchrow_array;
-		$this_group{group_name} = $tmp_array[0];
-	    } #if
+	#For each group returned...
+	while( (my ($gid, $group_name, $members, $option_pid) 
+		= $groups_SQL->fetchrow_array)){
+
+	    debug_print("ManApp:show_app: For group[$gid]...");
+	    if($gid <1){last;}
+
+	    #set group_name
+	    my %this_group =();
+	    $this_group{"group_name"} = $group_name;
+
+	    #For each group, get the permission list.
+	    my $g_perm_result = $am->get_permission("g", "$gid", $app_name);
+	    my @g_perm = $g_perm_result->fetchrow_array;
+	    debug_print("ManApp:show_app: group_permission=[@g_perm]");
+
+	    if(@g_perm == ()){
+		for(my $num=1; 
+		    $num <= ($output_ref->{"num_action_types"}+3); $num++){
+		    push(@g_perm, 0);
+		}
+	    }
 
-	    #######################
-	    #Values
+	    #Set values
 	    my @data_array=();
 	    $this_group{data_array} = \@data_array;
+	    my $count=0; 
+	    my $count2=-3;
+	    foreach my $val (@g_perm){
+		if($count2 >= 0){ 
+		    my $chk_name = "formdata__g__" 
+			. $gid . "__" .  $type_array[$count2];
 
-	    my $count=0;
-	    foreach my $val (@perms){
-
-		my $chk_name = "formdata_pid" . $pid . "_" . $count;
-		push(@data_array, {value => $val,
-				   checkbox_name => $chk_name});
+		    push(@data_array, {value => $val,
+				       checkbox_name => $chk_name});
+		}
 		$count++;
+		$count2++;
 	    }
 
-	    $pid_list .= "$pid ";
-	} #while (for each group)
-
-	$output_ref->{"pid_list"} = $pid_list;
+	    push(@groups, \%this_group);
+	}#while
 
     }
 
@@ -177,11 +269,12 @@
 	my $af = shift;                 #arg(1) AF
 	my $output_ref = shift;         #arg(2) ref of %output_data; 
 
+	my $am = $af->getAM;
 	my @applications=();
 
 	my $install_name;
 	my $app;
-	while (($install_name, $app) = each(%{$af->getAM->{apps}})){
+	while (($install_name, $app) = each(%{$am->{apps}})){
 
 	    push(@applications, {install_title => $app->{install_title},
 				 install_name => $app->{install_name},
Index: affelio/lib/Affelio/App/Admin/ManageGroup.pm
diff -u affelio/lib/Affelio/App/Admin/ManageGroup.pm:1.4 affelio/lib/Affelio/App/Admin/ManageGroup.pm:1.5
--- affelio/lib/Affelio/App/Admin/ManageGroup.pm:1.4	Thu Oct 27 20:15:01 2005
+++ affelio/lib/Affelio/App/Admin/ManageGroup.pm	Tue Nov  8 14:16:28 2005
@@ -14,7 +14,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
-# $Id: ManageGroup.pm,v 1.4 2005/10/27 11:15:01 slash5234 Exp $
+# $Id: ManageGroup.pm,v 1.5 2005/11/08 05:16:28 slash5234 Exp $
 
 package Affelio::App::Admin::ManageGroup;
 {
@@ -57,6 +57,7 @@
 
 	#Create a new group
 	my $gid = $af->getGM->add_group($group_name);
+	debug_print("ManageGroup:add_group added group.");
 
 	#Get attribute table
 	my $attributes = $af->getPM->get_attribute_table();
@@ -66,10 +67,13 @@
 	      = $attributes->fetchrow_array){
 	    $g_perm[$attr_id] = 0;
 	}
-	$g_perm[1] = 0;
+	$g_perm[1] = 1;
 
 	debug_print("ManageGroup:add_group newg group=[@g_perm]");
-	$af->getPM->add_permission("g", $gid, \@g_perm);
+
+	$af->getPERM->add_permission("g", $gid, \@g_perm);
+
+	debug_print("ManageGroup:add_group end.");
     }
 
     #####################################################################


Affelio-cvs メーリングリストの案内
Back to archive index