This release fixes compatibility issues and now works with both 0.17 & 0.18 branches. The purpose of this plugin is to add the ability to attach notes to objects to track changes, service calls and other information to help support the environment. A new tab shows up under the Objects and object level. At the Objects level it will display all entries for all objects sorted by date. At the object level it will display all logs for that object sorted by date. Installation instructions are included at the top of the script.
<?php // // Objectlog // Version 0.5 // // Created by Ernest Shaffer // // The purpose is to keep notes for future reference like case numbers // History // Version 0.5: Updated queries to be compatible with 0.17 & 0.18 Branches // Version 0.4: Bug fix removed blank line at end of file that caused Rack images to not display // Version 0.4: Fixed typo finshPortlet to finishPortlet // Version 0.3: Auto create Object table if not exist // Version 0.3: Ability to delete logs at the object level // Version 0.2: Add datetime stamped logs to objects with username // Version 0.1: Initial release // // Installation: // 1) Copy script to inc folder as objectlog.php // 2) Add include to inc/local.php: include("objectlog.php"); // Table should automatically be created if needed /** CREATE TABLE IF NOT EXISTS `Objectlog` ( `id` int(10) NOT NULL auto_increment, `object_id` int(10) NOT NULL, `user` varchar(40) NOT NULL, `date` datetime NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ; **/ // Depot Tab for all objects $tab['depot']['objectlog'] = 'Object Logs'; $tabhandler['depot']['objectlog'] = 'allObjectLogs'; $ophandler['depot']['objectlog']['addObjectlog'] = 'addObjectlog'; //Object Tab for only one object $tab['object']['objectlog'] = 'Object Logs'; $tabhandler['object']['objectlog'] = 'ObjectLogs'; $ophandler['object']['objectlog']['addObjectlog'] = 'addObjectlog'; $ophandler['object']['objectlog']['deleteLog'] = 'deleteLog'; // // Set variables // $Version = "0.5"; $username = $_SERVER['PHP_AUTH_USER']; $nextorder['odd'] = 'even'; $nextorder['even'] = 'odd'; $logentry = $_POST['logentry']; $objectid = $_POST['objectid']; // // Check whether the table exists. If not, create it // Function is called only display functions to cut down on queries // function tableCheck($tableName) { global $dbxlink; $result = NULL; $result = $dbxlink->query("SHOW TABLES LIKE '{$tableName}'"); if ($result==NULL) { print_r($dbxlink->errorInfo()); die(); } if (!($row = $result->fetch (PDO::FETCH_NUM))) { $q = "CREATE TABLE IF NOT EXISTS `{$tableName}` ( `id` int(10) NOT NULL auto_increment, `object_id` int(10) NOT NULL, `user` varchar(40) NOT NULL, `date` datetime NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $result = $dbxlink->query($q); if ($result==NULL) { print_r($dbxlink->errorInfo()); die(); } } } // The ophandler to delete a log entry $msgcode['deleteLog']['OK'] = 77; $msgcode['deleteLog']['ERR'] = 100; // // The ophandler to delete log entry // function deleteLog () { global $dbxlink; global $logentry; global $objectid; global $username; $logid = $_GET['logid']; $log = emptyLog(); $query = "DELETE FROM `Objectlog` WHERE `id` = ".$logid." LIMIT 1"; $result = NULL; $result = $dbxlink->exec($query); $log = mergeLogs ($log, oneLiner (77, array ('log entry'))); return buildWideRedirectURL ($log); } // // The ophandler to insert new log // function addObjectlog () { global $dbxlink; global $logentry; global $objectid; global $username; $log = emptyLog(); $datetime = date("Y-m-d H:i:s"); $query= "INSERT INTO `Objectlog` (`object_id`,`user`,`date`,`content`) VALUES("; $query .= "'$objectid', '$username', '$datetime', '$logentry');"; $result = NULL; $result = $dbxlink->exec($query); $log = mergeLogs ($log, oneLiner (80, array ('log entry'))); return buildWideRedirectURL ($log); } // // Display object level logs // function ObjectLogs () { tableCheck("Objectlog"); // check if table exists if not create global $dbxlink; global $nextorder; global $username; global $logentry; global $Version; $object = $_REQUEST['object_id']; $query = "SELECT o.id as logid, r.name, o.content, o.date, o.user, r.id as object_id FROM Objectlog o Left JOIN RackObject r ON o.object_id = r.id WHERE r.id = $object ORDER BY o.date DESC"; $result = NULL; $result = $dbxlink->query($query); echo "<style type='text/css'>\n"; echo "tr.has_problems {\n"; echo "background-color: #ffa0a0;\n"; echo "}\n"; echo "</style>\n"; startPortlet ('Add Object Log'); echo "<table with=80% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>"; echo "<th align=left>Enter new log</th>"; echo "<form method=post name=addOjectlog action='process.php?page=object&tab=objectlog&op=addObjectlog&object_id=".$object."'>"; echo "<tr>"; echo "<input type=hidden value=$object name=objectid>"; echo "<td align=left><table border=0 cellpadding=0 cellspacing=0><tr><td colspan=2><textarea name=logentry rows=3 cols=80></textarea></td><tr><td align=left><font size=1em color=gray>version ${Version}</font></td><td align=right><input type=submit name=got_very_fast_data value='Post'></td></tr></table></td></tr>"; echo "</form>"; echo "</table>"; finishPortlet (); startPortlet ('Object Logs'); echo "<table width=80% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>"; echo "<th align=left>Name</th>"; echo "<th align=left>Log</th>"; echo "<th align=left>Date</th>"; echo "<th align=left>User</th>"; echo "<th> </th>"; $order = 'odd'; while ($row = $result->fetch (PDO::FETCH_ASSOC)) { echo "<tr class=row_${order} valign=top>"; #echo "<td align=left> id: ".$row['logid']." <a href='".makeHref(array('page'=>'object', 'object_id'=>$row['object_id']))."'>${row['name']}</a></td>"; echo "<td align=left><a href='".makeHref(array('page'=>'object', 'object_id'=>$row['object_id']))."'>${row['name']}</a></td>"; echo "<td align=left>".nl2br($row['content'])."</td>"; echo "<td align=left>".date("m/d/y g:i A",strtotime($row['date']))."</td>"; echo "<td align=left>".$row['user']."</td>"; echo "<td align=left><a href=\"".makeHrefProcess(array('op'=>'deleteLog', 'logid'=>$row['logid'], 'object_id'=>$row['object_id']))."\">"; printImageHREF ('destroy', 'Delete log entry'); echo "</a></td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortlet (); } // // Display form and All log entries // function allObjectLogs () { tableCheck("Objectlog"); // check if table exists if not create $serverSelect = getNarrowObjectList(); global $dbxlink; global $nextorder; global $username; global $logentry; global $objectid; global $Version; $query = "SELECT o.id as logid, r.name, o.content, o.date, o.user, r.id as object_id FROM Objectlog o Left JOIN RackObject r ON o.object_id = r.id ORDER BY o.date DESC"; $result = NULL; $result = $dbxlink->query($query); echo "<style type='text/css'>\n"; echo "tr.has_problems {\n"; echo "background-color: #ffa0a0;\n"; echo "}\n"; echo "</style>\n"; startPortlet('Add Object Log'); echo "<table with=80% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>"; echo "<form method=post name=addOjectlog action='process.php?page=depot&tab=objectlog&op=addObjectlog'>"; echo "<th align=left>Name"; echo "<select name=objectid>"; foreach ($serverSelect as $k => $v) { echo "<option value=$k>$v</option>"; } echo "</select>"; echo "</th>"; echo "<tr><td align=left><table with=100% border=0 cellpadding=0 cellspacing=0><tr><td colspan=2><textarea name=logentry rows=3 cols=80></textarea></td></tr>"; echo "<tr><td align=left><font size=1em color=gray>version ${Version}</font></td><td align=right><input type=submit name=got_very_fast_data value='Post'></td></tr></table></td></tr>"; echo "</form>"; echo "</table>"; finishPortlet(); startPortlet('Object Logs'); echo "<table width=80% align=center border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>"; echo "<th align=left>Name</th>"; echo "<th align=left>Log</th>"; echo "<th align=left>Date</th>"; echo "<th align=left>User</th>"; $order = 'odd'; while ($row = $result->fetch (PDO::FETCH_ASSOC)) { echo "<tr class=row_${order} valign=top>"; echo "<td align=left><a href='".makeHref(array('page'=>'object', 'object_id'=>$row['object_id']))."'>${row['name']}</a></td>"; echo "<td align=left>".nl2br($row['content'])."</td>"; echo "<td align=left>".date("m/d/y g:i A",strtotime($row['date']))."</td>"; echo "<td align=left>".$row['user']."</td>"; echo "</tr>\n"; $order = $nextorder[$order]; } echo "</table>\n"; finishPortlet(); } ?>