1 <?php
  2 
  3   4   5   6   7   8   9  10 
 11 
 12 namespace Icybee;
 13 
 14 use ICanBoogie\Debug;
 15 use ICanBoogie\Operation;
 16 use ICanBoogie\Route;
 17 
 18 use Brickrouge\A;
 19 use Brickrouge\Alert;
 20 use Brickrouge\DropdownMenu;
 21 
 22 class AdminDecorator
 23 {
 24     protected $component;
 25 
 26     public function __construct($component)
 27     {
 28         $this->component = $component;
 29     }
 30 
 31     protected $changed_site = false;
 32 
 33     public function __toString()
 34     {
 35         try
 36         {
 37             return $this->render();
 38         }
 39         catch (\Exception $e)
 40         {
 41             return Debug::format_alert($e);
 42         }
 43     }
 44 
 45     public function render()
 46     {
 47         global $core;
 48 
 49         $this->add_assets($core->document);
 50 
 51         
 52 
 53         if ($core->session->last_site_id)
 54         {
 55             if ($core->session->last_site_id != $core->site_id)
 56             {
 57                 $core->session->last_site_id = $core->site_id;
 58 
 59                 if (!$core->request['ssc'])
 60                 {
 61                     $this->changed_site = true;
 62                 }
 63             }
 64         }
 65         else
 66         {
 67             $core->session->last_site_id = $core->site_id;
 68         }
 69 
 70         if ($this->changed_site)
 71         {
 72             \ICanBoogie\log_info("Vous avez changé de site.");
 73         }
 74 
 75         
 76 
 77         $component = (string) $this->component;
 78         $actionbar = new \Icybee\Element\Actionbar;
 79         $shortcuts = $this->render_shortcuts();
 80         $navigation = $this->render_navigation();
 81 
 82         $alert = $this->render_alerts();
 83 
 84         return <<<EOT
 85 <div id="body-wrapper">
 86     $shortcuts
 87     $navigation
 88     $actionbar
 89 
 90     <div id="contents">
 91         <div class="alert-wrapper">$alert</div>
 92         $component
 93     </div>
 94 </div>
 95 EOT;
 96     }
 97 
 98     protected function add_assets(\Brickrouge\Document $document)
 99     {
100         $document->css->add(\Brickrouge\ASSETS . 'brickrouge.css', -250);
101         $document->css->add(\Icybee\ASSETS . 'icybee.css', -240);
102         $document->css->add(\Icybee\ASSETS . 'admin.css', -200);
103         $document->css->add(\Icybee\ASSETS . 'admin-more.css', -200);
104 
105         $document->js->add(\Icybee\ASSETS . 'mootools.js', -200);
106         $document->js->add(\ICanBoogie\ASSETS . 'icanboogie.js', -190);
107         $document->js->add(\Brickrouge\ASSETS . 'brickrouge.js', -190);
108         $document->js->add(\Icybee\ASSETS . 'admin.js', -180);
109     }
110 
111     protected function render_navigation()
112     {
113         global $core;
114 
115         $user = $core->user;
116 
117         if ($user->is_guest || $user instanceof \Icybee\Modules\Members\Member)
118         {
119             $this->title = 'Icybee';
120 
121             return;
122         }
123 
124         return new \Icybee\Element\Navigation(array('id' => 'navigation'));
125     }
126 
127     protected function render_shortcuts()
128     {
129         global $core;
130 
131         $user = $core->user;
132         $site = $core->site;
133 
134         if ($user->is_guest)
135         {
136             $this->page_title = 'Icybee';
137 
138             $html = '<a href="' . $site->url . '" class="home">' . \ICanBoogie\escape($site->title) . '</a> <i class="icon-home icon-white"></i>';
139         }
140         else
141         {
142             $html = new \Icybee\Element\SiteMenu(array('class' => 'pull-left'))
143             . new \Icybee\Element\UserMenu(array('class' => 'pull-right'));
144         }
145 
146         return '<div id="quick">' . $html . '</div>';
147     }
148 
149     protected function render_alerts()
150     {
151         global $core;
152 
153         $html = '';
154         $types = array('success', 'info', 'error');
155 
156         if (Debug::$mode == Debug::MODE_DEV || $core->user->is_admin)
157         {
158             $types[] = 'debug';
159         }
160 
161         foreach ($types as $type)
162         {
163             $html .= new Alert(Debug::fetch_messages($type), array(Alert::CONTEXT => $type));
164         }
165 
166         return $html;
167     }
168 }