public function html($active = true) { global $browser, $conf, $registry; if (!$this->contact || !$this->contact->hasPermission(Horde_Perms::READ)) { echo '<h3>' . _("The requested contact was not found.") . '</h3>'; return; } $vars = new Horde_Variables(); $form = new Turba_Form_Contact($vars, $this->contact); $form->setOpenSection(Horde_Util::getFormData('section', 0)); /* Get the contact's history. */ $history = $this->contact->getHistory(); foreach ($history as $what => $when) { $v = $form->addVariable($what == 'created' ? _("Created") : _("Last Modified"), 'object[__' . $what . ']', 'text', false, false); $v->disable(); $vars->set('object[__' . $what . ']', $when); } echo '<div id="Contact"' . ($active ? '' : ' style="display:none"') . '>'; $form->renderInactive($form->getRenderer(), $vars); /* Comments. */ if (!empty($conf['comments']['allow']) && $registry->hasMethod('forums/doComments')) { try { $comments = $registry->call('forums/doComments', array('turba', $this->contact->driver->getName() . '.' . $this->contact->getValue('__key'), 'commentCallback')); } catch (Horde_Exception $e) { Horde::log($e, 'DEBUG'); $comments = array(); } } if (!empty($comments['threads'])) { echo '<br />' . $comments['threads']; } if (!empty($comments['comments'])) { echo '<br />' . $comments['comments']; } echo '</div>'; if ($active && $browser->hasFeature('dom')) { if ($this->contact->hasPermission(Horde_Perms::EDIT)) { $edit = new Turba_View_EditContact($this->contact); $edit->html(false); } if ($this->contact->hasPermission(Horde_Perms::DELETE)) { $delete = new Turba_View_DeleteContact($this->contact); $delete->html(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; $fieldform->addVariable($param['label'], $field_id, $param['type'], $param['required'], $param['readonly'], $param['desc']); } /* Set the current field type to the old field type var. */ $vars->set('old_field_type', $field_type); if ($fieldform->validate($vars)) { /* Save field if valid and the current and old field type match. */ $fieldform->getInfo($vars, $info); try { $save_field = $injector->getInstance('Ulaform_Factory_Driver')->create()->saveField($info); $notification->push(_("Field saved."), 'horde.success'); Horde::url('fields.php', true)->add('form_id', $info['form_id'])->redirect(); } catch (Horde_Exception $e) { $notification->push(sprintf(_("Error saving field. %s."), $e->getMessage()), 'horde.error'); } } /* Get a field list. */ try { $fields_list = $ulaform_driver->getFieldsList($form_id); if (empty($fields_list)) {
foreach ($action_params as $id => $param) { $param['required'] = isset($param['required']) ? $param['required'] : true; $param['readonly'] = isset($param['readonly']) ? $param['readonly'] : false; $param['desc'] = isset($param['desc']) ? $param['desc'] : null; $param['params'] = isset($param['params']) ? $param['params'] : null; $form->addVariable($param['label'], 'form_params[' . $id . ']', $param['type'], $param['required'], $param['readonly'], $param['desc'], $param['params']); } } /* Set default language for the form. */ $v = $form->addVariable(_("Default language"), 'form_params[language]', 'enum', false, false, null, array($registry->nlsconfig->languages, _("-- default configured --"))); $v->setOption('htmlchars', true); /* TODO: set up Ulaform to insert any javascript saved here into the form. */ $v = $form->addVariable(_("Javascript to execute on form \"submit\":"), 'form_onsubmit', 'longtext', false, false, null, array(3, 40)); $v->setHelp('on-submit'); /* Set up the action choice fields. */ $vars->set('old_form_action', $form_action); if ($formname && !$changed_action) { $form->validate($vars); if ($form->isValid()) { $form->getInfo($vars, $info); try { $form_id = $ulaform_driver->saveForm($info); $notification->push(_("Form details saved."), 'horde.success'); Horde::url('forms.php', true)->redirect(); } catch (Ulaform_Exception $e) { $notification->push(sprintf(_("Error saving form. %s."), $e->getMessage()), 'horde.error'); } } } /* Render the form. */ $view = new Horde_View(array('templatePath' => ULAFORM_TEMPLATES));
$notification->push(_("Could not post the message: ") . $messages->getMessage(), 'horde.warning'); Horde::url('forums.php', true)->redirect(); } /* Check edit permissions */ if (!$messages->hasPermission(Horde_Perms::EDIT)) { $notification->push(sprintf(_("You don't have permission to post 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; } /* Check if a message is being edited. */ if ($message_id) { $message = $messages->getMessage($message_id); if (!$formname) { $vars = new Horde_Variables($message); $vars->set('message_subject', $message['message_subject']); $vars->set('message_body', $message['body']); } if ($message['attachments']) { $attachment_link = $messages->getAttachmentLink($message_id); if ($attachment_link) { $vars->set('attachment_preview', $attachment_link); } } } else { $vars->set('forum_id', $forum_id); $vars->set('message_id', $message_id); } /* Get the forum details. */ $forum_name = $messages->_forum['forum_name']; /* Set the title. */
$beatnik = Horde_Registry::appInit('beatnik'); require_once BEATNIK_BASE . '/lib/Forms/EditRecord.php'; $domains = array(); if (Horde_Util::getGet('domain') == 'current') { $url = Horde::url('viewzone.php'); $domains[] = $_SESSION['beatnik']['curdomain']; } elseif (Horde_Util::getGet('domain') == 'all') { $url = Horde::url('listzones.php'); foreach (Beatnik::needCommit() as $domain) { $domains[] = $beatnik->driver->getDomain($domain); } } foreach ($domains as $domain) { $_SESSION['beatnik']['curdomain'] = $domain; $vars = new Horde_Variables(); $vars->set('rectype', 'soa'); foreach ($domain as $field => $value) { $vars->set($field, $value); } $vars->set('serial', Beatnik::incrementSerial($domain['serial'])); $form = new EditRecord($vars); $form->useToken(false); $form->setSubmitted(true); if ($form->validate($vars)) { $form->getInfo($vars, $info); try { $result = $beatnik->driver->saveRecord($info); } catch (Exception $e) { $notification->push($e->getMessage(), 'horde.error'); } $notification->push(sprintf(_('Zone serial for %s incremented.'), $domain['zonename']), 'horde.success');
/** * Sets all properties of the ticket necessary to display the * TicketDetailsForm. * * @param Horde_Variables $vars The form variables object to set info in. * @param bool $split_owners This has to be set if you want to use the * $vars var for saving later or otherwise * $form->validate() will fail */ public function setDetails(Horde_Variables $vars, $split_owners = false) { $vars->set('id', $this->getId()); foreach ($this->getDetails() as $varname => $value) { if ($varname == 'owners') { $owners = $gowners = array(); foreach ($value as $owner) { if (strpos($owner, 'user:'******'owners', $owners); $vars->add('group_owners', $gowners); } $vars->add($varname, $value); } /* User formatting. */ $vars->set('user_id_requester', Whups::formatUser($this->get('user_id_requester'))); $vars->set('user_id_owner', Whups::getOwners($this->_id)); }
* did not receive this file, see http://www.horde.org/licenses/gpl. * * @author Marko Djukic <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('agora'); /* Set up the forums object. */ $forums = $injector->getInstance('Agora_Factory_Driver')->create(); list($forum_id, , $scope) = Agora::getAgoraId(); $scope = Horde_Util::getGet('scope', 'agora'); $vars = Horde_Variables::getDefaultVariables(); /* Check if a forum is being edited. */ if (isset($forum_id) && !$vars->get('forum_name')) { try { $vars = new Horde_Variables($forums->getForum($forum_id)); $vars->set('forum_id', $forum_id); } catch (Horde_Exception $e) { $notification->push($e->getMessage()); unset($forum_id); } } $title = isset($forum_id) ? _("Edit Forum") : _("New Forum"); /* Check permissions */ if (isset($forum_id) && !$registry->isAdmin(array('permission' => 'agora:admin'))) { $notification->push(sprintf(_("You don't have permissions to edit forum %s"), $registry->get('name', $scope)), 'horde.warning'); Horde::url('forums.php', true)->redirect(); } if (!$registry->isAdmin(array('permission' => 'agora:admin'))) { $notification->push(sprintf(_("You don't have permissions to create a new forum in %s"), $registry->get('name', $scope)), 'horde.warning'); Horde::url('forums.php', true)->redirect(); }
/** * Performs a Task search. self::_tasks is populated with the results. * * @throws Nag_Exception */ protected function _doSearch() { // Clear the tag browser in case we have an active browse set. $this->_browser->clearSearch(); // Don't show the tag browser. $this->_showTagBrowser = false; $form = new Nag_Form_Search($this->_vars); if ($form->validate($this->_vars, true)) { $form->getInfo($this->_vars, $info); } else { throw new Nag_Exception(current($form->getErrors())); } // Text filter $search_pattern = $this->_vars->search_pattern; $search_in = empty($this->_vars->search_in) ? array() : $this->_vars->search_in; $search_name = in_array('search_name', $search_in) ? Nag_Search::MASK_NAME : 0; $search_desc = in_array('search_desc', $search_in) ? Nag_Search::MASK_DESC : 0; $search_tags = !empty($this->_vars->search_tags) ? Nag_Search::MASK_TAGS : 0; $search_completed = $this->_vars->search_completed; $this->_vars->set('show_completed', $search_completed); $mask = $search_name | $search_desc | $search_tags; // Date filter $date = $info['due_date']; if (empty($date)) { $date = array(); } // Prepare the search $search = new Nag_Search($search_pattern, $mask, array('completed' => $search_completed, 'due' => $date, 'tags' => empty($this->_vars->search_tags) ? array() : $GLOBALS['injector']->getInstance('Nag_Tagger')->split($this->_vars->search_tags))); try { $tasks = $search->getSlice(); } catch (Nag_Exception $e) { $GLOBALS['notification']->push($tasks, 'horde.error'); $tasks = new Nag_Task(); } // Save as a smart list? if ($id = $this->_vars->get('smart_id')) { // Existing list. $smartlist = $GLOBALS['nag_shares']->getShare($id); Nag::updateTasklist($smartlist, array('name' => $this->_vars->get('smartlist_name'), 'search' => serialize($search))); $this->_title = $smartlist->get('name'); $this->_smartShare = $smartlist; } elseif ($this->_vars->get('save_smartlist')) { $this->_smartShare = Nag::addTasklist(array('name' => $this->_vars->get('smartlist_name'), 'search' => serialize($search)), false); $this->_title = $this->_vars->get('smartlist_name'); } else { // Build a page title based on criteria. $this->_title = sprintf(_("Search: Results for")); $have_title = false; if (!empty($search_pattern)) { $have_title = true; $this->_title .= ' "' . $search_pattern . '" '; } else { $this->_title .= ' ' . _("tasks") . ' '; } if (!empty($date)) { if ($have_title) { $this->_title .= _("and") . ' '; } else { $this->_title .= _("with") . ' '; $have_title = true; } $this->_title .= sprintf(_("due date within %d days of %s"), $date[0], $date[1]) . ' '; } if (!empty($search_tags)) { if ($have_title) { $this->_title .= _("and") . ' '; } else { $this->_title .= _("with") . ' '; } $this->_title .= sprintf(_("and tagged with %s"), $this->_vars->search_tags); } } $GLOBALS['session']->set('nag', 'search', $search, Horde_Session::TYPE_OBJECT); $this->_haveSearch = true; $this->_tasks = $tasks; }
/** * Allows other Horde apps to post messages. * * The forum name is constructed by just the $forum_name variable under the * data root 'agora.forums.<app>'. It is up to the apps themselves to make * sure that the forum name is unique. * * If the forum does not exist, it will be automatically created by Agora. * * @access private * * @param string $scope The application which is posting this message. * @param string $forum_name The unique name for the forum. * @param string $callback A callback method of the specified application * that gets called to make sure that posting to * this forum is allowed. * @param array $params Any parameters for the forum message posting. * <pre> * message_id - An existing message to edit * message_parent_id - The ID of the parent message * title - Posting title * </pre> * @param string $url If specified, the form gets submitted to this URL * instead of the current page. * @param array $variables A hash with all variables of a submitted form * generated by this method. * * @return mixed Returns either the rendered Horde_Form for posting a message * or PEAR_Error object on error, or true in case of a * successful post. */ public function postMessage($scope, $forum_name, $callback, $params = array(), $url = null, $variables = null) { global $registry; /* Check if posting messages is allowed. */ $check = $registry->callByPackage($scope, $callback, array($forum_name)); if ($check instanceof PEAR_Error || !$check) { return ''; } /* Create a separate notification queue. */ $queue = Horde_Notification::singleton('agoraPostMessage'); $queue->attach('status'); /* Set up the forums object. */ $forums = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope); /* Set up form variables. */ $vars = Horde_Variables::getDefaultVariables(); if (is_array($variables)) { foreach ($variables as $varname => $value) { $vars->add($varname, $value); } } $formname = $vars->get('formname'); /* Check if the forum exists and fetch the ID. */ $params['forum_id'] = $forums->getForumId($forum_name); if ($params['forum_id'] === null) { $vars->set('new_forum', $forum_name); } else { $vars->set('forum_id', $params['forum_id']); } /* Set up the messages control object. */ $messages = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $params['forum_id']); if ($messages instanceof PEAR_Error) { $queue->push(_("Could not post the message: ") . $messages->getMessage(), 'horde.error'); Horde::startBuffer(); $queue->notify(array('listeners' => 'status')); return Horde::endBuffer(); } /* Check post permissions. */ if (!$messages->hasPermission(Horde_Perms::EDIT)) { Horde::permissionDeniedError('agora', null); return PEAR::raiseError(sprintf(_("You don't have permission to post messages in forum %s."), $params['forum_id'])); } if (isset($params['message_id'])) { $message = $messages->getMessage($params['message_id']); if (!$formname) { $vars = new Horde_Variables($message); $vars->set('message_subject', $message['message_subject']); $vars->set('message_body', $message['body']); } $editing = true; } else { $editing = false; $params['message_id'] = null; } /* Set a default title if one not specified. */ if (!isset($params['title'])) { $params['title'] = $editing ? _("Edit Message") : _("Post a New Message"); } /* Get the form object. */ $form = $messages->getForm($vars, $params['title'], $editing, is_null($params['forum_id'])); /* Validate the form. */ if ($form->validate($vars)) { $form->getInfo($vars, $info); if (isset($info['new_forum'])) { $forum_info = $this->prepareFormData($scope, false, array('forum_name' => $info['new_forum']), $callback); if ($forum_info instanceof PEAR_Error) { return $forum_info; } $info['forum_id'] = $m_params['forum_id'] = $forums->saveForum($forum_info); $result = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create($scope, $info['forum_id']); if ($result instanceof PEAR_Error) { return $result; } } /* Try and store this message and get back a new message_id */ $message_id = $messages->saveMessage($info); if ($message_id instanceof PEAR_Error) { $queue->push(_("Could not post the message: ") . $message_id->getMessage(), 'horde.error'); } else { $queue->push(_("Message posted."), 'horde.success'); $count = $messages->countMessages(); $registry->callByPackage($scope, $callback, array($forum_name, 'messages', $count)); Horde::startBuffer(); $queue->notify(array('listeners' => 'status')); return Horde::endBuffer(); } } /* Replying to a previous post? */ if (isset($params['message_parent_id']) && !$form->isSubmitted()) { $message = $messages->replyMessage($params['message_parent_id']); if (!$message instanceof PEAR_Error) { $vars->set('message_parent_id', $params['message_parent_id']); $vars->set('message_subject', $message['message_subject']); $vars->set('message_body', $message['body']); } else { /* Bad parent message id, offer to do a regular post. */ $vars->set('message_parent_id', ''); } } if (!$url) { $url = Horde::selfUrl(true, false, true); } Horde::startBuffer(); $form->renderActive(null, $vars, $url, 'post', null, false); return Horde::endBuffer(); }
/** * Sets all properties of the ticket necessary to display the * TicketDetailsForm. * * @param Horde_Variables $vars The form variables object to set info in. */ public function setDetails(Horde_Variables $vars) { $vars->set('id', $this->getId()); foreach ($this->getDetails() as $varname => $value) { $vars->set($varname, $value); } /* User formatting. */ $vars->set('user_id_requester', Whups::formatUser($this->get('user_id_requester'))); $vars->set('user_id_owner', Whups::getOwners($this->_id)); }
} catch (Horde_Share_Exception $e) { $notification->push(sprintf(_("Access denied editing task: %s"), $e->getMessage()), 'horde.error'); } if (!$share->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing task."), 'horde.error'); } else { $task = Nag::getTask($tasklist_id, $task_id); if (!isset($task) || !isset($task->id)) { $notification->push(_("Task not found."), 'horde.error'); } elseif ($task->private && $task->owner != $registry->getAuth()) { $notification->push(_("Access denied editing task."), 'horde.error'); } else { $h = $task->toHash(); $h['tags'] = implode(',', $h['tags']); $vars = new Horde_Variables($h); $vars->set('old_tasklist', $task->tasklist); $vars->set('url', Horde_Util::getFormData('url')); if ($sl = Horde_Util::getFormData('list')) { $vars->set('list', $sl); } if ($tn = Horde_Util::getFormData('tab_name')) { $vars->set('tab_name', $tn); } $form = new Nag_Form_Task($vars, sprintf(_("Edit: %s"), $task->name)); if (!$task->completed) { $task->loadChildren(); $form->setTask($task); } break; } }
/** * Populate a Horde_Variables instance with the search values for this * search. * * @param Horde_Variables $vars The Horde_Variables object. */ public function getVars(Horde_Variables &$vars) { $vars->set('search_pattern', $this->_search); $vars->set('search_tags', implode(',', $this->_tags)); $vars->set('search_completed', $this->_completed); $vars->set('due_within', $this->_due[0]); $vars->set('due_of', $this->_due[1]); $mask = array(); if ($this->_mask & self::MASK_NAME) { $mask[] = 'search_name'; } if ($this->_mask & self::MASK_DESC) { $mask[] = 'search_desc'; } if (!empty($mask)) { $vars->set('search_in', $mask); } }
/** * Path to form * * @param Horde_Variables $vars * * @return string * @throws Whups_Exception */ public function pathToForm(&$vars) { $path = Whups_Query::stringToPath($vars->get('path')); $parent = null; $qobj = $this->query; for ($i = 0, $c = count($path); $i < $c; $i++) { $parent = $qobj; $qobj = $qobj['children'][$path[$i]]; } if ($qobj['type'] != Whups_Query::TYPE_CRITERION) { // Search for any criteria that have been combined automatically // with an AND or OR. switch ($qobj['type']) { case Whups_Query::TYPE_OR: // Search for multiple ids. $criteria = array(); foreach ($qobj['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_ID) { $criteria = false; break; } $criteria[] = $child['value']; } if ($criteria) { $vars->set('id', implode(',', $criteria)); return 'props'; } // Search for user criteria. $criteria = array(); $operator = $value = null; foreach ($qobj['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_OWNERS && $child['criterion'] != Whups_Query::CRITERION_REQUESTER && $child['criterion'] != Whups_Query::CRITERION_ADDED_COMMENT || isset($operator) && $operator != $child['operator'] || isset($value) && $value != $child['value']) { $criteria = false; break; } $criteria[] = $child['criterion']; $operator = $child['operator']; $value = $child['value']; } if ($criteria) { $vars->set('user', $value); $vars->set('operator', $operator); foreach ($criteria as $criterion) { switch ($criterion) { case Whups_Query::CRITERION_OWNERS: $vars->set('owners', true); break; case Whups_Query::CRITERION_REQUESTER: $vars->set('requester', true); break; case Whups_Query::CRITERION_ADDED_COMMENT: $vars->set('comments', true); break; } } return 'user'; } // Search for text criteria. $criteria = array(); $operator = $value = null; foreach ($qobj['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_COMMENT && $child['criterion'] != Whups_Query::CRITERION_SUMMARY || isset($operator) && $operator != $child['operator'] || isset($value) && $value != $child['value']) { $criteria = false; break; } $criteria[] = $child['criterion']; $operator = $child['operator']; $value = $child['value']; } if ($criteria) { $vars->set('text', $value); $vars->set('operator', $operator); foreach ($criteria as $criterion) { if ($criterion == Whups_Query::CRITERION_COMMENT) { $vars->set('comments', true); } elseif ($criterion == Whups_Query::CRITERION_SUMMARY) { $vars->set('summary', true); } } return 'text'; } // Search for attributes. $attribs = array_keys($GLOBALS['whups_driver']->getAttributesForType()); $criteria = array(); $operator = $value = null; foreach ($qobj['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_ATTRIBUTE || isset($operator) && $operator != $child['operator'] || isset($value) && $value != $child['value'] || !in_array($child['cvalue'], $attribs)) { $criteria = false; break; } $criteria[] = $child['cvalue']; $operator = $child['operator']; $value = $child['value']; } if ($criteria) { $vars->set('text', $value); $vars->set('operator', $operator); foreach ($criteria as $criterion) { $vars->set('a' . $criterion, true); } return 'attribs'; } break; case Whups_Query::TYPE_AND: // Search for date criteria. $criteria = false; foreach ($qobj['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_TIMESTAMP && $child['criterion'] != Whups_Query::CRITERION_UPDATED && $child['criterion'] != Whups_Query::CRITERION_RESOLVED && $child['criterion'] != Whups_Query::CRITERION_ASSIGNED && $child['criterion'] != Whups_Query::CRITERION_DUE) { $criteria = false; break; } $criteria = true; } if ($criteria) { foreach ($qobj['children'] as $child) { switch ($child['criterion'] . $child['operator']) { case Whups_Query::CRITERION_TIMESTAMP . Whups_Query::OPERATOR_GREATER: $vars->set('ticket_timestamp[from]', $child['value']); break; case Whups_Query::CRITERION_TIMESTAMP . Whups_Query::OPERATOR_LESS: $vars->set('ticket_timestamp[to]', $child['value']); break; case Whups_Query::CRITERION_UPDATED . Whups_Query::OPERATOR_GREATER: $vars->set('date_updated[from]', $child['value']); break; case Whups_Query::CRITERION_UPDATED . Whups_Query::OPERATOR_LESS: $vars->set('date_updated[to]', $child['value']); break; case Whups_Query::CRITERION_RESOLVED . Whups_Query::OPERATOR_GREATER: $vars->set('date_resolved[from]', $child['value']); break; case Whups_Query::CRITERION_RESOLVED . Whups_Query::OPERATOR_LESS: $vars->set('date_resolved[to]', $child['value']); break; case Whups_Query::CRITERION_ASSIGNED . Whups_Query::OPERATOR_GREATER: $vars->set('date_assigned[from]', $child['value']); break; case Whups_Query::CRITERION_ASSIGNED . Whups_Query::OPERATOR_LESS: $vars->set('date_assigned[to]', $child['value']); break; case Whups_Query::CRITERION_DUE . Whups_Query::OPERATOR_GREATER: $vars->set('ticket_due[from]', $child['value']); break; case Whups_Query::CRITERION_DUE . Whups_Query::OPERATOR_LESS: $vars->set('ticket_due[to]', $child['value']); break; } } return 'date'; } // Search for version criterion. if (count($qobj['children']) == 2 && $qobj['children'][0]['type'] == Whups_Query::TYPE_CRITERION && $qobj['children'][0]['criterion'] == Whups_Query::CRITERION_QUEUE && $qobj['children'][1]['type'] == Whups_Query::TYPE_CRITERION && $qobj['children'][1]['criterion'] == Whups_Query::CRITERION_VERSION) { $vars->set('queue', $qobj['children'][0]['value']); $vars->set('version', $qobj['children'][1]['value']); return 'props'; } break; } throw new Whups_Exception(_("This query element cannot be edited.")); } switch ($qobj['criterion']) { case Whups_Query::CRITERION_ID: $multiple = false; if ($parent && $parent['type'] == Whups_Query::TYPE_OR) { $multiple = array(); foreach ($parent['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_ID) { $multiple = false; break; } $multiple[] = $child['value']; } } if ($multiple) { array_pop($path); $vars->set('path', Whups_Query::pathToString($path)); $vars->set('id', implode(',', $multiple)); } else { $vars->set('id', $qobj['value']); } return 'props'; case Whups_Query::CRITERION_QUEUE: if ($parent && $parent['type'] == Whups_Query::TYPE_AND && count($parent['children']) == 2 && $parent['children'][1]['type'] == Whups_Query::TYPE_CRITERION && $parent['children'][1]['criterion'] == Whups_Query::CRITERION_VERSION) { array_pop($path); $vars->set('path', Whups_Query::pathToString($path)); $vars->set('version', $parent['children'][1]['value']); } $vars->set('queue', $qobj['value']); return 'props'; case Whups_Query::CRITERION_VERSION: array_pop($path); $vars->set('path', Whups_Query::pathToString($path)); $vars->set('queue', $parent['children'][0]['value']); $vars->set('version', $qobj['value']); return 'props'; case Whups_Query::CRITERION_TYPE: $vars->set('ttype', $qobj['value']); return 'props'; case Whups_Query::CRITERION_STATE: $vars->set('state', $qobj['value']); return 'props'; case Whups_Query::CRITERION_PRIORITY: $vars->set('priority', $qobj['value']); return 'props'; case Whups_Query::CRITERION_TIMESTAMP: case Whups_Query::CRITERION_UPDATED: case Whups_Query::CRITERION_RESOLVED: case Whups_Query::CRITERION_ASSIGNED: case Whups_Query::CRITERION_DUE: $criteria = false; if ($parent && $parent['type'] == Whups_Query::TYPE_AND) { foreach ($parent['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_TIMESTAMP && $child['criterion'] != Whups_Query::CRITERION_UPDATED && $child['criterion'] != Whups_Query::CRITERION_RESOLVED && $child['criterion'] != Whups_Query::CRITERION_ASSIGNED && $child['criterion'] != Whups_Query::CRITERION_DUE) { $criteria = false; break; } $criteria = true; } } if ($criteria) { array_pop($path); $vars->set('path', Whups_Query::pathToString($path)); foreach ($parent['children'] as $child) { switch ($child['criterion'] . $child['operator']) { case Whups_Query::CRITERION_TIMESTAMP . Whups_Query::OPERATOR_GREATER: $vars->set('ticket_timestamp[from]', $child['value']); break; case Whups_Query::CRITERION_TIMESTAMP . Whups_Query::OPERATOR_LESS: $vars->set('ticket_timestamp[to]', $child['value']); break; case Whups_Query::CRITERION_UPDATED . Whups_Query::OPERATOR_GREATER: $vars->set('date_updated[from]', $child['value']); break; case Whups_Query::CRITERION_UPDATED . Whups_Query::OPERATOR_LESS: $vars->set('date_updated[to]', $child['value']); break; case Whups_Query::CRITERION_RESOLVED . Whups_Query::OPERATOR_GREATER: $vars->set('date_resolved[from]', $child['value']); break; case Whups_Query::CRITERION_RESOLVED . Whups_Query::OPERATOR_LESS: $vars->set('date_resolved[to]', $child['value']); break; case Whups_Query::CRITERION_ASSIGNED . Whups_Query::OPERATOR_GREATER: $vars->set('date_assigned[from]', $child['value']); break; case Whups_Query::CRITERION_ASSIGNED . Whups_Query::OPERATOR_LESS: $vars->set('date_assigned[to]', $child['value']); break; case Whups_Query::CRITERION_DUE . Whups_Query::OPERATOR_GREATER: $vars->set('ticket_due[from]', $child['value']); break; case Whups_Query::CRITERION_DUE . Whups_Query::OPERATOR_LESS: $vars->set('ticket_due[to]', $child['value']); break; } } } return 'date'; case Whups_Query::CRITERION_OWNERS: case Whups_Query::CRITERION_REQUESTER: case Whups_Query::CRITERION_ADDED_COMMENT: $criteria = false; if ($parent && $parent['type'] == Whups_Query::TYPE_OR) { $criteria = array(); foreach ($parent['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || !in_array($child['criterion'], array(Whups_Query::CRITERION_OWNERS, Whups_Query::CRITERION_REQUESTER, Whups_Query::CRITERION_ADDED_COMMENT))) { $criteria = false; break; } $criteria[] = $child['criterion']; } if ($criteria) { array_pop($path); $vars->set('path', Whups_Query::pathToString($path)); } } if (!$criteria) { $criteria = array($qobj['criterion']); } $vars->set('user', $qobj['value']); $vars->set('operator', $qobj['operator']); foreach ($criteria as $criterion) { switch ($criterion) { case Whups_Query::CRITERION_OWNERS: $vars->set('owners', true); break; case Whups_Query::CRITERION_REQUESTER: $vars->set('requester', true); break; case Whups_Query::CRITERION_ADDED_COMMENT: $vars->set('comments', true); break; } } return 'user'; case Whups_Query::CRITERION_GROUPS: $vars->set('groups', $qobj['value']); return 'group'; case Whups_Query::CRITERION_COMMENT: case Whups_Query::CRITERION_SUMMARY: $criteria = false; if ($parent && $parent['type'] == Whups_Query::TYPE_OR) { $criteria = array(); $operator = $value = null; foreach ($parent['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_COMMENT && $child['criterion'] != Whups_Query::CRITERION_SUMMARY || isset($operator) && $operator != $child['operator'] || isset($value) && $value != $child['value']) { $criteria = false; break; } $criteria[] = $child['criterion']; $operator = $child['operator']; $value = $child['value']; } if ($criteria) { array_pop($path); $vars->set('path', Whups_Query::pathToString($path)); } } else { $operator = $qobj['operator']; $value = $qobj['value']; } if (!$criteria) { $criteria = array($qobj['criterion']); } $vars->set('text', $value); $vars->set('operator', $operator); foreach ($criteria as $criterion) { if ($criterion == Whups_Query::CRITERION_COMMENT) { $vars->set('comments', true); } elseif ($criterion == Whups_Query::CRITERION_SUMMARY) { $vars->set('summary', true); } } return 'text'; case Whups_Query::CRITERION_ATTRIBUTE: $attribs = array_keys($GLOBALS['whups_driver']->getAttributesForType()); $criteria = false; if ($parent && $parent['type'] == Whups_Query::TYPE_OR) { $criteria = array(); $operator = $value = null; foreach ($parent['children'] as $child) { if ($child['type'] != Whups_Query::TYPE_CRITERION || $child['criterion'] != Whups_Query::CRITERION_ATTRIBUTE || isset($operator) && $operator != $child['operator'] || isset($value) && $value != $child['value'] || !in_array($child['cvalue'], $attribs)) { $criteria = false; break; } $criteria[] = $child['cvalue']; $operator = $child['operator']; $value = $child['value']; } if ($criteria) { array_pop($path); $vars->set('path', Whups_Query::pathToString($path)); } } else { $operator = $qobj['operator']; $value = $qobj['value']; } if (!$criteria) { $criteria = array($qobj['cvalue']); } $vars->set('text', $value); $vars->set('operator', $operator); foreach ($criteria as $criterion) { $vars->set('a' . $criterion, true); } return 'attribs'; } throw new Whups_Exception(_("This query element cannot be edited.")); }
$Form->execute(); $notification->push(_("Device information updated."), 'horde.success'); $action = 'list'; break; } catch (Exception $e) { $notification->push($e); } } elseif ($Form->isSubmitted()) { // Submitted but not valid $notification->push(_("Problem processing the form. Please check below and try again."), 'horde.warning'); } // Create a new add/edit form $devid = Horde_Util::getFormData('devid'); $devices = $shout->devices->getDevices($curaccount); $vars = new Horde_Variables($devices[$devid]); $vars->set('action', $action); $Form = new DeviceDetailsForm($vars); // Make sure we get the right template below. $action = 'edit'; break; case 'delete': $title .= sprintf(_("Delete Devices %s"), $extension); $devid = Horde_Util::getFormData('devid'); $vars = Horde_Variables::getDefaultVariables(); $vars->set('account', $curaccount); $Form = new DeviceDeleteForm($vars); $FormValid = $Form->validate($vars, true); if ($Form->isSubmitted() && $FormValid) { try { $Form->execute(); $notification->push(_("Device Deleted."));
/** * Render the table. * * @param array $data The data to render (unused). * * @return mixed The HTML needed to render the table or false if failed. */ public function render($data = null) { global $notification; try { $result = $this->getMetaData(); } catch (Hermes_Exception $e) { $notification->push($e->getMessage(), 'horde.error'); return false; } $varRenderer = new Horde_Core_Ui_VarRenderer_Html(); $html = '<h1 class="header">'; // Table title. if (isset($this->_config['title'])) { $html .= $this->_config['title']; } else { $html .= _("Table"); } // Hook for icons and things if (isset($this->_config['title_extra'])) { $html .= $this->_config['title_extra']; } $html .= '</h1>'; // Column titles. $html .= '<table class="time striped" id="hermes_time" cellspacing="0"><thead><tr class="item">'; foreach ($this->_metaData['sections']['data']['columns'] as $col) { $html .= '<th' . (isset($col['colspan']) ? ' colspan="' . $col['colspan'] . '"' : '') . '>' . $col['title'] . '</th>'; } $html .= '</tr></thead>'; // Display data. try { $data = $this->_getData(); } catch (Hermes_Exception $e) { $notification->push($e, 'horde.error'); $data = array(); } foreach ($this->_metaData['sections'] as $secname => $section) { if (empty($data[$secname])) { continue; } /* Open the table section, either a tbody or the tfoot. */ $html .= $secname == 'footer' ? '<tfoot>' : '<tbody>'; // This Horde_Variables object is populated for each table row // so that we can use the Horde_Core_Ui_VarRenderer. $vars = new Horde_Variables(); $form = null; foreach ($data[$secname] as $row) { $html .= '<tr>'; foreach ($row as $key => $value) { $vars->set($key, $value); } foreach ($section['columns'] as $col) { $value = null; if (isset($row[$col['name']])) { $value = $row[$col['name']]; } $align = ''; if (isset($col['align'])) { $align = ' align="' . htmlspecialchars($col['align']) . '"'; } $colspan = ''; if (isset($col['colspan'])) { $colspan = ' colspan="' . htmlspecialchars($col['colspan']) . '"'; } $html .= "<td{$align}{$colspan}"; if (!empty($col['nobr'])) { $html .= ' class="nowrap"'; } $html .= '>'; // XXX: Should probably be done at the <tr> with a class. if (!empty($row['strong'])) { $html .= '<strong>'; } if (isset($col['type']) && substr($col['type'], 0, 1) == '%') { switch ($col['type']) { case '%html': if (!empty($row[$col['name']])) { $html .= $row[$col['name']]; } break; } } else { $html .= $varRenderer->render($form, $this->_formVars[$secname][$col['name']], $vars); } if (!empty($row['strong'])) { $html .= '</strong>'; } $html .= '</td>'; } $html .= '</tr>'; } // Close the table section. $html .= $secname == 'footer' ? '</tfoot>' : '</tbody>'; } $GLOBALS['page_output']->addScriptFile('stripe.js', 'horde'); return $html . '</table>'; }
/** * Create a permission editing form. * * @param Horde_Perms_Permission $permission TODO */ public function setupEditForm($permission) { /* Initialise form if required. */ $this->_formInit(); $this->_form->setButtons(Horde_Core_Translation::t("Update"), true); $this->_vars->set('perm_id', $this->_perms->getPermissionId($permission)); $this->_form->addHidden('', 'perm_id', 'text', false); /* Get permission configuration. */ $this->_type = $permission->get('type'); $params = $this->_corePerms->getParams($permission->getName()); /* Default permissions. */ $perm_val = $permission->getDefaultPermissions(); $this->_form->setSection('default', Horde_Core_Translation::t("All Authenticated Users"), Horde_Themes_Image::tag('perms.png'), false); /* We MUST use 'deflt' for the variable name because 'default' is a * reserved word in JavaScript. */ if ($this->_type == 'matrix') { /* Set up the columns for the permissions matrix. */ $cols = Horde_Perms::getPermsArray(); /* Define a single matrix row for default perms. */ $matrix = array(Horde_Perms::integerToArray($perm_val)); $this->_form->addVariable('', 'deflt', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); } else { $var = $this->_form->addVariable('', 'deflt', $this->_type, false, false, null, $params); $var->setDefault($perm_val); } /* Guest permissions. */ $perm_val = $permission->getGuestPermissions(); $this->_form->setSection('guest', Horde_Core_Translation::t("Guest Permissions"), '', false); if ($this->_type == 'matrix') { /* Define a single matrix row for guest perms. */ $matrix = array(Horde_Perms::integerToArray($perm_val)); $this->_form->addVariable('', 'guest', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); } else { $var = $this->_form->addVariable('', 'guest', $this->_type, false, false, null, $params); $var->setDefault($perm_val); } /* Object creator permissions. */ $perm_val = $permission->getCreatorPermissions(); $this->_form->setSection('creator', Horde_Core_Translation::t("Creator Permissions"), Horde_Themes_Image::tag('user.png'), false); if ($this->_type == 'matrix') { /* Define a single matrix row for creator perms. */ $matrix = array(Horde_Perms::integerToArray($perm_val)); $this->_form->addVariable('', 'creator', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); } else { $var = $this->_form->addVariable('', 'creator', $this->_type, false, false, null, $params); $var->setDefault($perm_val); } /* Users permissions. */ $perm_val = $permission->getUserPermissions(); $this->_form->setSection('users', Horde_Core_Translation::t("Individual Users"), Horde_Themes_Image::tag('user.png'), false); $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create(); $user_list = array(); if ($auth->hasCapability('list')) { /* The auth driver has list capabilities so set up an array which * the matrix field type will recognise to set up an enum box for * adding new users to the permissions matrix. */ $new_users = array(); try { $user_list = $auth->listNames(); foreach ($user_list as $user => $name) { if (!isset($perm_val[$user])) { $new_users[$user] = $name; } } } catch (Horde_Auth_Exception $e) { $new_users = true; } } else { /* No list capabilities, setting to true so that the matrix field * type will offer a text input box for adding new users. */ $new_users = true; } if ($this->_type == 'matrix') { /* Set up the matrix array, breaking up each permission integer * into an array. The keys of this array will be the row * headers. */ $rows = array(); $matrix = array(); foreach ($perm_val as $u_id => $u_perms) { $rows[$u_id] = isset($user_list[$u_id]) ? $user_list[$u_id] : $u_id; $matrix[$u_id] = Horde_Perms::integerToArray($u_perms); } $this->_form->addVariable('', 'u', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_users)); } else { if ($new_users) { if (is_array($new_users)) { $u_n = Horde_Util::getFormData('u_n'); $u_n = empty($u_n['u']) ? null : $u_n['u']; $user_html = '<select name="u_n[u]"><option value="">' . Horde_Core_Translation::t("-- select --") . '</option>'; foreach ($new_users as $new_user => $name) { $user_html .= '<option value="' . $new_user . '"'; $user_html .= $u_n == $new_user ? ' selected="selected"' : ''; $user_html .= '>' . htmlspecialchars($name) . '</option>'; } $user_html .= '</select>'; } else { $user_html = '<input type="text" name="u_n[u]" />'; } $this->_form->addVariable($user_html, 'u_n[v]', $this->_type, false, false, null, $params); } foreach ($perm_val as $u_id => $u_perms) { $var = $this->_form->addVariable($u_id, 'u_v[' . $u_id . ']', $this->_type, false, false, null, $params); $var->setDefault($u_perms); } } /* Groups permissions. */ $perm_val = $permission->getGroupPermissions(); $this->_form->setSection('groups', Horde_Core_Translation::t("Groups"), Horde_Themes_Image::tag('group.png'), false); try { $group_list = $GLOBALS['injector']->getInstance('Horde_Group')->listAll(); } catch (Horde_Group_Exception $e) { $GLOBALS['notification']->push($e); $group_list = array(); } if (!empty($group_list)) { /* There is an available list of groups so set up an array which * the matrix field type will recognise to set up an enum box for * adding new groups to the permissions matrix. */ $new_groups = array(); foreach ($group_list as $groupId => $group) { if (!isset($perm_val[$groupId])) { $new_groups[$groupId] = $group; } } } else { /* Do not offer a text box to add new groups. */ $new_groups = false; } if ($this->_type == 'matrix') { /* Set up the matrix array, break up each permission integer into * an array. The keys of this array will be the row headers. */ $rows = array(); $matrix = array(); foreach ($perm_val as $g_id => $g_perms) { $rows[$g_id] = isset($group_list[$g_id]) ? $group_list[$g_id] : $g_id; $matrix[$g_id] = Horde_Perms::integerToArray($g_perms); } $this->_form->addVariable('', 'g', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_groups)); } else { if ($new_groups) { if (is_array($new_groups)) { $g_n = Horde_Util::getFormData('g_n'); $g_n = empty($g_n['g']) ? null : $g_n['g']; $group_html = '<select name="g_n[g]"><option value="">' . Horde_Core_Translation::t("-- select --") . '</option>'; foreach ($new_groups as $groupId => $group) { $group_html .= '<option value="' . $groupId . '"'; $group_html .= $g_n == $groupId ? ' selected="selected"' : ''; $group_html .= '>' . htmlspecialchars($group) . '</option>'; } $group_html .= '</select>'; } else { $group_html = '<input type="text" name="g_n[g]" />'; } $this->_form->addVariable($group_html, 'g_n[v]', $this->_type, false, false, null, $params); } foreach ($perm_val as $g_id => $g_perms) { $var = $this->_form->addVariable(isset($group_list[$g_id]) ? $group_list[$g_id] : $g_id, 'g_v[' . $g_id . ']', $this->_type, false, false, null, $params); $var->setDefault($g_perms); } } /* Set form title. */ $this->_form->setTitle(sprintf(Horde_Core_Translation::t("Edit permissions for \"%s\""), $this->_corePerms->getTitle($permission->getName()))); }
/** * 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); } } }