Index: og_teampage.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_teampage/og_teampage.module,v
retrieving revision 1.33
diff -u -F^f -r1.33 og_teampage.module
--- og_teampage.module	6 Jul 2007 12:58:05 -0000	1.33
+++ og_teampage.module	9 Jul 2007 14:51:08 -0000
@@ -55,76 +55,64 @@ function og_teampage_nodeapi(&$node, $op
 			$res = db_query("SELECT * FROM {og_teampage_members}
 				WHERE uid='0' AND gid='".$node->nid."' AND hidden='3'");
 			if (db_num_rows($res) > 0) {
+				$row = db_fetch_object($res);
 				$node->content['og_mission']['#value'] =
 				substr($node->content['og_mission']['#value'],0,
 				strlen($node->content['og_mission']['#value'])-6);
 				$node->content['og_mission']['#value'] =
-				$node->content['og_mission']['#value'].og_teampage_teamtable($node->nid)."</div>";
+				$node->content['og_mission']['#value'].og_teampage_teamtable($node->nid, $row->weight)."</div>";
 			}
 		}
 	}
 }
 
-function sort_members_array($a, $b) {
-	if ($a[data]->weight == $b[data]->weight) return 0;
-	return ($a[data]->weight > $b[data]->weight) ? 1 : -1;
-}
-
-function og_teampage_teamtable($gid) {
-	$res = db_query("SELECT * FROM {og_teampage_members} WHERE uid='0' AND gid='".$gid."'");
-	$test = db_fetch_object($res);
-	$use_userimage = 0;
-	if ($test->weight == '1') $use_userimage = 1;
-	
-	$table = '<div class="clear-block"><br /></div><div class="teammembers-list">';
- 	$table .= '<table width="100%">';
+function og_teampage_teamtable($gid, $use_userimage) {
 	$min_is_active = 1;
 	$min_is_admin = 0;
 	
-	$sql = "SELECT u.uid, u.name, u.picture, ou.* FROM {og_uid} ou INNER JOIN {users} u ON ou.uid = u.uid WHERE ou.nid = %b AND u.status > 0 AND is_active >= $min_is_active AND is_admin >= $min_is_admin ORDER BY u.name ASC";
+	$sql = "SELECT u.uid, u.name as user_name, u.picture as user_picture, tm.picture1 as member_picture, tm.name as member_name, tm.description as member_description FROM {og_uid} ou INNER JOIN {users} u ON ou.uid = u.uid INNER JOIN {og_teampage_members} tm ON ou.uid = tm.uid WHERE ou.nid = %b AND u.status > 0 AND is_active >= $min_is_active AND is_admin >= $min_is_admin AND tm.hidden != 1 ORDER BY tm.weight ASC";
 	$result = db_query($sql, $gid);
-    $i=0;
-    while ($account = db_fetch_object($result)) {
-        $rows[$i][username] = $account->name;
-		$rows[$i][uid] = $account->uid;
-		$rows[$i][picture] = $account->picture;
-		$res = db_query("SELECT * FROM {og_teampage_members} WHERE uid='".$account->uid."' AND gid='".$gid."'");
-		if (db_num_rows($res) < 1) {
-			$res = db_query("SELECT * FROM {og_teampage_members} WHERE uid='".$account->uid."' AND gid='0'");
-		}
-		$rows[$i][data] = db_fetch_object($res);
-        $i++;
-    }
+
+	$rows = array();
+	
+  while ($account = db_fetch_object($result)) {
+		$rows[] = $account;
+  }
+	
+	return theme('og_teampage_table', $rows, $use_userimage);
+}
+
+function theme_og_teampage_table($rows, $use_userimage) {
 	$trows = array();
 	$rowcounter = 1;
 	$colcounter = 0;
 	$colcount = variable_get('og_teampage_colcount',5);
-	$colwidth = 100/variable_get('og_teampage_colcount',5);
-	$colwidth = round($colwidth);
+	$colwidth = round(100/variable_get('og_teampage_colcount',5));
 	$colwidthstring = $colwidth.'%';
+
+	$output = '<div class="teammembers-list">';
+ 	$output .= '<table width="100%">';
 	
-	usort($rows, sort_members_array);
-	foreach($rows as $row)
-	{
-		if ($row[data]->hidden != '1') {
+	foreach($rows as $row) {			
 			$colcounter++;
 			if ($colcounter > $colcount) {
 				$rowcounter++;
 				$colcounter = 1;
 			} 
-			$picsource = base_path().drupal_get_path('module', 'og_teampage').'/no-pic.png';
-			if ($row[data]->picture1 != '')
-			{
-				$picsource = $row[data]->picture1;
+			
+			// theme member picture
+			if ($row->member_picture != '') {
+				$picsource = $row->member_picture;
 				$picsource = str_replace("system/files/", "", $picsource);
 				$picsource = file_create_url($picsource);
-			} else if (($row[picture] != '') && ($use_userimage == 1) && (file_exists($row[picture]))) $picsource = file_create_url($row[picture]);
-			if ($row[data]->name != '')
-			{
-				$name = $row[data]->name;
-			} else $name = $row[username];
-
-			$description = $row[data]->description;
+			}
+			else if (($row->user_picture != '') && ($use_userimage == 1) && (file_exists($row->user_picture))) {
+				$picsource = file_create_url($row->user_picture);
+			}
+			else {
+				$picsource = base_path().drupal_get_path('module', 'og_teampage').'/no-pic.png';
+			}
+			
 			$width = variable_get('og_teampage_imagewidth','');
 			$height = variable_get('og_teampage_imageheight','');
 			$width_attr = '';
@@ -132,42 +120,55 @@ function og_teampage_teamtable($gid) {
 			if ($width != '') $width_attr = 'width="'.$width.'" ';
 			if ($height != '') $height_attr = 'height="'.$height.'" ';
 			
-			$attr=array();
-			$attr['target'] = '_blank';
-			$piclink = l('<img src="'.$picsource.'" '.$width_attr.$height_attr.'alt="user-image">','user/'.$row[uid], $attr, NULL, NULL, FALSE, TRUE);
+			$attr = array('target' => '_blank');
+			$piclink = l('<img src="'.$picsource.'" '.$width_attr.$height_attr.'alt="user-image">','user/'.$row->uid, $attr, NULL, NULL, FALSE, TRUE);
+						
+			// theme member name
+			if ($row->member_name != '') {
+				$name = $row->member_name;
+			}
+			else {
+				$name = $row->user_name;
+			}
 			$textlink = l($name,'user/'.$row[uid], $attr);
+			
+			// theme member description
+			$description = $row[data]->description;
+
+			// theme member record
 			$member = '<table class="teammember"><tr><td align="center">'.$piclink.'</td></tr>';
 			$member .= '<tr><td align="center">'.$textlink.'</td></tr>';
 			if ($description != '') $member .= '<tr><td align="center" class="small">'.$description.'</td></tr>';
 			$member .= '</table>';
 			
 			$cell = '<td align="center" valign="top" width="'.$colwidthstring.'">'.$member.'</td>';
-			$trows[$rowcounter] .= $cell;
-		}
-		
-   }
+			$trows[$rowcounter] .= $cell;		
+  }
+
 	foreach ($trows as $trow) {
 		$trcount++;
 		if (($trcount < $rowcounter) || ($colcounter == $colcount)) {
-			$table .= '<tr>'.$trow.'</tr>';
+			$output .= '<tr>'.$trow.'</tr>';
 		};
 	}
-	$table .= '</table>';
-	if ($colcounter < $colcount)
-	{
-		$table .= '<table width="100%"><tr>';
+
+	$output .= '</table>';
+	
+	if ($colcounter < $colcount) {
+		$output .= '<table width="100%"><tr>';
 		$diff = $colcount - $colcounter;
 		$dummywidth = $colwidth * $diff / 2;
 		$dummywidth = round($dummywidth);
 		$dummywidthstr = $dummywidth.'%';
-		$table .= '<td width="'.$dummywidthstr.'">&nbsp;</td>';
-		$table .= $trows[$rowcounter];
-		$table .= '<td width="'.$dummywidthstr.'">&nbsp;</td>';
-		$table .= '</tr></table>';	
+		$output .= '<td width="'.$dummywidthstr.'">&nbsp;</td>';
+		$output .= $trows[$rowcounter];
+		$output .= '<td width="'.$dummywidthstr.'">&nbsp;</td>';
+		$output .= '</tr></table>';	
 	}
-   	$table .= '</div>';
-   	$table .= '<br class="clear">';
-	return $table;
+  
+  $output .= '</div>';
+   	
+	return $output;
 }
 
 function og_teampage_admin_members($gid) {
