Index: core/units/configuration/configuration_event_handler.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/units/configuration/configuration_event_handler.php (revision 15716) +++ core/units/configuration/configuration_event_handler.php (revision ) @@ -470,51 +470,42 @@ } /** - * Returns auto-complete values for ajax-dropdown + * Prepares a suggestion list based on a given term. * * @param kEvent $event * @return void * @access protected */ - protected function OnSuggestValues(kEvent $event) + protected function getAutoCompleteSuggestions(kEvent $event, $term) { - if ( !$this->Application->isAdminUser ) { - // very careful here, because this event allows to - // view every object field -> limit only to logged-in admins - return; - } - - $event->status = kEvent::erSTOP; - - $field = $this->Application->GetVar('field'); - $cur_value = $this->Application->GetVar('cur_value'); - $object = $event->getObject(); /* @var $object kDBItem */ - if ( !$field || !$cur_value || !$object->isField($field) ) { - return; + $field = $this->Application->GetVar('field'); + + if ( !$field || !$term || !$object->isField($field) ) { + return array(); } $limit = $this->Application->GetVar('limit'); + if ( !$limit ) { $limit = 20; } $sql = 'SELECT DISTINCT ' . $field . ', ModuleOwner FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' - WHERE ' . $field . ' LIKE ' . $this->Conn->qstr('%' . $cur_value . '%') . ' + WHERE ' . $field . ' LIKE ' . $this->Conn->qstr('%' . $term . '%') . ' ORDER BY ' . $field . ' ASC'; - $raw_suggestions = $this->Conn->Query($sql); + $data = $this->Conn->Query($sql); - $suggestions = Array (); - $this->Application->XMLHeader(); + $suggestions = array(); - foreach ($raw_suggestions as $raw_suggestion) { + foreach ($data as $raw_suggestion) { $suggestion = $raw_suggestion[$field]; if ( !isset($suggestions[$suggestion]) ) { - $suggestions[$suggestion] = Array (); + $suggestions[$suggestion] = array(); } $suggestions[$suggestion][] = $raw_suggestion['ModuleOwner']; @@ -522,24 +513,26 @@ array_splice($suggestions, $limit); - echo ''; + $ret = array(); $of_label = $this->Application->Phrase('la_From', false); foreach ($suggestions as $suggestion_value => $suggestion_modules) { $suggestion_module = in_array('In-Portal', $suggestion_modules) ? 'In-Portal' : implode(', ', $suggestion_modules); $suggestion_title = $suggestion_value . ' ' . $of_label . ' ' . $suggestion_module . ''; - echo '' . htmlspecialchars($suggestion_title, null, CHARSET) . ''; + $ret[$suggestion_value] = $suggestion_title; } - echo ''; + return $ret; } /** * Prefills module dropdown * - * @param kEvent $event - * @return void + * @param kEvent $event Event. + * @param string $term Term. + * + * @return Array * @access protected */ protected function OnAfterConfigRead(kEvent $event) \ No newline at end of file Index: core/kernel/globals.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/kernel/globals.php (revision 15733) +++ core/kernel/globals.php (revision ) @@ -21,6 +21,19 @@ const POUND_TO_KG = 0.45359237; /** + * Checks, that given array is associative. + * + * @param array $array Array. + * + * @return bool + * @access public + */ + public static function isAssoc($array) + { + return array_keys($array) !== range(0, count($array) - 1); + } + + /** * Similar to array_merge_recursive but keyed-valued are always overwritten. * Priority goes to the 2nd array. * \ No newline at end of file Index: core/kernel/db/db_event_handler.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/kernel/db/db_event_handler.php (revision 15733) +++ core/kernel/db/db_event_handler.php (revision ) @@ -83,10 +83,6 @@ $this->Application->LinkVar('m_cat_id'); } - if ( $event->Name == 'OnSaveWidths' ) { - return $this->Application->isAdminUser; - } - return parent::CheckPermission($event); } @@ -104,7 +100,8 @@ $permissions = Array ( 'OnLoad' => Array ('self' => 'view', 'subitem' => 'view'), 'OnItemBuild' => Array ('self' => 'view', 'subitem' => 'view'), - 'OnSuggestValues' => Array ('self' => 'view', 'subitem' => 'view'), + 'OnSuggestValues' => Array ('self' => 'admin', 'subitem' => 'admin'), + 'OnSuggestValuesJSON' => Array ('self' => 'admin', 'subitem' => 'admin'), 'OnBuild' => Array ('self' => true), @@ -168,7 +165,7 @@ 'OnDeleteFile' => Array ('self' => true, 'subitem' => true), 'OnViewFile' => Array ('self' => true, 'subitem' => true), - 'OnSaveWidths' => Array ('self' => true, 'subitem' => true), + 'OnSaveWidths' => Array ('self' => 'admin', 'subitem' => 'admin'), 'OnValidateMInputFields' => Array ('self' => 'view'), 'OnValidateField' => Array ('self' => true, 'subitem' => true), @@ -3463,45 +3460,76 @@ */ protected function OnSuggestValues(kEvent $event) { - if ( !$this->Application->isAdminUser ) { - // very careful here, because this event allows to - // view every object field -> limit only to logged-in admins - return; + $event->status = kEvent::erSTOP; + + $this->Application->XMLHeader(); + $data = $this->getAutoCompleteSuggestions($event, $this->Application->GetVar('cur_value')); + + echo ''; + + if ( kUtil::isAssoc($data) ) { + foreach ($data as $key => $title) { + echo '' . htmlspecialchars($title, null, CHARSET) . ''; - } + } + } + else { + foreach ($data as $title) { + echo '' . htmlspecialchars($title, null, CHARSET) . ''; + } + } + echo ''; + } + + /** + * Returns auto-complete values for jQueryUI.AutoComplete + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnSuggestValuesJSON(kEvent $event) + { $event->status = kEvent::erSTOP; - $field = $this->Application->GetVar('field'); - $cur_value = $this->Application->GetVar('cur_value'); - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); + $data = $this->getAutoCompleteSuggestions($event, $this->Application->GetVar('term')); + echo json_encode($data); + } + + /** + * Prepares a suggestion list based on a given term. + * + * @param kEvent $event Event. + * @param string $term Term. + * + * @return Array + * @access protected + */ + protected function getAutoCompleteSuggestions(kEvent $event, $term) + { $object = $event->getObject(); + /* @var $object kDBItem */ - if ( !$field || !$cur_value || !$object->isField($field) ) { - return; + $field = $this->Application->GetVar('field'); + + if ( !$field || !$term || !$object->isField($field) ) { + return array(); } $limit = $this->Application->GetVar('limit'); + if ( !$limit ) { $limit = 20; } $sql = 'SELECT DISTINCT ' . $field . ' FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' - WHERE ' . $field . ' LIKE ' . $this->Conn->qstr($cur_value . '%') . ' + WHERE ' . $field . ' LIKE ' . $this->Conn->qstr($term . '%') . ' ORDER BY ' . $field . ' LIMIT 0,' . $limit; - $data = $this->Conn->GetCol($sql); - $this->Application->XMLHeader(); - - echo ''; - - foreach ($data as $item) { - echo '' . htmlspecialchars($item, null, CHARSET) . ''; - } - - echo ''; + return $this->Conn->GetCol($sql); } /** \ No newline at end of file