Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / List.class.php
blobb531059c8d5d18a8771f61b11f045efd6eec6bc4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * hold the PMA_List base class
6 * @version $Id$
7 */
9 /**
10 * @todo add caching
11 * @since phpMyAdmin 2.9.10
12 * @abstract
14 /* abstract public */ class PMA_List
16 /**
17 * @var array the list items
18 * @access public
20 var $items = array();
22 /**
23 * @var array details for list items
24 * @access public
26 var $details = array();
28 /**
29 * @var bool whether we need to re-index the database list for consistency keys
30 * @access protected
32 var $_need_to_reindex = false;
34 /**
35 * @var mixed empty item
37 var $item_empty = '';
39 /**
40 * returns first item from list
42 * @uses PMA_List::$items to get first item
43 * @uses reset() to retrive first item from PMA_List::$items array
44 * @return string value of first item
46 function getFirst()
48 return reset($this->items);
51 /**
52 * returns item only if there is only one in the list
54 * @uses PMA_List::count() to decide what to return
55 * @uses PMA_List::getFirst() to return it
56 * @uses PMA_List::getEmpty() to return it
57 * @return single item
59 function getSingleItem()
61 if ($this->count() === 1) {
62 return $this->getFirst();
65 return $this->getEmpty();
68 /**
69 * returns list item count
71 * @uses PMA_List::$items to count it items
72 * @uses count() to count items in PMA_List::$items
73 * @return integer PMA_List::$items count
75 function count()
77 return count($this->items);
80 /**
81 * defines what is an empty item (0, '', false or null)
83 * @uses PMA_List::$item_empty as return value
84 * @return mixed an empty item
86 function getEmpty()
88 return $this->item_empty;
91 /**
92 * checks if the given db names exists in the current list, if there is
93 * missing at least one item it reutrns false other wise true
95 * @uses PMA_List::$items to check for existence of specific item
96 * @uses func_get_args()
97 * @uses in_array() to check if given arguments exists in PMA_List::$items
98 * @param string $db_name,.. one or more mysql result resources
99 * @return boolean true if all items exists, otheriwse false
101 function exists()
103 foreach (func_get_args() as $result) {
104 if (! in_array($result, $this->items)) {
105 return false;
109 return true;
113 * returns HTML <option>-tags to be used inside <select></select>
115 * @uses PMA_List::$items to build up the option items
116 * @uses PMA_List::getDefault() to mark this as selected if requested
117 * @uses htmlspecialchars() to escape items
118 * @param mixed $selected the selected db or true for selecting current db
119 * @param boolean $include_information_schema
120 * @return string HTML option tags
122 function getHtmlOptions($selected = '', $include_information_schema = true)
124 if (true === $selected) {
125 $selected = $this->getDefault();
128 $options = '';
129 foreach ($this->items as $each_db) {
130 if (false === $include_information_schema && 'information_schema' === $each_db) {
131 continue;
133 $options .= '<option value="' . htmlspecialchars($each_db) . '"';
134 if ($selected === $each_db) {
135 $options .= ' selected="selected"';
137 $options .= '>' . htmlspecialchars($each_db) . '</option>' . "\n";
140 return $options;
144 * returns default item
146 * @uses PMA_List::getEmpty() as fallback
147 * @return string default item
149 function getDefault()
151 return $this->getEmpty();
155 * builds up the list
157 * @abstract
159 /* abstract public */ function build() {}