~xibo-maintainers/xibo/tuttle

« back to all changes in this revision

Viewing changes to server/lib/pages/admin.class.php

  • Committer: Dan Garner
  • Date: 2014-09-19 11:56:41 UTC
  • mfrom: (332.8.73 server-170-alpha)
  • Revision ID: dan@xibo.org.uk-20140919115641-pwvuhq0cy4xkmytq
MergedĀ lp:~dangarner/xibo/server-170alpha

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
20
20
 */ 
21
21
defined('XIBO') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");
22
 
 
23
 
class adminDAO 
24
 
{
25
 
        private $db;
26
 
        private $user;
27
 
 
28
 
        function __construct(database $db, user $user) 
29
 
        {
30
 
                $this->db       =& $db;
31
 
                $this->user =& $user;
32
 
                
33
 
                require_once('lib/data/setting.data.class.php');
34
 
        }
 
22
require_once('lib/data/setting.data.class.php');
 
23
class adminDAO extends baseDAO {
35
24
        
36
25
        function displayPage() {
37
26
        
38
27
                // Set some information about the form
39
28
        Theme::Set('form_id', 'SettingsForm');
40
 
        Theme::Set('form_action', 'index.php?p=group&q=Delete');
41
 
                Theme::Set('settings_help_button_url', HelpManager::Link('Content', 'Config'));
42
 
                Theme::Set('settings_form', $this->display_settings());
 
29
        Theme::Set('form_action', 'index.php?p=admin&q=Edit');
 
30
 
 
31
        $libraryLimit = Config::GetSetting('LIBRARY_SIZE_LIMIT_KB');
 
32
 
 
33
        // Get all of the settings in an array
 
34
        $settings = Config::GetAll(NULL, array('userSee' => 1));
 
35
 
 
36
        $currentCategory = '';
 
37
        $catagories = array();
 
38
        $formFields = array();
 
39
 
 
40
        // Go through each setting, validate it and add it to the array
 
41
        foreach ($settings as $setting) {
 
42
 
 
43
            if ($currentCategory != $setting['cat']) {
 
44
                $currentCategory = $setting['cat'];
 
45
                $catagories[] = array('tabId' => $setting['cat'], 'tabName' => ucfirst($setting['cat']));
 
46
            }
 
47
 
 
48
            // Are there any options
 
49
            $options = NULL;
 
50
            if (!empty($setting['options'])) {
 
51
                // Change to an id=>value array
 
52
                foreach (explode('|', Kit::ValidateParam($setting['options'], _HTMLSTRING)) as $tempOption)
 
53
                    $options[] = array('id' => $tempOption, 'value' => $tempOption);
 
54
            }
 
55
 
 
56
            // Validate the current setting
 
57
            if ($setting['type'] == 'checkbox' && isset($setting['value']))
 
58
                $validated = $setting['value'];
 
59
            else if (isset($setting['value']))
 
60
                $validated = Kit::ValidateParam($setting['value'], $setting['type']);
 
61
            else
 
62
                $validated = $setting['default'];
 
63
 
 
64
            // Time zone type requires special handling.
 
65
            if ($setting['fieldType'] == 'timezone') {
 
66
                $options = $this->TimeZoneDropDown($validated);
 
67
            }
 
68
 
 
69
            // Get a list of settings and assign them to the settings field
 
70
            $formFields[] = array(
 
71
                'name' => $setting['setting'],
 
72
                'type' => $setting['type'],
 
73
                'fieldType' => $setting['fieldType'],
 
74
                'helpText' => $setting['helptext'],
 
75
                'title' => $setting['title'],
 
76
                'options' => $options,
 
77
                'validation' => $setting['validation'],
 
78
                'value' => $validated,
 
79
                'enabled' => $setting['userChange'],
 
80
                'catId' => $setting['cat'],
 
81
                'cat' => ucfirst($setting['cat'])
 
82
            );
 
83
        }
 
84
 
 
85
        Theme::Set('cats', $catagories);
 
86
                Theme::Set('form_fields', $formFields);
 
87
 
 
88
        // Provide some bandwidth and library information to the theme.
 
89
        // Library Size in Bytes
 
90
        $fileSize = $this->db->GetSingleValue('SELECT IFNULL(SUM(FileSize), 0) AS SumSize FROM media', 'SumSize', _INT);
 
91
        $limitPcnt = ($libraryLimit > 0) ? (($fileSize / ($libraryLimit * 1024)) * 100) : '';
 
92
 
 
93
        Theme::Set('library_info', $this->FormatByteSize($fileSize) . (($libraryLimit > 0) ? sprintf(__(' / %d %% of %s'), $limitPcnt, $this->FormatByteSize($libraryLimit * 1024)) : ''));
 
94
    
 
95
        // Monthly bandwidth - optionally tested against limits
 
96
        $xmdsLimit = Config::GetSetting('MONTHLY_XMDS_TRANSFER_LIMIT_KB');
 
97
        $startOfMonth = strtotime(date('m').'/01/'.date('Y').' 00:00:00');
 
98
 
 
99
        $sql = sprintf('SELECT IFNULL(SUM(Size), 0) AS BandwidthUsage FROM `bandwidth` WHERE Month > %d AND Month < %d', $startOfMonth, $startOfMonth + (86400 * 2));
 
100
        $bandwidthUsage = $this->db->GetSingleValue($sql, 'BandwidthUsage', _INT);
 
101
        $usagePcnt = ($xmdsLimit > 0) ? (((double)$bandwidthUsage / ($xmdsLimit * 1024)) * 100) : '';
 
102
        
 
103
        Theme::Set('bandwidth_info', $this->FormatByteSize($bandwidthUsage) . (($xmdsLimit > 0) ? sprintf(__(' / %d %% of %s'), $usagePcnt, $this->FormatByteSize($xmdsLimit * 1024)) : ''));
 
104
 
43
105
 
44
106
                // Render the Theme and output
45
107
        Theme::Render('settings_page');
46
108
        }
47
109
 
48
 
        function modify() 
49
 
        {
50
 
                $db =& $this->db;
51
 
 
52
 
                // Check the token
 
110
    function actionMenu() {
 
111
 
 
112
        $menu = array();
 
113
        
 
114
        if (Config::GetSetting('SETTING_IMPORT_ENABLED') == 1) {
 
115
            $menu[] = array(
 
116
                'title' => __('Import'),
 
117
                'class' => 'XiboFormButton',
 
118
                'selected' => false,
 
119
                'link' => 'index.php?p=admin&q=RestoreForm',
 
120
                'help' => __('Import a database'),
 
121
                'onclick' => ''
 
122
                );
 
123
        }
 
124
 
 
125
        // Always show export
 
126
        $menu[] = array(
 
127
            'title' => __('Export'),
 
128
            'class' => 'XiboFormButton',
 
129
            'selected' => false,
 
130
            'link' => 'index.php?p=admin&q=BackupForm',
 
131
            'help' => __('Export a database'),
 
132
            'onclick' => ''
 
133
            );
 
134
 
 
135
        if (Config::GetSetting('SETTING_LIBRARY_TIDY_ENABLED') == 1) {
 
136
            $menu[] = array(
 
137
                'title' => __('Tidy Library'),
 
138
                'class' => 'XiboFormButton',
 
139
                'selected' => false,
 
140
                'link' => 'index.php?p=admin&q=TidyLibrary',
 
141
                'help' => __('Run through the library and remove and unnecessary files'),
 
142
                'onclick' => ''
 
143
                );
 
144
        }
 
145
 
 
146
        return $menu;                 
 
147
    }
 
148
 
 
149
    function Edit() {
 
150
        $response = new ResponseManager();
 
151
 
 
152
        // Check the token
53
153
        if (!Kit::CheckToken())
54
154
            trigger_error(__('Sorry the form has expired. Please refresh.'), E_USER_ERROR);
55
155
 
56
 
                $refer          = Kit::GetParam('refer', _POST, _STRING);
57
 
                $usertype       = Kit::GetParam('usertype', _SESSION, _INT);
58
 
                
59
 
                $ids            = Kit::GetParam('id', _POST, _ARRAY);
60
 
                $values         = Kit::GetParam('value', _POST, _ARRAY);
61
 
                
62
 
                $size           = count($ids);
63
 
                
64
 
                if ($usertype != 1) 
65
 
                {
66
 
                        setMessage(__("Only admin users are allowed to modify settings"));
67
 
                        return $refer;
68
 
                }
69
 
                
70
 
                // Get the SettingId for LIBRARY_LOCATION
71
 
                $SQL = sprintf("SELECT settingid FROM setting WHERE setting = '%s'", 'LIBRARY_LOCATION');
72
 
                
73
 
                if (!$result = $db->query($SQL))
74
 
                {
75
 
                        trigger_error($db->error());
76
 
                        trigger_error(__('Cannot find the Library Location Setting - this is serious.'), E_USER_ERROR);
77
 
                }
78
 
                
79
 
                if ($db->num_rows($result) == 0)
80
 
                {
81
 
                        trigger_error(__('Cannot find the Library Location Setting - this is serious.'), E_USER_ERROR);
82
 
                }
83
 
                
84
 
                $row                            = $db->get_row($result);
85
 
                $librarySettingId       = $row[0];
86
 
        
87
 
                // Loop through and modify the settings
88
 
                for ($i=0; $i<$size; $i++) 
89
 
                {
90
 
                        $value = Kit::ValidateParam($values[$i], _STRING);
91
 
                        $id = $ids[$i];
92
 
                        
93
 
                        // Is this the library location setting
94
 
                        if ($id == $librarySettingId)
95
 
                        {
96
 
                                // Check for a trailing slash and add it if its not there
97
 
                                $value = rtrim($value, '/') . '/';
98
 
                                
99
 
                                // Attempt to add the directory specified
100
 
                                if (!file_exists($value . 'temp'))
101
 
                                {
102
 
                                        // Make the directory with broad permissions recursively (so will add the whole path)
103
 
                                        mkdir($value . 'temp', 0777, true);
104
 
                                }
105
 
                                
106
 
                                if (!is_writable($value . 'temp'))
107
 
                                {
108
 
                                        trigger_error(__('The Library Location you have picked is not writable'), E_USER_ERROR);
109
 
                                }
110
 
                        }
111
 
                        
112
 
                        $SQL = sprintf("UPDATE setting SET value = '%s' WHERE settingid = %d ", $db->escape_string($value), $id);
113
 
 
114
 
                        if(!$db->query($SQL)) 
115
 
                        {
116
 
                                trigger_error($db->error());
117
 
                                trigger_error(__('Update of settings failed.'), E_USER_ERROR);
118
 
                        }
119
 
                }
120
 
 
121
 
                $response = new ResponseManager();
122
 
                $response->SetFormSubmitResponse(__('Settings Updated'), false);
 
156
        Kit::ClassLoader('setting');
 
157
        $data = new Setting($this->db);
 
158
 
 
159
        // Get all of the settings in an array
 
160
        $settings = Config::GetAll(NULL, array('userChange' => 1, 'userSee' => 1));
 
161
 
 
162
        // Go through each setting, validate it and add it to the array
 
163
        foreach ($settings as $setting) {
 
164
            // Check to see if we have a setting that matches in the provided POST vars.
 
165
            $value = Kit::GetParam($setting['setting'], _POST, $setting['type'], (($setting['type'] == 'checkbox') ? NULL : $setting['default']));
 
166
 
 
167
            // Check the library location setting
 
168
            if ($setting['setting'] == 'LIBRARY_LOCATION') {
 
169
                // Check for a trailing slash and add it if its not there
 
170
                $value = rtrim($value, '/');
 
171
                $value = rtrim($value, '\\') . DIRECTORY_SEPARATOR;
 
172
                
 
173
                // Attempt to add the directory specified
 
174
                if (!file_exists($value . 'temp'))
 
175
                    // Make the directory with broad permissions recursively (so will add the whole path)
 
176
                    mkdir($value . 'temp', 0777, true);
 
177
                
 
178
                if (!is_writable($value . 'temp'))
 
179
                    trigger_error(__('The Library Location you have picked is not writeable'), E_USER_ERROR);
 
180
            }
 
181
 
 
182
            // Actually edit
 
183
            if (!$data->Edit($setting['setting'], $value))
 
184
                trigger_error($data->GetErrorMessage(), E_USER_ERROR);
 
185
        }
 
186
 
 
187
        $response->SetFormSubmitResponse(__('Settings Updated'), false);
123
188
        $response->Respond();
124
 
        }
125
 
        
126
 
        function display_settings() 
127
 
        {
128
 
                $db                     =& $this->db;
129
 
                $user                   =& $this->user;
130
 
                
131
 
                $helpObject             = new HelpManager($db, $user);
132
 
                        
133
 
                $helpButton     = $helpObject->HelpButton("content/config/settings", true);
134
 
                
135
 
                //one giant form, split into tabs
136
 
                $form = '<form id="SettingsForm" method="post" class="XiboForm" action="index.php?p=admin&q=modify">' . Kit::Token();
137
 
                $tabs = '';
138
 
                $pages = '';
139
 
                
140
 
                //get all the tabs, ordered by catagory
141
 
                $SQL = "SELECT DISTINCT cat FROM setting WHERE userChange = 1 ORDER BY cat";
142
 
                
143
 
                if (!$results = $db->query($SQL)) 
144
 
                {
145
 
                        trigger_error($db->error());
146
 
                        trigger_error(__("Can't get the setting catagories"), E_USER_ERROR);
147
 
                }
148
 
                
149
 
                while ($row = $db->get_row($results)) 
150
 
                {
151
 
                        $cat = $row[0];
152
 
                        $ucat = ucfirst($cat);
153
 
                        $cat_tab = $cat."_tab";
154
 
                        
155
 
                        // generate the li and a for this tab
156
 
                        $tabs .= "<li><a href='#$cat_tab'><span>$ucat</span><i class='icon-chevron-right pull-right'></i></a></li>";
157
 
                
158
 
                        // for each one, call display_cat to get the settings specific to that cat
159
 
                        $cat_page = $this->display_cat($cat);
160
 
                        
161
 
                        $pages .= <<<PAGES
162
 
                        <div id="$cat_tab">
163
 
                                $cat_page
164
 
                        </div>
165
 
PAGES;
166
 
                }
167
 
                
168
 
                $msgSave = __('Save');
169
 
                $msgCategories = __('Categories');
170
 
 
171
 
                // Output it all
172
 
                $form .= <<<FORM
173
 
                <div class="span2">
174
 
                        <div class="well affix">
175
 
                                <ul class="nav nav-list ">
176
 
                                        <li class="nav-header">$msgCategories</li>
177
 
                                        $tabs
178
 
                                </ul>
179
 
                        </div>
180
 
                </div>
181
 
                <div class="span10">
182
 
                        $pages
183
 
                </div>
184
 
FORM;
185
 
        
186
 
                //end the form and output
187
 
                $form .= "</form>";
188
 
                
189
 
                return $form;
190
 
        }
191
 
 
192
 
        function display_cat($cat) 
193
 
        {
194
 
                $db =& $this->db;
195
 
                
196
 
                $output = "";
197
 
                
198
 
                $title   = ucfirst($cat);
199
 
                $output .= '<h3>' . __($title) . ' ' . __('Settings') . '</h3>';
200
 
                        
201
 
                /*
202
 
                        Firstly we want to individually get the user module
203
 
                */
204
 
                if ($cat == 'user')
205
 
                {
206
 
                
207
 
                        $SQL = "";
208
 
                        $SQL.= "SELECT settingid, setting, value, helptext FROM setting WHERE setting = 'userModule'";
209
 
        
210
 
                        if(!$results = $db->query($SQL))
211
 
                        {
212
 
                                trigger_error($db->error());
213
 
                                trigger_error(__('Can not get settings'), E_USER_ERROR);                                
214
 
                        }
215
 
        
216
 
                        $row            = $db->get_row($results);
217
 
                        $settingid      = Kit::ValidateParam($row[0], _INT);
218
 
                        $setting        = Kit::ValidateParam($row[1], _STRING);
219
 
                        $setting        = __($setting);
220
 
                        $value          = Kit::ValidateParam($row[2], _STRING);
221
 
                        $helptext       = Kit::ValidateParam($row[3], _HTMLSTRING);
222
 
                        
223
 
                        $output .= <<<END
224
 
                        <h5>$setting</h5>
225
 
                        <p>$helptext</p>
226
 
END;
227
 
 
228
 
                        // we need to make a drop down out of the files that match a string, in a directory
229
 
                        $files  = scandir("modules/");
230
 
                        $select = "";
231
 
                        
232
 
                        foreach ($files as $file) 
233
 
                        {
234
 
                            $selected = "";
235
 
                            if($file == $value) $selected = "selected";
236
 
 
237
 
                            if(preg_match("^module_user^", $file))
238
 
                            {
239
 
                                    //var for drop down
240
 
                                    $select.= "<option value='$file' $selected>$file</option>";
241
 
                            }
242
 
                        }
243
 
                                
244
 
                        $output .=  <<<END
245
 
                        <input type="hidden" name="id[]" value="$settingid">
246
 
                        <select name="value[]">
247
 
                                $select
248
 
                        </select>
249
 
END;
250
 
                }
251
 
 
252
 
                if ($cat == 'content')
253
 
                {
254
 
                    $libraryLimit = Config::GetSetting('LIBRARY_SIZE_LIMIT_KB');
255
 
 
256
 
                    // Library Size in Bytes
257
 
                    $fileSize = $this->db->GetSingleValue('SELECT IFNULL(SUM(FileSize), 0) AS SumSize FROM media', 'SumSize', _INT);
258
 
                    $limitPcnt = ($libraryLimit > 0) ? (($fileSize / ($libraryLimit * 1024)) * 100) : '';
259
 
 
260
 
                    $output .= '<p>' . sprintf(__('You have %s of media in the library.'), $this->FormatByteSize($fileSize)) . (($libraryLimit > 0) ? sprintf(__(' This is %d %% of your %s limit.'), $limitPcnt, $this->FormatByteSize($libraryLimit * 1024)) : '') . '</p>';
261
 
                
262
 
                    // Monthly bandwidth - optionally tested against limits
263
 
                    $xmdsLimit = Config::GetSetting('MONTHLY_XMDS_TRANSFER_LIMIT_KB');
264
 
                    $startOfMonth = strtotime(date('m').'/01/'.date('Y').' 00:00:00');
265
 
 
266
 
                    $sql = sprintf('SELECT IFNULL(SUM(Size), 0) AS BandwidthUsage FROM `bandwidth` WHERE Month = %d', $startOfMonth);
267
 
                    $bandwidthUsage = $this->db->GetSingleValue($sql, 'BandwidthUsage', _INT);
268
 
 
269
 
                    Debug::LogEntry('audit', $sql);
270
 
                    
271
 
                    $usagePcnt = ($xmdsLimit > 0) ? (($bandwidthUsage / ($xmdsLimit * 1024)) * 100) : '';
272
 
                    
273
 
                    $output .= '<p>' . sprintf(__('You have used %s of bandwidth this month.'), $this->FormatByteSize($bandwidthUsage)) . (($xmdsLimit > 0) ? sprintf(__(' This is %d %% of your %s limit.'), $usagePcnt, $this->FormatByteSize($xmdsLimit * 1024)) : '') . '</p>';
274
 
                }
275
 
 
276
 
                if ($cat == 'general')
277
 
                {
278
 
                    $output .= '<p>' . __('Import / Export Database') . '</p>';
279
 
 
280
 
                    if (Config::GetSetting('SETTING_IMPORT_ENABLED') == 'On')
281
 
                        $output .= '<button class="XiboFormButton" href="index.php?p=admin&q=RestoreForm">' . __('Import') . '</button>';
282
 
                    
283
 
                    $output .= '<button class="XiboFormButton" href="index.php?p=admin&q=BackupForm">' . __('Export') . '</button>';
284
 
                    
285
 
                    if (Config::GetSetting('SETTING_LIBRARY_TIDY_ENABLED') == 'On')
286
 
                        $output .= '<button class="XiboFormButton" href="index.php?p=admin&q=TidyLibrary">' . __('Tidy Library') . '</button>';
287
 
                }
288
 
                
289
 
                // Need to now get all the Misc settings 
290
 
                $SQL = "";
291
 
                $SQL.= sprintf("SELECT settingid, setting, value, helptext FROM setting WHERE type = 'text' AND cat='%s' AND userChange = 1", $cat);
292
 
 
293
 
                if (!$results = $db->query($SQL))
294
 
                {
295
 
                        trigger_error($db->error());
296
 
                        trigger_error(__('Can not get settings'), E_USER_ERROR);                                
297
 
                }
298
 
 
299
 
                while($row = $db->get_row($results)) 
300
 
                {
301
 
                        $settingid      = Kit::ValidateParam($row[0], _INT);
302
 
                        $setting        = Kit::ValidateParam($row[1], _STRING);
303
 
                        $value          = Kit::ValidateParam($row[2], _STRING);
304
 
                        $helptext       = Kit::ValidateParam($row[3], _HTMLSTRING);
305
 
 
306
 
                        $output .=  <<<END
307
 
                        <h5>$setting</h5>
308
 
                        <p>$helptext</p>
309
 
                        <input type="hidden" name="id[]" value="$settingid">
310
 
                        <input type="text" name="value[]" value="$value">
311
 
END;
312
 
                        if($setting == "mail_to") 
313
 
                        {
314
 
                                $msgTestEmail = __('Test Email');
315
 
                                //show another form here, for test
316
 
                                $output .= <<<END
317
 
                                <a id="test_email" href="index.php?p=admin&q=SendEmail" class="XiboFormButton">$msgTestEmail</a>
318
 
END;
319
 
                        }
320
 
                }       
321
 
                        
322
 
                // Drop downs
323
 
                $SQL = "";
324
 
                $SQL.= sprintf("SELECT settingid, setting, value, helptext, options FROM setting WHERE type = 'dropdown' AND cat='%s' AND userChange = 1", $db->escape_string($cat));
325
 
 
326
 
                if (!$results = $db->query($SQL))
327
 
                {
328
 
                        trigger_error($db->error());
329
 
                        trigger_error(__('Can not get settings'), E_USER_ERROR);                                
330
 
                }
331
 
 
332
 
                while($row = $db->get_row($results)) 
333
 
                {
334
 
                        $settingid      = Kit::ValidateParam($row[0], _INT);
335
 
                        $setting        = Kit::ValidateParam($row[1], _STRING);
336
 
                        $value          = Kit::ValidateParam($row[2], _STRING);
337
 
                        $helptext       = Kit::ValidateParam($row[3], _HTMLSTRING);
338
 
                        $options        = Kit::ValidateParam($row[4], _STRING);
339
 
 
340
 
                        $select = "";
341
 
                        
342
 
                        $options = explode("|", $options);
343
 
                        foreach ($options as $option) 
344
 
                        {
345
 
                                if($option == $value) 
346
 
                                {
347
 
                                        $select.="<option value='$option' selected>$option</option>";
348
 
                                }
349
 
                                else 
350
 
                                {
351
 
                                        $select.="<option value='$option'>$option</option>";
352
 
                                }
353
 
                        }
354
 
                        
355
 
                        $output .= <<<END
356
 
                        <h5>$setting</h5>
357
 
                        <p>$helptext</p>
358
 
                        <input type="hidden" name="id[]" value="$settingid">
359
 
                        <select name="value[]">$select</select>
360
 
END;
361
 
                }
362
 
                
363
 
                // Also deal with the timezone setting type
364
 
                $SQL = "";
365
 
                $SQL.= sprintf("SELECT settingid, setting, value, helptext FROM setting WHERE type = 'timezone' AND cat='%s' AND userChange = 1", $cat);
366
 
 
367
 
                if (!$results = $db->query($SQL))
368
 
                {
369
 
                        trigger_error($db->error());
370
 
                        trigger_error(__('Can not get settings'), E_USER_ERROR);                                
371
 
                }
372
 
 
373
 
                while($row = $db->get_row($results)) 
374
 
                {
375
 
                        $settingid      = Kit::ValidateParam($row[0], _INT);
376
 
                        $setting        = Kit::ValidateParam($row[1], _STRING);
377
 
                        $selectedzone = Kit::ValidateParam($row[2], _STRING);
378
 
                        $helptext       = Kit::ValidateParam($row[3], _HTMLSTRING);
379
 
                        $options        = $this->TimeZoneIdentifiersList();
380
 
                        
381
 
                        $structure      = '';
382
 
                        $i                      = 0;
383
 
                        
384
 
                        // Create a Zone array containing the timezones
385
 
                        // From: http://php.oregonstate.edu/manual/en/function.timezone-identifiers-list.php
386
 
                        foreach($options as $zone) 
387
 
                        {
388
 
                                $zone                                   = explode('/',$zone);
389
 
                                $zonen[$i]['continent'] = isset($zone[0]) ? $zone[0] : '';
390
 
                                $zonen[$i]['city']              = isset($zone[1]) ? $zone[1] : '';
391
 
                                $zonen[$i]['subcity']   = isset($zone[2]) ? $zone[2] : '';
392
 
                                $i++;
393
 
                        }
394
 
                        
395
 
                        // Sort them
396
 
                        asort($zonen);
397
 
                        
398
 
                        foreach($zonen as $zone) 
399
 
                        {
400
 
                                extract($zone);
401
 
                                
402
 
                                if($continent == 'Africa' || $continent == 'America' || $continent == 'Antarctica' || $continent == 'Arctic' || $continent == 'Asia' || $continent == 'Atlantic' || $continent == 'Australia' || $continent == 'Europe' || $continent == 'Indian' || $continent == 'Pacific' || $continent == 'General') 
403
 
                                {
404
 
                                        if(!isset($selectcontinent)) 
405
 
                                        {
406
 
                                                $structure .= '<optgroup label="'.$continent.'">'; // continent
407
 
                                        } 
408
 
                                        elseif($selectcontinent != $continent) 
409
 
                                        {
410
 
                                                $structure .= '</optgroup><optgroup label="'.$continent.'">'; // continent
411
 
                                        }
412
 
                        
413
 
                                        if(isset($city) != '')
414
 
                                        {
415
 
                                                if (!empty($subcity) != '')
416
 
                                                {
417
 
                                                        $city = $city . '/'. $subcity;
418
 
                                                }
419
 
                                                $structure .= "<option ".((($continent.'/'.$city)==$selectedzone)?'selected="selected "':'')." value=\"".($continent.'/'.$city)."\">".str_replace('_',' ',$city)."</option>"; //Timezone
420
 
                                        } 
421
 
                                        else 
422
 
                                        {
423
 
                                                if (!empty($subcity) != '')
424
 
                                                {
425
 
                                                        $city = $city . '/'. $subcity;
426
 
                                                }
427
 
                                                $structure .= "<option ".(($continent==$selectedzone)?'selected="selected "':'')." value=\"".$continent."\">".$continent."</option>"; //Timezone
428
 
                                        }
429
 
                        
430
 
                                        $selectcontinent = $continent;
431
 
                                }
432
 
                        }
433
 
                        $structure .= '</optgroup>';
434
 
                        
435
 
                        // End
436
 
                        
437
 
                        $output .= <<<END
438
 
                        <h5>$setting</h5>
439
 
                        <p>$helptext</p>
440
 
                        <input type="hidden" name="id[]" value="$settingid">
441
 
                        <select name="value[]">$structure</select>
442
 
END;
443
 
                }
444
 
                
445
 
                return $output;
446
 
        }
 
189
    }
447
190
        
448
191
        /**
449
192
         * Timezone functionality
450
193
         * @return 
451
194
         */
452
 
        private function TimeZoneIdentifiersList()
453
 
        {
454
 
                if (function_exists('timezone_identifiers_list')) 
455
 
                {
456
 
                        return timezone_identifiers_list();
457
 
                }
458
 
 
 
195
        private function TimeZoneIdentifiersList() {
 
196
                
 
197
        if (function_exists('timezone_identifiers_list')) 
 
198
            return timezone_identifiers_list();
 
199
                
459
200
                $list[] = 'Europe/London';
460
201
                $list[] = 'America/New_York';
461
202
                $list[] = 'Europe/Paris';
476
217
                
477
218
                return $list;
478
219
        }
 
220
 
 
221
    public function TimeZoneDropDown($selectedzone) {
 
222
        $structure  = '';
 
223
        $i = 0;
 
224
        
 
225
        // Create a Zone array containing the timezones
 
226
        // From: http://php.oregonstate.edu/manual/en/function.timezone-identifiers-list.php
 
227
        foreach($this->TimeZoneIdentifiersList() as $zone)
 
228
        {
 
229
            $zone                   = explode('/',$zone);
 
230
            $zonen[$i]['continent'] = isset($zone[0]) ? $zone[0] : '';
 
231
            $zonen[$i]['city']      = isset($zone[1]) ? $zone[1] : '';
 
232
            $zonen[$i]['subcity']   = isset($zone[2]) ? $zone[2] : '';
 
233
            $i++;
 
234
        }
 
235
        
 
236
        // Sort them
 
237
        asort($zonen);
 
238
        
 
239
        foreach($zonen as $zone) 
 
240
        {
 
241
            extract($zone);
 
242
            
 
243
            if($continent == 'Africa' || $continent == 'America' || $continent == 'Antarctica' || $continent == 'Arctic' || $continent == 'Asia' || $continent == 'Atlantic' || $continent == 'Australia' || $continent == 'Europe' || $continent == 'Indian' || $continent == 'Pacific' || $continent == 'General') 
 
244
            {
 
245
                if(!isset($selectcontinent)) 
 
246
                {
 
247
                    $structure .= '<optgroup label="'.$continent.'">'; // continent
 
248
                } 
 
249
                elseif($selectcontinent != $continent) 
 
250
                {
 
251
                    $structure .= '</optgroup><optgroup label="'.$continent.'">'; // continent
 
252
                }
 
253
        
 
254
                if(isset($city) != '')
 
255
                {
 
256
                    if (!empty($subcity) != '')
 
257
                    {
 
258
                        $city = $city . '/'. $subcity;
 
259
                    }
 
260
                    $structure .= "<option ".((($continent.'/'.$city)==$selectedzone)?'selected="selected "':'')." value=\"".($continent.'/'.$city)."\">".str_replace('_',' ',$city)."</option>"; //Timezone
 
261
                } 
 
262
                else 
 
263
                {
 
264
                    if (!empty($subcity) != '')
 
265
                    {
 
266
                        $city = $city . '/'. $subcity;
 
267
                    }
 
268
                    $structure .= "<option ".(($continent==$selectedzone)?'selected="selected "':'')." value=\"".$continent."\">".$continent."</option>"; //Timezone
 
269
                }
 
270
        
 
271
                $selectcontinent = $continent;
 
272
            }
 
273
        }
 
274
        $structure .= '</optgroup>';
 
275
 
 
276
        return $structure;
 
277
    }
479
278
        
480
279
        /**
481
280
         * Sets all debugging to maximum
641
440
    {
642
441
        $response = new ResponseManager();
643
442
 
644
 
        if (Config::GetSetting('SETTING_IMPORT_ENABLED') != 'On')
 
443
        if (Config::GetSetting('SETTING_IMPORT_ENABLED') != 1)
645
444
                trigger_error(__('Sorry this function is disabled.'), E_USER_ERROR);
646
445
 
647
446
        // Check we have permission to do this
681
480
    {
682
481
        $db =& $this->db;
683
482
 
684
 
        if (Config::GetSetting('SETTING_IMPORT_ENABLED') != 'On')
 
483
        if (Config::GetSetting('SETTING_IMPORT_ENABLED') != 1)
685
484
                trigger_error(__('Sorry this function is disabled.'), E_USER_ERROR);
686
485
 
687
486
        include('install/header.inc');
754
553
        $db =& $this->db;
755
554
        $response = new ResponseManager();
756
555
 
757
 
        if (Config::GetSetting('SETTING_LIBRARY_TIDY_ENABLED') != 'On')
 
556
        if (Config::GetSetting('SETTING_LIBRARY_TIDY_ENABLED') != 1)
758
557
                trigger_error(__('Sorry this function is disabled.'), E_USER_ERROR);
759
558
 
760
559
        // Also run a script to tidy up orphaned media in the library
809
608
            }
810
609
        }
811
610
 
812
 
        trigger_error(__('Library Tidy Complete'));
 
611
        trigger_error(__('Library Tidy Complete'), E_USER_ERROR);
813
612
    }
814
613
}
815
614
?>