Merge branch 'maint/7.0'
[ninja.git] / application / controllers / external_widget.php
blobfe3900bf0e48505d02614c8aaa44b549a1d412e1
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Controller for displaying single widget on an external web
5 * @package NINJA
6 * @author op5 AB
7 * @license GPL
8 * @copyright 2009 op5 AB
9 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
10 * or registered trademarks of op5 AB.
11 * All other trademarks, servicemarks, registered trademarks, and registered
12 * servicemarks mentioned herein may be the property of their respective owner(s).
13 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
14 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
15 * PARTICULAR PURPOSE.
17 class External_widget_Controller extends Widget_Controller {
18 public $widgets = array();
19 public function __construct()
21 parent::__construct();
22 $this->template = $this->add_view('external_widget');
23 $this->template->current_skin = 'default/';
26 /**
27 * Show page with single widget
28 * @param $name str widget name to show, defaults to netw_health
30 public function show_widget($name = null, $instance_id = null)
32 if (is_null($name)) {
33 $name = Kohana::config('external_widget.widget_name');
34 if (empty($name)) {
35 die(_("Don't know what widget to show since no ".
36 "default widget is specified in config file (config/external_widget.php)."));
41 $this->template->content = $this->add_view('single_widget');
42 $this->template->title = _('External widget');
43 $this->template->js[] = $this->add_path('/js/widgets.js');
45 $model = Ninja_widget_Model::get(Router::$controller.'/'.Router::$method, $name, $instance_id);
46 if (!$model) {
47 $this->template->content->widget = false;
48 return;
50 if (!isset($model->id) || !$model->id)
51 $model->save();
52 $user = Auth::instance()->get_user();
53 $_SESSION['external_widget_username'] = $user->username;
54 $_SESSION['external_widget_groups'] = $user->groups;
55 $widget = widget::add($model, $this);
57 $this->template->inline_js = $this->inline_js;
59 $this->template->content->widget = $widget;
60 $this->template->disable_refresh = true;