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