Changed the modules settings page, now it is 'automatic', plus a few bug fixes.
[estigi.git] / core / system / system.admin
blob14e15fe2425e8c99dd24bed079a3c844d2be1d9c
1 <?php
3 function system_main_links(){
5         global $admin_links;
7         if(user_access('admin site')){
8                 $admin_links['System']['Settings'][] = array('href' => 'system/admin/settings', 'text' => 'System settings', 'help' => 'Main system settings');
9                 $admin_links['System']['Settings'][] = array('href' => 'system/admin/php', 'text' => 'PHP Info');
10                 $admin_links['System']['Modules'][] = array('href' => 'system/admin/rebuild/modules', 'text' => 'Rebuild Module Settings');
11                 $admin_links['System']['Modules'][] = array('href' => 'system/admin/modules', 'text' => 'Handle Modules');
12         }
15 function system_links_main(&$links){
17         if($links == ''){
18                 return NULL;
19         }
21         foreach($links as $cat => $details){
22                 $final_links .= '<h2> '.$cat.' </h2><hr/>';
24                 foreach($details as $d => $data){
25                         foreach($data as $content => $c){
26                                 $final_links .= path_link($c['href'], $c['text'], $c['help']) .'<br />';
27                         }
28                 }
30                 $final_links .= '<br/>';
31         }
33         return $final_links;
36 /**
37  * Add tabs to the system admin pages
38  */
39 function system_admin_tabs(){
41         $skin_tabs = array('admin' => 'Main Page',
42                                                          'block/admin/new' => 'Add Block'
43                                                 );
45         skin_tabs($skin_tabs);
48 function system_admin_main(){
50         global $admin_links, $skin, $admin_notices;
52         //Call hook for admin main page
53         system_main_links();
54         hooks_invoke('admin_page');
56         $skin['page_title'] = 'Adiminstrative Center';
59         $content = implode("<br />", $admin_notices) . "<br /><br /><hr/><br />";
61         $content .= system_links_main($admin_links);
63         return $content;
67 function system_settings_form(){
69         global $settings;
71         $form['system_admin']['site_name'] = array(
72                 'type'  => 'text',
73                 'text'  => 'Site Name',
74                 'value' => 'esTigi',
75                 'size' => 50
76                 );
78         $form['system_admin']['site_slogan'] = array(
79                 'type'  => 'text',
80                 'text' =>'Slogan',
81                 'value' => '',
82                 'size' => 50
83                 );
85         $form['system_admin']['site_mail'] = array(
86                 'type'  => 'text',
87                 'text' =>'Default email',
88                 'value' => '',
89                 'size' => 50
90                 );
92         $form['system_admin']['anon_name'] = array(
93                 'type'  => 'text',
94                 'text' =>'Anonymous name',
95                 'value' => 'Anonymous',
96                 'size' => 50
97                 );
99         $form['system_admin']['site_frontpage'] = array(
100                 'type'  => 'text',
101                 'text' => 'Front page ' . $settings['base_root'].$settings['base_url'] . $settings['base_path'] . '?x=',
102                 'help' => 'Leave blank for node',
103                 'value' => '',
104                 'size' => 50
105                 );
107         $form['system_admin']['debug_info'] = array(
108                 'type'  => 'select',
109                 'text' => 'Display Debug info',
110                 'help' => 'Leave blank for node',
111                 'value' => 'No',
112                 'options' => array('No', 'Yes'),
113                 'help' => 'This will be displayed for all acounts'
114                 );
116         $form['system_admin']['db_errors'] = array(
117                 'type'  => 'select',
118                 'text' => 'Display Database errors',
119                 'value' => 'Screen Only',
120                 'options' => array('Screen Only', 'Screen and Database', 'Database Only', 'Do not Display'),
121                 'help' => 'This will be displayed for all acounts'
122                 );
124         return $form;
128  * Set values for admin form
130  * @param &$form 
131  *  The form with the values
132  * @param $module
133  *  Working module
134  */
135 function system_convert_form_admin(&$form, $module){
137         //modify default values if they have been set already
138         foreach($form[$module.'_admin'] as $item => $value){
140                 //Fieldsets
141                 if($value['type'] == 'fieldset'){
142                         foreach($value as $field => $field_value){
143                                 if(is_array($field_value)){
144                                         $form[$module.'_admin'][$item][$field]['value'] = core_variable_get($field, $field_value['value'], $module);
145                                 }
146                         } 
147                 }
149         }
154  * Registers modules variables for the modules settings
156  * @param &$form
157  *  The form with the information
158  * @param $module
159  *  The working module
160  * @todo
161  *  Not very convinced in the fieldset handling method
162  */
163 function system_process_form_admin(&$form, $module){
165         global $x;
167         //Remove all variables
168         core_variable_rm(FALSE, $module, TRUE);
170         foreach($form[$module.'_admin'] as $item => $value){
172                 if($value['type'] == 'fieldset'){
173                         foreach($value as $field => $field_value){
174                                 if(is_array($field_value)){
175                                         core_variable_set($field, $field_value['value'], $module);
176                                 }
177                         } 
178                 }
179                 if($value['type'] != 'submit' && $value['type'] != 'fieldset'){
180                         core_variable_set($item, $value['value'], $module);
181                 }
182         }
184         system_warnings("Changes succesfully made");
185         path_redirect($x);
190  * Gets settigs for an administrative form, any module can/should use this.
192  * @param $func
193  *  Function to call in order to get the appropriate form
194  * @param $module
195  *  The module that wants to get/set settings
196  * @param $perms
197  *  An array with a list of access permissions in order to access this form
198  * @param $title
199  *  The page title, will use 'Foo Settings Page' by default
200  * @param $file
201  *  The file extension in which your function is located, default = admin (will load foo.admin)
202  * 
203  */
204 function system_settings_page($func, $module, $perms, $title = NULL, $file = 'admin'){
206         global $form_status, $skin;
208         //No access by default
209         $access = FALSE;
211         foreach($perms as $perm){
212                 if(user_access($perm)){
213                         $access = TRUE;
214                 }
215         }
217         if(!$access){
218                 return PATH_NO_ACCESS;
219         }
221         $skin['page_title'] = (!$title ? $module.' Settings Page' : $title);
223         core_load($module, $file);
225         $form = call_user_func($func);
227         //Convert accordingly
228         if(!isset($_POST['form_id'])){
229                 system_convert_form_admin($form, $module);
230         }
232         //Add a few buttons
233         $form[$module . '_admin']['submit'] = array(
234                 'type' => 'submit',
235                 'value' => 'Submit'
236         );
238         $content = form_form($form, 'post', NULL, (isset($_POST['form_id']) ? FALSE : TRUE));
240         if($form_status == 'verified'){
241                 //Process the form
242                 system_process_form_admin($content, $module);
243         }
245         return $content;
249 //FORMS
251 function system_settings(){
253         global $skin;
255         $skin['page_title'] = 'System main settings';
257         return system_settings_page('system_settings_form', 'system');
262  This page will manually rebuild the modules in the database
264 function system_rebuild_modules(){
266         global $skin;
268         include_once('./includes/modules.admin.inc');
270         $skin['page_title'] = "Module rebuild system";
272         $modules = modules_rebuild_module_settings();
274         $content = "The following modules where proccesed: <br /><br />" ;
276         foreach($modules as $module => $status){
277                 $content .= $module . " ........... " . $status . "<br />";
278         }
280         return $content;
284 function system_modules_overview(){
286         global $skin;
288         include_once('./includes/modules.admin.inc');
290         $skin['page_title'] = "Module administration page";
291         system_warnings("I am not doing any dependency verifications, if you install something without its dependencies you may crash your system.");
293         //Full available module list
294         $modules = modules_get_modules_list();
296         //Required modules
297         $core_modules = modules_required_modules();
299         //Installed modules
300         $module_list = modules_list(-1, TRUE);
302         //Details of all available modules
303         $details = modules_get_module_settings($modules);
305         $content .='<table id="system_module_list">
306                                                 <thead><tr>
307                                                         <th>Status</th>
308                                                         <th>Description</th>
309                                                 </tr>
310                                                 </thead>';
312         foreach($details as $module => $module_details){
314                 if(isset($module_list[$module])){
315                         if($module_list[$module]['status'] == 1){
316                                 $module_status = 'Installed';
317                         }
318                         elseif($module_list[$module]['status'] == 0){
319                                 $module_status = 'Disabled';
320                         }
321                 }
322                 else{
323                         $module_status = 'Not Installed';
324                 }
326                 $content .= '<tr>
327                                                         <td>'.$module_status.'</td>
328                                                         <td>'. module_parse_details($module_details). '</td>
329                                                 </tr>';
331         }
333         $content .= '</table>';
335         return $content;
338 function system_modules_admin($module){
340         global $skin;
341         system_admin_tabs();
343         include_once('./includes/modules.admin.inc');
344         $skin['page_title'] = "Module Administration Page";
345         system_warnings("I am not doing any dependency verifications, if you install something without its dependencies you may crash your system.");
347         $module_list = modules_list(-1, TRUE);
349         //I have no idea if the module is installed or not at this point. Let's find out where it is
350         if(is_file('./modules/'.$module.'/'.$module.'.install')){
351                 include_once('./modules/'.$module.'/'.$module.'.install');
352         }
353         elseif(is_file('./core/'.$module.'/'.$module.'.install')){
354                 include_once('./core/'.$module.'/'.$module.'.install');
355         }
357         //Operations
358         if(isset($_GET['t'])){
359                 if($_GET['t'] == 'enable' && user_access('admin modules')){
360                         module_admin_status(1, $module);
361                 }
362                 else if($_GET['t'] == 'install' && user_access('admin modules')){
363                         if(function_exists($module.'_install')){
364                                 call_user_func($module.'_install'); //Install the module, or at least tell it to run its own installation procedures
365                                 echo module_admin_status(1, $module);
366                         }
367                 }
368         }
370         if(!isset($module_list[$module])){
371                 $module_details = array($module => 'modules/'.$module.'/'.$module.'.module', 'status' => -1);
372         }
373         else{
374                 $module_details = $module_list[$module];
375         }
377         $module_ini = modules_get_module_settings(array($module => $module_details[$module]));
379         if($module_details['status'] == 1){
380                 $module_status = 'Installed';
381         }
382         elseif($module_details['status'] == 0){
383                 $module_status = 'Disabled';
384         }
385         else{
386                 $module_status = 'Not Installed';
387         }
389         $content = '<h2>Module Details</h2';
390         $content .= '<div>'.module_parse_details($module_ini[$module]).'</div><br />';
391         $content .= 'Module Status: ' . $module_status . '<br />';
392         $content .= 'Operations: ';
394         if($module_details['status'] == 1){
395                 $content .= path_link('system/admin/modules/admin/'.$module.'&t=uninstall', 'Uninstall');
396                 $content .= ' ' . path_link('system/admin/modules/admin/'.$module.'&t=disable', 'Disable');
397         }
398         elseif($module_details['status'] == -1){
399                 $content .= path_link('system/admin/modules/admin/'.$module.'&t=install', 'Install');
400         }
401         else{
402                 $content .= path_link('system/admin/modules/admin/'.$module.'&t=enable', 'Enable');
403         }
405         //Perms
406         if(function_exists($module.'_perms') && $module_details['status'] == 1){
407                 $content .= system_module_perms($module);
408         }
410         return $content;
414  * Permisions?
416  * 
418 function system_module_perms($module){
420         $roles = user_roles();
421         core_load('form', 'api');
422         //foreach()
423         $content = form_set_head('roles_perms');
424         $content .= '<table id="roles_perms">
425                                                 <thead><tr>
426                                                         <th>Owner</th>
427                                                         <th>(Id)Title</th>
428                                                         <th>Pos</th>
429                                                 </tr>
430                                                 </thead>';
432         $content .= '<tr>
433                                                 <td>'.$block['owner'].'</td>
434                                                 <td> ('. $block['rid']. ')' .$block['title']. '</td>
435                                                 <td>'.$pos.'</td>
436                                         </tr>';
438         $content .= '</table></form>';
440         return $content;
445  *      Page to display php information
447 function system_show_php_info(){
449         ob_start () ;
450         phpinfo () ;
451         $pinfo = ob_get_contents () ;
452         ob_end_clean () ;
454         // the name attribute "module_Zend Optimizer" of an anker-tag is not xhtml valide, so replace it with "module_Zend_Optimizer"
455         $content = ( str_replace ( "module_Zend Optimizer", "module_Zend_Optimizer", preg_replace ( '%^.*<body>(.*)</body>.*$%ms', '$1', $pinfo ) ) ) ;
456         return $pinfo;