Name()); ?>
Id()] = $Group; } # This array is indexed by parent_id $children = array(); foreach ( $Groups as $id=>$Group ) { if ( $Group->ParentId() != null ) { if ( ! isset( $children[$Group->ParentId()] ) ) $children[$Group->ParentId()] = array(); $children[$Group->ParentId()][] = $Group; } } function get_Id( $G ) { return $G->Id(); } function get_children($Group) { global $children; $kids = array(); if ( isset( $children[$Group->Id()] ) ) { $kids += array_map('get_Id', $children[$Group->Id()]); foreach ( $children[$Group->Id()] as $G ) { foreach ( get_children($G) as $id ) { $kids[] = $id; } } } return $kids; } $kids = get_children($newGroup); if ( $newGroup->Id() ) $kids[] = $newGroup->Id(); $sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids)).')' : '').' ORDER BY Name'; $options = array(''=>'None'); foreach ( dbFetchAll($sql, null, $kids) as $option ) { $options[$option['Id']] = str_repeat('  ', $Groups[$option['Id']]->depth()) . $option['Name']; } echo htmlSelect('newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);')); ?>