looking through old posts/emails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



enclosed is a php for oracle that worked on Windows AND Fedora 9

<?php
/*
Oracle 11g1 version handle_log_book11g1.php
 drop sequence log_id;
 create sequence log_id
 increment by 1
 start with 1;

drop table log_book_id;

create table log_book_id ( log_id number primary key, fdate date, actype varchar2(16), acid varchar(16), nlandings number, nhoursnumber);

insert into log_book_id values (logid.nextval, TO_DATE('08/12/1973','MM/dd/YYYY'),'C150','N5787G',1,1.8);

insert into log_book_id values (logid.nextval, TO_DATE('08/17/1973','MM/dd/YYYY'),'C150','N5787G',3,1.5);

insert into log_book_id values (logid.nextval, TO_DATE('08/26/1973','MM/dd/YYYY'),'C150','N5787G',10,1.8);

insert into log_book_id values (logid.nextval, TO_DATE('09/01/1973','MM/dd/YYYY'),'C150','N5293S',9,1.7);
*/
//construct a global variable for the form profile
$fields = array("fdate", "actype", "acid", "nlandings", "nhours");

global $connection;
session_start();
$db = "(DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = landon)(PORT = 1521))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME = LMKGDN)
   )
 )";

	$user = $_SESSION['userx'] ;
	$password = $_SESSION['passwordx'] ;
	$user = "lmkiii";
	$password = "xxxxxxxxx" ;


if(!$connection && $user && $password)
{
	if ($connection=oci_connect($user, $password, $db))
	{
       		 echo "Successfully connected to Oracle.\n";
	}
	else
	{
		 $err = OCIError();
	 echo "Oracle Connect Error " . $err['message'];
	}
}

if(isset($_POST['delete'])){
    deleteRecords();
} elseif(isset($_POST['login'])){
    loginOracle();
} elseif (isset($_POST['continue'])){
    displayDeleteForm();
} elseif (isset($_POST['new'])){
    displayEntryForm();
} elseif (isset($_POST['update'])){
    showRecord();
} elseif (isset($_POST['timeInType'])){
	timeInType();
} else {

//first time execution
    echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p>
Oracle User Name:<br />
<input type="text" size="20" maxlength="40" name="user"
value="$user" />
</p>
<p>
Oracle Password:<br />
<input type="password" size="20" maxlength="40" name="password"
value="$password" />
</p>
<button type="submit" name = "login" value="<b>Login!</b>"
style="color:maroon font:18pt Courier; font-weight:bold ">LOGIN
</button>
</form>
HTML;
	 $_SESSION['userx'] =  $_POST[$user] ;
	 $_SESSION['passwordx'] = $_POST[$password] ;
}


//...........................................................................function loginOracle()

function loginOracle(){
global $connection;


$db = "(DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = LANDON)(PORT = 1521))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SID = LMKGDN)
   )
 )";
	$_SESSION['userx'] = $_POST['user'];
	$_SESSION['passwordx'] = $_POST['password'];
$connection=oci_pconnect($_POST['user'], $_POST['password'], $db);
if ($connection)
{
	echo "Successfully connected to Oracle.\n";
    //default action

    displayDeleteForm();
}
else
{
 $err = OCIError();
 echo "Oracle Connect Error " . $err['message'];
}
}

//...........................................................................function displayDeleteForm()

function displayDeleteForm(){
    //get $fields into the function namespace
    global $fields;
	global $connection;


/* Create and execute query. */
// Loop through each row, outputting the actype and name
     echo <<<HTML
    Pilots Logbook entries stored in Oracle Relational Database
under Redhat Fedora 9 Linux
    <form action="{$_SERVER['PHP_SELF']}" method="post">
    <table width="50%" align="center" border="1">
    <tr>
        <td colspan="7">
            <input type="submit" name="delete" value="delete checked items"/>&nbsp;
            <input type="submit" name="update" value="update checked items"/>&nbsp;
            <input type="submit" name="new" value="new log entry"/>&nbsp;
		<input type="submit" name="timeInType" value="Time In Type" />
        </td>
    </tr>
    <tr>
        <th>checked</th>
        <th>rowID</th>
        <th>fdate</th>
        <th>actype</th>
        <th>acid</th>
        <th>nlandings</th>
        <th>nhours</th>
    </tr>
HTML;

    //get log_book_id table information
    $user = "select * from log_book_id order by log_id";
    $result = oci_parse($connection, $user);
	$r = oci_execute($result);

    //display log_book_id information

    while ($newArray = oci_fetch_assoc($result)) {
        foreach ($fields as $field){
$fieldx = strtoupper($field);
            ${$field} = $newArray[$fieldx];
        }
        $rowID = $newArray['LOG_ID'];

        echo <<<HTML
    <TR>
        <td>
            <input type="checkbox" name="checkbox[$rowID]" value="$rowID">Check to select record
        </td>
        <TD>$rowID</TD>
        <TD>$fdate</TD>
        <TD>$actype</TD>
        <TD>$acid</TD>
        <TD>$nlandings</TD>
        <TD>$nhours</TD>
    </TR>

HTML;

    }    // while
    echo <<<HTML
    </table>
    </form>
    
HTML;
}    //close function

// ................................................................. function timeInType()
//

function timeInType()
{

global $connection;

$query = "select actype,sum(nhours) from log_book_id group by actype";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);
// Loop through each row, outputting the actype and name
     echo <<<HTML

    <form action="{$_SERVER['PHP_SELF']}" method="post">
    <table width="30%" align="center" border="1">

    <tr>
        <th>A/C Type</th>
        <th>Time in Type</th>

    </tr>
HTML;

	while ($row = oci_fetch_array ($statement, OCI_ASSOC)) {
	$actype = $row['ACTYPE'];
	$sum = $row['SUM(NHOURS)'];
	echo <<<HTML
    	<TR>
	       	<TD>$actype</TD>
        	<TD>$sum</TD>

    	</TR>
HTML;
	}	// while

$query = "select sum(nhours) from log_book_id";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);
// Loop through each row, outputting the actype and name

	while ($row = oci_fetch_array ($statement, OCI_ASSOC)) {
	$sum = $row['SUM(NHOURS)'];
	echo <<<HTML
    	<TR>
        	<TD>Total Hours =$sum</TD>
   	</TR>
HTML;
	}	// while

echo <<<HTML
    <tr>
        <td colspan="7">
		<input type="submit" name="continue" value="Continue" />
        </td>
    </tr>
HTML;
}

// ................................................................. function deleteRecords()
//

function deleteRecords()
{

global $connection;
// Loop through each log_book_id with an enabled checkbox

    if (!isset($_POST['checkbox'])){
    	displayDeleteForm();
        return true;
    }
    //else
    
    foreach($_POST['checkbox'] as $key=>$val){
        $toDelete[] = $key;
    }    
    //expand the array for an IN query
    $where = implode(',', $toDelete);
    $query = "DELETE FROM log_book_id WHERE log_id IN ($where)";
    $result = oci_parse($connection, $query);
	$r = oci_execute($result);
// Commit transaction
	$committed = oci_commit($connection);
// Test whether commit was successful. If error occurred, return error message
if (!$committed) {
    $error = oci_error($connection);
    echo 'Commit failed. Oracle reports: ' . $error['message'];
}
    // Should have one affected row
    if ((oci_num_rows($result)== 0) ) {
        echo "<p>There was a problem deleting some of the selected items.</p><p>".oci_error().'</p>';
//        exit();
    } else {
        echo "<p>The selected items were successfully deleted.</p>";    
    }
    //direct the user back to the delete form
    displayDeleteForm();
} //end function

//...........................................................................function insertRecord()

