histogram: Make histograms crash less
[ninja.git] / application / views / command / request.php
blobc9c5de2372b87964d3fc5303a98b25e977ecad61
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 echo '<div>';
4 if (!isset($info['brief'])) {
5 echo "Unknown command: $cmd_typ<br />\n";
6 return;
9 echo "<style>table td {vertical-align: top;border: none;} input, select {margin: 0 0 6px 0;} b {margin: 0 0 6px 0; display: inline-block;}</style>";
11 echo "<h2>{$info['brief']}</h2>\n";
12 echo "<p>{$info['description']}</p>\n";
13 echo form::open('command/commit', array('id' => 'command_form'));
14 echo "<table>";
16 $params = $info['params'];
18 # check if we need to make room for help icon
19 $use_help = false;
20 foreach ($params as $pname => $ary) {
21 if (array_key_exists('help', $ary)) {
22 $use_help = true;
23 break;
27 foreach ($params as $pname => $ary) {
28 $form_name = "cmd_param[$pname]";
29 $dflt = false;
30 if (isset($ary['default']))
31 $dflt = $ary['default'];
33 # help column only printed if we really have a help key
35 echo "<tr><td style='width: 100px'>";
36 echo $use_help ? (isset($ary['help']) ? '<span style="width: 16px">'.$ary['help'].'</span>&nbsp;' : '') : '';
37 if($ary['type'] === 'immutable') {
38 echo $ary['name'];
39 } else {
40 echo "<label for='field_$pname'>".$ary['name'].'</label>';
42 echo "</td><td>";
45 switch ($ary['type']) {
46 case 'select':
47 if (!is_array($dflt) && $cmd_typ != 'DEL_ALL_HOST_COMMENTS' && $cmd_typ != 'DEL_ALL_SVC_COMMENTS') {
48 if ($dflt && false !== array_search($dflt, $ary['options'])) {
49 $dflt = array_search($dflt, $ary['options']);
51 echo form::dropdown(array('name' => $form_name, 'id' => 'field_'.$pname, 'style' => 'width: auto;'), $ary['options'], $dflt);
52 } elseif ($cmd_typ == 'DEL_ALL_SVC_COMMENTS' || $cmd_typ == 'DEL_ALL_HOST_COMMENTS') {
53 if ($dflt && false !== array_search($dflt, $ary['options'])) {
54 $dflt = array_search($dflt, $ary['options']);
56 echo form::dropdown(array('name' => $form_name.'[]', 'id' => 'field_'.$pname, 'multiple' => 'multiple', 'style' => 'width: auto;'), $ary['options'], $dflt);
57 } else if (!empty($dflt)) {
58 $tmp_obj = false;
59 foreach($dflt as $tmp) {
60 $tmp_obj[$tmp] = isset($ary['options'][$tmp]) ? $ary['options'][$tmp] : $tmp;
62 $size = count($tmp_obj);
63 if($size > 15) {
64 $size = 15;
66 echo '<br />' . form::dropdown(array('name' => $form_name.'[]', 'multiple' => 'multiple', 'id' => 'field_'.$pname, 'size' => $size, 'style' => 'width: 350px;'), $tmp_obj);
68 break;
69 case 'checkbox':
70 if (isset($ary['options'])) {
71 foreach ($ary['options'] as $k => $v) {
72 echo form::checkbox($form_name . "[$k]", 'class="checkbox"');
74 break;
76 # fallthrough
77 case 'bool':
78 $checked = (bool)$dflt;
79 echo form::checkbox(array('name' => $form_name, 'id' => 'field_'.$pname), true, $checked, 'class="checkbox"');
80 break;
81 case 'float':
82 case 'int':
83 echo form::input(array('name' => $form_name, 'id' => 'field_'.$pname), $dflt, 'size="10"');
84 break;
85 case 'immutable':
86 if(is_array($dflt)) {
87 $dflt = current($dflt);
89 echo form::hidden($form_name, $dflt);
90 echo '<b style="font-weight: bold;">'.$dflt.'</b>';
91 break;
92 case 'string':
93 default:
94 if ($form_name == 'cmd_param[comment]')
95 echo form::input(array('class' => 'autotest-required', 'id' => 'field_'.$pname, 'name' => $form_name, 'title' => _('Required field'), 'style' => 'width: 280px'), $dflt, '');
96 else {
97 switch($pname) {
98 case "start_time":
99 case "end_time":
100 case "check_time":
101 $classname = 'date';
102 break;
103 case "duration":
104 $classname = 'float';
105 break;
106 default:
107 $classname = 'required';
109 echo form::input(array('class' => "autotest-$classname", 'name' => $form_name, 'title' => _('Required field'), 'id' => 'field_'.$pname), $dflt, '');
111 break;
114 echo "</td></tr>\n";
117 echo "<tr><td colspan='2'>";
118 echo form::hidden('cmd_typ', $cmd_typ);
119 echo form::submit('Commit', _('Submit'), 'class="submit"');
120 if (!empty($params)) {
121 echo " &nbsp;<input type='reset' value='" . _("Reset") . "'>\n";
123 echo "</td></tr></table>";
124 echo form::close();
125 echo '</div>';