Beispiel #1
0
 protected function get_check_info($check_id)
 {
     $query = "SELECT \n\t\t\t\tservice_checks.check_id,\n\t\t\t\tservice_checks.name as name,\n\t\t\t\tservice_checks.device_id,\n\t\t\t\tservice_checks.template_id,\n\t\t\t\tservice_checks.last_event_id,\n\t\t\t\tservice_checks.last_check,\n\t\t\t\tservice_checks.arguments,\n\t\t\t\tservice_checks.check_script,\n\t\t\t\tservice_checks.check_interval,\n\t\t\t\tservice_checks.key1,\n\t\t\t\tservice_checks.key2,\n\t\t\t\tservice_checks.notes,\n\t\t\t\tservice_checks.description,\n\t\t\t\tservice_checks_template.key1_name,\n\t\t\t\tservice_checks_template.key2_name,\n\t\t\t\tservice_checks_template.name as template_name,\n\t\t\t\tservice_checks_template.description as template_desc,\n\t\t\t\tservice_checks_template.script as template_script\n\n\t\t\tFROM \n\t\t\t\tservice_checks, service_checks_template\n\t\t\tWHERE\n\t\t\t\tservice_checks_template.template_id = service_checks.template_id\n\t\t\t\tAND service_checks.check_id = '{$check_id}' \n\t\t ";
     // execute the query
     $result = mysql_query($query);
     if (!$result) {
         $this->error = mysql_error() . "   -- query: {$query} ";
         print "ANDREE {$this->error} <br>";
         return false;
     }
     if (mysql_numrows($result) < 1) {
         $this->error = "No data found for this event";
         return false;
     }
     $obj = mysql_fetch_object($result);
     if (is_numeric($obj->template_id)) {
     }
     $this->check_id = $obj->check_id;
     $this->name = $obj->name;
     $this->device_id = $obj->device_id;
     $this->template_id = $obj->template_id;
     $this->template_name = $obj->template_name;
     $this->last_event_id = $obj->last_event_id;
     $this->last_check = $obj->last_check;
     $this->arguments = $obj->arguments;
     $this->check_script = $obj->template_script;
     $this->desc = $obj->template_desc;
     $this->interval = $obj->check_interval;
     $this->key1 = $obj->key1;
     $this->key2 = $obj->key2;
     $this->key1_name = $obj->key1_name;
     $this->key2_name = $obj->key2_name;
     $this->desc = $obj->description;
     $this->notes = $obj->notes;
     $dev = new Device($this->device_id);
     $this->hostname = $dev->get_name();
     $this->parse_arguments();
     return true;
 }
     break;
 case 'export':
     try {
         $device_parts = $device->get_parts();
         if ($export_only_missing) {
             foreach ($device_parts as $key => $devicepart) {
                 $needed = $devicepart->get_mount_quantity() * $export_multiplier;
                 $instock = $devicepart->get_part()->get_instock();
                 $mininstock = $devicepart->get_part()->get_mininstock();
                 if ($instock - $needed >= $mininstock) {
                     unset($device_parts[$key]);
                 }
             }
         }
         $download = isset($_REQUEST['export_download']);
         $export_string = export_parts($device_parts, 'deviceparts', $export_format_id, $download, 'deviceparts_' . $device->get_name(), array('export_quantity' => $export_multiplier));
     } catch (Exception $e) {
         $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
     }
     break;
 case 'import_readtext':
     try {
         $import_data = import_text_to_array($import_file_content, $import_format, $import_separator);
         match_devicepart_names_to_ids($database, $current_user, $log, $import_data);
         $import_loop = build_deviceparts_import_template_loop($database, $current_user, $log, $import_data);
     } catch (Exception $e) {
         $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
     }
     break;
 case 'import':
     $only_check_data = isset($_REQUEST['check_import_data']);
