1 <?php
2
3 namespace Icybee\Modules\Users;
4
5 use Brickrouge\Button;
6 use Brickrouge\Element;
7 use Brickrouge\Form;
8
9 class AvailableSitesBlock extends Element
10 {
11 public function render()
12 {
13 global $core;
14
15 $document = $core->document;
16 $document->js->add('available-sites.js');
17 $document->page_title = 'Select a website';
18
19 $ws_title = \ICanBoogie\escape($core->site->admin_title ? $core->site->admin_title : $core->site->title .':' . $core->site->language);
20 $site_model = $core->models['sites'];
21
22 $available = $site_model
23 ->where('siteid IN(' . implode(',', $core->user->restricted_sites_ids) . ')')
24 ->order('admin_title, title')
25 ->all;
26
27 $uri = substr($_SERVER['REQUEST_URI'], strlen($core->site->path));
28 $options = [];
29
30 foreach ($available as $site)
31 {
32 $title = $site->title . ':' . $site->language;
33
34 if ($site->admin_title)
35 {
36 $title .= ' (' . $site->admin_title . ')';
37 }
38
39 $options[$site->url . $uri] = $title;
40 }
41
42 $form = new Form([
43
44 Form::ACTIONS => new Button('Change', [
45
46 'class' => 'btn-primary',
47 'type' => 'submit'
48
49 ]),
50
51 Form::RENDERER => 'Simple',
52
53 Element::CHILDREN => [
54
55 new Element('select', [
56
57 Element::DESCRIPTION => "Select one of the website available to your profile.",
58 Element::OPTIONS => $options
59
60 ])
61 ],
62
63 'name' => 'change-working-site',
64 'class' => 'form-primary'
65
66 ]);
67
68 return <<<EOT
69 <div id="block--site-access-denied" class="block-alert">
70 <h2>Access denied</h2>
71 <p>You don't have permission to access the administration interface for the website <q>$ws_title</q>,
72 please select another website to work with:</p>
73 $form
74 </div>
75 EOT;
76 }
77 }