diff --git a/preferences/inc/class.preferences_hooks.inc.php b/preferences/inc/class.preferences_hooks.inc.php index 69f0fef770..78ae8b1882 100644 --- a/preferences/inc/class.preferences_hooks.inc.php +++ b/preferences/inc/class.preferences_hooks.inc.php @@ -144,7 +144,7 @@ class preferences_hooks 'type' => 'select', 'label' => 'Theme (colors/fonts) Selection', 'name' => 'theme', - 'values' => isset($GLOBALS['egw']->framework) ? $GLOBALS['egw']->framework->list_themes() : array(), + 'values' => !$hook_data['setup'] ? $GLOBALS['egw']->framework->list_themes() : array(), 'help' => 'A theme defines the colors and fonts used by the template.', 'xmlrpc' => True, 'admin' => False, diff --git a/preferences/inc/class.preferences_settings.inc.php b/preferences/inc/class.preferences_settings.inc.php index 4fb0a71d15..339b8d9116 100644 --- a/preferences/inc/class.preferences_settings.inc.php +++ b/preferences/inc/class.preferences_settings.inc.php @@ -43,71 +43,222 @@ class preferences_settings */ function index(array $content=null, $msg='') { - $tpl = new etemplate_new('preferences.settings'); + $tpl = new etemplate_old('preferences.settings'); if (!is_array($content)) { $appname = isset($_GET['appname']) ? $_GET['appname'] : 'preferences'; - if (!$this->call_hook($appname)) + $type = 'user'; + $account_id = $GLOBALS['egw_info']['user']['account_id']; + if ($GLOBALS['egw_info']['user']['apps']['admin'] && + isset($_GET['account_id']) && (int)$_GET['account_id'] && + $GLOBALS['egw']->accounts->exists((int)$_GET['account_id'])) { - throw new egw_exception_wrong_parameter("Could not find settings for application: ".$_GET['appname']); + $account_id = (int)$_GET['account_id']; + $type = $_GET['account_id'] < 0 ? 'group' : 'user'; } - //_debug_array($this->settings); exit; - $sel_options = $readonlys = $content = $tabs = array(); - // disable all but first tab and name current tab "tab1", for apps not using sections - $tab = 'tab1'; - $readonlys['tabs'] = array( - 'tab2' => true, - 'tab3' => true, - 'tab4' => true, - 'tab5' => true, - ); - - foreach($this->settings as $setting) - { - if (!is_array($setting)) continue; - switch($setting['type']) - { - case 'section': - $tabs[] = $setting['title']; - $tab = 'tab'.count($tabs); - $tpl->setElementAttribute($tab, 'label', $setting['title']); - $readonlys['tabs'][$tab] = false; - // fall through - case 'subsection': // is in old code, but never seen it used - continue 2; - - case 'input': - $setting['type'] = 'textbox'; - break; - case 'check': - $setting['type'] = 'select'; - $setting['values'] = array('no', 'yes'); - break; - case 'multiselect': - $setting['type'] = 'select'; - break; - case 'color': - $setting['type'] = 'colorpicker'; - break; - } - // move values/options to sel_options array - if (isset($setting['values']) && is_array($setting['values'])) - { - // need to call fix_encoded_options manually, as id is not matching because of autorepeat - etemplate_widget_menupopup::fix_encoded_options($setting['values']); - $sel_options[$tab][count($content[$tab]).'[value]'] = $setting['values']; - unset($setting['values']); - } - $content[$tab][] = $setting; - } - //_debug_array($content); exit; - //_debug_array($sel_options); exit; } else { - $this->appname = $content['appname']; + //_debug_array($content); + $appname = $content['appname'] ? $content['appname'] : 'preferences'; + list($type,$account_id) = explode(':', $content['type']); + $prefs = array_merge($content['tab1'], $content['tab2'], $content['tab3'], $content['tab4']); + if ($content['button']) + { + list($button) = each($content['button']); + switch($button) + { + case 'save': + case 'apply': + // ToDo: save preferences + + $msg = lang('Preferences saved.').array2string($prefs); + if ($button == 'apply') break; + // fall throught + case 'cancel': + egw::redirect_link('/preferences/index.php'); + } + } + //_debug_array($prefs); } - $tpl->exec('preferences.preferences_settings.index', $content, $sel_options, $readonlys, $content); + if ($account_id && $account_id != $GLOBALS['egw']->preferences->account_id) + { + $GLOBALS['egw']->preferences->account_id = $account_id; + $GLOBALS['egw']->preferences->read_repository(); + } + $content = $this->get_content($appname, $type, $sel_options, $readonlys, $tpl); + $content['msg'] = $msg; + + $tpl->exec('preferences.preferences_settings.index', $content, $sel_options, $readonlys, array( + 'appname' => $content['appname'], + 'type' => $content['type'], + )); + } + + /** + * Get content, sel_options and readonlys for given appname and type + * + * @param string $appname + * @param string $type + * @param array &$sel_options + * @param array &$readonlys + * @param etemplate $tpl + * @throws egw_exception_wrong_parameter + * @return array content + */ + function get_content($appname, $type, &$sel_options, &$readonlys, $tpl) + { + if (!$this->call_hook($appname, $type)) + { + throw new egw_exception_wrong_parameter("Could not find settings for application: ".$_GET['appname']); + } + if ($appname == 'preferences') $appname = 'common'; + $attribute = $type == 'group' ? 'user' : $type; + //error_log(__METHOD__."('$appname', '$type' ) attribute='$attribute', preferences->account_id=".$GLOBALS['egw']->preferences->account_id); + + //_debug_array($this->settings); exit; + $sel_options = $readonlys = $content = $tabs = array(); + // disable all but first tab and name current tab "tab1", for apps not using sections + $tab = 'tab1'; + foreach($this->settings as $setting) + { + if (!is_array($setting)) continue; + if ($type != 'forced' && !empty($GLOBALS['egw']->preferences->forced[$appname][$setting['name']])) + { + continue; // forced preferences are not displayed, unless we edit them + } + switch($old_type = $setting['type']) + { + case 'section': + $tab = 'tab'.(1+count($tabs)); + $tabs[$tab] = $setting['title']; + $tpl->setElementAttribute($tab, 'label', $setting['title']); + if (count($tabs) > 5) + { + throw new egw_exception_assertion_failed("App $appname has more then 4 preference tabs!"); + } + // fall through + case 'subsection': // is in old code, but never seen it used + continue 2; + + case 'vfs_file': + case 'vfs_dir': + case 'vfs_dirs': + case 'notify': + // ToDo: implementation ... + // handle as input for now + case 'input': + $setting['type'] = 'textbox'; + if (isset($setting['size'])) + { + $tpl->setElementAttribute($tab.'['.$setting['name'].']', 'size', $setting['size']); + } + break; + case 'check': + $setting['type'] = 'select'; + $setting['values'] = array('1' => lang('yes'), '0' => lang('no')); + break; + case 'multiselect': + $setting['type'] = 'select'; + $tpl->setElementAttribute($tab.'['.$setting['name'].']', 'multiple', 5); + if (!isset($setting['size'])) $setting['size'] = '5'; // old eT + break; + case 'color': + $setting['type'] = 'colorpicker'; + break; + } + // move values/options to sel_options array + if (isset($setting['values']) && is_array($setting['values'])) + { + if ($old_type != 'multiselect') + { + switch($type) + { + case 'user': + $setting['values'] = array('' => lang('Use default'))+$setting['values']; + break; + case 'forced'; + $setting['values'] = array('' => lang('Users choice'))+$setting['values']; + break; + } + } + // need to call fix_encoded_options manually, as id is not matching because of autorepeat + etemplate_widget_menupopup::fix_encoded_options($setting['values']); + $sel_options[$setting['name']] = $setting['values']; + } + if ($type == 'user') + { + $default = $GLOBALS['egw']->preferences->default[$appname][$setting['name']]; + if (isset($setting['values']) && (string)$setting['values'][$default] !== '') + { + $default = $setting['values'][$default]; + } + elseif (strpos($default, ',') !== false) + { + $values = array(); + foreach(explode(',', $default) as $value) + { + if (isset($setting['values'][$value])) $values[] = $setting['values'][$value]; + } + if ($values) $default = implode(', ', $values); + } + } + $content[$tab][] = array( + 'name' => $setting['name'], + 'type' => $setting['type'], + 'label' => str_replace('
', "\n", $setting['label']), + 'help' => str_replace('
', "\n", $setting['help']), + 'size' => $setting['size'], // old eT + 'default' => !empty($default) ? lang('Default').': '.$default : null, + ); + $content[$tab][$setting['name']] = $GLOBALS['egw']->preferences->{$attribute}[$appname][$setting['name']]; + //if ($old_type == 'multiselect') $content[$tab][$setting['name']] = explode(',', $content[$tab][$setting['name']]); + } + // disabling not used tabs, does NOT work in new eT + $readonlys['tabs'] = array( + 'tab2' => !isset($tabs['tab2']), + 'tab3' => !isset($tabs['tab3']), + 'tab4' => !isset($tabs['tab4']), + 'tab5' => !isset($tabs['tab5']), + ); + $tpl->setElementAttribute('tabs', 'label', implode('|', $tabs)); // old eT + + $content['appname'] = $appname; + $sel_options['appname'] = array(); + foreach($GLOBALS['egw']->hooks->hook_implemented('settings') as $app) + { + if ($app != 'preferences' && $GLOBALS['egw_info']['apps'][$app]) + { + $sel_options['appname'][$app] = $GLOBALS['egw_info']['apps'][$app]['title']; + } + } + natcasesort($sel_options['appname']); + + if ($GLOBALS['egw_info']['apps']['admin']) + { + $sel_options['type'] = array( + 'user' => 'Your preferences', + 'default' => 'Default preferences', + 'forced' => 'Forced preferences', + ); + $content['type'] = $type; + if ($GLOBALS['egw']->preferences->account_id != $GLOBALS['egw_info']['user']['account_id']) + { + $content['type'] .= ':'.$GLOBALS['egw']->preferences->account_id; + $sel_options['type'][$content['type']] = common::grab_owner_name($GLOBALS['egw']->preferences->account_id); + } + foreach($GLOBALS['egw']->accounts->search(array('type' => 'groups', 'sort' => 'account_lid')) as $account_id => $group) + { + $sel_options['type']['group:'.$account_id] = common::display_fullname($group['account_lid'], '', '', $account_id); + } + } + else + { + $content['type'] = 'user'; + } + //_debug_array($content); exit; + //_debug_array($sel_options); //exit; + return $content; } /** @@ -118,7 +269,7 @@ class preferences_settings * @param string $appname * @return boolean */ - protected function call_hook($appname) + protected function call_hook($appname, $type='user') { $this->appname = $appname; @@ -128,16 +279,19 @@ class preferences_settings translation::add_app('preferences'); // we need the prefs translations too } + // make type available, to hooks from applications can use it, eg. activesync + $GLOBALS['type'] = $type; + // calling app specific settings hook $settings = $GLOBALS['egw']->hooks->single('settings',$this->appname); // it either returns the settings or save it in $GLOBALS['settings'] (deprecated!) if (isset($settings) && is_array($settings) && $settings) { - $this->settings = array_merge($this->settings,$settings); + $this->settings = array_merge($this->settings, $settings); } elseif(isset($GLOBALS['settings']) && is_array($GLOBALS['settings']) && $GLOBALS['settings']) { - $this->settings = array_merge($this->settings,$GLOBALS['settings']); + $this->settings = array_merge($this->settings, $GLOBALS['settings']); } else { diff --git a/preferences/setup/etemplates.inc.php b/preferences/setup/etemplates.inc.php new file mode 100644 index 0000000000..e946ebfebd --- /dev/null +++ b/preferences/setup/etemplates.inc.php @@ -0,0 +1,30 @@ + 'preferences.settings','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:5:{i:0;a:3:{s:4:"name";s:3:"msg";s:4:"type";s:5:"label";s:4:"span";s:10:",redItalic";}i:1;a:3:{s:4:"type";s:6:"select";s:4:"name";s:4:"type";s:8:"onchange";i:1;}i:2;a:5:{s:4:"type";s:6:"select";s:4:"name";s:7:"appname";s:4:"size";s:18:"Common preferences";s:5:"label";s:11:"Application";s:8:"onchange";i:1;}i:3;a:3:{s:4:"name";s:29:"tabs=tab1|tab2|tab3|tab4|tab5";s:4:"type";s:3:"tab";s:5:"label";s:29:"Tab 1|Tab 2|Tab 3|Tab 4|Tab 5";}i:4;a:5:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"3";i:1;a:3:{s:5:"label";s:4:"Save";s:4:"name";s:12:"button[save]";s:4:"type";s:6:"button";}i:2;a:3:{s:5:"label";s:5:"Apply";s:4:"name";s:13:"button[apply]";s:4:"type";s:6:"button";}i:3;a:3:{s:5:"label";s:6:"Cancel";s:4:"name";s:14:"button[cancel]";s:4:"type";s:6:"button";}}}','size' => '','style' => '','modified' => '1367564824',); + +$templ_data[] = array('name' => 'preferences.settings.general','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:7:{s:4:"type";s:4:"grid";s:4:"name";s:7:"general";s:4:"data";a:2:{i:0;a:2:{s:1:"A";s:3:"50%";s:2:"c1";s:7:"prefRow";}i:1;a:2:{s:1:"A";a:5:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";s:4:"span";s:9:",prefName";i:1;a:2:{s:4:"name";s:13:"${row}[label]";s:4:"type";s:5:"label";}i:2;a:3:{s:4:"name";s:12:"${row}[help]";s:4:"type";s:5:"label";s:4:"span";s:9:",prefHelp";}}s:1:"B";a:4:{s:4:"name";s:13:"${row}[value]";s:4:"type";s:4:"text";s:4:"span";s:10:",prefValue";s:4:"size";s:13:"@${row}[size]";}}}s:4:"cols";i:2;s:4:"rows";i:1;s:4:"size";s:16:"100%,,,prefTable";s:7:"options";a:2:{i:3;s:9:"prefTable";i:0;s:4:"100%";}}}','size' => '100%,,,prefTable','style' => '','modified' => '1367140794',); + +$templ_data[] = array('name' => 'preferences.settings.tab1','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:7:{s:4:"type";s:4:"grid";s:4:"name";s:4:"tab1";s:4:"data";a:2:{i:0;a:2:{s:1:"A";s:3:"50%";s:2:"c1";s:7:"prefRow";}i:1;a:2:{s:1:"A";a:5:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";s:4:"span";s:9:",prefName";i:1;a:3:{s:3:"for";s:13:"${row}[value]";s:4:"name";s:13:"${row}[label]";s:4:"type";s:5:"label";}i:2;a:3:{s:4:"name";s:12:"${row}[help]";s:4:"type";s:5:"label";s:4:"span";s:9:",prefHelp";}}s:1:"B";a:4:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";i:1;a:5:{s:4:"type";s:13:"@${row}[type]";s:4:"size";s:13:"@${row}[size]";s:7:"no_lang";s:1:"1";s:4:"name";s:13:"@${row}[name]";s:4:"span";s:10:",prefValue";}i:2;a:4:{s:7:"no_lang";s:1:"1";s:4:"name";s:15:"${row}[default]";s:4:"type";s:5:"label";s:4:"span";s:12:",prefDefault";}}}}s:4:"cols";i:2;s:4:"rows";i:1;s:4:"size";s:33:"100%,,,prefTable egwGridView_grid";s:7:"options";a:2:{i:3;s:26:"prefTable egwGridView_grid";i:0;s:4:"100%";}}}','size' => '100%,,,prefTable egwGridView_grid','style' => '','modified' => '1367565943',); + +$templ_data[] = array('name' => 'preferences.settings.tab2','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:7:{s:4:"type";s:4:"grid";s:4:"name";s:4:"tab2";s:4:"data";a:2:{i:0;a:2:{s:1:"A";s:3:"50%";s:2:"c1";s:7:"prefRow";}i:1;a:2:{s:1:"A";a:5:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";s:4:"span";s:9:",prefName";i:1;a:3:{s:3:"for";s:13:"${row}[value]";s:4:"name";s:13:"${row}[label]";s:4:"type";s:5:"label";}i:2;a:3:{s:4:"name";s:12:"${row}[help]";s:4:"type";s:5:"label";s:4:"span";s:9:",prefHelp";}}s:1:"B";a:4:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";i:1;a:5:{s:4:"type";s:13:"@${row}[type]";s:4:"size";s:13:"@${row}[size]";s:7:"no_lang";s:1:"1";s:4:"name";s:13:"@${row}[name]";s:4:"span";s:10:",prefValue";}i:2;a:4:{s:7:"no_lang";s:1:"1";s:4:"name";s:15:"${row}[default]";s:4:"type";s:5:"label";s:4:"span";s:12:",prefDefault";}}}}s:4:"cols";i:2;s:4:"rows";i:1;s:4:"size";s:33:"100%,,,prefTable egwGridView_grid";s:7:"options";a:2:{i:3;s:26:"prefTable egwGridView_grid";i:0;s:4:"100%";}}}','size' => '100%,,,prefTable egwGridView_grid','style' => '','modified' => '1367566575',); + +$templ_data[] = array('name' => 'preferences.settings.tab3','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:7:{s:4:"type";s:4:"grid";s:4:"name";s:4:"tab3";s:4:"data";a:2:{i:0;a:2:{s:1:"A";s:3:"50%";s:2:"c1";s:7:"prefRow";}i:1;a:2:{s:1:"A";a:5:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";s:4:"span";s:9:",prefName";i:1;a:3:{s:3:"for";s:13:"${row}[value]";s:4:"name";s:13:"${row}[label]";s:4:"type";s:5:"label";}i:2;a:3:{s:4:"name";s:12:"${row}[help]";s:4:"type";s:5:"label";s:4:"span";s:9:",prefHelp";}}s:1:"B";a:4:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";i:1;a:5:{s:4:"type";s:13:"@${row}[type]";s:4:"size";s:13:"@${row}[size]";s:7:"no_lang";s:1:"1";s:4:"name";s:13:"@${row}[name]";s:4:"span";s:10:",prefValue";}i:2;a:4:{s:7:"no_lang";s:1:"1";s:4:"name";s:15:"${row}[default]";s:4:"type";s:5:"label";s:4:"span";s:12:",prefDefault";}}}}s:4:"cols";i:2;s:4:"rows";i:1;s:4:"size";s:33:"100%,,,prefTable egwGridView_grid";s:7:"options";a:2:{i:3;s:26:"prefTable egwGridView_grid";i:0;s:4:"100%";}}}','size' => '100%,,,prefTable egwGridView_grid','style' => '','modified' => '1367566588',); + +$templ_data[] = array('name' => 'preferences.settings.tab4','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:7:{s:4:"type";s:4:"grid";s:4:"name";s:4:"tab4";s:4:"data";a:2:{i:0;a:2:{s:1:"A";s:3:"50%";s:2:"c1";s:7:"prefRow";}i:1;a:2:{s:1:"A";a:5:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";s:4:"span";s:9:",prefName";i:1;a:3:{s:3:"for";s:13:"${row}[value]";s:4:"name";s:13:"${row}[label]";s:4:"type";s:5:"label";}i:2;a:3:{s:4:"name";s:12:"${row}[help]";s:4:"type";s:5:"label";s:4:"span";s:9:",prefHelp";}}s:1:"B";a:4:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";i:1;a:5:{s:4:"type";s:13:"@${row}[type]";s:4:"size";s:13:"@${row}[size]";s:7:"no_lang";s:1:"1";s:4:"name";s:13:"@${row}[name]";s:4:"span";s:10:",prefValue";}i:2;a:4:{s:7:"no_lang";s:1:"1";s:4:"name";s:15:"${row}[default]";s:4:"type";s:5:"label";s:4:"span";s:12:",prefDefault";}}}}s:4:"cols";i:2;s:4:"rows";i:1;s:4:"size";s:33:"100%,,,prefTable egwGridView_grid";s:7:"options";a:2:{i:3;s:26:"prefTable egwGridView_grid";i:0;s:4:"100%";}}}','size' => '100%,,,prefTable egwGridView_grid','style' => '','modified' => '1367566604',); + +$templ_data[] = array('name' => 'preferences.settings.tab5','template' => '','lang' => '','group' => '0','version' => '1.9.001','data' => 'a:1:{i:0;a:7:{s:4:"type";s:4:"grid";s:4:"name";s:4:"tab5";s:4:"data";a:2:{i:0;a:2:{s:1:"A";s:3:"50%";s:2:"c1";s:7:"prefRow";}i:1;a:2:{s:1:"A";a:5:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";s:4:"span";s:9:",prefName";i:1;a:3:{s:3:"for";s:13:"${row}[value]";s:4:"name";s:13:"${row}[label]";s:4:"type";s:5:"label";}i:2;a:3:{s:4:"name";s:12:"${row}[help]";s:4:"type";s:5:"label";s:4:"span";s:9:",prefHelp";}}s:1:"B";a:4:{s:4:"type";s:3:"box";s:4:"size";s:1:"2";i:1;a:5:{s:4:"type";s:13:"@${row}[type]";s:4:"size";s:13:"@${row}[size]";s:7:"no_lang";s:1:"1";s:4:"name";s:13:"@${row}[name]";s:4:"span";s:10:",prefValue";}i:2;a:4:{s:7:"no_lang";s:1:"1";s:4:"name";s:15:"${row}[default]";s:4:"type";s:5:"label";s:4:"span";s:12:",prefDefault";}}}}s:4:"cols";i:2;s:4:"rows";i:1;s:4:"size";s:33:"100%,,,prefTable egwGridView_grid";s:7:"options";a:2:{i:3;s:26:"prefTable egwGridView_grid";i:0;s:4:"100%";}}}','size' => '100%,,,prefTable egwGridView_grid','style' => '','modified' => '1367583114',); + +$templ_data[] = array('name' => 'preferences.test','template' => '','lang' => '','group' => '0','version' => '','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:2:{i:0;a:0:{}i:1;a:1:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:5:"label";s:5:"Label";s:4:"name";s:2:"id";}}}s:4:"rows";i:1;s:4:"cols";i:1;}}','size' => '','style' => '','modified' => '1367563385',); + diff --git a/preferences/templates/default/app.css b/preferences/templates/default/app.css index 43061f9f83..18a021572b 100644 --- a/preferences/templates/default/app.css +++ b/preferences/templates/default/app.css @@ -14,7 +14,7 @@ table.prefTable { tr.prefRow { position: relative; } -td.prefName, td.prefValue { +td.prefName { width: 50%; } .prefHelp { @@ -30,4 +30,10 @@ td.prefName, td.prefValue { tr.prefRow:hover .prefHelp { display: block; z-index: 10; /* FF: displays it under next prefName without */ -} \ No newline at end of file +} +.prefDefault, .prefValue { + float: left; +} +.prefValue { + margin-right: 5px; +} diff --git a/preferences/templates/default/settings.xet b/preferences/templates/default/settings.xet index 11624c770f..eb0e14180b 100644 --- a/preferences/templates/default/settings.xet +++ b/preferences/templates/default/settings.xet @@ -10,10 +10,13 @@ - + - + + + + @@ -27,10 +30,13 @@ - + - + + + + @@ -44,10 +50,13 @@ - + - + + + + @@ -61,10 +70,13 @@ - + - + + + + @@ -78,16 +90,25 @@ - + - + + + +