1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16: 17: 18:
19: class Kronolith_Form_CreateResource extends Horde_Form
20: {
21: 22: 23:
24: public function __construct($vars)
25: {
26: parent::__construct($vars, _("Create Resource"));
27:
28: $responses = array(Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT => _("Always Accept"),
29: Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE => _("Always Decline"),
30: Kronolith_Resource::RESPONSETYPE_AUTO => _("Automatically"),
31: Kronolith_Resource::RESPONSETYPE_MANUAL => _("Manual"),
32: Kronolith_Resource::RESPONSETYPE_NONE => _("None"));
33:
34:
35: $groups = Kronolith::getDriver('Resource')
36: ->listResources(Horde_Perms::READ,
37: array('type' => Kronolith_Resource::TYPE_GROUP));
38: $enum = array();
39: foreach ($groups as $id => $group) {
40: $enum[$id] = $group->get('name');
41: }
42:
43: $this->addVariable(_("Name"), 'name', 'text', true);
44: $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
45: $this->addVariable(_("Email"), 'email', 'email', false);
46: $v = $this->addVariable(_("Response type"), 'responsetype', 'enum', true, false, null, array('enum' => $responses));
47: $v->setDefault(Kronolith_Resource::RESPONSETYPE_AUTO);
48: $this->addVariable(_("Groups"), 'category', 'multienum', false, false, null, array('enum' => $enum));
49: $this->setButtons(array(_("Create")));
50: }
51:
52: 53: 54:
55: public function execute()
56: {
57: $new = array('name' => $this->_vars->get('name'),
58: 'description' => $this->_vars->get('description'),
59: 'response_type' => $this->_vars->get('responsetype'),
60: 'email' => $this->_vars->get('email'));
61: $resource = Kronolith_Resource::addResource(new Kronolith_Resource_Single($new));
62:
63:
64: $groups = $this->_vars->get('category');
65: if (!empty($groups)) {
66: foreach ($groups as $group_id) {
67: $group = Kronolith::getDriver('Resource')->getResource($group_id);
68: $members = $group->get('members');
69: $members[] = $resource->getId();
70: $group->set('members', $members);
71: $group->save();
72: }
73: }
74: }
75:
76: }
77: