Procházet zdrojové kódy

User Edit: Fix Contact filtering.

Nate před 6 roky
rodič
revize
f271463235
1 změnil soubory, kde provedl 26 přidání a 6 odebrání
  1. 26 6
      core/users/user_edit.php

+ 26 - 6
core/users/user_edit.php

@@ -730,13 +730,33 @@
 		echo "	<tr>";
 		echo "		<td class='vncell' valign='top'>".$text['label-contact']."</td>";
 		echo "		<td class='vtable'>\n";
-		$sql = "select contact_uuid, contact_organization, contact_name_given, contact_name_family, contact_nickname from v_contacts ";
-		$sql .= "where domain_uuid = '".escape($domain_uuid)."' ";
-		$sql .= "and ( ";
-		$sql .= "	contact_uuid = '".escape($contact_uuid)."' or ";
-		$sql .= "	contact_uuid not in (select contact_uuid from v_users where domain_uuid = '".escape($domain_uuid)."') ";
+		$sql = "select ";
+		$sql .= "c.contact_uuid, ";
+		$sql .= "c.contact_organization, ";
+		$sql .= "c.contact_name_given, ";
+		$sql .= "c.contact_name_family, ";
+		$sql .= "c.contact_nickname ";
+		$sql .= "from ";
+		$sql .= "v_contacts as c ";
+		$sql .= "where ";
+		$sql .= "c.domain_uuid = '".escape($domain_uuid)."' ";
+		$sql .= "and not exists ( ";
+		$sql .= "	select ";
+		$sql .= "	contact_uuid ";
+		$sql .= "	from ";
+		$sql .= "	v_users as u ";
+		$sql .= "	where ";
+		$sql .= "	u.domain_uuid = '".escape($domain_uuid)."' ";
+		if (is_uuid($contact_uuid)) { //don't exclude currently assigned contact
+			$sql .= "and u.contact_uuid <> '".escape($contact_uuid)."' ";
+		}
+		$sql .= "	and u.contact_uuid = c.contact_uuid ";
 		$sql .= ") ";
-		$sql .= "order by contact_organization desc, contact_name_family asc, contact_name_given asc, contact_nickname asc ";
+		$sql .= "order by ";
+		$sql .= "lower(c.contact_organization) asc, ";
+		$sql .= "lower(c.contact_name_family) asc, ";
+		$sql .= "lower(c.contact_name_given) asc, ";
+		$sql .= "lower(c.contact_nickname) asc ";
 		$prep_statement = $db->prepare(check_sql($sql));
 		$prep_statement->execute();
 		$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);