/** * View this PHAT_Dropobox * * The view function provides the HTML for a user to view the PHAT_Dropbox. * * @param mixed $value whatever needed to match in the dropbox * @return string The HTML to be shown */ function view($value = NULL) { $label = $this->getLabel(); if (isset($_REQUEST['PHAT_' . $label])) { $this->setValue($_REQUEST['PHAT_' . $label]); } if ($this->isRequired()) { $viewTags['REQUIRED_FLAG'] = '*'; } $optionText = $this->getOptionText(); $optionValues = $this->getOptionValues(); for ($i = 0; $i < sizeof($optionText); $i++) { $options[$optionValues[$i]] = $optionText[$i]; } $viewTags['BLURB'] = PHPWS_Text::parseOutput($this->getBlurb(), ENCODE_PARSED_TEXT, false, true); $element = new Form_Select('PHAT_' . $label, $options); $element->setMatch($this->getValue()); $element->setId($element->name); $viewTags['ID'] = $element->getId(); $viewTags['DROPBOX'] = $element->get(); return PHPWS_Template::process($viewTags, 'phatform', 'dropbox/view.tpl'); }
function display_row($trc, $value, $fieldname, $type, $rowhelper, $description, $ewidth = null) { global $text, $group; switch ($type) { case "input": $inpt = new Form_Input($fieldname . $trc, null, 'text', $value); $inpt->setHelp($description); if ($ewidth) { $inpt->setWidth($ewidth); } $group->add($inpt); break; case "checkbox": $group->add(new Form_Checkbox($fieldname . $trc, null, null, $value, 'ON'))->setHelp($description); break; case "password": $group->add(new Form_Input($fieldname . $trc, null, 'password', $value))->setHelp($description); break; case "textarea": $group->add(new Form_Textarea($fieldname . $trc, null, $value))->setHelp($description); break; case "select": $options = array(); foreach ($rowhelper['options']['option'] as $rowopt) { $options[$rowopt['value']] = $rowopt['name']; } $grp = new Form_Select($fieldname . $trc, null, $value, $options); $grp->setHelp($description); if ($ewidth) { $grp->setWidth($ewidth); } $group->add($grp); break; case "interfaces_selection": $size = $size ? "size=\"{$size}\"" : ''; $multiple = ''; if (isset($rowhelper['multiple'])) { $multiple = "multiple"; } echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$size} {$multiple}>\n"; $ifaces = get_configured_interface_with_descr(); $additional_ifaces = $rowhelper['add_to_interfaces_selection']; if (!empty($additional_ifaces)) { $ifaces = array_merge($ifaces, explode(',', $additional_ifaces)); } if (is_array($value)) { $values = $value; } else { $values = explode(',', $value); } $ifaces["lo0"] = "loopback"; $options = array(); $selected = array(); foreach ($ifaces as $ifname => $iface) { $options[$ifname] = $iface; if (in_array($ifname, $values)) { array_push($selected, $ifname); } } $group->add(new Form_Select($fieldname . $trc, null, $multiple ? $selected : $selected[0], $options, $multiple))->setHelp($description); //echo "</select>\n"; break; case "select_source": $options = array(); $selected = array(); if (isset($rowhelper['show_disable_value'])) { $options[$rowhelper['show_disable_value']] = $rowhelper['show_disable_value']; } $source_url = $rowhelper['source']; eval("\$pkg_source_txt = &{$source_url};"); foreach ($pkg_source_txt as $opt) { $source_name = $rowhelper['source_name'] ? $opt[$rowhelper['source_name']] : $opt[$rowhelper['name']]; $source_value = $rowhelper['source_value'] ? $opt[$rowhelper['source_value']] : $opt[$rowhelper['value']]; $options[$source_value] = $source_name; if ($source_value == $value) { array_push($selected, $value); } } $group->add(new Form_Select($fieldname . $trc, null, $multiple ? $selected : $selected[0], $options, $multiple))->setHelp($description); break; } }
} if ($config['l2tp']['mode'] == "server" && have_ruleint_access("l2tp")) { $interfaces['l2tp'] = 'L2TP VPN'; } if (is_pppoe_server_enabled() && have_ruleint_access("pppoe")) { $interfaces['pppoe'] = "PPPoE Server"; } // add ipsec interfaces if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']) && have_ruleint_access("enc0")) { $interfaces["enc0"] = "IPsec"; } // add openvpn/tun interfaces if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) { $interfaces["openvpn"] = "OpenVPN"; } $section->addInput($input = new Form_Select('interface', 'Interface', $pconfig['interface'], $interfaces, $if == "FloatingRules" || isset($pconfig['floating'])))->setHelp('Choose on which interface packets must come in to match this ' . 'rule.'); if ($if == "FloatingRules" || isset($pconfig['floating'])) { $input->setHelp('Choose the interface(s) for this rule.'); } if ($if == "FloatingRules" || isset($pconfig['floating'])) { $section->addInput(new Form_Select('direction', 'Direction', $pconfig['direction'], array('any' => 'any', 'in' => 'in', 'out' => 'out'))); $section->addInput(new Form_Input('floating', 'Floating', 'hidden', 'floating')); } $section->addInput(new Form_Select('ipprotocol', 'TCP/IP Version', $pconfig['ipprotocol'], array('inet' => 'IPv4', 'inet6' => 'IPv6', 'inet46' => 'IPv4+IPv6')))->setHelp('Select the Internet Protocol version this rule applies to'); $section->addInput(new Form_Select('proto', 'Protocol', $pconfig['proto'], array('tcp' => 'TCP', 'udp' => 'UDP', 'tcp/udp' => 'TCP/UDP', 'icmp' => 'ICMP', 'esp' => 'ESP', 'ah' => 'AH', 'gre' => 'GRE', 'ipv6' => 'IPV6', 'igmp' => 'IGMP', 'pim' => 'PIM', 'ospf' => 'OSPF', 'sctp' => 'SCTP', 'any' => 'any', 'carp' => 'CARP', 'pfsync' => 'PFSYNC')))->setHelp('Choose which IP protocol this rule should match.'); $section->addInput(new Form_Select('icmptype', 'ICMP type', $pconfig['icmptype'], $icmptypes))->setHelp('If you selected ICMP for the protocol above, you may specify an ICMP type here.'); $section->addInput(new Form_Select('icmp6type', 'ICMPv6 type', $pconfig['icmptype'], $icmp6types))->setHelp('If you selected ICMP for the protocol above, you may specify an ICMP type here.'); $form->add($section); // Source and destination share a lot of logic. Loop over the two foreach (['src' => 'Source', 'dst' => 'Destination'] as $type => $name) { $section = new Form_Section($name);
if (in_array($opt['value'], $items)) { array_push($selectedlist, $opt['value']); } } if (isset($pkga['advancedfield']) && isset($advfield_count)) { $function = $grouping ? $advanced->add : $advanced->addInput; } else { $function = $grouping ? $section->add : $section->addInput; } if ($grouping) { $group->add(new Form_Select($pkga['fieldname'], strip_tags($pkga['fielddescr']), isset($pkga['multiple']) ? $selectedlist : $selectedlist[0], $optionlist, isset($pkga['multiple'])))->setHelp($pkga['description'])->setOnchange($onchange)->setAttribute('size', $pkga['size']); } else { if (isset($pkga['advancedfield']) && isset($advfield_count)) { $advanced->addInput(new Form_Select($pkga['fieldname'], $pkga['fielddescr'], isset($pkga['multiple']) ? $selectedlist : $selectedlist[0], $optionlist, isset($pkga['multiple'])))->setHelp($pkga['description'])->setOnchange($onchange)->setAttribute('size', $pkga['size']); } else { $selector = new Form_Select($pkga['fieldname'], strip_tags($pkga['fielddescr']), isset($pkga['multiple']) ? $selectedlist : $selectedlist[0], $optionlist, isset($pkga['multiple'])); $selector->setHelp($pkga['description'])->setOnchange($onchange)->setAttribute('size', $pkga['size']); if ($pkga['width']) { $selector->setWidth($pkga['width']); } $section->addInput($selector); } } break; case "select_source": if (isset($pkga['multiple'])) { $items = explode(',', $value); $fieldname .= "[]"; } else { $items = array($value); }
public static function formSelect($name, $opt_array, $match = null, $ignore_index = false, $match_to_value = false, $onchange = null, $label = null) { $element = new Form_Select($name, $opt_array); $element->setMatch($match); if ($onchange) { $element->setExtra(sprintf('onchange="%s"', $onchange)); } return $element->get(); }
/** * Returns a list of items based on the table currently set in this manager * * @param string $listName The name of the list wanting to be returned * @param string $title The title of the list * @param boolean $makeForm Flag whether or not to make a form out of the list * @access public */ function getList($listName, $title = NULL, $makeForm = TRUE, $overRideOp = NULL) { $this->listName = $listName; if (!isset($this->_table) && !isset($this->_request)) { $message = _('Manager was not fully initialized to get a list.'); $error = new PHPWS_Error('core', 'PHPWS_Manager::getList()', $message, 'exit', 1); $error->message(NULL); } $theme = Layout::getCurrentTheme(); $themeModuleRowTpl = "themes/{$theme}/templates/" . $this->_module . '/' . $this->_templates[$this->listName] . '/row.tpl'; $moduleRowTpl = PHPWS_SOURCE_DIR . 'mod/' . $this->_module . '/templates/' . $this->_templates[$this->listName] . '/row.tpl'; $themeCoreRowTpl = 'themes/' . $theme . '/templates/core/defaultRow.tpl'; $coreRowTpl = PHPWS_SOURCE_DIR . 'templates/defaultRow.tpl'; $themeModuleListTpl = "themes/{$theme}/templates/" . $this->_module . '/' . $this->_templates[$this->listName] . '/list.tpl'; $moduleListTpl = PHPWS_SOURCE_DIR . 'mod/' . $this->_module . '/templates/' . $this->_templates[$this->listName] . '/list.tpl'; $themeCoreListTpl = "themes/{$theme}/templates/core/defaultList.tpl"; $coreListTpl = PHPWS_SOURCE_DIR . 'templates/defaultList.tpl'; if (file_exists($themeModuleRowTpl)) { $rowTpl = $themeModuleRowTpl; } else { if (file_exists($moduleRowTpl)) { $rowTpl = $moduleRowTpl; } else { if (file_exists($themeCoreRowTpl)) { $rowTpl = $themeCoreRowTpl; } else { $rowTpl = $coreRowTpl; } } } if (file_exists($themeModuleListTpl)) { $listTpl = $themeModuleListTpl; } else { if (file_exists($moduleListTpl)) { $listTpl = $moduleListTpl; } else { if (file_exists($themeCoreListTpl)) { $listTpl = $themeCoreListTpl; } else { $listTpl = $coreListTpl; } } } if (isset($_REQUEST['PHPWS_MAN_LIST']) && $this->listName == $_REQUEST['PHPWS_MAN_LIST']) { $this->catchOrder(); } if (isset($overRideOp)) { $op = $overRideOp; } else { if (isset($this->_listPaging[$this->listName]['op'])) { $op = $this->_listPaging[$this->listName]['op']; } } if (isset($this->_listPaging[$this->listName]) && is_array($this->_listPaging[$this->listName])) { if (!isset($this->_pagers[$this->listName])) { $this->_pagers[$this->listName] = new PHPWS_Pager(); $this->_pagers[$this->listName]->setLinkBack('./index.php?module=' . $this->_module . '&' . $op . '&PHPWS_MAN_PAGE=' . $this->listName); $this->_pagers[$this->listName]->setLimits($this->_listPaging[$this->listName]['limits']); $this->_pagers[$this->listName]->makeArray(TRUE); if ($this->_anchor) { $this->_pagers[$this->listName]->setAnchor('#' . $this->listName); } $this->_pagers[$this->listName]->limit = $this->_listPaging[$this->listName]['limit']; } $this->_pagers[$this->listName]->setData($this->_getIds()); if (isset($_REQUEST['PHPWS_MAN_PAGE']) && $this->listName == $_REQUEST['PHPWS_MAN_PAGE']) { $this->_pagers[$this->listName]->pageData(); } else { $this->_pagers[$this->listName]->pageData(FALSE); } if (isset($this->_class)) { $items = $this->getItems($this->_pagers[$this->listName]->getData(), FALSE, TRUE); } else { $items = $this->getItems($this->_pagers[$this->listName]->getData()); } $totalItems = count($items); // $totalItems = $this->_pagers[$this->listName]->getNumRows(); } else { if (isset($this->_class)) { $items = $this->getItems(NULL, FALSE, TRUE); } else { $items = $this->getItems(); } $totalItems = sizeof($items); } /* Begin building main list tags array for processTemplate() */ $listTags = array(); if (isset($this->_listExtraLabels) && is_array($this->_listExtraLabels)) { $listTags = $this->_listExtraLabels; } $listTags['TITLE'] = $title; $listTags['ANCHOR'] = '<a id="' . $this->listName . '" name="' . $this->listName . '"></a>'; if ($makeForm) { $listTags['SELECT_LABEL'] = ' '; } $columns = 0; foreach ($this->_listColumns[$this->listName] as $listColumn => $listLabel) { $column = strtoupper($listColumn); $key0 = $column . '_LABEL'; $key1 = $column . '_ORDER_LINK'; $listTags[$key0] = NULL; $listTags[$key1] = NULL; $listTags[$key0] = $listLabel; if (isset($overRideOp)) { $request = $overRideOp; } else { if (isset($this->_listPaging[$this->listName]['op'])) { $request = $this->_listPaging[$this->listName]['op']; } else { $request = $this->_request . '=list'; } } if ($totalItems > 0) { $anchor = ''; if ($this->_anchor) { $anchor = '#' . $this->listName; } if (isset($this->_overrideOrder[$this->listName][$listColumn][0])) { $overRide = $this->_overrideOrder[$this->listName][$listColumn][0]; } else { $overRide = 'default'; } if (isset($this->_listPaging[$this->listName])) { switch ($overRide) { case 0: $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&' . $request . '&PHPWS_MAN_LIST=' . $this->listName . '&PHPWS_MAN_COLUMN=' . $listColumn . '&PHPWS_MAN_ORDER=1&' . 'PHPWS_MAN_PAGE=' . $this->listName . '&' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">'; $listTags[$key1] .= Icon::show('sort') . '</a>'; break; case 1: $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&' . $request . '&PHPWS_MAN_LIST=' . $this->listName . '&PHPWS_MAN_COLUMN=' . $listColumn . '&PHPWS_MAN_ORDER=2&' . 'PHPWS_MAN_PAGE=' . $this->listName . '&' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">'; $listTags[$key1] .= Icon::show('sort-up') . '</a>'; break; case 2: $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&' . $request . '&PHPWS_MAN_LIST=' . $this->listName . '&PHPWS_MAN_COLUMN=' . $listColumn . '&PHPWS_MAN_ORDER=0&' . 'PHPWS_MAN_PAGE=' . $this->listName . '&' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">'; $listTags[$key1] .= Icon::show('sort-down') . '</a>'; break; default: $listTags[$key1] .= '<a href="./index.php?module=' . $this->_module . '&' . $request . '&PHPWS_MAN_LIST=' . $this->listName . '&PHPWS_MAN_COLUMN=' . $listColumn . '&PHPWS_MAN_ORDER=1&' . 'PHPWS_MAN_PAGE=' . $this->listName . '&' . 'PAGER_limit=' . $this->_pagers[$this->listName]->limit . '&' . 'PAGER_start=' . $this->_pagers[$this->listName]->start . '&' . 'PAGER_section=' . $this->_pagers[$this->listName]->section . $anchor . '">'; $listTags[$key1] .= Icon::show('sort') . '</a>'; } } } $columns++; } /* Build each item's row */ $listTags['LIST_ITEMS'] = NULL; if ($totalItems > 0) { $tog = 1; foreach ($items as $item) { $object = NULL; if (isset($this->_class)) { $object = new $this->_class($item); $className = get_class($object); $classMethods = get_class_methods($className); @array_walk($classMethods, 'manager_lower_methods'); $objectVars = get_object_vars($object); if (is_array($objectVars)) { $item = $objectVars; foreach ($item as $key => $value) { if ($key[0] == '_') { $key = substr($key, 1, strlen($key)); $item[$key] = $value; } } } } if ($tog % 2) { $row_class = ' class="bgcolor1"'; } else { $row_class = null; } $tog++; /* Build row tags array for processTemplate() */ $rowTags = array(); if (isset($this->_listExtraLabels) && is_array($this->_listExtraLabels)) { $rowTags = $this->_listExtraLabels; } $rowTags['ROW_CLASS'] = $row_class; if ($makeForm) { $ele = new Form_CheckBox('PHPWS_MAN_ITEMS[]', $item['id']); $rowTags['SELECT'] = $ele->get(); } foreach ($this->_listColumns[$this->listName] as $listColumn => $listLabel) { $column = strtoupper($listColumn); if ($listColumn == 'created') { /* Set created date using phpwebsite's default date and time formats */ $rowTags['CREATED'] = date(PHPWS_DATE_FORMAT . ' ' . PHPWS_TIME_FORMAT, $item['created']); } else { if ($listColumn == 'updated') { /* Set updated date using phpwebsite's default date and time formats */ $rowTags['UPDATED'] = date(PHPWS_DATE_FORMAT . ' ' . PHPWS_TIME_FORMAT, $item['updated']); } else { if ($listColumn == 'hidden') { /* Setting message depending if this item is hidden or not */ if (isset($this->_listValues['hidden'])) { $rowTags['HIDDEN'] = $this->_listValues['hidden'][$item['hidden']]; } else { if ($item['hidden'] == 1) { $rowTags['HIDDEN'] = _('Hidden'); } else { $rowTags['HIDDEN'] = _('Visible'); } } } else { if ($listColumn == 'approved') { /* Setting message depending if this item is approved or not */ if (isset($this->_listValues['hidden'])) { $rowTags['APPROVED'] = $this->_listValues['approved'][$item['approved']]; } else { if ($item['approved'] == 1) { $rowTags['APPROVED'] = _('Approved'); } else { $rowTags['APPROVED'] = _('Unapproved'); } } } else { if ($listColumn == 'groups') { $groups = unserialize($item['groups']); if (is_array($groups) && sizeof($groups) > 0) { /* Set flag to check whether to add a comma or not */ $flag = FALSE; /* Create a string of group names the current item belongs to */ foreach ($groups as $group) { if ($flag) { $rowTags['GROUPS'] .= ', '; } $rowTags['GROUPS'] .= $group; $flag = TRUE; } } else { $rowTags['GROUPS'] = _('All'); } } else { $method = 'get' . $listColumn; if (is_object($object) && in_array($method, $classMethods)) { $rowTags[$column] = $object->{$method}(); } else { $rowTags[$column] = $item[$listColumn]; } } } } } } } /* Process this item and concatenate onto the current list of items */ $listTags['LIST_ITEMS'] .= PHPWS_Template::processTemplate($rowTags, 'core', $rowTpl, FALSE); } if (isset($this->_listPaging[$this->listName]) && is_array($this->_listPaging[$this->listName]) && sizeof($this->_listPaging[$this->listName]) > 0) { $listTags['NAV_BACKWARD'] = $this->_pagers[$this->listName]->getBackLink($this->_listPaging[$this->listName]['back']); $listTags['NAV_FORWARD'] = $this->_pagers[$this->listName]->getForwardLink($this->_listPaging[$this->listName]['forward']); if (isset($this->_listPaging[$this->listName]['section'])) { $listTags['NAV_SECTIONS'] = $this->_pagers[$this->listName]->getSectionLinks(); } $listTags['NAV_LIMITS'] = $this->_pagers[$this->listName]->getLimitLinks(); $listTags['NAV_INFO'] = $this->_pagers[$this->listName]->getSectionInfo(); } $actions = array(); if (isset($this->_listActions[$this->listName]) && is_array($this->_listActions[$this->listName])) { foreach ($this->_listActions[$this->listName] as $actionString => $actionLabel) { if (isset($this->_listPermissions[$this->listName][$actionString])) { $permission = $this->_listPermissions[$this->listName][$actionString]; } if (isset($permission)) { if (Current_User::allow($this->_module, $permission)) { $actions[$actionString] = $actionLabel; } } else { $actions[$actionString] = $actionLabel; } } } if ($makeForm) { /* Create action select and Go button */ $ele = new Form_Select($this->_request, $actions); $listTags['ACTION_SELECT'] = $ele->get(); $listTags['ACTION_BUTTON'] = sprintf('<input type="submit" value="%s" />', _('Go')); $listTags['TOGGLE_ALL'] = javascript('check_all', array('FORM_NAME' => 'PHPWS_MAN_LIST_' . $this->listName)); /* Add hidden variable to designate the current module */ $ele = new Form_Hidden('module', $this->_module); $elements[0] = $ele->get(); $elements[0] .= PHPWS_Template::processTemplate($listTags, 'core', $listTpl, FALSE); /* Create final form and dump it into a content variable to be returned */ $content = sprintf('<form name="%s" action="index.php" method="post">%s</form>', 'PHPWS_MAN_LIST_' . $this->listName, implode("\n", $elements)); } else { $content = PHPWS_Template::processTemplate($listTags, 'core', $listTpl, FALSE); } } else { $listTags['LIST_ITEMS'] = '<tr><td colspan="' . $columns . '">' . _('No items for the current list.') . '</td></tr>'; $content = PHPWS_Template::processTemplate($listTags, 'core', $listTpl, FALSE); } /* reinitialize sort and order before next list */ $this->setSort(NULL); $this->setOrder(NULL); $this->_class = NULL; return $content; }