Beispiel #3
0
function addDeviceForm($devices)
{
    //global all variables and make the tool bar
    global $tool, $deviceForm, $headings, $titles, $deviceKey, $deviceTypes, $location;
    /*Taken out for user interface issues
    	$toolNames = array("All Devices", "All Archived Devices");
    	$toolIcons = array("devices", "devices");
    	$toolHandlers = array("handleEvent('devices.php')", "handleEvent('devices.php?action=showArchived')");
    	echo $tool->createNewTools($toolNames, $toolIcons, $toolHandlers);*/
    $deviceForm->setCols(2);
    if ($_GET['item'] == mPort) {
        $devices = new Device($_GET['ID']);
        $deviceForm->setCols(2);
        $name = $devices->get_name();
        $deviceKey = array("pType", "description", "physicalPort", "portName", "portType", "controlledDevice");
        $headings = array("Port Info for " . $name);
        $titles = array("pType", "Description.tip.A descriptive name for this connection, i.e. \"console connection for router1, routing engine 2\" or \"Remote power cycle group for router1\"", "Physical port.tip.Which port is this device physically connected to", "Port name.tip.Name of port. This will also be the name used for scripts", "Port type", "Control device");
        $dropDownAction = "LoadPage('devices.php?action=changeControlledPort&mode='+this.value, 'controlledPort');";
        $types = array("power_control" => "Power Port", "console_server" => "Console Port");
        $fieldType = array("hidden", "", "", "", "drop_down.handler:" . $dropDownAction, "custom");
        $fieldInfo = array("mport", "", "", "", "", "<div id='controlledPort'></div>");
        $deviceForm->setFieldType($fieldType);
        $deviceForm->setData($fieldInfo);
        echo $deviceForm->newPortForm($headings, $titles, $deviceKey, $types);
    } else {
        if ($_GET['item'] == cPort) {
            $devices = new Device($_GET['ID']);
            $deviceForm->setCols(2);
            $name = $devices->get_name();
            $deviceKey = array("pType", "description", "physicalPort", "portName", "portType", "managedDevice");
            $headings = array("Port Info for " . $name);
            $titles = array("pType", "Description.tip.A descriptive name for this connection, i.e. \"console connection for router1, routing engine 2\" or \"Remote power cycle group for router1\"", "Physical port.tip.Which port is this device physically connected to", "Port name.tip.Name of port. This will also be the name used for scripts", "Port type", "Managed device.tip.Select a device or select \"Other Device\" if you want to manage a device that is not in the database. If you select \"Other Device\" please make sure to have a good port description.");
            $titles = array("pType", "Description", "Physical port", "Port name", "Port type", "Managed device");
            $types = $devices->get_devices();
            $fieldType = array("hidden", "", "", "", "static", "drop_down");
            if ($_GET['deviceClass'] == "console_server") {
                $port = "console";
            } else {
                $port = "power";
            }
            $fieldInfo = array("cport", "", "", "", $port, "");
            $deviceForm->setData($fieldInfo);
            $deviceForm->setFieldType($fieldType);
            echo $deviceForm->newPortForm($headings, $titles, $deviceKey, $types);
        } else {
            //create a new client form
            $fieldType = array("", "", "drop_down", "drop_down", "", "text_area", "", "", "", "", "");
            $type = array($location, $deviceTypes);
            $deviceForm->setFieldType($fieldType);
            echo $deviceForm->newDeviceForm($headings, $titles, $deviceKey, $type);
        }
    }
}
Beispiel #4
0
 private function get_files_for_device($device_id)
 {
     if (!is_numeric($device_id)) {
         return;
     }
     $selectedDevice = new Device($device_id);
     $output = "<h2>Displaying Counters for: <b>" . $selectedDevice->get_name() . "</b></h2><br>";
     //print $selectedDevice->get_name() . "<br>";
     $property = new Property();
     if ($rrdtool = $property->get_property("path_rrdtool")) {
     } else {
         return;
     }
     if ($rrd_dir = $property->get_property("path_rrddir")) {
     } else {
         return;
     }
     $pattern = "{$rrd_dir}/fwcounters/fwcounter_deviceid" . $device_id . "_*.rrd";
     $files = glob($pattern);
     foreach ($files as $v) {
         $path_parts = pathinfo($v);
         $fullPath = "fwcounters/" . $path_parts['basename'];
         $fileName = $path_parts['filename'];
         //(\d+)_(.+)$
         $searchPattern = '/fwcounter_deviceid(\\d+)_(.+)$/';
         $replacement = $selectedDevice->get_name() . ' $2';
         $counterName = preg_replace($searchPattern, $replacement, $fileName);
         // If this is an interface-specific counter then show more info about the interface
         $outputPortInfo = "";
         // print strtolower($counterName);
         //ge-0-2-5.0
         $arrPortTypes = array();
         $arrPortTypes[] = "fe";
         $arrPortTypes[] = "ge";
         $arrPortTypes[] = "xe";
         $arrPortTypes[] = "et";
         $interfaceName = false;
         foreach ($arrPortTypes as $k => $v) {
             $interfaceName = strstr($counterName, $v . "-");
             if ($interfaceName != false) {
                 $interfaceName = strtr($interfaceName, array('-' => '/'));
                 $interfaceName = str_replace($v . "/", $v . "-", $interfaceName);
                 break;
             }
         }
         if ($interfaceName != false) {
             $thisDevice = new Device($device_id);
             $interfaceID = $thisDevice->get_interface_id_by_name($interfaceName);
             if ($interfaceID) {
                 $thisPort = new Port($interfaceID);
                 $outputPortInfo = "<br>Port description: " . $thisPort->get_alias();
             }
         }
         $output .= "<table>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td colspan='2'><h3>RRD File: {$fileName} {$outputPortInfo} </h3></td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>";
         $height = 150;
         $width = 550;
         $from = "-1d";
         if (isset($_GET['From'])) {
             $from = $_GET['From'];
         }
         $graph = "Bits Per Second";
         $graph = str_replace(" ", "%20", $graph);
         $type = "traffic";
         $type = str_replace(" ", "%20", $type);
         $link = "rrdgraph.php?file={$fullPath}&title=" . $fileName . " --- " . $graph . "&height=" . $height . "&width=" . $width . "&type=" . $type;
         $output .= "<a href='#'><img src='rrdgraph.php?file={$fullPath}&title=" . $counterName . " --- " . $graph . "&from={$from}&height={$height}&width={$width}&type={$type}'></a><br><br>";
         $output .= "</td><td>";
         $graph = "Unicast Packets Per Second";
         $graph = str_replace(" ", "%20", $graph);
         $type = "unicastpkts";
         $type = str_replace(" ", "%20", $type);
         $link = "rrdgraph.php?file={$fullPath}&title=" . $fileName . " --- " . $graph . "&height=" . $height . "&width=" . $width . "&type=" . $type;
         $output .= "<a href='#'><img src='rrdgraph.php?file={$fullPath}&title=" . $counterName . " --- " . $graph . "&from={$from}&height={$height}&width={$width}&type={$type}'></a><br>";
         $output .= "</td></tr><br><hr>";
     }
     return $output;
 }
