1: <?php
 2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 
13: class Sam_Form_Options extends Horde_Form
14: {
15:     public function __construct($vars)
16:     {
17:         parent::__construct($vars, _("Spam Options"));
18:         $this->setButtons(_("Save"), true);
19: 
20:         try {
21:             $sam_driver = $GLOBALS['injector']->getInstance('Sam_Driver');
22:         } catch (Sam_Exception $e) {
23:             return;
24:         }
25: 
26:         foreach (Sam::getAttributes() as $key => $attribute) {
27:             if (!Sam::infoAttribute($attribute['type']) &&
28:                 !$sam_driver->hasCapability($key)) {
29:                 continue;
30:             }
31:             $var = $this->addVariable($attribute['label'],
32:                                       $key, $attribute['type'],
33:                                       !empty($attribute['required']),
34:                                       !empty($attribute['readonly']),
35:                                       isset($attribute['description'])
36:                                           ? $attribute['description']
37:                                           : null,
38:                                       isset($attribute['params'])
39:                                           ? $attribute['params']
40:                                           : array());
41: 
42:             $var->setHelp($key);
43:             if (isset($attribute['default'])) {
44:                 $var->setDefault($attribute['default']);
45:             }
46: 
47:             if ($vars->exists($key)) {
48:                 continue;
49:             }
50: 
51:             if (isset($attribute['basepref'])) {
52:                 53: 54: 
55:                 $value = $sam_driver->getListOption($attribute['basepref']);
56: 
57:                 
58:                 $elements = preg_split('/\n/', $value, -1, PREG_SPLIT_NO_EMPTY);
59: 
60:                 foreach ($elements as $element) {
61:                     62: 
63:                     $pref = explode(' ', $element);
64: 
65:                     
66:                     if (isset($pref[0]) && $pref[0] == $attribute['subtype']) {
67:                         if (isset($pref[1])) {
68:                             
69:                             $vars->set($key, $pref[1]);
70:                         } else {
71:                             $vars->set($key, '');
72:                         }
73:                         break;
74:                     }
75:                 }
76:             } else {
77:                 $value = $sam_driver->getOption($key);
78:                 if (!is_null($value)) {
79:                     if ($attribute['type'] == 'boolean') {
80:                         $boolean = $sam_driver->optionToBoolean($value);
81:                         $vars->set($key, $boolean);
82:                     } else {
83:                         $vars->set($key, $value);
84:                     }
85:                 }
86:             }
87:         }
88: 
89:         if ($sam_driver->hasCapability('global_defaults') &&
90:             $GLOBALS['registry']->isAdmin()) {
91:             $this->addVariable('', '', 'spacer', false);
92:             $var = $this->addVariable(_("Make Settings Global"),
93:                                       'global_defaults', 'boolean', false);
94:             $var->setHelp('global_defaults');
95:         }
96:     }
97: }
98: