Example #1
0
 /**
  * AccountDetailsForm constructor.
  *
  * @param mixed reference $vars
  * @return boolean
  */
 function __construct(&$vars)
 {
     $action = $vars->get('action');
     if ($action == 'edit') {
         $title = _("Edit Number");
     } else {
         $title = _("Add Number");
     }
     parent::__construct($vars, $title);
     $this->addHidden('', 'action', 'text', true);
     //$this->addHidden('', 'oldaccount', 'text', false);
     $this->addVariable(_("Telephone Number"), 'number', 'phone', true);
     $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
     $accounts = $shout->storage->getAccounts();
     $list = array();
     foreach ($accounts as $id => $info) {
         $list[$id] = $info['name'];
     }
     $select = $this->addVariable(_("Account Code"), 'accountcode', 'enum', false, false, null, array($list));
     $action =& Horde_Form_Action::factory('reload');
     $select->setAction($action);
     $select->setOption('trackchange', true);
     $accountcode = $vars->get('accountcode');
     if (!empty($accountcode)) {
         $menus = $shout->storage->getMenus($accountcode);
         $list = array('INACTIVE' => '-- None --');
         foreach ($menus as $id => $info) {
             $list[$id] = $info['name'];
         }
         $this->addVariable(_("Menu"), 'menuName', 'enum', false, false, null, array($list));
     }
     return true;
 }
Example #2
0
 public function __construct(&$vars)
 {
     global $whups_driver;
     parent::__construct($vars, _("Create Ticket - Step 2"));
     $types = $whups_driver->getTypes($vars->get('queue'));
     $info = $whups_driver->getQueue($vars->get('queue'));
     $type = $whups_driver->getDefaultType($vars->get('queue'));
     if (count($types) == 0) {
         $typetype = 'invalid';
         $type_params = array(_("There are no ticket types associated with this queue; until there are, you cannot create any tickets in this queue."));
     } else {
         $typetype = 'enum';
         $type_params = array($types);
         if (empty($type) || !isset($types[$type])) {
             $type_params[] = _("Choose:");
         }
     }
     $types =& $this->addVariable(_("Ticket Type"), 'type', $typetype, true, false, null, $type_params);
     $types->setDefault($type);
     if (!empty($info['versioned'])) {
         $versions = $whups_driver->getVersions($vars->get('queue'));
         if (count($versions) == 0) {
             $vtype = 'invalid';
             $v_params = array(_("This queue requires that you specify a version, but there are no versions associated with it. Until versions are created for this queue, you will not be able to create tickets."));
         } else {
             $vtype = 'enum';
             $v_params = array($versions);
         }
         $this->addVariable(_("Queue Version"), 'version', $vtype, true, false, null, $v_params);
     } else {
         $types->setAction(Horde_Form_Action::factory('submit'));
     }
 }
Example #3
0
 /**
  * Returns the submitted or default value of this variable.
  * If an action is attached to this variable, the value will get passed to
  * the action object.
  *
  * @param Variables $vars  The {@link Variables} instance of the submitted
  *                         form.
  * @param integer $index   If the variable is an array variable, this
  *                         specifies the array element to return.
  *
  * @return mixed  The variable or element value.
  */
 function getValue(&$vars, $index = null)
 {
     if ($this->_arrayVal) {
         $name = str_replace('[]', '', $this->varName);
     } else {
         $name = $this->varName;
     }
     $value = $vars->getExists($name, $wasset);
     if (!$wasset) {
         $value = $this->getDefault();
     }
     if ($this->_arrayVal && !is_null($index)) {
         if (!$wasset && !is_array($value)) {
             $return = $value;
         } else {
             $return = isset($value[$index]) ? $value[$index] : null;
         }
     } else {
         $return = $value;
     }
     if ($this->hasAction()) {
         $this->_action->setValues($vars, $return, $this->_arrayVal);
     }
     return $return;
 }
Example #4
0
 public function __construct($vars, Turba_Object $contact = null)
 {
     // @TODO: $addSources should be injected
     global $addSources, $notification;
     parent::__construct($vars, '', 'turba_form_addcontact');
     $this->_contact = $contact;
     $this->setButtons(_("Add"));
     $this->addHidden('', 'url', 'text', false);
     $this->addHidden('', 'key', 'text', false);
     /* Check if a source selection box is required. */
     if (count($addSources) > 1) {
         /* Multiple sources, show a selection box. */
         $options = array();
         foreach ($addSources as $key => $config) {
             $options[$key] = $config['title'];
         }
         $v = $this->addVariable(_("Choose an address book"), 'source', 'enum', true, false, null, array($options, true));
         $action = Horde_Form_Action::factory('submit');
         $v->setAction($action);
         $v->setOption('trackchange', true);
         if (is_null($vars->get('formname')) && $vars->get($v->getVarName()) != $vars->get('__old_' . $v->getVarName())) {
             $notification->push(sprintf(_("Selected address book \"%s\"."), $addSources[$vars->get('source')]['title']), 'horde.message');
         }
     } else {
         /* One source, no selection box but store the value in a
          * hidden field. */
         $this->addHidden('', 'source', 'text', true);
     }
     if ($this->_contact) {
         parent::_addFields($this->_contact);
     }
 }
 public function __construct(&$vars)
 {
     parent::__construct($vars, _("Edit Attribute"));
     $attribute = $vars->get('attribute');
     $info = $GLOBALS['whups_driver']->getAttributeDesc($attribute);
     $this->addHidden('', 'type', 'int', true, true);
     $this->addHidden('', 'attribute', 'int', true, true);
     $pname =& $this->addVariable(_("Attribute Name"), 'attribute_name', 'text', true);
     $pname->setDefault($info['name']);
     $pdesc =& $this->addVariable(_("Attribute Description"), 'attribute_description', 'text', true);
     $pdesc->setDefault($info['description']);
     $preq =& $this->addVariable(_("Required Attribute?"), 'attribute_required', 'boolean', false);
     $preq->setDefault($info['required']);
     $ptype =& $this->addVariable(_("Attribute Type"), 'attribute_type', 'enum', true, false, null, array(Whups::fieldTypeNames()));
     $ptype->setAction(Horde_Form_Action::factory(array('whups', 'whups_reload'), array('formname' => 'whups_form_admin_editattributesteptwo_reload')));
     $ptype->setDefault($info['type']);
     $type = $vars->get('attribute_type');
     if (empty($type)) {
         $type = $info['type'];
     }
     foreach (Whups::fieldTypeParams($type) as $param => $param_info) {
         $pparam =& $this->addVariable($param_info['label'], 'attribute_params[' . $param . ']', $param_info['type'], false);
         if (isset($info['params'][$param])) {
             $pparam->setDefault($info['params'][$param]);
         }
     }
 }
Example #6
0
 public function __construct(&$vars)
 {
     parent::__construct($vars, _("Select Client"));
     $action =& Horde_Form_Action::factory('submit');
     list($clienttype, $clientparams) = $this->getClientType();
     $cli =& $this->addVariable(_("Client"), 'client_id', $clienttype, true, false, null, $clientparams);
     $cli->setAction($action);
     $this->setButtons(_("Edit Deliverables"));
 }
Example #7
0
 public function __construct($vars)
 {
     parent::__construct($vars);
     // This is probably wrong. The library should get the driver
     // or the properties passed
     $sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
     $this->appendButtons(_("Save Category"));
     $category_id = $vars->get('category_id');
     $priorities = array();
     for ($i = 0; $i < 100; $i++) {
         $priorities[] = $i;
     }
     try {
         $allproperties = $sesha_driver->getProperties();
     } catch (Sesha_Exception $e) {
         throw new Sesha_Exception($e);
     }
     $a = array();
     foreach ($allproperties as $p) {
         $a[$p['property_id']] = $p['property'];
     }
     if (!empty($category_id)) {
         try {
             $properties = $sesha_driver->getPropertiesForCategories($category_id);
         } catch (Sesha_Exception $e) {
             throw new Sesha_Exception($e);
         }
         $current = array();
         foreach ($properties as $s) {
             $current[$s['property_id']] = $s['property'];
         }
     }
     $this->addHidden('', 'actionID', 'text', false, false, null);
     $this->addHidden('', 'category_id', 'text', false, false, null);
     $this->addHidden('', 'submitbutton', 'text', false, false, null);
     $this->addVariable(_("Category Name"), 'category', 'text', true);
     $this->addVariable(_("Description"), 'description', 'longtext', false);
     $this->addVariable(_("Sort Weight"), 'priority', 'enum', false, false, _("When categories are displayed, they will be shown in weight order from highest to lowest"), array($priorities));
     if (!count($a)) {
         $fieldtype = 'invalid';
         $a = _("No properties are currently configured. Use the \"Manage Properties\" tab above to add some.");
     } else {
         $fieldtype = 'multienum';
     }
     $mp = $this->addVariable(_("Properties"), 'properties', $fieldtype, true, false, null, array($a));
     if (!empty($current)) {
         $mp->setDefault(array_keys($current));
     }
     $action = Horde_Form_Action::factory('submit');
 }
Example #8
0
 /**
  */
 function __construct(&$vars)
 {
     $channel_id = $vars->get('channel_id');
     $editing = !empty($channel_id);
     parent::__construct($vars, $editing ? _("Edit Feed") : _("New Feed"));
     $this->addHidden('', 'channel_id', 'int', false);
     $this->addHidden('', 'old_channel_type', 'text', false);
     $select_type =& $this->addVariable(_("Type"), 'channel_type', 'enum', true, false, null, array(Jonah::getAvailableTypes()));
     $select_type->setDefault(Jonah::INTERNAL_CHANNEL);
     $select_type->setHelp('feed-type');
     $select_type->setAction(Horde_Form_Action::factory('submit'));
     $this->addVariable(_("Name"), 'channel_name', 'text', true);
     $this->addVariable(_("Extra information for this feed type"), 'extra_info', 'header', false);
 }
Example #9
0
 public function __construct(&$vars)
 {
     global $conf;
     if ($vars->exists('id')) {
         parent::__construct($vars, _("Update Time"));
         $delete_link = Horde::url('time.php')->add('delete', $vars->get('id'))->link(array('title' => _("Delete Entry"))) . _("Delete");
         $this->setExtra('<span class="smallheader">' . $delete_link . '</a></span>');
     } else {
         parent::__construct($vars, _("New Time"));
     }
     $this->setButtons(_("Save"));
     list($clienttype, $clientparams) = $this->getClientType();
     if ($clienttype == 'enum') {
         $action =& Horde_Form_Action::factory('submit');
     }
     list($typetype, $typeparams) = $this->getJobTypeType();
     if ($vars->exists('id')) {
         $this->addHidden('', 'id', 'int', true);
     }
     if ($vars->exists('url')) {
         $this->addHidden('', 'url', 'text', true);
     }
     $var = $this->addVariable(_("Date"), 'date', 'monthdayyear', true, false, null, array(date('Y') - 1));
     $var->setDefault(date('Y-m-d'));
     $cli = $this->addVariable(_("Client"), 'client', $clienttype, true, false, null, $clientparams);
     if (isset($action)) {
         $cli->setAction($action);
         $cli->setOption('trackchange', true);
     }
     $this->addVariable(_("Job Type"), 'type', $typetype, true, false, null, $typeparams);
     $this->_costObjects = $this->addVariable(_("Cost Object"), 'costobject', 'enum', false, false, null, array(array()));
     $this->addVariable(_("Hours"), 'hours', 'number', true);
     if ($conf['time']['choose_ifbillable']) {
         $yesno = array(1 => _("Yes"), 0 => _("No"));
         $this->addVariable(_("Billable?"), 'billable', 'enum', true, false, null, array($yesno));
     }
     if ($vars->exists('client') && $vars->get('client')) {
         try {
             $info = $GLOBALS['injector']->getInstance('Hermes_Driver')->getClientSettings($vars->get('client'));
         } catch (Horde_Exception_NotFound $e) {
         }
         if (!$info['enterdescription']) {
             $vars->set('description', _("See Attached Timesheet"));
         }
     }
     $descvar = $this->addVariable(_("Description"), 'description', 'longtext', true, false, null, array(4, 60));
     $this->addVariable(_("Additional Notes"), 'note', 'longtext', false, false, null, array(4, 60));
 }
Example #10
0
 /**
  */
 function __construct(&$vars)
 {
     parent::__construct($vars, $vars->get('id') ? _("Edit Story") : _("Add New Story"));
     $this->setButtons(_("Save"));
     $channel_id = $this->addHidden('', 'channel_id', 'int', false);
     $channel = $vars->get('channel_id');
     if ($channel) {
         $channel_id->setDefault($channel_id);
     }
     $this->addHidden('', 'id', 'int', false);
     $this->addHidden('', 'read', 'int', false);
     $this->addVariable(_("Story Title (Headline)"), 'title', 'text', true);
     $this->addVariable(_("Short Description"), 'description', 'longtext', true, false, null, array(2, 80));
     $this->addVariable(_("Publish Now?"), 'publish_now', 'boolean', false);
     $published = $vars->get('published');
     if ($published) {
         $date_params = array(min(date('Y', $published), date('Y')), max(date('Y', $published), date('Y') + 10));
     } else {
         $date_params = array();
     }
     $d =& $this->addVariable(_("Or publish on this date:"), 'publish_date', 'monthdayyear', false, false, null, $date_params);
     $d->setDefault($published);
     $t =& $this->addVariable('', 'publish_time', 'hourminutesecond', false);
     $t->setDefault($published);
     $v =& $this->addVariable(_("Story body type"), 'body_type', 'enum', false, false, null, array(Jonah::getBodyTypes()));
     $v->setAction(Horde_Form_Action::factory('submit'));
     $v->setOption('trackchange', true);
     /* If no body type specified, default to one. */
     $body_type = $vars->get('body_type');
     if (empty($body_type)) {
         $body_type = Jonah::getDefaultBodyType();
         $vars->set('body_type', $body_type);
     }
     /* Set up the fields according to what the type of body requested. */
     if ($body_type == 'text') {
         $this->addVariable(_("Full Story Text"), 'body', 'longtext', false, false, null, array(15, 80));
     } elseif ($body_type == 'richtext') {
         $this->addVariable(_("Full Story Text"), 'body', 'longtext', false, false, null, array(20, 80, array('rte')));
     }
     $this->addVariable(_("Tags"), 'tags', 'text', false, false, _("Enter keywords to tag this story, separated by commas"));
     /* Only show URL insertion if it has been enabled in config. */
     if (in_array('links', $GLOBALS['conf']['news']['story_types'])) {
         $this->addVariable(_("Story URL"), 'url', 'text', false, false, _("If you enter a URL without a full story text, clicking on the story will send the reader straight to the URL, otherwise it will be shown at the end of the full story."));
     }
 }
Example #11
0
 public function __construct(&$vars)
 {
     parent::__construct($vars, _("Add Attribute"));
     $this->addHidden('', 'type', 'int', true, true);
     $this->addVariable(_("Attribute Name"), 'attribute_name', 'text', true);
     $this->addVariable(_("Attribute Description"), 'attribute_description', 'text', true);
     $this->addVariable(_("Required Attribute?"), 'attribute_required', 'boolean', false);
     $v =& $this->addVariable(_("Attribute Type"), 'attribute_type', 'enum', true, false, null, array(Whups::fieldTypeNames()));
     $v->setDefault('text');
     $v->setAction(Horde_Form_Action::factory(array('whups', 'whups_reload'), array('formname' => 'whups_form_admin_addattribute_reload')));
     $type = $vars->get('attribute_type');
     if (empty($type)) {
         $type = 'text';
     }
     foreach (Whups::fieldTypeParams($type) as $param => $info) {
         $this->addVariable($info['label'], 'attribute_params[' . $param . ']', $info['type'], false);
     }
 }
Example #12
0
 public function __construct(&$vars, &$object, $params = array())
 {
     $this->koward =& Koward::singleton();
     $this->object =& $object;
     parent::__construct($vars);
     $type = false;
     if (empty($this->object)) {
         $title = _("Add Object");
         $this->setButtons(_("Add"));
         foreach ($this->koward->objects as $key => $config) {
             if (!$this->koward->hasAccess('object/add/' . $key, Koward::PERM_EDIT)) {
                 continue;
             }
             $options[$key] = $config['label'];
         }
         $v = $this->addVariable(_("Choose an object type"), 'type', 'enum', true, false, null, array($options, true));
         $action = Horde_Form_Action::factory('submit');
         $v->setAction($action);
         $v->setOption('trackchange', true);
         if (is_null($vars->get('formname')) && $vars->get($v->getVarName()) != $vars->get('__old_' . $v->getVarName())) {
             $this->koward->notification->push(sprintf(_("Selected object type \"%s\"."), $object_conf[$vars->get('type')]['label']), 'horde.message');
         }
         $type = $vars->get('type');
     } else {
         $title = _("Edit Object");
         $type = $this->koward->getType($this->object);
         if (empty($type)) {
             throw new Koward_Exception('Undefined object class!');
         }
         if (!$this->isSubmitted()) {
             $vars->set('type', $type);
             $keys = array_keys($this->_getFields($this->koward->objects[$type]));
             $vars->set('object', $this->object->toHash($keys));
             $this->setButtons(true);
         }
     }
     if (isset($params['title'])) {
         $title = $params['title'];
     }
     $this->setTitle($title);
     if (!empty($type)) {
         $this->_addFields($this->koward->objects[$type]);
     }
 }
Example #13
0
 public function __construct($vars)
 {
     global $whups_driver;
     parent::__construct($vars, _("Create Ticket - Step 1"));
     $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::EDIT);
     if (!$queues) {
         $this->addVariable(_("Queue Name"), 'queue', 'invalid', true, false, null, array(_("There are no queues which you can create tickets in.")));
     } else {
         foreach (array_keys($queues) as $queue_id) {
             $info = $whups_driver->getQueue($queue_id);
             if (!empty($info['description'])) {
                 $queues[$queue_id] .= ' [' . $info['description'] . ']';
             }
         }
         // Auto-select the only queue if only one option is available
         if (count($queues) == 1) {
             $vars->set('queue', array_pop(array_keys($queues)));
         }
         $queues = $this->addVariable(_("Queue Name"), 'queue', 'enum', true, false, null, array($queues, _("Choose:")));
         $queues->setAction(Horde_Form_Action::factory('submit'));
     }
 }
Example #14
0
 public function __construct(&$vars)
 {
     parent::__construct($vars, _("Search For Time"));
     if ($GLOBALS['registry']->isAdmin(array('permission' => 'hermes:review'))) {
         $type = Hermes::getEmployeesType();
         $this->addVariable(_("Employees"), 'employees', $type[0], false, false, null, array($type[1]));
     }
     $type = $this->getClientsType();
     $cli = $this->addVariable(_("Clients"), 'clients', $type[0], false, false, null, $type[1]);
     $cli->setAction(Horde_Form_Action::factory('submit'));
     $cli->setOption('trackchange', true);
     $type = $this->getJobTypesType();
     $this->addVariable(_("Job Types"), 'jobtypes', $type[0], false, false, null, $type[1]);
     $this->addVariable(_("Cost Objects"), 'costobjects', 'multienum', false, false, null, array(Hermes::getCostObjectType($vars->get('clients'))));
     $this->addVariable(_("Do not include entries before"), 'start', 'monthdayyear', false, false, null, array(date('Y') - 10));
     $this->addVariable(_("Do not include entries after"), 'end', 'monthdayyear', false, false, null, array(date('Y') - 10));
     $states = array('' => '', '1' => _("Yes"), '0' => _("No"));
     $this->addVariable(_("Submitted?"), 'submitted', 'enum', false, false, null, array($states));
     $this->addVariable(_("Exported?"), 'exported', 'enum', false, false, null, array($states));
     $this->addVariable(_("Billable?"), 'billable', 'enum', false, false, null, array($states));
     $this->setButtons(_("Search"));
 }
Example #15
0
 public function __construct($vars)
 {
     global $whups_driver;
     parent::__construct($vars, $vars->get('edit') ? _("Edit Property Criterion") : _("Add Property Criterion"), 'Whups_Form_Query_PropertyCriterion');
     $this->addHidden('', 'edit', 'boolean', false);
     $this->addVariable(_("Id"), 'id', 'intlist', false);
     /* Types. */
     $this->addVariable(_("Type"), 'ttype', 'enum', false, false, null, array($whups_driver->getAllTypes(), _("Any")));
     /* Queues. */
     $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::READ);
     if (count($queues)) {
         $v = $this->addVariable(_("Queue"), 'queue', 'enum', false, false, null, array($queues, _("Any")));
         $v->setAction(Horde_Form_Action::factory('reload'));
         if ($vars->get('queue')) {
             $this->addVariable(_("Version"), 'version', 'enum', false, false, null, array($whups_driver->getVersions($vars->get('queue')), _("Any")));
         }
     }
     /* States. */
     $states = $whups_driver->getStates();
     $this->addVariable(_("State"), 'state', 'enum', false, false, null, array($states, _("Any")));
     /* Priorities. */
     $priorities = $whups_driver->getPriorities();
     $this->addVariable(_("Priority"), 'priority', 'enum', false, false, null, array($priorities, _("Any")));
 }
Example #16
0
 /**
  */
 function EditRecord(&$vars)
 {
     $isnew = !$vars->exists('id');
     $rectype = $vars->get('rectype');
     $recset = Beatnik::getRecFields($rectype);
     if ($isnew) {
         // Pre-load the field defaults on a new record
         foreach ($recset as $field => $fdata) {
             if (isset($fdata['default'])) {
                 $vars->set($field, $fdata['default']);
             }
         }
     }
     parent::__construct($vars, $isnew ? _("Add DNS Record") : _("Edit DNS Record"));
     $types = Beatnik::getRecTypes();
     if (empty($_SESSION['beatnik']['curdomain'])) {
         // Without an active domain, limit the form to creating a new zone.
         $types = array('soa' => _('SOA (Start of Authority)'));
     }
     $action =& Horde_Form_Action::factory('reload');
     $select =& $this->addVariable(_("Record Type"), 'rectype', 'enum', true, false, null, array($types, true));
     $select->setAction($action);
     $select->setOption('trackchange', true);
     // Do not show record-specific fields until a record type is chosen
     if (!$rectype) {
         return true;
     }
     foreach ($recset as $field => $fdata) {
         if ($fdata['type'] == 'hidden' || $fdata['infoset'] != 'basic' && !$_SESSION['beatnik']['expertmode']) {
             $this->addHidden(_($fdata['description']), $field, 'text', $fdata['required']);
         } else {
             $this->addVariable(_($fdata['description']), $field, $fdata['type'], $fdata['required']);
         }
     }
     return true;
 }
Example #17
0
 public function __construct($vars)
 {
     parent::__construct($vars);
     $this->appendButtons(_("Save Property"));
     $types = array();
     $datatypes = $GLOBALS['conf']['datatypes']['types'];
     foreach ($datatypes as $d) {
         $types[$d] = $d;
     }
     $priorities = array();
     for ($i = 0; $i < 100; $i++) {
         $priorities[] = $i;
     }
     $this->addHidden('', 'actionID', 'text', false, false, null);
     $this->addHidden('', 'property_id', 'text', false, false, null);
     $this->addVariable(_("Property Name"), 'property', 'text', true);
     $action = Horde_Form_Action::factory('submit');
     $v = $this->addVariable(_("Data Type"), 'datatype', 'enum', true, false, null, array($types, true));
     $v->setAction($action);
     $v->setOption('trackchange', true);
     $this->addVariable(_("Unit"), 'unit', 'text', false);
     $this->addVariable(_("Description"), 'description', 'longtext', false);
     $this->addVariable(_("Sort Weight"), 'priority', 'enum', false, false, _("When properties are displayed, they will be shown in weight order from highest to lowest"), array($priorities));
 }
Example #18
0
 /**
  * The default constructor for the StockForm class.
  *
  * @param Horde_Variables $vars  The default variables to use.
  */
 public function __construct($vars)
 {
     parent::__construct($vars);
     $sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
     // Buttons and hidden configuration
     $this->setButtons(_("Save Item"));
     $this->addHidden('', 'actionId', 'text', true);
     // Prepare the categories
     $cat = array();
     $categories = $sesha_driver->getCategories();
     foreach ($categories as $c) {
         $cat[$c->category_id] = $c->category;
     }
     // Get the list of selected categories
     $categoryIds = array();
     $t = $vars->get('category_id');
     if (!is_array($t)) {
         $t = array($t);
     }
     $categoryIds = array_merge($categoryIds, $t);
     // The stock ID should only be editable if you are adding a new item;
     // otherwise let the user know what the stock_id is, and then make a
     // read-only required hidden variable
     if ($vars->get('actionId') == 'add_stock') {
         $this->addVariable(_("Stock ID"), 'stock_id', 'int', false, false);
     } else {
         $this->addVariable(_("Stock ID"), 'stock_id', 'int', false, true);
         $this->addHidden('', 'stock_id', 'int', true, true);
     }
     // Basic variables for any stock item
     $this->addVariable(_("Name"), 'stock_name', 'text', false, false);
     if (!count($cat)) {
         $fieldtype = 'invalid';
         $cat = _("No categories are currently configured. Click \"Administration\" on the left to add some.");
     } else {
         $fieldtype = 'multienum';
     }
     $categoryVar = $this->addVariable(_("Category"), 'category_id', $fieldtype, true, false, null, array($cat));
     // Set the variables already stored in the Driver, if applicable
     try {
         $properties = $sesha_driver->getPropertiesForCategories($categoryIds);
     } catch (Sesha_Exception $e) {
         throw new Sesha_Exception($e);
     }
     foreach ($properties as $property) {
         $fieldname = 'property[' . $property->property_id . ']';
         $fieldtitle = $property->property;
         $fielddesc = $property->description;
         if (!empty($property->unit)) {
             if (!empty($fielddesc)) {
                 $fielddesc .= ' -- ';
             }
             $fielddesc .= _("Unit: ") . $property->unit;
         }
         $fieldtype = $property->datatype;
         $fieldparams = array();
         if (is_array($property->parameters)) {
             $fieldparams = $property->parameters;
             if (in_array($fieldtype, array('link', 'enum', 'multienum', 'mlenum', 'radio', 'set', 'sorter'))) {
                 $fieldparams->values = Sesha::getStringlistArray($fieldparams->values);
             }
         }
         $this->addVariable($fieldtitle, $fieldname, $fieldtype, false, false, $fielddesc, $fieldparams);
     }
     $this->addVariable(_("Note"), 'note', 'longtext', false);
     // Default action
     $action = Horde_Form_Action::factory('submit');
     $categoryVar->setAction($action);
     $categoryVar->setOption('trackchange', true);
 }
Example #19
0
File: Task.php Project: horde/horde
 /**
  * Const'r
  *
  * @param Horde_Form_Variables $vars  The form variables.
  * @param string $title               The form title.
  *
  * @return Nag_Form_Task
  */
 public function __construct($vars, $title = '')
 {
     global $injector, $nag_shares, $prefs, $registry;
     parent::__construct($vars, $title);
     $user = $registry->getAuth();
     $tasklist_enums = array();
     foreach (Nag::listTasklists(false, Horde_Perms::SHOW, false) as $tl_id => $tl) {
         if (!$tl->hasPermission($user, Horde_Perms::EDIT)) {
             continue;
         }
         $tasklist_enums[$tl_id] = Nag::getLabel($tl);
     }
     $tasklist = $vars->get('tasklist_id');
     if (empty($tasklist)) {
         reset($tasklist_enums);
         $tasklist = key($tasklist_enums);
     }
     $priorities = array(1 => '1 ' . _("(highest)"), 2 => 2, 3 => 3, 4 => 4, 5 => '5 ' . _("(lowest)"));
     $this->addHidden('', 'mobile', 'boolean', false);
     $this->addHidden('', 'task_id', 'text', false);
     $this->addHidden('', 'old_tasklist', 'text', false);
     $this->addHidden('', 'url', 'text', false);
     $this->addHidden('', 'uid', 'text', false);
     $this->addHidden('', 'owner', 'text', false);
     $this->addHidden('', 'list', 'text', false);
     $this->addHidden('', 'tab_name', 'text', false);
     $this->setSection(self::SECTION_GENERAL, _("General"));
     $this->addVariable(_("Name"), 'name', 'text', true);
     if (!$prefs->isLocked('default_tasklist') && count($tasklist_enums) > 1) {
         $v = $this->addVariable(_("Task List"), 'tasklist_id', 'enum', true, false, false, array($tasklist_enums));
         if (!$vars->get('mobile')) {
             $v->setAction(Horde_Form_Action::factory('reload'));
         }
     }
     if (!$vars->get('mobile')) {
         $tasks = Nag::listTasks(array('tasklists' => array($tasklist), 'complete' => Nag::VIEW_FUTURE_INCOMPLETE, 'include_history' => false));
         $task_enums = array('' => _("No parent task"));
         $tasks->reset();
         while ($task = $tasks->each()) {
             if ($vars->get('task_id') == $task->id) {
                 continue;
             }
             $task_enums[htmlspecialchars($task->id)] = str_repeat('&nbsp;', $task->indent * 4) . htmlspecialchars($task->name);
         }
         $v = $this->addVariable(_("Parent task"), 'parent', 'enum', false, false, false, array($task_enums));
         $v->setOption('htmlchars', true);
     }
     $this->addVariable(_("Tags"), 'tags', 'Nag:NagTags', false);
     // Only display the delete button if this is an existing task and the
     // user has HORDE_PERMS::DELETE
     $share = $nag_shares->getShare($tasklist);
     $delete = $share->hasPermission($registry->getAuth(), Horde_Perms::DELETE) && $vars->get('task_id');
     if (!$vars->get('mobile')) {
         $users = $share->listUsers(Horde_Perms::READ);
         $groups = $share->listGroups(Horde_Perms::READ);
         if (count($groups)) {
             $horde_group = $injector->getInstance('Horde_Group');
             foreach ($groups as $group) {
                 $users = array_merge($users, $horde_group->listUsers($group));
             }
         }
         if (empty($GLOBALS['conf']['assignees']['allow_external'])) {
             $users = array_flip($users);
             if (count($users)) {
                 foreach (array_keys($users) as $user) {
                     $identity = $injector->getInstance('Horde_Core_Factory_Identity')->create($user);
                     $fullname = $identity->getValue('fullname');
                     $users[$user] = strlen($fullname) ? $fullname : $user;
                 }
             }
             $this->addVariable(_("Assignee"), 'assignee', 'enum', false, false, null, array($users, _("None")));
         } else {
             $this->addVariable(_("Assignee"), 'assignee', 'Nag:NagContact', false);
         }
     }
     $this->addVariable(_("Private?"), 'private', 'boolean', false);
     $this->addVariable(_("Due By"), 'due', 'Nag:NagDue', false);
     if (!$vars->get('mobile')) {
         $this->addVariable(_("Delay Start Until"), 'start', 'Nag:NagStart', false);
     }
     $this->addVariable(_("Alarm"), 'alarm', 'Nag:NagAlarm', false);
     if (!$vars->get('mobile')) {
         $v = $this->addVariable(_("Notification"), 'methods', 'Nag:NagMethod', false);
         $v->setAction(Horde_Form_Action::factory('reload'));
         $v = $this->addVariable(_("Priority"), 'priority', 'enum', false, false, false, array($priorities));
         $v->setDefault(3);
         $this->addVariable(_("Estimated Time"), 'estimate', 'number', false);
         $this->addVariable(_("Actual Time"), 'actual', 'number', false);
         $this->_completedVar = $this->addVariable(_("Completed?"), 'completed', 'boolean', false);
         $this->setSection(self::SECTION_RECUR, _("Recurrence"));
         $this->addVariable(_("Recurrence"), 'recurrence', 'Nag:NagRecurrence', false);
     }
     $this->setSection(self::SECTION_DESC, _("Description"));
     try {
         $description = Horde::callHook('description_help', array(), 'nag');
     } catch (Horde_Exception_HookNotSet $e) {
         $description = '';
     }
     $this->addVariable(_("Description"), 'desc', 'longtext', false, false, $description);
     $buttons = array(array('value' => _("Save")));
     if ($delete) {
         $buttons[] = array('value' => _("Delete"), 'name' => 'deletebutton', 'class' => 'horde-delete');
     }
     if (!$vars->get('task_id')) {
         $buttons[] = array('value' => _("Save and New"), 'name' => 'savenewbutton', 'class' => 'horde-create');
     }
     if (Horde_Util::getFormData('have_search')) {
         $buttons[] = array('value' => _("Return to Search Results"), 'name' => 'search_return', 'class' => 'horde-button');
     }
     $this->setButtons($buttons);
 }
Example #20
0
 /**
  * Attempts to return a reference to a concrete
  * Horde_Form_Action instance based on $action. It will only
  * create a new instance if no Horde_Form_Action instance with
  * the same parameters currently exists.
  *
  * This should be used if multiple types of form renderers (and,
  * thus, multiple Horde_Form_Action instances) are required.
  *
  * This method must be invoked as: $var =
  * &Horde_Form_Action::singleton()
  *
  * @param mixed $action  The type of concrete Horde_Form_Action subclass to return.
  *                       The code is dynamically included. If $action is an array,
  *                       then we will look in $action[0]/lib/Form/Action/ for
  *                       the subclass implementation named $action[1].php.
  * @param array $params  A hash containing any additional configuration a
  *                       form might need.
  *
  * @return Horde_Form_Action  The concrete Horde_Form_Action reference, or
  *                            false on an error.
  */
 function &singleton($action, $params = null)
 {
     static $instances = array();
     $signature = serialize(array($action, $params));
     if (!isset($instances[$signature])) {
         $instances[$signature] =& Horde_Form_Action::factory($action, $params);
     }
     return $instances[$signature];
 }
Example #21
0
    Horde::url('forums.php', true)->redirect();
}
/* Check delete permissions */
if (!$messages->hasPermission(Horde_Perms::DELETE)) {
    $notification->push(sprintf(_("You don't have permission to delete messages in forum %s."), $forum_id), 'horde.warning');
    $url = Agora::setAgoraId($forum_id, $message_id, Horde::url('messages/index.php', true), $scope);
    header('Location: ' . $url);
    exit;
}
/* Get the form object. */
$vars = Horde_Variables::getDefaultVariables();
$form = new Horde_Form($vars, sprintf(_("Merge \"%s\" with another thread"), $message['message_subject']));
$form->setButtons(array(_("Merge"), _("Cancel")));
$form->addHidden('', 'agora', 'text', false);
$form->addHidden('', 'scope', 'text', false);
$action_submit = Horde_Form_Action::factory('submit');
$threads_list = array();
foreach ($messages->getThreads(0, false, 'message_subject', 0) as $thread) {
    $threads_list[$thread['message_id']] = $thread['message_subject'];
}
$v = $form->addVariable(_("With Thread: "), 'new_thread_id', 'enum', true, false, null, array($threads_list));
$v->setAction($action_submit);
$v->setOption('trackchange', true);
// TODO: show message list on first page load too.
if ($vars->get('new_thread_id')) {
    $message_list = array();
    foreach ($messages->getThreads($vars->get('new_thread_id'), true) as $thread) {
        $message_list[$thread['message_id']] = $thread['message_subject'] . ' (' . $thread['message_author'] . ' ' . $thread['message_date'] . ')';
    }
    $form->addVariable(_("After Message: "), 'after_message_id', 'enum', true, false, null, array($message_list));
}
Example #22
0
    $vars = $ulaform_driver->getField($form_id, $vars->get('field_id'));
    $vars = new Horde_Variables($vars);
}
/* Set up the form. */
$fieldform = new Horde_Form($vars, _("Field Details"));
$fieldform->setButtons(_("Save Field"));
$fieldform->addHidden('', 'field_id', 'int', false);
$fieldform->addHidden('', 'form_id', 'int', false);
$fieldform->addHidden('', 'field_order', 'int', false);
$fieldform->addHidden('', 'old_field_type', 'text', false);
$fieldform->addVariable(_("Label"), 'field_label', 'text', true);
$fieldform->addVariable(_("Internal name"), 'field_name', 'text', false, false, _("Set this name if you have a particular reason to override the automatic internal naming of fields."));
/* Set up the field type selection, with a submit action. */
$fields = Ulaform::getFieldTypes();
$v = $fieldform->addVariable(_("Type"), 'field_type', 'enum', true, false, null, array($fields, true));
$v->setAction(Horde_Form_Action::factory('submit'));
$v->setOption('trackchange', true);
$fieldform->addVariable(_("Required"), 'field_required', 'boolean', false);
$fieldform->addVariable(_("Read only"), 'field_readonly', 'boolean', false);
$fieldform->addVariable(_("Description"), 'field_desc', 'longtext', false, false, '', array(3, 40));
/* Check if the submitted field type has extra parameters and set them up. */
$field_type = $vars->get('field_type');
$available_params = Ulaform::getFieldParams($field_type);
if (!is_null($vars->get('formname')) && $vars->get($v->getVarName()) != $vars->get('__old_' . $v->getVarName()) && !empty($available_params)) {
    $notification->push(_("This field type has extra parameters."), 'horde.message');
}
foreach ($available_params as $name => $param) {
    $field_id = 'field_params[' . $name . ']';
    $param['required'] = isset($param['required']) ? $param['required'] : null;
    $param['readonly'] = isset($param['readonly']) ? $param['readonly'] : null;
    $param['desc'] = isset($param['desc']) ? $param['desc'] : null;
Example #23
0
    $domain = Vilma::stripDomain($vars->virtual_destination);
}
$users = $vilma->driver->getUsers($domain);
$user_list = array();
foreach ($users as $user) {
    $virtual_destination = substr($user['user_name'], 0, strpos($user['user_name'], '@'));
    $user_list[$user['user_name']] = $virtual_destination;
}
$form = new Horde_Form($vars, $editing ? _("Edit Virtual Email Address") : _("New Virtual Email Address"));
/* Set up the form. */
$form->setButtons(true, true);
$form->addHidden('', 'virtual_id', 'int', false);
$form->addHidden('', 'domain', 'text', false);
$form->addVariable(_("Virtual Email"), 'stripped_email', 'text', true, false, sprintf(_("Enter a virtual email address @%s and then indicate below where mail sent to that address is to be delivered. The address must begin with an alphanumerical character, it must contain only alphanumerical and '._-' characters, and must end with an alphanumerical character."), $domain), array('~^[a-zA-Z0-9]{1,1}[a-zA-Z0-9._-]*[a-zA-Z0-9]$~'));
$var =& $form->addVariable(_("Destination type"), 'destination_type', 'enum', true, false, null, array(array('local' => _("Local user"), 'remote' => _("Remote address"))));
$var->setAction(Horde_Form_Action::factory('reload'));
if ($vars->destination_type == 'remote') {
    $form->addVariable(_("Remote e-mail address"), 'virtual_destination', 'email', true, false);
} else {
    $form->addVariable(_("Destination"), 'virtual_destination', 'enum', true, false, null, array($user_list, true));
}
if ($form->validate($vars)) {
    $form->getInfo($vars, $info);
    $info['stripped_email'] = Horde_String::lower($info['stripped_email']);
    if ($info['destination_type'] == 'remote') {
        $info['virtual_destination'] = Horde_String::lower($info['virtual_destination']);
    }
    try {
        $virtual_id = $vilma->driver->saveVirtual($info, $domain);
        $notification->push(_("Virtual email saved."), 'horde.success');
        Horde::url('virtuals/index.php', true)->add('user', $info['virtual_destination'])->redirect();
Example #24
0
}
/* Set up VFS. */
require_once HORDE_LIBS . 'VFS.php';
$vfs_type = $conf['vfs']['type'];
$vfs_args = Horde::getDriverConfig('vfs', $vfs_type);
$vfs_args['user'] = Auth::getAuth();
$vfs =& VFS::singleton($vfs_type, $vfs_args);
@define('TEMPLATES_VFS_PATH', '.horde_templates');
/* Require Horde_Form libs. */
require_once HORDE_LIBS . 'Horde/Form.php';
require_once HORDE_LIBS . 'Horde/Form/Renderer.php';
require_once HORDE_LIBS . 'Horde/Form/Action.php';
/* Set up Horde_Form. */
$vars =& Variables::getDefaultVariables();
$form =& Horde_Form::singleton('TemplatesForm', $vars);
$action =& Horde_Form_Action::factory('submit');
/* Set up form fields. */
$apps = _setValuesToKeys($registry->listApps());
$select_app =& $form->addVariable(_("Application"), 'app', 'enum', true, false, null, array($apps));
$select_app->setAction($action);
$form->addHidden('', 'old_app', 'text', false, false);
/* Set up some variables. */
$formname = $vars->get('formname');
$app = $vars->get('app');
$old_app = $vars->get('old_app');
$template_path = $vars->get('template_path');
$template_orig = $vars->get('template_orig');
$old_template_orig = $vars->get('old_template_orig');
$has_changed = false;
if ($app != $old_app) {
    $has_changed = true;
Example #25
0
 public function __construct(&$vars, &$ticket, $title = '')
 {
     global $whups_driver;
     parent::__construct($vars, $title);
     $type = $vars->get('type');
     $start_year = date('Y');
     if (is_numeric($d = $vars->get('due'))) {
         $start_year = min($start_year, date('Y', $d));
     }
     $fields = array('summary');
     $qinfo = $whups_driver->getQueue($vars->get('queue'));
     if (!empty($qinfo['versioned'])) {
         $fields[] = 'version';
     }
     $fields = array_merge($fields, array('state', 'priority', 'due'));
     try {
         $attributes = $ticket->addAttributes();
     } catch (Whups_Exception $e) {
         $attributes = array();
     }
     foreach ($attributes as $attribute) {
         $fields[] = 'attribute_' . $attribute['id'];
     }
     $fields = array_merge($fields, array('owner', 'attachments', 'comment'));
     $grouped_fields = array($fields);
     $grouped_hook = false;
     try {
         $grouped_fields = Horde::callHook('group_fields', array($ticket->get('type'), $fields), 'whups');
         $grouped_hook = true;
     } catch (Horde_Exception_HookNotSet $e) {
     } catch (Horde_Exception $e) {
         Horde::log($e, 'ERR');
     }
     $this->addHidden('', 'id', 'int', true, true);
     $this->addHidden('', 'type', 'int', true, true);
     foreach ($grouped_fields as $header => $fields) {
         if ($grouped_hook) {
             $this->addVariable($header, null, 'header', false);
         }
         foreach ($fields as $field) {
             switch ($field) {
                 case 'summary':
                     $this->addVariable(_("Summary"), 'summary', 'text', true);
                     break;
                 case 'version':
                     $versions = $whups_driver->getVersions($vars->get('queue'));
                     if (count($versions) == 0) {
                         $vtype = 'invalid';
                         $v_params = array(_("This queue requires that you specify a version, but there are no versions associated with it. Until versions are created for this queue, you will not be able to create tickets."));
                     } else {
                         $vtype = 'enum';
                         $v_params = array($versions);
                     }
                     $this->addVariable(_("Queue Version"), 'version', $vtype, true, false, null, $v_params);
                     break;
                 case 'state':
                     $this->addVariable(_("State"), 'state', 'enum', true, false, null, array($whups_driver->getStates($type)));
                     break;
                 case 'priority':
                     $this->addVariable(_("Priority"), 'priority', 'enum', true, false, null, array($whups_driver->getPriorities($type)));
                     break;
                 case 'due':
                     $this->addVariable(_("Due Date"), 'due', 'datetime', false, false, null, array($start_year));
                     break;
                 case 'owner':
                     if (Whups::hasPermission($vars->get('queue'), 'queue', 'assign')) {
                         $groups = $GLOBALS['injector']->getInstance('Horde_Group');
                         $mygroups = $groups->listAll($GLOBALS['conf']['prefs']['assign_all_groups'] ? null : $GLOBALS['registry']->getAuth());
                         asort($mygroups);
                         $f_users = array();
                         $users = $whups_driver->getQueueUsers($vars->get('queue'));
                         foreach ($users as $user) {
                             $f_users['user:'******'group:' . $id] = $groups->getName($id);
                             }
                         }
                         if (count($f_users)) {
                             asort($f_users);
                             $this->addVariable(_("Owners"), 'owners', 'multienum', false, false, null, array($f_users));
                         }
                         if (count($f_groups)) {
                             asort($f_groups);
                             $this->addVariable(_("Group Owners"), 'group_owners', 'multienum', false, false, null, array($f_groups));
                         }
                     }
                     break;
                 case 'attachments':
                     $this->addVariable(_("Attachment"), 'newattachment', 'file', false);
                     break;
                 case 'comment':
                     $cvar = $this->addVariable(_("Comment"), 'newcomment', 'longtext', false);
                     /* Form replies. */
                     try {
                         $replies = Whups::permissionsFilter($whups_driver->getReplies($type), 'reply');
                     } catch (Whups_Exception $e) {
                         $replies = array();
                     }
                     if (count($replies)) {
                         $params = array();
                         foreach ($replies as $key => $reply) {
                             $params[$key] = $reply['reply_name'];
                         }
                         $rvar = $this->addVariable(_("Form Reply:"), 'reply', 'enum', false, false, null, array($params, true));
                         $rvar->setAction(Horde_Form_Action::factory('reload'));
                         if ($vars->get('reply')) {
                             $reply = $vars->get('newcomment');
                             if (strlen($reply)) {
                                 $reply .= "\n\n";
                             }
                             $reply .= $replies[$vars->get('reply')]['reply_text'];
                             $vars->set('newcomment', $reply);
                             $vars->remove('reply');
                         }
                     }
                     /* Comment permissions. */
                     $groups = $GLOBALS['injector']->getInstance('Horde_Group');
                     $mygroups = $groups->listGroups($GLOBALS['registry']->getAuth());
                     if ($mygroups) {
                         foreach (array_keys($mygroups) as $gid) {
                             $grouplist[$gid] = $groups->getName($gid, true);
                         }
                         asort($grouplist);
                         $grouplist = array(0 => _("This comment is visible to everyone")) + $grouplist;
                         $this->addVariable(_("Make this comment visible only to members of a group?"), 'group', 'enum', false, false, null, array($grouplist));
                     }
                     break;
                 default:
                     /* Ticket attributes. */
                     if ($ticket && substr($field, 0, 10) == 'attribute_' && isset($attributes[substr($field, 10)])) {
                         $attribute = $attributes[substr($field, 10)];
                         $var = $this->addVariable($attribute['human_name'], 'attribute_' . $attribute['id'], $attribute['type'], $attribute['required'], $attribute['readonly'], $attribute['desc'], $attribute['params']);
                         $var->setDefault($attribute['value']);
                     }
             }
         }
     }
 }
Example #26
0
 /**
  * Set up the Horde_Form fields for $contact's attributes.
  *
  * @param Turba_Object $contact  The contact
  */
 protected function _addFields(Turba_Object $contact, $useTabs = true)
 {
     // @TODO: inject this
     global $attributes, $injector;
     // Run through once to see what form actions, if any, we need
     // to set up.
     $actions = array();
     $map = $contact->driver->map;
     $fields = array_keys($contact->driver->getCriteria());
     foreach ($fields as $field) {
         if (is_array($map[$field])) {
             foreach ($map[$field]['fields'] as $action_field) {
                 if (!isset($actions[$action_field])) {
                     $actions[$action_field] = array();
                 }
                 $actions[$action_field]['fields'] = $map[$field]['fields'];
                 $actions[$action_field]['format'] = $map[$field]['format'];
                 $actions[$action_field]['target'] = $field;
             }
         }
     }
     // Now run through and add the form variables.
     $tabs = $contact->driver->tabs;
     if (!count($tabs)) {
         $tabs = array('' => $fields);
     }
     $i = 0;
     foreach ($tabs as $tab => $tab_fields) {
         if (!empty($tab)) {
             if ($useTabs) {
                 $this->setSection($i++, $tab);
             } else {
                 $this->addVariable($tab, '', 'header', false);
             }
         }
         foreach ($tab_fields as $field) {
             if (!in_array($field, $fields) || !isset($attributes[$field]) || $attributes[$field]['type'] == 'image' && strpos($field, '_orig') !== false) {
                 continue;
             }
             $attribute = $attributes[$field];
             $params = isset($attribute['params']) ? $attribute['params'] : array();
             $desc = isset($attribute['desc']) ? $attribute['desc'] : null;
             if (is_array($map[$field])) {
                 $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], false, false, $desc, $params);
                 $v->disable();
             } else {
                 $readonly = isset($attribute['readonly']) ? $attribute['readonly'] : null;
                 $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], $attribute['required'], $readonly, $desc, $params);
                 if (!empty($actions[$field])) {
                     $actionfields = array();
                     foreach ($actions[$field]['fields'] as $f) {
                         $actionfields[] = $this->_getId('object[' . $f . ']');
                     }
                     $a = Horde_Form_Action::factory('updatefield', array('format' => $actions[$field]['format'], 'target' => $this->_getId('object[' . $actions[$field]['target'] . ']'), 'fields' => $actionfields));
                     $v->setAction($a);
                 }
             }
             if (isset($attribute['default'])) {
                 $v->setDefault($attribute['default']);
             }
         }
     }
     /* Add tags. */
     if (isset($map['__uid']) && ($tagger = $injector->getInstance('Turba_Tagger')) && !$tagger instanceof Horde_Core_Tagger_Null) {
         $this->addVariable(_("Tags"), 'object[__tags]', 'Turba:TurbaTags', false);
     }
 }
Example #27
0
 /**
  * Builds the form based on the specified level of the configuration tree.
  *
  * @param array $config   The portion of the configuration tree for that
  *                        the form fields should be created.
  * @param string $prefix  A string representing the current position
  *                        inside the configuration tree.
  */
 protected function _buildVariables($config, $prefix = '')
 {
     if (!is_array($config)) {
         return;
     }
     foreach ($config as $name => $configitem) {
         $prefixedname = empty($prefix) ? $name : $prefix . '|' . $name;
         $varname = str_replace('|', '__', $prefixedname);
         if ($configitem == 'placeholder') {
             continue;
         } elseif (isset($configitem['tab'])) {
             $this->setSection($configitem['tab'], $configitem['desc']);
         } elseif (isset($configitem['switch'])) {
             $selected = $this->_vars->getExists($varname, $wasset);
             $var_params = array();
             $select_option = true;
             if (is_bool($configitem['default'])) {
                 $configitem['default'] = $configitem['default'] ? 'true' : 'false';
             }
             foreach ($configitem['switch'] as $option => $case) {
                 $var_params[$option] = $case['desc'];
                 if ($option == $configitem['default']) {
                     $select_option = false;
                     if (!$wasset) {
                         $selected = $option;
                     }
                 }
             }
             $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']';
             $desc = $configitem['desc'];
             $v =& $this->addVariable($name, $varname, 'enum', true, false, $desc, array($var_params, $select_option));
             if (array_key_exists('default', $configitem)) {
                 $v->setDefault($configitem['default']);
                 if ($this->_fillvars) {
                     $this->_vars->set($varname, $configitem['default']);
                 }
             }
             if (!empty($configitem['is_default'])) {
                 $v->_new = true;
             }
             $v_action = Horde_Form_Action::factory('reload');
             $v->setAction($v_action);
             if (isset($selected) && isset($configitem['switch'][$selected])) {
                 $this->_buildVariables($configitem['switch'][$selected]['fields'], $prefix);
             }
         } elseif (isset($configitem['_type'])) {
             $required = isset($configitem['required']) ? $configitem['required'] : true;
             $type = $configitem['_type'];
             if ($type == 'header' || $type == 'description') {
                 $required = false;
             }
             $var_params = $type == 'multienum' || $type == 'enum' ? array($configitem['values']) : array();
             if ($type == 'header' || $type == 'description') {
                 $name = $configitem['desc'];
                 $desc = null;
             } else {
                 $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']';
                 $desc = $configitem['desc'];
                 if ($type == 'php') {
                     $type = 'text';
                     $desc .= "\nEnter a valid PHP expression.";
                 }
             }
             $v =& $this->addVariable($name, $varname, $type, $required, false, $desc, $var_params);
             if (isset($configitem['default'])) {
                 $v->setDefault($configitem['default']);
                 if ($this->_fillvars) {
                     switch ($type) {
                         case 'boolean':
                             if ($configitem['default']) {
                                 $this->_vars->set($varname, 'on');
                             }
                             break;
                         case 'int':
                             $this->_vars->set($varname, (string) $configitem['default']);
                             break;
                         default:
                             $this->_vars->set($varname, $configitem['default']);
                             break;
                     }
                 }
             }
             if (!empty($configitem['is_default'])) {
                 $v->_new = true;
             }
         } else {
             $this->_buildVariables($configitem, $prefixedname);
         }
     }
 }