Initial
[qwikioffice:qwikioffice.git] / public / QoDesk.php
1 <?php\r
2 //Header("content-type: application/x-javascript");\r
3 \r
4 require_once('server/os.php');\r
5 if(!class_exists('os')){ die('os class is missing!'); }\r
6 \r
7 class QoDesk {\r
8    private $os = null;\r
9 \r
10    private $member_id = null;\r
11    private $group_id = null;\r
12    public $member_info = null;\r
13    private $preferences = null;\r
14 \r
15    /**\r
16     * __construct()\r
17     *\r
18     * @access public\r
19     * @param {class} $os The os.\r
20     */\r
21    public function __construct(os $os){\r
22       if(!$os->session_exists()){\r
23          die('Session does not exist!');\r
24       }\r
25 \r
26       $this->member_id = $os->get_member_id();\r
27       $this->group_id = $os->get_group_id();\r
28 \r
29       if(!isset($this->member_id, $this->group_id)){\r
30          die('Member/Group not found!');\r
31       }\r
32 \r
33       $this->os = $os;\r
34       $this->member_info = $this->get_member_info();\r
35       $this->preferences = $this->get_preferences();\r
36    } // end __construct()\r
37 \r
38    private function get_member_info(){\r
39       $this->os->load('member');\r
40       $name = $this->os->member->get_name($this->member_id);\r
41       $this->os->load('group');\r
42       $group = $this->os->group->get_name($this->group_id);\r
43 \r
44       $member_info = new stdClass();\r
45       $member_info->name = $name ? $name : '';\r
46       $member_info->group = $group ? $group : '';\r
47 \r
48       return $member_info;\r
49    }\r
50 \r
51    private function get_preferences(){\r
52       $member_id = $this->member_id;\r
53       $group_id = $this->group_id;\r
54 \r
55       // get the member/group preference\r
56       $member_preference = $this->os->get_member_preference($member_id, $group_id);\r
57 \r
58       // get the default preference\r
59       $preference = $this->os->get_member_preference('0', '0');\r
60 \r
61       // overwrite default with any member/group preference\r
62       foreach($member_preference as $id => $property){\r
63          $preference->$id = $property;\r
64       }\r
65 \r
66       // do we have the theme id\r
67       if(isset($preference->appearance->themeId)){\r
68          $this->os->load('theme');\r
69          $theme = $this->os->theme->get_by_id($preference->appearance->themeId);\r
70          $theme_dir = $this->os->get_theme_dir();\r
71 \r
72          $preference->appearance->theme = new stdClass();\r
73          $preference->appearance->theme->id = $preference->appearance->themeId;\r
74          $preference->appearance->theme->name = $theme->name;\r
75          // local file?\r
76          if(stripos($theme->file, 'http://') === false){\r
77             $preference->appearance->theme->file = $theme_dir.$theme->file;\r
78          }else{\r
79             $preference->appearance->theme->file = $theme->file;\r
80          }\r
81 \r
82          unset($preference->appearance->themeId);\r
83       }\r
84 \r
85       // do we have the wallpaper id\r
86       if(isset($preference->background->wallpaperId)){\r
87          $this->os->load('wallpaper');\r
88          $wallpaper = $this->os->wallpaper->get_by_id($preference->background->wallpaperId);\r
89          $wallpaper_dir = $this->os->get_wallpaper_dir();\r
90 \r
91          $preference->background->wallpaper = new stdClass();\r
92          $preference->background->wallpaper->id = $preference->background->wallpaperId;\r
93          $preference->background->wallpaper->name = $wallpaper->name;\r
94          $preference->background->wallpaper->file = $wallpaper_dir.$wallpaper->file;\r
95 \r
96          unset($preference->background->wallpaperId);\r
97       }\r
98 \r
99       return $preference;\r
100    }\r
101 \r
102    public function print_privileges(){\r
103       // have a group id?\r
104       if(!isset($this->group_id)){\r
105          print '{}';\r
106          return false;\r
107       }\r
108 \r
109       // get the privilege id for the group\r
110       $this->os->load('group');\r
111       $privilege_id = $this->os->group->get_privilege_id($this->group_id);\r
112 \r
113       if(!$privilege_id){\r
114          print '{}';\r
115          return false;\r
116       }\r
117 \r
118       // get the privilege data\r
119       $this->os->load('privilege');\r
120       $data = $this->os->privilege->get_data($privilege_id);\r
121 \r
122       if(!isset($data)){\r
123          print '{}';\r
124          return false;\r
125       }\r
126 \r
127       print json_encode($data);\r
128       return true;\r
129    }\r
130 \r
131    public function print_modules(){\r
132       $response = '';\r
133       $ms = $this->os->get_modules();\r
134 \r
135       if(!isset($ms) || !is_array($ms) || count($ms) == 0){\r
136          print '';\r
137          return false;\r
138       }\r
139 \r
140       foreach($ms as $id => $m){\r
141          $response .= '{'.\r
142             '"id":"'.$id.'",'.\r
143             '"type":"'.$m->type.'",'.\r
144             '"className":"'.$m->client->class.'",'.\r
145             '"launcher":'.json_encode($m->client->launcher->config).','.\r
146             '"launcherPaths":'.json_encode($m->client->launcher->paths).\r
147          '},';\r
148       }\r
149 \r
150       print rtrim($response, ',');\r
151    }\r
152 \r
153    public function print_launchers(){\r
154       print isset($this->preferences->launchers) ? json_encode($this->preferences->launchers) : "{}";\r
155    }\r
156 \r
157    public function print_appearance(){\r
158       print isset($this->preferences->appearance) ? json_encode($this->preferences->appearance) : "{}";\r
159    }\r
160 \r
161    public function print_background(){\r
162       print isset($this->preferences->background) ? json_encode($this->preferences->background) : "{}";\r
163    }\r
164 }\r
165 \r
166 $os = new os();\r
167 $qo_desk = new QoDesk($os);\r
168 ?>\r
169 /*\r
170  * qWikiOffice Desktop 1.0\r
171  * Copyright(c) 2007-2010, Murdock Technologies, Inc.\r
172  * licensing@qwikioffice.com\r
173  *\r
174  * http://www.qwikioffice.com/license\r
175  */\r
176 \r
177 Ext.namespace('Ext.ux','QoDesk');\r
178 \r
179 QoDesk.App = new Ext.app.App({\r
180    init : function(){\r
181       Ext.BLANK_IMAGE_URL = 'resources/images/default/s.gif';\r
182       Ext.QuickTips.init();\r
183    },\r
184 \r
185    /**\r
186     * The member's name and group name for this session.\r
187     */\r
188    memberInfo: {\r
189       name: '<?php print $qo_desk->member_info->name ?>',\r
190       group: '<?php print $qo_desk->member_info->group ?>'\r
191    },\r
192 \r
193    /**\r
194     * An array of the module definitions.\r
195     * The definitions are used until the module is loaded on demand.\r
196     */\r
197    modules: [ <?php $qo_desk->print_modules(); ?> ],\r
198 \r
199    /**\r
200      * The members privileges.\r
201      */\r
202    privileges: <?php $qo_desk->print_privileges(); ?>,\r
203 \r
204    /**\r
205     * The desktop config object.\r
206     */\r
207    desktopConfig: {\r
208       appearance: <?php $qo_desk->print_appearance(); ?>,\r
209       background: <?php $qo_desk->print_background(); ?>,\r
210       launchers: <?php $qo_desk->print_launchers(); ?>,\r
211       taskbarConfig: {\r
212          buttonScale: 'large',\r
213          position: 'bottom',\r
214          quickstartConfig: {\r
215             width: 120\r
216          },\r
217          startButtonConfig: {\r
218             iconCls: 'icon-qwikioffice',\r
219             text: 'Start'\r
220          },\r
221          startMenuConfig: {\r
222             iconCls: 'icon-user-48',\r
223             title: '<?php print $qo_desk->member_info->name ?>',\r
224             width: 320\r
225          }\r
226       }\r
227    }\r
228 });