add the roadmap .dia file for 2019Q2
[racktables-contribs] / configs.php
1 <?php
2
3 /*
4 * Configs tab by John Millington
5 * Version 0.5
6 *
7 * A tab to store key levels of configuration such as base, build doc and staging
8 *
9 * REQUIREMENTS:
10 * PHP 5
11 * Racktables 0.20.5+
12 *
13 * INSTALL:
14 * 1. create ObjectConfigs Table in your RackTables database
15 *
16 CREATE TABLE IF NOT EXISTS `ObjectConfigs` (
17 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
18 `object_id` int(10) unsigned NOT NULL,
19 `config` longtext DEFAULT NULL,
20 `comments` longtext DEFAULT NULL,
21 `date` text DEFAULT NULL,
22 PRIMARY KEY (`id`),
23 KEY `object_id` (`object_id`),
24 CONSTRAINT `ObjectConfigs-FK-object_id` FOREIGN KEY (`object_id`) REFERENCES
25 `Object` (`id`) ON DELETE CASCADE
26 )
27 ENGINE=InnoDB DEFAULT CHARSET=utf8;
28
29 * 2. copy configs.php to plugins directory
30 * 3. chmod 644 configs.php
31
32 */
33
34 $tab['object']['configs'] = 'Config';
35 $tabhandler['object']['configs'] = 'ConfigTabHandler';
36
37
38 // Adding new Config
39 function commitNewConfig ($object_id, $config, $comments, $date)
40 {
41 return usePreparedExecuteBlade
42 (
43 "INSERT INTO ObjectConfigs (object_id, config, comments, date) VALUES (?, ?, ?, ?)",
44 array ($object_id, $config, $comments, $date)
45 );
46 }
47
48
49 // Updating existing configs
50 function commitUpdateConfig ($conf_id, $config, $comments, $date)
51 {
52 return usePreparedExecuteBlade
53 (
54 "UPDATE ObjectConfigs SET config=?,comments = ?,date =? WHERE id = ?",
55 array ($config, $comments, $conf_id, $date)
56 );
57 }
58
59
60 // Deleting configs
61 function commitDeleteConfig ($conf_id)
62 {
63 return usePreparedExecuteBlade
64 (
65 "DELETE FROM ObjectConfigs WHERE id = ?",
66 array ($conf_id)
67 );
68 }
69
70
71 // Main
72 function ConfigTabHandler ()
73 {
74 $dateadd = date("Y-m-d H:i:s");
75
76 // Add show/hide JS functionality for existing configuration fields
77 echo "<SCRIPT language=\"JavaScript\">
78 <!--
79 function toggle_visibility(id){
80 var e = document.getElementById(id);
81 if(e.style.display == 'block')
82 e.style.display = 'none';
83 else
84 e.style.display = 'block';
85 }
86 //-->
87 </script>
88 ";
89
90 // Print markup content for config tab
91 $display ="<center>\n";
92 if (isset($_POST['op'])) {
93 if ($_POST['op'] == "addConfig") {
94 commitNewConfig($_POST['object_id'], $_POST['config'], $_POST['comments'], $_POST['dateadd']);
95 }
96 if ($_POST['op'] == "editConfig") {
97 commitUpdateConfig($_POST['conf_id'], $_POST['config'], $_POST['comments'], $_POST['dateadd']);
98 }
99 }
100 if (isset($_GET['op'])) {
101 if ($_GET['op'] == "delConfig") {
102 commitDeleteConfig($_GET['conf_id']);
103 }
104 }
105
106
107 // Table header
108 $display .= "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>";
109 $display .= "<tr><th>&nbsp;</th>";
110 $display .= "<th class=tdleft></br>Saved Configurations</th>";
111 //$display .= "<th class=tdleft>Comment</th>";
112 $display .= "<th>&nbsp;</th></tr>";
113
114 assertUIntArg ('object_id', __FUNCTION__);
115 $object = spotEntity ('object', $_REQUEST['object_id']);
116
117
118 // Existing configs
119 $query = "SELECT * FROM ObjectConfigs WHERE object_id = '$object[id]'";
120 $result = NULL;
121 $result = usePreparedSelectBlade ($query);
122 while ($row = $result->fetch (PDO::FETCH_ASSOC)) {
123 $conf_id = $row['id'];
124 $object_id = $row['object_id'];
125 $config = $row['config'];
126 $comments = $row['comments'];
127 $date = $row['date'];
128
129 $display .= "<form method=post id=editConfig name=editConfig autocomplete=off action=\"\">";
130 $display .= "<input type=hidden name=\"conf_id\" value=\"".$conf_id."\">";
131 $display .= "<input type=hidden name=\"date\" value=\"".$date."\">";
132 $display .= "<input type=hidden name=\"op\" value=\"editConfig\">";
133 $display .= "<input type=hidden name=\"object_id\" value=\"".$object_id."\">";
134 $display .= "<tr><td><a href='?page=object&tab=configs&object_id=".$object_id."&op=delConfig&conf_id=".$conf_id."'onclick=\"javascript:return confirm('Are you sure you want to delete this Config?')\">";
135 $display .= "<img src='?module=chrome&uri=pix/tango-list-remove.png' width=16 height=16 border=0 title='Delete this Config'></a></td>";
136 $display .= "<td><a href=# onclick=toggle_visibility('$conf_id');>$date &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Comments:&nbsp&nbsp$comments</a>";
137 $display .= "</br><div id=$conf_id style=display:none;><textarea style=background-color:#CCCCCC form=editConfig name=\"config\" cols=125 rows=15>".$config."</textarea></div></td><td></td>";
138 //$display .= "<td class='tdleft' NOWRAP><textarea name=comment value='".$comments."' cols=25 maxlength=254></textarea></td>";
139 $display .= "<td><input type=image name=submit class=icon src='?module=chrome&uri=pix/tango-document-save-16x16.png' border=0 title='Save' onclick=\"javascript:return confirm('Are you sure you want to overwrite this Config?')\"></td></form></tr>";
140
141 }
142
143 // New config
144 $display .= "<form action=\"\" method=post autocomplete=off id=\"addConfig\" name=\"addConfig\">";
145 $display .= "<input type=hidden name=\"object_id\" value=\"".$object['id']."\">";
146 $display .= "<input type=hidden name=\"dateadd\" value=\"".$dateadd."\">";
147 $display .= "<input type=hidden name=\"op\" value=\"addConfig\">";
148 $display .= "<tr><td><input type=image name=submit class=icon src='?module=chrome&uri=pix/tango-list-add.png' border=0 title='Add a Config'></td>";
149 $display .= "<td class='tdleft'></br></br><p style=font-weight:bold;> Add New Configurations</p>Comment: <input cols=40 name=comments tabindex=102></br><textarea cols=125 rows=20 name=config tabindex=100 required></textarea></br></td></tr>";
150 $display .= "</form></br></table></br></center>";
151
152 // Output all .display strings to markup
153 echo $display;
154
155 }