Beispiel #5
0
 /**
  * 
  * Enter description here ...
  * @param Device $d
  */
 public static function save(Device $d)
 {
     $dbh = $GLOBALS['dbh'];
     if ($d->get_id()) {
         // Update
         $data = $dbh->prepare("\n\t\t\t\tUPDATE \n\t\t\t\t\tdevice\n\t\t\t\tSET \n\t\t\t\t\tuid=:uid, name=:name, cost=:cost, `range`=:range, `status`=:status\n\t\t\t\tWHERE \n\t\t\t\t\tid=:id\n\t\t\t");
         $data->execute(array(':uid' => $d->get_uid(), ':name' => $d->get_name(), ':cost' => $d->get_cost(), ':range' => $d->get_range(), ':status' => $d->get_status(), ':id' => $d->get_id()));
     } else {
         // Insert
         $data = $dbh->prepare("\n\t\t\t\tINSERT \n\t\t\t\t\tINTO device (uid, name, cost, `range`)\n\t\t\t\tVALUES\n\t\t\t\t\t(:uid, :name, :cost, :range)\n\t\t\t");
         $data->execute(array(':uid' => $d->get_uid(), ':name' => $d->get_name(), ':cost' => $d->get_cost(), ':range' => $d->get_range()));
     }
 }
 /**
  * @brief Create a new device-part
  *
  * @param Database  &$database          reference to the database object
  * @param User      &$current_user      reference to the current user which is logged in
  * @param Log       &$log               reference to the Log-object
  * @param integer   $device_id          the ID of the device
  * @param integer   $part_id            the ID of the part
  * @param integer   $quantity           the mount quantity (see DevicePart::set_mount_quantity())
  * @param string    $mountnames         the mountname(s) (see DevicePart::set_mount_name())
  * @param boolean   $increase_if_exist  @li if true, and there is already a DevicePart with the same
  *                                          part ID + device ID, the mount quantity of the existing
  *                                          DevicePart will be incremented by $quantity. In addition,
  *                                          the new mount name ($mountname) will be attached (with a
  *                                          comma) at the end of the mount name of the existing DevicePart.
  *                                      @li if false, and there is already a DevicePart with the same
  *                                          part ID + device ID, this method will throw an exception.
  *
  * @retval DevicePart   the new device-part
  * @retval DevicePart   the existing device-part, if there is already a DevicePart with
  *                      the same part ID + device ID and "$increment_if_exist == true"
  *
  * @throws Exception    if (this combination of) values is not valid
  * @throws Exception    if there was an error
  *
  * @see DBElement::add()
  */
 public static function add(&$database, &$current_user, &$log, $device_id, $part_id, $quantity, $mountnames = '', $increase_if_exist = false)
 {
     $existing_devicepart = DevicePart::get_device_part($database, $current_user, $log, $device_id, $part_id);
     if (is_object($existing_devicepart)) {
         if ($increase_if_exist) {
             if (!is_int($quantity) && !ctype_digit($quantity) || $quantity < 0) {
                 debug('error', 'quantity = "' . $quantity . '"', __FILE__, __LINE__, __METHOD__);
                 throw new Exception('Die Bestückungs-Anzahl ist ungültig!');
             }
             $quantity = $existing_devicepart->get_mount_quantity() + $quantity;
             $old_mountnames = $existing_devicepart->get_mount_names();
             if (strlen($mountnames) > 0) {
                 if (strlen($old_mountnames) > 0) {
                     $mountnames = $old_mountnames . ', ' . $mountnames;
                 }
             } else {
                 $mountnames = $old_mountnames;
             }
             $existing_devicepart->set_attributes(array('quantity' => $quantity, 'mountnames' => $mountnames));
             return $existing_devicepart;
         } else {
             $device = new Device($database, $current_user, $log, $device_id);
             $part = new Part($database, $current_user, $log, $part_id);
             throw new Exception('Die Baugruppe "' . $device->get_name() . '" enthält bereits das Bauteil "' . $part->get_name() . '"!');
         }
     }
     // there is no such DevicePart, so we will create it
     return parent::add($database, $current_user, $log, 'device_parts', array('id_device' => $device_id, 'id_part' => $part_id, 'quantity' => $quantity, 'mountnames' => $mountnames));
 }
Beispiel #7
0
 function render_add_rrd_to_profile()
 {
     include_once "classes/Device.php";
     $device_name_cache = array();
     if (isset($_GET['pid']) && is_numeric($_GET['pid'])) {
         $pid = $_GET['pid'];
     } else {
         return "<b>Sorry invalid profile id " . $_GET['pid'] . "</b>";
     }
     $content = "";
     // Get all SCU-DCU files
     $query = "select id, device_id, title, file \n\t\t\tFROM accounting_sources ";
     $result = mysql_query($query);
     if (!$result) {
         return "<b>No SCU-DCU profiles found information found</b>";
     }
     $content .= "<p>";
     $tool = new EdittingTools();
     $content .= $tool->createNewFilters();
     $content .= "<div style=\"clear:both;\"></div> </p>";
     $content .= "<form method=get name='graph_profiles'>\n\t\t\t<INPUT TYPE=hidden NAME=tab VALUE='" . $_GET['tab'] . "'>\n\t\t\t<INPUT TYPE=hidden NAME=pluginID VALUE='" . $_GET['pluginID'] . "'>\n\t\t\t<INPUT TYPE=hidden NAME=pid VALUE='{$pid}'>\n\t\t\t<INPUT TYPE=hidden NAME=action VALUE='add_rrd_to_profile'>";
     $keyData = array();
     while ($obj = mysql_fetch_object($result)) {
         if (!array_key_exists($obj->device_id, $device_name_cache)) {
             $device = new Device($obj->device_id);
             $device_name_cache[$obj->device_id] = $device->get_name();
         }
         //$content .= "<tr><td><input type=checkbox name=scu_files[] value='$obj->id'></td>";
         //$content .=  "<td>". $device_name_cache{$obj->device_id} ."</td><td>
         //	$obj->title</a></td></tr>";
         array_push($keyData, "<input type='checkbox' name='scu_files[]' value='{$obj->id}'>");
         array_push($keyData, $device_name_cache[$obj->device_id]);
         array_push($keyData, $obj->title);
     }
     $headings = array(" ", "Device", "SCU-DCU profile");
     $form = new Form();
     $form->setCols(3);
     $form->setTableWidth("auto");
     $form->setData($keyData);
     $form->setHeadings($headings);
     $form->setSortable(true);
     $content .= $form->showForm();
     $content .= "<div style='clear:both'></div>";
     $content .= "<input name='add_rrd' type='submit'\n\t\t\tid='graph_submit' value='Add Selected Graphs to profile' >\n\t\t\t</form>";
     return $content;
 }
if (!$fatal_error) {
    try {
        $order_devices = Device::get_order_devices($database, $current_user, $log);
        $order_devices_loop = array();
        $row_odd = true;
        foreach ($order_devices as $device) {
            $too_less_parts = 0;
            foreach ($device->get_parts() as $devicepart) {
                $needed = $devicepart->get_mount_quantity() * $device->get_order_quantity();
                $instock = $devicepart->get_part()->get_instock();
                $mininstock = $devicepart->get_part()->get_mininstock();
                if ($instock - $needed < $mininstock) {
                    $too_less_parts++;
                }
            }
            $order_devices_loop[] = array('row_odd' => $row_odd, 'id' => $device->get_id(), 'name' => $device->get_name(), 'full_path' => $device->get_full_path(), 'order_quantity' => $device->get_order_quantity(), 'only_missing_parts' => $device->get_order_only_missing_parts(), 'parts_count' => $device->get_parts_count(), 'parts_count_to_order' => $too_less_parts);
            $row_odd = !$row_odd;
        }
        $html->set_loop('order_devices_loop', $order_devices_loop);
    } catch (Exception $e) {
        $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
        $fatal_error = true;
    }
}
/********************************************************************************
 *
 *   Set the rest of the HTML variables
 *
 *********************************************************************************/
$html->use_javascript(array('popup', 'validatenumber'));
if (!$fatal_error) {
Beispiel #9
0
function displayGraphListResult($keyword)
{
    //global the tool and make a tool bar for adding a client
    global $tool, $deviceForm;
    $interfaces = array();
    $allDevices = Device::get_devices();
    foreach ($allDevices as $id => $value) {
        $device = new Device($id);
        $interfaceStorage = $device->get_interfaces();
        foreach ($interfaceStorage as $iID => $iValue) {
            array_push($interfaces, $iValue);
        }
    }
    $numInterface = count($interfaces);
    if (!isset($_GET['mode'])) {
        $searchAction = "statistics.php?action=showGraphListResult";
        echo $tool->createSearchBar($searchAction);
    }
    echo "<div id='filteredResult' style='width:1024px; text-align:left;'>";
    echo "<form name='listForm' method='post' action='statistics.php?action=showGraphResult&ID=" . $_GET['ID'] . "&pageNum=1'>\r\n\t\t<input type='submit' name='returnResults' value='Display Checked Graphs' style='float:right; margin-bottom:5px;'></input>\r\n\t\t<table id=\"dataTable\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\" style='width:100%; clear:left;'>\r\n\t\t<thead><tr><th colspan='4'>\r\n\t\t<input type='checkbox' name='all' onclick=\"checkAll(document.listForm['list[]'], all)\">Select All</input> | Statistics\r\n\t\t</th></tr></thead>";
    #"<select name='interfaces' onchange=\"return LoadPage('statistics.php?action=showCurGraph&mode=graphTime'+this.value, 'statGraphs')\">";
    if (isset($interfaces)) {
        foreach ($interfaces as $id => $value) {
            $device = new Device($value->get_device_id());
            $deviceName = $device->get_name();
            $link = "statistics.php?action=showGraphDetail&ID=" . $value->get_device_id() . "&interID=" . $value->get_interface_id() . "&active=" . $value->get_oper_status() . "&type=";
            $all = "statistics.php?action=showGraphResult&ID=" . $value->get_device_id() . "&interID=" . $value->get_interface_id() . "&pageNum=1&active=yes";
            $specialChars = array('/', '(', ')', '>', '<', '[', ']');
            $newKey = $keyword;
            foreach ($specialChars as $sid => $svalue) {
                $newKey = str_replace($svalue, "\\" . $svalue, $newKey);
            }
            if (preg_match("/" . $newKey . "/i", $value->get_name()) || preg_match("/" . $newKey . "/i", $value->get_descr()) || preg_match("/" . $newKey . "/i", $value->get_alias())) {
                echo "<tr><td style='width:20%; border-bottom:solid thin;'><input type='checkbox' name='list[]' value='" . $value->get_interface_id() . "//" . $value->get_device_id() . "'>" . $value->get_name() . "</input></td>\r\n\t\t\t\t<td style='border-bottom:solid thin;'>" . $value->get_descr() . " | " . $value->get_alias() . "</td>\r\n\t\t\t\t<td style='border-bottom:solid thin;'>" . $deviceName . "</td>\r\n\t\t\t\t<td style='border-bottom:solid thin; width:35%'>\r\n\t\t\t\t<input type='button' onclick=\"handleEvent('" . $link . "traffic')\" value='Traffic' />\r\n\t\t\t\t<input type='button' onclick=\"handleEvent('" . $link . "errors')\" value='Error' />\r\n\t\t\t\t<input type='button' onclick=\"handleEvent('" . $link . "unicastpkts')\" value='Unicast' />\r\n\t\t\t\t<input type='button' onclick=\"handleEvent('" . $link . "nonunicastpkts')\" value='Nonunicast' />\r\n\t\t\t\t<input type='button' onclick=\"handleEvent('" . $all . "')\" value='All' />\r\n\t\t\t\t</td></tr>";
            }
        }
    } else {
        $deviceForm->warning("No interfaces for this device");
    }
    echo "</table>\r\n\t<input type='submit' name='returnResults' value='Display Checked Graphs' style='float:right; margin-bottom:5px;'></input>\r\n\t</form>\r\n\t</div>";
}
Beispiel #10
0
 function render_edit_change()
 {
     // First determine change id
     if (isset($_GET[cid]) && is_numeric($_GET[cid])) {
         $cid = $_GET[cid];
     } else {
         return "<b>Sorry change not found<br></b>";
     }
     //$content = "<h1>Change Details (#$cid) </h1>";
     $contentH .= "<div><p><a href='{$this->url}&action=edit_change&cid={$cid}&add_device#new_device'>\n<img src='icons/Add.png'>Add Device Component</a><br></p></div>";
     if (isset($_GET['add_device'])) {
         $add_device = 1;
     } else {
         $add_device = 0;
     }
     // Get all users
     $allUsers_real = User::get_users_by_fullname();
     $allUsers = User::get_users_by_fullname();
     // Do not show Administrator account in changed by dropdown
     unset($allUsers[1]);
     array_push($allUsers, "  ");
     asort($allUsers);
     /*
     	First Generic change info
     */
     $query = "SELECT change_id, title, notes, record_date, \n\t\t\t\t\tUNIX_TIMESTAMP(change_date) as change_date,\n\t\t\t\t\tUNIX_TIMESTAMP(planned_change_date) as planned_change_date,\n\t\t\t\t\tchange_contact_1, change_contact_2, impact, status\n\t\t\t\t\tFROM plugin_ChangeManager_Changes\n\t\t\t\t\tWHERE change_id = '{$cid}'";
     $result = mysql_query($query);
     if (!$result) {
         return "<b>Oops something went wrong, unable to select changes 'Error, query failed. '" . mysql_error() . "</b>";
     }
     $values = array();
     $form = new Form("auto", 2);
     // Need to count the number of sections in this form
     // Used by editForm($numHead)  later
     $form_sections = 1;
     while ($obj = mysql_fetch_object($result)) {
         // First initialized with correct date
         if (is_null($obj->change_date)) {
             $custom_date = '';
         } else {
             $year = date("Y", $obj->change_date);
             $month = date("m", $obj->change_date);
             $day = date("d", $obj->change_date);
             $hour = date("H", $obj->change_date);
             $minute = date("i", $obj->change_date);
             $sql_time = "{$hour}:{$minute}";
             $custom_date = "{$year}-{$month}-{$day}";
         }
         // First initialized with correct date
         if (is_null($obj->planned_change_date)) {
             $custom_planned_date = '';
         } else {
             $planned_year = date("Y", $obj->planned_change_date);
             $planned_month = date("m", $obj->planned_change_date);
             $planned_day = date("d", $obj->planned_change_date);
             $planned_hour = date("H", $obj->planned_change_date);
             $planned_minute = date("i", $obj->planned_change_date);
             $planned_sql_time = "{$planned_hour}:{$planned_minute}";
             $custom_planned_date = "{$planned_year}-{$planned_month}-{$planned_day}";
         }
         // Create status array
         /**
         $status_arr= array();
         $status_arr = $this->status_values;
         if ($obj->status == 1) {
         	$status_arr = array();
         	//$status_arr[0] = $this->status_values[0];
         	$status_arr[1] = $this->status_values[1];
         	$status_arr[2] = $this->status_values[2];
         }
         elseif ($obj->status == 2) {
         	//unset($status_arr[0]);
         	unset($status_arr[1]);
         }
         else {
         	unset($status_arr[0]);
         	unset($status_arr[1]);
         	unset($status_arr[2]);
         }
         */
         $status_arr = array();
         $status_arr = $this->status_values;
         // date and time for planned change date
         $fieldType[1] = "date_picker";
         $fieldType[2] = "drop_down";
         $form->setType($this->timetable);
         // Drop down
         // date and time for actual (completion)change date
         $custom_date = "{$year}-{$month}-{$day}";
         $fieldType[3] = "date_picker";
         $fieldType[4] = "drop_down";
         $form->setType($this->timetable);
         // Drop down
         $notes = $obj->notes;
         $user1 = new User($obj->change_contact_1);
         $contact_name1 = $user1->get_full_name();
         $user2 = new User($obj->change_contact_2);
         $contact_name2 = $user2->get_full_name();
         $fieldType[5] = "drop_down";
         $form->setType($allUsers);
         // Drop down
         $fieldType[6] = "drop_down";
         $form->setType($allUsers);
         // Drop down
         $fieldType[7] = "drop_down";
         $impact_name = "";
         if ($obj->impact == "0") {
             // Make it none of the existing drop down selected options if none were previously chosen
             $impact_name = "  ";
         } else {
             $impact_name = $this->impact_values[$obj->impact];
         }
         $form->setType($this->impact_values);
         // Drop down
         $fieldType[8] = "drop_down";
         $status_name = "";
         if ($obj->status == "0") {
             // Make it none of the existing drop down selected options if none were previously chosen
             $status_name = "  ";
         } else {
             $status_name = $this->status_values[$obj->status];
         }
         $form->setType($status_arr);
         // Drop down
         // End Custom field
         $title = $obj->title;
         $fieldType[9] = "text_area";
         array_push($values, $obj->title, $custom_planned_date, $planned_sql_time, $custom_date, $sql_time, $contact_name1, $contact_name2, $impact_name, $status_name, $notes);
     }
     $content = "<hr align=\"left\" style=\"width:94%;border:1px solid #C0C0C0;\">\n\t\t\t\t\t<h2>CHANGE (#{$cid}): {$title}</h2>\n\t\t\t\t\t<hr align=\"left\" style=\"width:94%;border:1px solid #C0C0C0;\">" . $contentH;
     $javascriptFormValidation = "\n\t\t<script language=\"javascript\">\n\t\tfunction validateForm()\n\t\t{\n\t\t\t// Parse Date and then check if change date is before planned date\n\t\t\tvar PlannedChangeDateStr = document.forms[\"MyClassForm\"][\"PlannedChangeDate\"].value;\n\t\t\tvar PlannedChangeDateStringArray = PlannedChangeDateStr.split(\"-\",3);\t\t\t\n\t\t\tvar PlannedYear = PlannedChangeDateStringArray[0];\n\t\t\tvar PlannedMonth = PlannedChangeDateStringArray[1];\n\t\t\tvar PlannedDay = PlannedChangeDateStringArray[2];\t\t\t\t\t\t\n\t\t\tvar PlannedChangeTimeStr = document.forms[\"MyClassForm\"][\"PlannedChangeTime\"].value;\n\t\t\tvar PlannedChangeTimeStringArray = PlannedChangeTimeStr.split(\":\",2);\t\t\t\n\t\t\tvar PlannedHour = PlannedChangeTimeStringArray[0];\n\t\t\tvar PlannedMinute = PlannedChangeTimeStringArray[1];\n\t\t\t\n\t\t\tvar PlannedChangeDateTime = new Date(PlannedYear,PlannedMonth,PlannedDay,PlannedHour,PlannedMinute);\n\t\t\t\n\t\t\t// alert('Date: ' + PlannedChangeDateTime.getDate());\n\t\t\t// alert('Month: ' + PlannedChangeDateTime.getMonth());\n\t\t\t// alert('Year: ' + PlannedChangeDateTime.getFullYear());\n\t\t\t// alert('Hour: ' + PlannedChangeDateTime.getHours());\n\t\t\t// alert('Minute: ' + PlannedChangeDateTime.getMinutes());\n\t\t\t\n\t\t\t// alert('PlannedChangeDate ' + document.forms[\"MyClassForm\"][\"PlannedChangeDate\"].value + ' was chosen.');\n\t\t\t// alert('PlannedChangeTime ' + document.forms[\"MyClassForm\"][\"PlannedChangeTime\"].value + ' was chosen.');\n\t\t\t\n\t\t\tif (document.forms[\"MyClassForm\"][\"PlannedChangeDate\"].value == \"\")\n\t\t\t{\n\t\t\t\talert('No Planned Change Date or Time entered!');\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tvar CompletionChangeDateStr = document.forms[\"MyClassForm\"][\"ChangeDate\"].value;\n\t\t\tvar CompletionChangeTimeStr = document.forms[\"MyClassForm\"][\"ChangeTime\"].value;\n\n\t\t\tif (\n\t\t\t\t(\n\t\t\t\t\t(\n\t\t\t\t\t\t(CompletionChangeDateStr != \"\")\n\t\t\t\t\t\t && \n\t\t\t\t\t\t(CompletionChangeTimeStr == \"Pick an option\")\n\t\t\t\t\t)\n\t\t\t\t) \n\t\t\t\t||\t\t\n\t\t\t\t(\n\t\t\t\t\t(\n\t\t\t\t\t\t(CompletionChangeDateStr == \"\")\n\t\t\t\t\t\t&&\n\t\t\t\t\t\t(CompletionChangeTimeStr != \"Pick an option\")\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\t{\n\t\t\t\talert('Ensure both Completion Date and Completion Time entered!');\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tif(CompletionChangeDateStr != \"\" && CompletionChangeTimeStr != \"Pick an option\")\n\t\t\t{\t\t\t\n\t\t\t\tvar CompletionChangeDateStringArray = CompletionChangeDateStr.split(\"-\",3);\t\t\t\n\t\t\t\tvar CompletionYear = CompletionChangeDateStringArray[0];\n\t\t\t\tvar CompletionMonth = CompletionChangeDateStringArray[1];\n\t\t\t\tvar CompletionDay = CompletionChangeDateStringArray[2];\t\t\t\t\t\t\n\n\t\t\t\tvar CompletionChangeTimeStringArray = CompletionChangeTimeStr.split(\":\",2);\t\t\t\n\t\t\t\tvar CompletionHour = CompletionChangeTimeStringArray[0];\n\t\t\t\tvar CompletionMinute = CompletionChangeTimeStringArray[1];\n\t\t\t\t\n\t\t\t\tvar CompletionChangeDateTime = new Date(CompletionYear,CompletionMonth,CompletionDay,CompletionHour,CompletionMinute);\n\t\t\t\t\n\t\t\t\t/* alert('Date: ' + CompletionChangeDateTime.getDate());\n\t\t\t\talert('Month: ' + CompletionChangeDateTime.getMonth());\n\t\t\t\talert('Year: ' + CompletionChangeDateTime.getFullYear());\n\t\t\t\talert('Hour: ' + CompletionChangeDateTime.getHours());\n\t\t\t\talert('Minute: ' + CompletionChangeDateTime.getMinutes()); */\n\t\t\t\t\n\t\t\t\t//alert('CompletionChangeDate ' + document.forms[\"MyClassForm\"][\"ChangeDate\"].value + ' was chosen.');\n\t\t\t\t//alert('CompletionChangeTime ' + document.forms[\"MyClassForm\"][\"ChangeTime\"].value + ' was chosen.');\n\n\t\t\t\tif(CompletionChangeDateTime < PlannedChangeDateTime)\n\t\t\t\t{\n\t\t\t\t\talert(\"Completion Date: \" + document.forms[\"MyClassForm\"][\"PlannedChangeDate\"].value + \" \" + document.forms[\"MyClassForm\"][\"PlannedChangeTime\"].value + \" entered is before Planned Date: \" + document.forms[\"MyClassForm\"][\"PlannedChangeDate\"].value + \" \" + document.forms[\"MyClassForm\"][\"PlannedChangeTime\"].value + \"!\"); \n\t\t\t\t\treturn false;\n\t\t\t\t}\t\n\t\t\t}\n\t\t\t\n\t\t\tif (document.forms[\"MyClassForm\"][\"Summary\"].value == \"\")\n\t\t\t{\n\t\t\t\talert(\"Summary must be filled out!\");\n\t\t\t\treturn false;\n\t\t\t}\t\n\t\t}\n\t\t</script>";
     $content .= $javascriptFormValidation;
     $heading = array("Change Details");
     $titles = array("Summary", "Planned Date", "Planned Time", "Completion Date", "Completion Time", "Primary Contact", "Secondary Contact", "Impact", "Status", "Change Description");
     $postkeys = array("Summary", "PlannedChangeDate", "PlannedChangeTime", "ChangeDate", "ChangeTime", "PrimaryContact", "SecondaryContact", "Impact", "Status", "ChangeDescription");
     /*
     	Device specific change info
     */
     $query2 = "SELECT id, device_id, impact, effects, chgby_id, change_date, description, back_out, status\n\t\t\t\t\tFROM plugin_ChangeManager_Components\n\t\t\t\t\tWHERE change_id = '{$cid}'";
     $result2 = mysql_query($query2);
     if (!$result2) {
         return "<b>Oops something went wrong, unable to select changes </b>";
     }
     // Get all devices
     $allDevices = Device::get_devices();
     // For Field type index:
     $i = 9;
     while ($obj = mysql_fetch_object($result2)) {
         $form_sections++;
         // Determine device name
         $device = new Device($obj->device_id);
         $device_name = $device->get_name();
         $form->setType($allDevices);
         // Drop down
         $fieldType[$i + 1] = "drop_down";
         $form->setType($allUsers);
         // Drop down
         $fieldType[$i + 2] = "drop_down";
         // Determine user changed by name
         $user = new User($obj->chgby_id);
         $fullname = $user->get_full_name();
         $effects = $obj->effects;
         array_push($values, $device_name, $fullname, stripslashes($obj->description), stripslashes($effects), stripslashes($obj->back_out));
         array_push($heading, "*<break>*", "Device Details:  {$device_name}  <div style='text-align: right;'> \n<a href='{$this->url}&action=delete_device_component&cid={$cid}&component_id={$obj->id}&return=edit_change' style='color:#FFFFFF'>\nDelete <img src='icons/Delete.png' height=20></a></div>");
         array_push($titles, "*<break>*", "Device", "Changed By", "Change Details", "Effects", "Backout Procedure");
         array_push($postkeys, "device_component[{$obj->id}][Device]", "device_component[{$obj->id}][ChangedBy]", "device_component[{$obj->id}][Description]", "device_component[{$obj->id}][Effects]", "device_component[{$obj->id}][BackoutProcedure]");
         $fieldType[$i + 3] = "text_area.height:230px";
         $fieldType[$i + 4] = "text_area.height:90px";
         $fieldType[$i + 5] = "text_area.height:90px";
         //Update with the number of rows/fields we just added
         $i = $i + 5;
     }
     if ($add_device) {
         $form_sections++;
         array_push($heading, "*<break>*", "Device Details - New Device <span id=new_device></span>");
         array_push($titles, "*<break>*", "Device", "Changed By", "Change Details", "Effects", "Backout Procedure");
         $form->setType($allDevices);
         // Drop down
         $fieldType[$i + 1] = "drop_down";
         $form->setType($allUsers);
         // Drop down
         $fieldType[$i + 2] = "drop_down";
         array_push($postkeys, "new_device_component[Device]", "new_device_component[ChangedBy]", "new_device_component[Description]", "new_device_component[Effects]", "new_device_component[BackoutProcedure]");
         $fieldType[$i + 3] = "text_area.height:230px";
         $fieldType[$i + 4] = "text_area.height:90px";
         $fieldType[$i + 5] = "text_area.height:90px";
         array_push($values, "", $_SESSION['fullname'], "", "", "");
     }
     // Create Device index
     //set the table size
     $form->setFieldType($fieldType);
     $form->setSortable(false);
     $form->setHeadings($heading);
     $form->setTitles($titles);
     $form->setDatabase($postkeys);
     $form->setData($values);
     //set the table size
     $form->setTableWidth("94%");
     $form->setTableWidth("94%");
     $form->setTitleWidth("20%");
     $content .= $form->EditForm($form_sections);
     return $content;
 }