function insertRecord()
{
// global $rowInsert;
global $connection;

global $dFields;
    // Retrieve the posted log book information.
    global $fields;
//	$messages = array();
    //add some very crude validation
    foreach ($fields as $field){
        if (empty($_POST[$field])){
            $messages[] = "You must complete the field $field \r\n";
        } else {
           // $dFields[$field] = mysql_real_escape_string(trim($_POST[$field]));
		$dFields[$field] = trim($_POST[$field]);
        }
    }

    if (count($messages)>0) {
        displayEntryForm($messages, $dFields);
        exit();
    }
    //end validation
    
	$rowInsert = $_SESSION['rowInsert'] ;
//	$rowInsert = $_COOKIE('row_insert');

    //get variables into the namespace
    extract($dFields);
    // Insert the log book information into the log book table

	if($rowInsert)
	{
		$query = "UPDATE log_book_id set fdate = '$fdate', actype='$actype', acid='$acid', nlandings='$nlandings', nhours='$nhours'  where log_id='$rowInsert'";
	}
	else
	{
		$query = "INSERT INTO log_book_id (log_id , fdate, actype, acid, nlandings, nhours) values (logid.nextval,'$fdate','$actype','$acid','$nlandings','$nhours')";
	}

	$rowInsert = 0;
	$_SESSION['rowInsert'] = $rowInsert;
    $result = oci_parse($connection, $query);
	$r = oci_execute($result);
// Display an appropriate message
    if ($r) {
        echo "<p>Product successfully inserted!</p>";
    }else {
        echo "<p>There was a problem inserting the log book!</p>";
    $error = oci_error($connection);
    echo 'Insert failed. Oracle reports: ' . $error['message'];

    }
    //direct the user back to the entry form
    
// Commit transaction
	$committed = oci_commit($connection);
// Test whether commit was successful. If error occurred, return error message
if (!$committed) {
    $error = oci_error($connection);
    echo 'Commit failed. Oracle reports: ' . $error['message'];
}
    // Should have one affected row
    if ((oci_num_rows($result)== 0) ) {
        echo "<p>There was a problem inserting some of the selected items.</p><p>".oci_error().'</p>';
//        exit();
    } else {
        echo "<p>The selected items were successfully inserted.</p>";    
    }
	displayDeleteForm();
}


//...........................................................................function showRecord()

function showRecord() {
// show selected record
    global $fields;
   global $dFields; 
 global $connection;


	global $rowInsert;
// Loop through each log_book_id with an enabled checkbox
    if (!isset($_POST['checkbox'])){
    	displayDeleteForm();
        return true;
    }
    //else
    
    foreach($_POST['checkbox'] as $key=>$val){
        $toDelete[] = $key;
    }    

// errors
    //get log_book_id table information
    $user = "select * from log_book_id where log_id = $toDelete[0]";

    $result = oci_parse($connection, $user);
	$r = oci_execute($result);

    //display log_book_id information

    $newArray = oci_fetch_assoc($result);
        foreach ($fields as $field){
		$fieldx = strtoupper($field);
		${$field} = $newArray[$fieldx];
            	$dFields[$field] = ${$field};
        }
        $rowID = $newArray['LOG_ID'];
	$rowInsert = $rowID;
	
	$_SESSION['rowInsert'] = $rowInsert;
//	setcookie('row_insert',$rowInsert)
        //note that we do not rely on the checkbox value as not all browsers submit it
        //instead we rely on the name of the checkbox.

    //  insert the row information in the entry form
    global $fields;
    //end validation
    displayEntryForm();
}

//...........................................................................function displayEntryForm()
function displayEntryForm($errorMessages=null, $dFields=null){
    if (!empty($errorMessages)){
	echo "<ul><li>".implode('</li><li>', $errorMessages) . "</li></ul>";
    }
    
    global $dFields;
    //sort out field values
    global $fields;
    foreach ($fields as $field){
	$fieldx = strtoupper($field);
        if (isset($dFields[$field])){
            ${$field} = $dFields[$field];
        } else {
            ${$field} = '';
        }
    }
// print_r($dFields);
    echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p>
Flight Date:<br />
<input type="text" size="20" maxlength="40" name="fdate"
value="$fdate" />
</p>
<p>
Aircraft Type:<br />
<input type="text" size="20" maxlength="40" name="actype"
value="$actype" />
</p>
<p>
Aircraft ID:<br />
<input type="text" size="20" maxlength="40" name="acid"
value="$acid" />
</p>
<p>
Number Landings:<br />
<input type="text" size="20" maxlength="40" name="nlandings"
value="$nlandings" />
</p>
<p>
Number Hours:<br />
<input type="text" size="20" maxlength="40" name="nhours"
value="$nhours" />
</p>
<button type="submit" name = "insert" value="<b>Insert Row!</b>"
style="color:maroon font:18pt Courier; font-weight:bold ">Insert/Update Row
</button>
</form>
HTML;
} //end display function
?>




      

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux