1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16: 17: 18:
19: class Kronolith_Form_EditResourceGroup extends Horde_Form
20: {
21: 22: 23: 24: 25:
26: protected $_resource;
27:
28: 29: 30:
31: public function __construct($vars, $resource)
32: {
33: $this->_resource = $resource;
34: parent::__construct($vars, sprintf(_("Edit %s"), $resource->get('name')));
35:
36: $resources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array('type' => Kronolith_Resource::TYPE_SINGLE));
37: $enum = array();
38: foreach ($resources as $r) {
39: $enum[$r->getId()] = htmlspecialchars($r->get('name'));
40: }
41:
42: $this->addHidden('', 'c', 'text', true);
43: $this->addVariable(_("Name"), 'name', 'text', true);
44: $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
45: $this->addVariable(_("Resources"), 'members', 'multienum', false, false, null, array('enum' => $enum));
46: $this->setButtons(array(_("Save")));
47: }
48:
49: 50: 51:
52: public function execute()
53: {
54: $original_name = $this->_resource->get('name');
55: $new_name = $this->_vars->get('name');
56: $this->_resource->set('name', $new_name);
57: $this->_resource->set('description', $this->_vars->get('description'));
58: $this->_resource->set('members', $this->_vars->get('members'));
59:
60: try {
61: $this->_resource->save();
62: } catch (Exception $e) {
63: throw new Kronolith_Exception(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $e->getMessage()));
64: }
65:
66: return $this->_resource;
67: }
68:
69: }
70: