[LON-CAPA-cvs] cvs: modules /hoeppner lonsearch.pm lonsearchcat.pm

hoeppner lon-capa-cvs-allow@mail.lon-capa.org
Tue, 01 Jul 2008 12:54:18 -0000


This is a MIME encoded message

--hoeppner1214916858
Content-Type: text/plain

hoeppner		Tue Jul  1 08:54:18 2008 EDT

  Modified files:              
    /modules/hoeppner	lonsearch.pm lonsearchcat.pm 
  Log:
  - evaluation per sort method possible
  
  
--hoeppner1214916858
Content-Type: text/plain
Content-Disposition: attachment; filename="hoeppner-20080701085418.txt"

Index: modules/hoeppner/lonsearch.pm
diff -u modules/hoeppner/lonsearch.pm:1.2 modules/hoeppner/lonsearch.pm:1.3
--- modules/hoeppner/lonsearch.pm:1.2	Sat Jun 28 20:22:14 2008
+++ modules/hoeppner/lonsearch.pm	Tue Jul  1 08:54:16 2008
@@ -204,16 +204,18 @@
 	my $comment = $_[1];
 	my $user = $_[2];
 	my $numberOfResults = $_[3];
-#	print DEBUG "----saving rating from: $user \n";
-	# 1) get the highest id for that user
-	my $id = &getCurrentId($user);		
-	# 2) update row with that id
-	my $sql = "UPDATE communities.Evaluation SET rating=?, comment=?, results=? WHERE id=$id";
-	my $stb = $dbh->prepare($sql)
-	        or die "Couldn't prepare statement: " . $dbh->errstr;
-	$stb->execute($rating, $comment,$numberOfResults);
-	print DEBUG "saved rating: $user";
-	print DEBUG $stb->errstr ."\n";
+	if ($rating>0 && $rating<6) {
+	#	print DEBUG "----saving rating from: $user \n";
+		# 1) get the highest id for that user
+		my $id = &getCurrentId($user);		
+		# 2) update row with that id
+		my $sql = "UPDATE communities.Evaluation SET rating=?, comment=?, results=? WHERE id=$id";
+		my $stb = $dbh->prepare($sql)
+		        or die "Couldn't prepare statement: " . $dbh->errstr;
+		$stb->execute($rating, $comment,$numberOfResults);
+		print DEBUG "saved rating: $user";
+		print DEBUG $stb->errstr ."\n";
+	} # else: call without the necessary parameters..after we change the sort field comment/rating are NULL
 }
 
 # to retrieve the keywords of the last search (that didnt extend)
@@ -237,13 +239,13 @@
 sub getEvalType() {
 	my $user = $_[0];
 	my $logged_in_userid = &getCurrentId($user);
-	my $sql = "select action from communities.Evaluation where user=? and id=?";
+	my $sql = "select action,results,total from communities.Evaluation where user=? and id=?";
 	my $stb = $dbh->prepare($sql)
 	        or die "Couldn't prepare statement: " . $dbh->errstr;
 	$stb->execute($user, $logged_in_userid);
-	my $action = $stb->fetchrow_array();
-	print DEBUG "FETCHED : " . $stb->err . $stb->errstr . "\n";
-	return $action;
+	my @action = $stb->fetchrow_array();
+#	print DEBUG "FETCHED : " . $stb->err . $stb->errstr . "\n";
+	return @action;
 }
 
 sub createEvaluationRow_Copy() {
@@ -252,11 +254,13 @@
 	my $rating = 0;
 	my $comment = 'none';
 	my $issuing_user = $_[2];
+	my $results = $_[3];
+	my $total = $_[4];
 	# create the row
 	my $insert = "INSERT INTO communities.Evaluation VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
 				my $stj = $dbh->prepare($insert)
 						        or die "Couldn't prepare statement: " . $dbh->errstr;
-				my @params = (&getCurrentId($issuing_user)+1,$issuing_user, $search_type, $rating, $comment, -1, -1, $sort);
+				my @params = (&getCurrentId($issuing_user)+1,$issuing_user, $search_type, $rating, $comment, $results, $total, $sort);
 #				print DEBUG "---eval row with: @params \n";
 				$stj->execute(@params);
 				print DEBUG $stj->err . $stj->errstr;
@@ -278,7 +282,12 @@
 	my $expand = $_[7]; # direct or sac
 	my $issuing_user = $_[8];
 #	print DEBUG "in search creating with $issuing_user \n"; 
-	
+	my $sort = 'count';
+	if ($algorithm eq 'usedauthors' || $algorithm eq 'relatedcoordinators') {
+		$sort = 'stdno';
+	} elsif ($algorithm eq 'sortfield') {
+		$sort = $degree;
+	}
 	# create the columns ...
 	my $search_type = ''; #
 	if ($expand eq '') {
@@ -292,7 +301,7 @@
 	my $insert = "INSERT INTO communities.Evaluation VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
 				my $stj = $dbh->prepare($insert)
 						        or die "Couldn't prepare statement: " . $dbh->errstr;
-				my @params = (&getCurrentId($issuing_user)+1,$issuing_user, $search_type, $rating, $comment, -1, -1, "unknown");
+				my @params = (&getCurrentId($issuing_user)+1,$issuing_user, $search_type, $rating, $comment, -1, -1, $sort);
 #				print DEBUG "---eval row with: @params \n";
 				$stj->execute(@params);
 				print DEBUG $stj->err . $stj->errstr;
@@ -306,10 +315,10 @@
 #	print DEBUG $sta->errstr ."\n";
 	my $id;	
 	if (my @id_data = $sta->fetchrow_array()) {
-		print DEBUG "retrieved  $id_data[1] id is: " . $id_data[0] . " for $_[0]\n";
+#		print DEBUG "retrieved  $id_data[1] id is: " . $id_data[0] . " for $_[0]\n";
 		$id = $id_data[1];
 	} else {
-		print DEBUG "nothing ...retrieved  $id_data[1] id is: " . $id_data[0] . " for $_[0]\n";
+#		print DEBUG "nothing ...retrieved  $id_data[1] id is: " . $id_data[0] . " for $_[0]\n";
 		$id = 0;		
 	}
 #	print DEBUG "chosen id is: " . $id . "\n";
@@ -317,7 +326,7 @@
 }
 
 sub standard() {
-	print "started.\n";
+#	print "started.\n";
 	createResultRow();
 }
 
@@ -329,20 +338,20 @@
 	        or die "Couldn't prepare statement: " . $dbh->errstr;
 	$stb->execute($user);	
 	my $logged_in_userid = $stb->fetchrow_array(); # this is not user id but the current Evaluation id for the user
-	print DEBUG "query result: $logged_in_userid; status?:" .$stb->err . " ".$stb->errstr ." " . $dbh->errstr . "\n";
+#	print DEBUG "query result: $logged_in_userid; status?:" .$stb->err . " ".$stb->errstr ." " . $dbh->errstr . "\n";
 	return $logged_in_userid;	
 }
 
 # last sort algorithm of evaluation that was a search ..
 sub getLastSort() {
 	my $user = $_[0];
-	my $id = &getLastId($user);
-	my $sql = "select sort from communities.Evaluation where id=?";
+	my $id = &getCurrentId($user);
+	my $sql = "select sort from communities.Evaluation where id=? and user=?";
 	my $stb = $dbh->prepare($sql)
 	        or die "Couldn't prepare statement: " . $dbh->errstr;
-	$stb->execute($id);	
+	$stb->execute($id, $user);	
 	my $logged_in_userid = $stb->fetchrow_array(); # this is not user id but the current Evaluation id for the user
-	print DEBUG "query result: $logged_in_userid; status?:" .$stb->err . " ".$stb->errstr ." " . $dbh->errstr . "\n";
+	print DEBUG "getLastSort() query result: $logged_in_userid; status?:" .$stb->err . " ".$stb->errstr ." " . $dbh->errstr . "\n";
 	return $logged_in_userid;	
 }
 
@@ -351,25 +360,25 @@
 sub expandSAC() {
 	my $community = $_[6];
 	$user = $_[5]; # this holds the logged in user, not the start user, contrary to the user_id in this case!!
-	print DEBUG "user is $user \n";
+#	print DEBUG "user is $user \n";
 	$user_id = &getUserId($_[3]); # using the start user here!!
 	my $keywords = $_[4];
 	if ($keywords eq '') {
 		
 		my $logged_in_userid = &getLastId($user);
-		print DEBUG "getting keywords from DB $user $logged_in_userid \n";
+#		print DEBUG "getting keywords from DB $user $logged_in_userid \n";
 		my $sql = "select action from communities.Evaluation where user=? and id=?";
 		my $stb = $dbh->prepare($sql)
 		        or die "Couldn't prepare statement: " . $dbh->errstr;
 		$stb->execute($user, $logged_in_userid);
 		my $data = $stb->fetchrow_array();	
-		print DEBUG $data ."\n";
+#		print DEBUG $data ."\n";
 		my @split_data = split(/;/,$data);
 		$keywords = @split_data[2];
-		print DEBUG "got keywords from DB: $keywords \n";		
+#		print DEBUG "got keywords from DB: $keywords \n";		
 	}
 	my @keys = split(/ /, $keywords);
-	print DEBUG "extending for $user_id by course+SAC+keys: " . $_[0] . " @keys \n";
+#	print DEBUG "extending for $user_id by course+SAC+keys: " . $_[0] . " @keys \n";
 	my $resource_id = $_[0];
 	$table = $_[1];
 	$r = $_[2];
@@ -397,7 +406,7 @@
 		}	
 		if (@courses>0) {
 		#	print DEBUG "courses: @courses \n";
-			print DEBUG "SAC for $user_id: ".@SAC. "\n";
+#			print DEBUG "SAC for $user_id: ".@SAC. "\n";
 		
 			for (my $i = 0; $i<@courses ; $i++) {
 				$courses[$i] = '%'.$courses[$i].'%';
@@ -437,9 +446,9 @@
 			print DEBUG "arguments: $actr authors and $cctr courses  and $kctr keywords for slots " . @params ."\n";		
 #			print DEBUG "parameters ". @keys ." ". @courses . " " . @SAC .": @params";
 			$sth->execute(@params);
-			print DEBUG "...\n";
-			print DEBUG "on selecting the resource entities:" .$sth->err();
-			print DEBUG $sth->errstr() ."\n";
+#			print DEBUG "...\n";
+#			print DEBUG "on selecting the resource entities:" .$sth->err();
+			print DEBUG "expandSAC(): " . $sth->errstr() ."\n";
 			# for each resource: saveExtend
 			while (my @result = $sth->fetchrow_array()) {
 		#		print "- result: @result \n";
@@ -478,18 +487,18 @@
 # were used before or after the resources
 sub expandPrePost() {
 	$user = $_[3];
-	print DEBUG "user is $user \n";
+#	print DEBUG "user is $user \n";
 #	print "extending by pre/post: " . $_[0] . "\n";
 	my $resource_id = $_[0];
 	$table = $_[1];
 	$r = $_[2];
-print DEBUG 'r in search expand: '.$r . "\n";
+#print DEBUG 'r in search expand: '.$r . "\n";
 #	print $resource_id . " \n";
 	my $stj = $dbh->prepare("SELECT comefrom, goto FROM ResourceEntity WHERE RESOURCE_IDENTITY=?")
 		        or die "Couldn't prepare statement: " . $dbh->errstr;
 	$stj->execute($resource_id);
 	# additional resources go to the bottom by default
-print DEBUG "pre/post for: " . $resource_id . "\n";
+#print DEBUG "pre/post for: " . $resource_id . "\n";
 	# add the access counts for the original and extended urls
 	my $sta = $dbh->prepare("SELECT url, ACCESS FROM ResourceEntity WHERE RESOURCE_IDENTITY=?")
 	        or die "Couldn't prepare statement: " . $dbh->errstr;
@@ -516,20 +525,6 @@
 	setFinishedExtend($table,$userda[0],$userda[1]);
 }
 
-## saves the statistics about the search and the user satisfaction into the DB
-#sub saveReport() {
-#	my $user = $user_id; 		# the user performing the search
-#	my $satisfaction = $_[0]; 	# 1-5
-#	my $comment = $_[1]; 		# text comment by the user
-#	my $searchaction = $_[2];	# the action (search by filter / extend) that led to that report
-#	# get the last reports id, increase and save a new report
-#	
-#	
-#	my $sth = $dbh->prepare("SELECT ACCESS, title, goto, comefrom, courses, RESOURCE_IDENTITY FROM ResourceEntity WHERE url=?")
-#	        or die "Couldn't prepare statement: " . $dbh->errstr;
-#	$sth->execute($before);	
-#}
-
 # handles one url that is added by the extension of the original url
 sub handleExtendUrl() {
 	my $before = $_[0];
@@ -567,8 +562,7 @@
 	my $sth = $dbh->prepare($sql)
 		        or die "Couldn't prepare statement: " . $dbh->errstr;
 	$sth->execute($url);	
-	print DEBUG $sth->err;
-	print DEBUG $sth->errstr;
+	print DEBUG "saveExtend(): " . $sth->err . $sth->errstr;
 	my $already_present = $sth->fetchrow_array();
 #	print DEBUG "result: " . $already_present ."\n";
 	unless ($already_present) {
@@ -576,8 +570,6 @@
 		my $returned_fields = &createResultRow($url, 'extension', 0); # TODO put them into proper position
 	    # Store the result in the mysql database
 	    my $result = &Apache::lonmysql::store_row($table,\%$returned_fields);
-	#   $r->print("<br>one result stored<br>");
-#	    $r->rflush();
 	    if (! defined($result)) {
 	  		$r->print(&Apache::lonmysql::get_error());
 	    } 	
@@ -590,7 +582,7 @@
 # (one might argue they're all of the same importance)
 # only sortable by author-names and access count for now
 sub filterByAuthorCommunity() {
-	print "author community for: " . $user_id . "\n";
+#	print "author community for: " . $user_id . "\n";
 	$coordinators_hash{$user_id} = 'included'; # should this be excluded?
 	my $sql = "";
 	if ($algorithm eq 'wac') {
@@ -610,9 +602,7 @@
 }
 
 sub doSort() {
-	if ($sort eq '') {
-		# dont sort.
-	} elsif ($sort eq 'sortbyreuse') {
+	if ($sort eq 'sortbyreuse') {
 		sortResultsByReuse();
 	} elsif ($sort eq 'sortbyauthor') {
 		sortResultsByAuthor();
@@ -620,15 +610,17 @@
 		sortByAccessCount();
 	} elsif ($sort eq 'sortbysimilarity') {
 		sortBySimilarity();
-	} 	
+	} elsif ($sort eq ''){
+		
+	}	
 }
 
 sub sortBySimilarity() {
 	print DEBUG "sorting by similarity \n";
 	# top ones are the ones used by coordinators with highest similarity
 	@result_list = sort { print DEBUG $simdata{$b} . "  " . $simdata{$b} . "\n"; $simdata{$a} <=> $simdata{$a} } keys %simdata;
-	print DEBUG "sorted list: \n";
-	print DEBUG "@result_list\n";
+#	print DEBUG "sorted list: \n";
+#	print DEBUG "@result_list\n";
 }
 
 # extracts the author name and domain name:domain from an url
@@ -707,10 +699,6 @@
 	for (my $i=1 ; $i<@keywords ; $i++) { 
 		$sql_query = $sql_query . " AND keywords LIKE ?";
 	}
-	# print "query: $sql_query \n";
-	# print "used with keywords: @keywords \n";
-	
-	# technical explanation: prepare returns a statement handle object
 	my $sth = $dbh->prepare($sql_query)
 	                or die "Couldn't prepare statement: " . $dbh->errstr;
 	$sth->execute(@keywords);    # TODO match this with the user filtered resources
@@ -723,8 +711,6 @@
 		$course_data{$url} = $resource_by_keyword[7];
 		push(@keyword_resources, $url); # push url to the keyword res
 		$keyword_resources_hash{$url} = 'yep';
-#	if ($url =~ m/^\/res\/lakefenton/) {
-#			print "adding resource id for: " . $url . "\n";
 		$resource_id{$url} = $resource_by_keyword[0];
 	}
 	my @num_keyword_res = keys %keyword_resources_hash;
Index: modules/hoeppner/lonsearchcat.pm
diff -u modules/hoeppner/lonsearchcat.pm:1.3 modules/hoeppner/lonsearchcat.pm:1.4
--- modules/hoeppner/lonsearchcat.pm:1.3	Sun Jun 29 18:50:29 2008
+++ modules/hoeppner/lonsearchcat.pm	Tue Jul  1 08:54:16 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.3 2008/06/29 22:50:29 www Exp $
+# $Id: lonsearchcat.pm,v 1.4 2008/07/01 12:54:16 hoeppner Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -384,7 +384,7 @@
     	# need to give the keywords as parameter for all extends..where do i get them TODO
     	
     	
-    	&Apache::lonsearch::createEvaluationRow('startuser', $env{'form.basicexp'}, 'a', 'd', 'c', 's', 'r','direct', $env{'user.name'}.':'.$env{'user.domain'});  	   	
+    	&Apache::lonsearch::createEvaluationRow('startuser', $env{'form.basicexp'}, 'sortfield', $env{'form.sortfield'}, 'c', 's', 'r','direct', $env{'user.name'}.':'.$env{'user.domain'});  	   	
 		&Apache::lonsearch::expandPrePost($env{'form.url_id'}, $table, $r, $env{'user.name'}.':'.$env{'user.domain'});
 		# then display again
 	#	print INFO "phase extenddirect: " .$env{'form.user'} . " " . $env{'form.domain'} . "\n";
@@ -397,7 +397,7 @@
     #	print INFO 'calling expand sac with table: ' .$table ."\n";
     #	print INFO 'keywords ' . $env{'form.basicexp'}."\n";
    # 	print INFO 'createrow with ' . $env{'user.name'}.':'.$env{'user.domain'} ."\n";
-    	&Apache::lonsearch::createEvaluationRow('startuser', $env{'form.basicexp'}, 'a', 'd', 'c', 's', 'r','sac',$env{'user.name'}.':'.$env{'user.domain'});
+    	&Apache::lonsearch::createEvaluationRow('startuser', $env{'form.basicexp'}, 'sortfield', $env{'form.sortfield'}, 'c', 's', 'r','sac',$env{'user.name'}.':'.$env{'user.domain'});
 		my $startuser;
 	#	print INFO "++++++####++++++username: " . $env{'form.username'} ."\n";
 		if ($env{'form.username'} ne '') { # if no explicit start user mentioned, assume the logged in user
@@ -424,7 +424,7 @@
     	my $keywords = &Apache::lonsearch::getKeywords($env{'user.name'}.':'.$env{'user.domain'});
    # 	print INFO "# # # # # # key: $keywords\n";
    # 	print INFO 'createrow with ' . $env{'user.name'}.':'.$env{'user.domain'} ."\n";
-    	&Apache::lonsearch::createEvaluationRow('startuser', $keywords, 'a', 'd', 'c', 's', 'r','wac',$env{'user.name'}.':'.$env{'user.domain'});
+    	&Apache::lonsearch::createEvaluationRow('startuser', $keywords, 'sortfield', $env{'form.sortfield'}, 'c', 's', 'r','wac',$env{'user.name'}.':'.$env{'user.domain'});
 		my $startuser;
 #		print INFO "++++++####++++++username: " . $env{'form.username'} ."\n";
 		if ($env{'form.username'} ne '') { # if no explicit start user mentioned, assume the logged in user
@@ -549,57 +549,6 @@
     return OK;
 } 
 
-#sub saveRating() {  
-#	my $rating = $_[0];
-#	my $comment = $_[1];
-#	my $user = $_[2];
-#	# 1) get the highest id for that user
-#	my $sta = $dbh->prepare("SELECT max(id) from communities.Evaluation WHERE user=?")
-#	        or die "Couldn't prepare statement: " . $dbh->errstr;
-#	$sta->execute($user);
-#	print INFO $sta->errstr ."\n";
-#	my $id = $sta->fetchrow_array());		
-#	# 2) update row with that id
-#	my $stb = $dbh->prepare("UPDATE communities.Evaluation SET rating=?, comment=?, WHERE id=?")
-#	        or die "Couldn't prepare statement: " . $dbh->errstr;
-#	$stb->execute($rating, $comment, $id);
-#	print INFO $stb->errstr ."\n";
-#}
-#
-#sub createEvaluationRow() {
-#	my $user = $_[0]; # is that the start user or the issuing user?
-#						# for filter: it's the start user ... another param for the issuing one..
-#						
-#	# for a filter search...otherwise they're ''
-#	my $keywords = $_[1];
-#	my $algorithm = $_[2];
-#	my $degree = $_[3];
-#	my $connectivity = $_[4];
-#	my $similarity = $_[5];
-#	my $reuseinstances = $_[6];
-#	# for expand
-#	my $expand = $_[7]; # direct or sac
-#	my $issuing_user = $_[8];
-#	# create the columns ...
-#	my $search_type = '';
-#	if ($expand eq '') {
-#		$search_type .= "search;$user;$keywords;$algorithm;$degree;$connectivity;$similarity;$reuseinstances";
-#	} else {
-#		$search_type .= "expand;$expand";
-#	}
-#	my $rating = 0;
-#	my $comment = 'none';
-#	# create the row
-#	my $insert = "INSERT INTO communities.Evaluation VALUES (?, ?, ?, ?)";
-#				my $stj = $dbh->prepare($insert)
-#						        or die "Couldn't prepare statement: " . $dbh->errstr;
-#				my @params = ($issuing_user, $search_type, $rating, $comment);
-#				$stj->execute(@params);
-#				print INFO $stj->err;
-#				print INFO $stj->errstr;
-#				print INFO " created eval row\n";	
-#}
-
 #
 # The mechanism used to store values away and retrieve them does not
 # handle the case of missing environment variables being significant.
@@ -3130,7 +3079,7 @@
          {key =>'author' },
          {key =>'url',desc=>'URL'},
          {key =>'keywords'},
-         {key =>'stdno',desc=>'relevance (only for Used Authors, Related Coordinators)'},
+         {key =>'stdno',desc=>'relevance (only for algorithms 1 and 2)'},
         );
     my %fieldnames = &Apache::lonmeta::fieldnames();
     my @field_order;
@@ -3156,12 +3105,15 @@
         }
     }
     if (! exists($env{'form.sortorder'})) {
-	if ($env{'form.sortfield'}=~/^(count|stdno|disc|clear|technical|correct|helpful)$/) {
-	    $env{'form.sortorder'}='desc';
-	} else {
-	    $env{'form.sortorder'}='asc';
-	}
+		if ($env{'form.sortfield'}=~/^(count|stdno|disc|clear|technical|correct|helpful)$/) {
+		    $env{'form.sortorder'}='desc';
+		} else {
+		    $env{'form.sortorder'}='asc';
+		}
     }
+	if ($env{'form.sortfield'} eq 'stdno') {
+		   $env{'form.sortorder'}='desc';
+	}    
     print INFO "		sort display: " . $env{'form.sortfield'} . "\n"; # . " no, instead: " . $mysort;
     my $sortform = &mt('Sort by [_1] [_2]',
                        &Apache::loncommon::select_form($env{'form.sortfield'},
@@ -3173,19 +3125,17 @@
                                                        desc=>&mt('Descending')
                                                        ))
                        );
-                       print INFO $sortform . "\n";
+#                       print INFO $sortform . "\n";
     ##
     ## Output links (if necessary) for 'prev' and 'next' pages.
     $r->print
         ('<table width="100%"><tr><td width="25%" align="right">'.
          '<nobr>'.$sortform.'</nobr>'.
          '<input type="hidden" name="catalogmode" value="import"/>'.
-#         '<input type="hidden" name="sortfield" value="'.$env{'form.sortfield'}.'"/>'.
          '</td><td width="25%" align="right">'.
          &prev_next_buttons($min,$env{'form.show'},$total_results).
          '</td><td align="right">'.
-         &viewoptions().'</td></tr></table>'.
-         '?????????????????????'
+         &viewoptions().'</td></tr></table>'
          );
     if ($total_results == 0) { #  && ($env{'finished' eq 'false'})
    # 	if ($env{'finished' eq 'false'}) {
@@ -3214,6 +3164,9 @@
         } else {
             $order = '';
         }
+        if ($env{'form.algorithm'} eq 'usedauthors' || $env{'form.algorithm'} eq 'relatedcoordinators') {
+        	$order = 'DESC';
+        }
     } else {
         $order = '';
     }
@@ -3224,11 +3177,12 @@
 		my $userhandle = $env{'user.name'}.":".$env{'user.domain'};
 		my $lastsort = &Apache::lonsearch::getLastSort($userhandle);
 		print INFO "%%%%%% lastsort/ current: " . $lastsort. " ". $env{'form.sortfield'} ."\n";
-#		if ($lastsort ne 'unkown') {
-#	        my $algodata = &Apache::lonsearch::getEvalType($userhandle);
-#	        print INFO "+F%%%%%% action: " . $algodata ."\n";
-#	        &Apache::lonsearch::createEvaluationRow_Copy($algodata, $env{'form.sortfield'}, $userhandle);
-#		}
+		if ($lastsort ne 'unkown' && $lastsort ne $env{'form.sortfield'}) { # todo bedingung?
+	        my @algodata = &Apache::lonsearch::getEvalType($userhandle);
+	        my $temp = $env{'form.sortfield'};
+	        print INFO "   %%%% changed sort from: $lastsort to $temp: @algodata \n";
+	        &Apache::lonsearch::createEvaluationRow_Copy($algodata[0], $env{'form.sortfield'}, $userhandle,$algodata[1],$algodata[2]);
+		}
         &Apache::lonsearch::saveSort($env{'form.sortfield'}, $userhandle); # ok
         $sort_command = $env{'form.sortfield'}.' IS NOT NULL '.
             'ORDER BY '.$env{'form.sortfield'}.' '.$order.
@@ -3566,7 +3520,7 @@
     }
 </script>
 SCRIPT
-	print INFO "table is here....: " . $env{'form.table'} ."\n";
+#	print INFO "table is here....: " . $env{'form.table'} ."\n";
     my $start_page  = &Apache::loncommon::start_page(undef,$js,
 						     {'only_body' =>1},$status);
     my $result=<<END;
@@ -3577,6 +3531,8 @@
 <input type="hidden" name="table" value="$env{'form.table'}" />
 <input type="hidden" name="username" value="$env{'form.username'}" />
 <input type="hidden" name="catalogmode" value="import" />
+<input type="hidden" name="sortorder" value="$env{'form.sortorder'}" />
+<input type="hidden" name="sortfield" value="$env{'form.sortfield'}" />
 <table>
 <tr>
 <td>
@@ -3587,7 +3543,7 @@
 <label> <input type="radio" name="rating" value="5"> 5 (good)</label>
 </td>
 <td>
-<label> your comment: <input type="text" size ="50" maxlength="2000" name="comment" value="" /> (max. 2000 characters)</label>
+<label> ;      your comment: <input type="text" size ="50" maxlength="2000" name="comment" value="" /> (max. 2000 characters)</label>
 <INPUT type="submit" value="Send">
 </td>
 </tr>
@@ -3854,9 +3810,9 @@
    target='preview'>$values{'title'}</a> <br />
 $link 
 
-<font size="-1" <a href="/adm/searchcat?&phase=extenddirect&url_id=$values{'goto'}&persistent_db_id=$env{'form.persistent_db_id'}&table=$env{'form.table'}&username=$username" onClick="javascript:document.bgColor='#AAAAAA';document.write('working... please stand by');">     ... Extend by direct relation </a> <br> 
-                      <a href="/adm/searchcat?&phase=extendsac&url_id=$values{'goto'}&persistent_db_id=$env{'form.persistent_db_id'}&table=$env{'form.table'}&username=$username"  onClick="javascript:document.bgColor='#AAAAAA';document.write('working... please stand by');">     ... Extend by course and SAC </a> <br>
-                      <a href="/adm/searchcat?&phase=extendwac&url_id=$values{'goto'}&persistent_db_id=$env{'form.persistent_db_id'}&table=$env{'form.table'}&username=$username"  onClick="javascript:document.bgColor='#AAAAAA';document.write('working... please stand by');">     ... Extend by course and WAC </a> <br>
+<font size="-1" <a href="/adm/searchcat?&phase=extenddirect&url_id=$values{'goto'}&persistent_db_id=$env{'form.persistent_db_id'}&table=$env{'form.table'}&username=$username&sortfield=$env{'form.sortfield'}&sortorder=$env{'form.sortorder'}" onClick="javascript:document.bgColor='#AAAAAA';document.write('working... please stand by');">     ... Extend by direct relation </a> <br> 
+                      <a href="/adm/searchcat?&phase=extendsac&url_id=$values{'goto'}&persistent_db_id=$env{'form.persistent_db_id'}&table=$env{'form.table'}&username=$username&sortfield=$env{'form.sortfield'}&sortorder=$env{'form.sortorder'}"  onClick="javascript:document.bgColor='#AAAAAA';document.write('working... please stand by');">     ... Extend by course and SAC </a> <br>
+                      <a href="/adm/searchcat?&phase=extendwac&url_id=$values{'goto'}&persistent_db_id=$env{'form.persistent_db_id'}&table=$env{'form.table'}&username=$username&sortfield=$env{'form.sortfield'}&sortorder=$env{'form.sortorder'}"  onClick="javascript:document.bgColor='#AAAAAA';document.write('working... please stand by');">     ... Extend by course and WAC </a> <br>
                       </font> <br>
                       <br /> >
 $values{'author'}<br />
@@ -4246,3 +4202,5 @@
 =back 
 
 =cut
+
+1;

--hoeppner1214916858--