[#6569] Restrict Comment To: groups lose group id when rendered
Summary Restrict Comment To: groups lose group id when rendered
Queue Whups
Type Bug
State Resolved
Priority 1. Low
Owners Chuck Hagenbuch <chuck (at) horde (dot) org>
Requester php (at) ideacode (dot) com
Created 04/04/2008 (95 days ago)
Due
Updated 04/23/2008 (76 days ago)
Assigned
Resolved 04/23/2008 (76 days ago)
Attachments issue.diff Download
Milestone
Patch No

History
04/23/2008 Chuck Hagenbuch Comment #2
State ⇒ Resolved
Assigned to Chuck Hagenbuch
Reply to this comment
Committed, thanks.
04/04/2008 php (at) ideacode (dot) com Comment #1
New Attachment: issue.diff Download
Patch ⇒
Milestone ⇒
Queue ⇒ Whups
Summary ⇒ Restrict Comment To: groups lose group id when rendered
Type ⇒ Bug
Priority ⇒ 1. Low
State ⇒ Unconfirmed
Reply to this comment
In lib/Forms/EditTicket.php, the comment restriction code goes like 
this (I've annotated, as the code isn't commented):
// get all the groups I can access in array (group_id => label, ...) format
foreach (array_keys($mygroups) as $gid) {
     $grouplist[$gid] = $groups->getGroupName($gid, true);
}
// sort those by name
asort($grouplist);
// tack "Any Group" onto the front
$grouplist = array_merge(array(0 => _("Any Group")), $grouplist);
// push into the form
$this->addVariable(_("Restrict Comment to:"), 'group', 'enum', true, 
false, null, array($grouplist));

The intent of this code seems to be to create the drop-down for 
restricting comments using the group ID (from the data tree) as the 
option value and the group Name (also from the data tree) as the 
option label.

However, array_merge() screws that up, because PHP 5 & PHP 4 re-index 
the array, destroying the key association needed:
[bishop@predator staging]$ cat array_merge.php
<?php
$a = array (23 => 'Hello', '42' => 'World');
$a = array_merge(array (0 => 'I say, '), $a);
var_dump($a);
?>
[bishop@predator staging]$ php-5.2.5 array_merge.php
array(3) {
   [0]=>
   string(7) "I say, "
   [1]=>
   string(5) "Hello"
   [2]=>
   string(5) "World"
}
[bishop@predator staging]$ php-4.4.7 array_merge.php
array(3) {
   [0]=>
   string(7) "I say, "
   [1]=>
   string(5) "Hello"
   [2]=>
   string(5) "World"
}

My suggested patch (attached) is to replace array_merge() with the 
plus operator.