|
16 | 16 | $cidReset = true; |
17 | 17 | require_once __DIR__.'/../inc/global.inc.php'; |
18 | 18 | $this_section = SECTION_PLATFORM_ADMIN; |
19 | | - |
20 | | -//api_protect_admin_script(); |
21 | 19 | api_protect_global_admin_script(); |
22 | 20 |
|
23 | 21 | $httpRequest = HttpRequest::createFromGlobals(); |
|
36 | 34 |
|
37 | 35 | switch ($httpRequest->query->get('action')) { |
38 | 36 | case 'delete_url': |
39 | | - $result = UrlManager::delete($url_id); |
40 | | - if ($result) { |
41 | | - echo Display::return_message(get_lang('URL deleted.'), 'normal'); |
42 | | - } else { |
43 | | - echo Display::return_message(get_lang('Cannot delete this URL.'), 'error'); |
44 | | - } |
| 37 | + $ok = UrlManager::delete($url_id); |
| 38 | + echo Display::return_message( |
| 39 | + $ok ? get_lang('URL deleted.') : get_lang('Cannot delete this URL.'), |
| 40 | + $ok ? 'normal' : 'error' |
| 41 | + ); |
45 | 42 |
|
46 | 43 | break; |
47 | 44 | case 'lock': |
|
55 | 52 |
|
56 | 53 | break; |
57 | 54 | case 'register': |
58 | | - // we are going to register the admin |
59 | | - if (api_is_platform_admin()) { |
60 | | - if (-1 != $current_access_url_id) { |
61 | | - $url_str = ''; |
62 | | - foreach ($url_list as $my_url) { |
63 | | - if (!in_array($my_url['id'], $my_user_url_list)) { |
64 | | - UrlManager::add_user_to_url(api_get_user_id(), $my_url['id']); |
65 | | - $url_str .= $my_url['url'].' <br />'; |
66 | | - } |
| 55 | + if (api_is_platform_admin() && -1 != $current_access_url_id) { |
| 56 | + $url_str = ''; |
| 57 | + foreach ($url_list as $u) { |
| 58 | + if (!in_array($u['id'], $my_user_url_list)) { |
| 59 | + UrlManager::add_user_to_url(api_get_user_id(), $u['id']); |
| 60 | + $url_str .= $u['url'] . '<br />'; |
67 | 61 | } |
68 | | - echo Display::return_message( |
69 | | - get_lang('Admin user assigned to this URL').': '.$url_str.'<br />', |
70 | | - 'normal', |
71 | | - false |
72 | | - ); |
73 | 62 | } |
| 63 | + echo Display::return_message( |
| 64 | + get_lang('Admin user assigned to this URL') . ': ' . $url_str, |
| 65 | + 'normal', |
| 66 | + false |
| 67 | + ); |
74 | 68 | } |
75 | 69 |
|
76 | 70 | break; |
|
81 | 75 |
|
82 | 76 | // Checking if the admin is registered in all sites |
83 | 77 | $url_string = ''; |
84 | | -$my_user_url_list = api_get_access_url_from_user(api_get_user_id()); |
85 | | -foreach ($url_list as $my_url) { |
86 | | - if (!in_array($my_url['id'], $my_user_url_list)) { |
87 | | - $url_string .= $my_url['url'].' <br />'; |
| 78 | +foreach ($url_list as $u) { |
| 79 | + if (!in_array($u['id'], $my_user_url_list)) { |
| 80 | + $url_string .= $u['url'] . '<br />'; |
88 | 81 | } |
89 | 82 | } |
90 | 83 | if (!empty($url_string)) { |
91 | 84 | echo Display::return_message( |
92 | | - get_lang('Admin user should be registered here').'<br />'.$url_string, |
| 85 | + get_lang('Admin user should be registered here') . '<br />' . $url_string, |
93 | 86 | 'warning', |
94 | 87 | false |
95 | 88 | ); |
|
98 | 91 | // checking the current installation |
99 | 92 | if (-1 == $current_access_url_id) { |
100 | 93 | echo Display::return_message( |
101 | | - get_lang('URL not configured yet, please add this URL :').': '.api_get_path(WEB_PATH), |
| 94 | + get_lang('URL not configured yet, please add this URL :') . ' ' . api_get_path(WEB_PATH), |
102 | 95 | 'warning' |
103 | 96 | ); |
104 | 97 | } elseif (api_is_platform_admin()) { |
105 | | - $quant = UrlManager::relation_url_user_exist( |
106 | | - api_get_user_id(), |
107 | | - $current_access_url_id |
108 | | - ); |
| 98 | + $quant = UrlManager::relation_url_user_exist(api_get_user_id(), $current_access_url_id); |
109 | 99 | if (0 == $quant) { |
110 | 100 | echo Display::return_message( |
111 | | - '<a href="'.api_get_self().'?action=register&sec_token='.$parameters['sec_token'].'">'. |
112 | | - get_lang('Click here to register the admin into all sites').'</a>', |
| 101 | + '<a href="' . api_get_self() . '?action=register&sec_token=' . $parameters['sec_token'] . '">' . |
| 102 | + get_lang('Click here to register the admin into all sites') . |
| 103 | + '</a>', |
113 | 104 | 'warning', |
114 | 105 | false |
115 | 106 | ); |
116 | 107 | } |
117 | 108 | } |
118 | 109 |
|
| 110 | +// 1) Find the default URL (ID = 1) |
| 111 | +$defaultUrl = 'http://localhost/'; |
| 112 | +foreach ($url_list as $u) { |
| 113 | + if ((string)$u['id'] === '1') { |
| 114 | + $defaultUrl = trim($u['url']); |
| 115 | + break; |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +// 2) Tooltip message (in English, per spec) |
| 120 | +$tooltip = 'Adding new URLs requires you to first set the first URL to a value different than localhost.'; |
| 121 | +$isLocalhost = ($defaultUrl === 'http://localhost/'); |
| 122 | + |
| 123 | +// 3) Decide link href and base attributes |
| 124 | +$attributes = ['id' => 'add-url-button']; |
| 125 | +if ($isLocalhost) { |
| 126 | + // Block the link and apply a “disabled” style |
| 127 | + $attributes['class'] = 'ch-disabled'; |
| 128 | + $linkHref = '#'; |
| 129 | +} else { |
| 130 | + $linkHref = api_get_path(WEB_CODE_PATH) . 'admin/access_url_edit.php'; |
| 131 | +} |
| 132 | + |
| 133 | +// 4) Build the “Add URL” action |
119 | 134 | $actions = Display::url( |
120 | | - Display::getMdiIcon('web-plus', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Add URL')), |
121 | | - api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php' |
| 135 | + Display::getMdiIcon( |
| 136 | + 'web-plus', |
| 137 | + 'ch-tool-icon', |
| 138 | + null, |
| 139 | + ICON_SIZE_MEDIUM, |
| 140 | + get_lang('Add URL') |
| 141 | + ), |
| 142 | + $linkHref, |
| 143 | + $attributes |
122 | 144 | ); |
| 145 | + |
| 146 | +// 5) Append the other “Manage” actions as before |
123 | 147 | if (api_get_multiple_access_url()) { |
124 | 148 | $actions .= Display::url( |
125 | 149 | Display::getMdiIcon('account', 'ch-tool-icon', null, ICON_SIZE_MEDIUM, get_lang('Manage users')), |
|
143 | 167 | ); |
144 | 168 | } |
145 | 169 |
|
146 | | -echo Display::toolbarAction('urls', [$actions]); |
147 | | - |
148 | | -$data = UrlManager::get_url_data(); |
149 | | -$urls = []; |
150 | | -foreach ($data as $row) { |
151 | | - // Title |
152 | | - $url = Display::url($row['url'], $row['url'], ['target' => '_blank']); |
153 | | - $description = $row['description']; |
154 | | - $createdAt = api_get_local_time($row['tms']); |
155 | | - |
156 | | - //Status |
157 | | - $active = $row['active']; |
158 | | - $action = 'unlock'; |
159 | | - $image = StateIcon::INACTIVE; |
160 | | - if ('1' == $active) { |
161 | | - $action = 'lock'; |
162 | | - $image = StateIcon::ACTIVE; |
163 | | - } |
164 | | - // you cannot lock the default |
165 | | - if ('1' == $row['id']) { |
166 | | - $status = Display::getMdiIcon($image, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang(ucfirst($action))); |
| 170 | +// 6) If still localhost, show the tooltip inline next to the button |
| 171 | +$toolbarItems = [$actions]; |
| 172 | +if ($isLocalhost) { |
| 173 | + $toolbarItems[] = '<span style=" |
| 174 | + margin-left: 8px; |
| 175 | + font-size: 0.9em; |
| 176 | + color: #666; |
| 177 | + ">'.$tooltip.'</span>'; |
| 178 | +} |
| 179 | + |
| 180 | +// 7) Render the toolbar |
| 181 | +echo Display::toolbarAction('urls', $toolbarItems); |
| 182 | + |
| 183 | +$rows = []; |
| 184 | +foreach ($url_list as $u) { |
| 185 | + $link = Display::url($u['url'], $u['url'], ['target' => '_blank']); |
| 186 | + $desc = $u['description']; |
| 187 | + $ts = api_get_local_time($u['tms']); |
| 188 | + $active = ($u['active'] === '1'); |
| 189 | + |
| 190 | + $iconAction = $active ? 'lock' : 'unlock'; |
| 191 | + $stateIcon = $active ? StateIcon::ACTIVE : StateIcon::INACTIVE; |
| 192 | + |
| 193 | + if ((string)$u['id'] === '1') { |
| 194 | + $status = Display::getMdiIcon($stateIcon, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang(ucfirst($iconAction))); |
167 | 195 | } else { |
168 | | - $status = '<a href="access_urls.php?action='.$action.'&url_id='.$row['id'].'">'. |
169 | | - Display::getMdiIcon($image, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang(ucfirst($action))).'</a>'; |
| 196 | + $status = '<a href="access_urls.php?action=' . $iconAction . '&url_id=' . $u['id'] . '">' . |
| 197 | + Display::getMdiIcon($stateIcon, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang(ucfirst($iconAction))) . |
| 198 | + '</a>'; |
170 | 199 | } |
171 | | - // Actions |
172 | | - $url_id = $row['id']; |
173 | | - $actions = Display::url( |
| 200 | + |
| 201 | + $rowActions = Display::url( |
174 | 202 | Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Edit')), |
175 | | - "access_url_edit.php?url_id=$url_id" |
| 203 | + "access_url_edit.php?url_id={$u['id']}" |
176 | 204 | ); |
177 | | - if ('1' != $url_id) { |
178 | | - $actions .= '<a href="access_urls.php?action=delete_url&url_id='.$url_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('Please confirm your choice'), ENT_QUOTES))."'".')) return false;">'. |
179 | | - Display::getMdiIcon('delete', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')).'</a>'; |
| 205 | + |
| 206 | + if ((string)$u['id'] !== '1') { |
| 207 | + $rowActions .= '<a href="access_urls.php?action=delete_url&url_id=' . $u['id'] . '" ' . |
| 208 | + 'onclick="return confirm(\'' . addslashes(get_lang('Please confirm your choice')) . '\');">' . |
| 209 | + Display::getMdiIcon('delete', 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Delete')) . |
| 210 | + '</a>'; |
180 | 211 | } |
181 | | - $urls[] = [$url, $description, $status, $createdAt, $actions]; |
| 212 | + |
| 213 | + $rows[] = [$link, $desc, $status, $ts, $rowActions]; |
182 | 214 | } |
183 | 215 |
|
184 | | -$table = new SortableTableFromArrayConfig($urls, 2, 50, 'urls'); |
| 216 | +$table = new SortableTableFromArrayConfig($rows, 2, 50, 'urls'); |
185 | 217 | $table->set_additional_parameters($parameters); |
186 | 218 | $table->set_header(0, 'URL'); |
187 | 219 | $table->set_header(1, get_lang('Description')); |
188 | | -$table->set_header(2, get_lang('active')); |
| 220 | +$table->set_header(2, get_lang('Active')); |
189 | 221 | $table->set_header(3, get_lang('Created at')); |
190 | 222 | $table->set_header(4, get_lang('Edit'), false); |
191 | 223 | $table->display(); |
192 | 224 |
|
193 | | -Display :: display_footer(); |
| 225 | +Display::display_footer(); |
0 commit comments