Location: PHPKode > projects > PHP Cad and Drawing Program > index.php
<?php
session_start();
$u = $_SESSION[xx];
$v = $_SESSION[yy];
$pfilez=$_SESSION[pfilez];
$PDir=$_GET[PDir];
$PObj=$_GET[PObj];
$_SESSION[flag]=0;
// needed for some reason so url for imagemap is clean
// take files from "functions" and sets them up
if ($_SESSION[firsttime] == "") {
    $_SESSION[firsttime]="done";
    header("Location: index.php");
}

//puts all .tobs in array and sets pfilez if empty
$b = opendir("./files");
$plist = array();
while($file = readdir($b)) if (ereg("tob",$file)) array_push($plist,$file);
sort($plist);
if ($pfilez == "") $_SESSION[pfilez] = $plist[0];
closedir($b);

// This parses server-side imagemaps since cgi attaches
// the coordinates such as ?212,121 to the end of the url.
$z = $_SERVER['QUERY_STRING'];
$a = explode(",",$z);
$xx=$a[0]*1;
$yy=$a[1]*1;
$ff=str_replace(".tob",".setup", $pfilez);
    if (file_exists("./files/$ff")) {
        include("./files/$ff");
    } else {
        include("./files/picture.setup");
    }
$_SESSION["xx"] = floor($xx/$scale);
$_SESSION["yy"] = floor($yy/$scale);
$xx=$_SESSION["xx"];
$yy=$_SESSION["yy"];


/**    File Managing Form, 1st form, is caught here.
 *     $pfile- file selection, $poptions - what to do with it.
 */
if ($_GET["formsent"] == "sent") {
    $u="";
    $v="";
    $_SESSION[xx]="";
    $_SESSION[yy]="";
    $_SESSION[pfilez]=$_GET["pfile"];
    $poptions=$_GET[poptions];
    if ($poptions == "View") header("Location: index.php");
    if ($poptions == "Edit-.setup") header("location: setup.php");
    if ($poptions == "Make-movies") header("location: movies.php");
    if ($poptions == "View-.tob") header("Location: ./files/$pfilez");
    if ($poptions == "View-.setup") {
        $a = str_replace(".tob",".setup",$pfilez);
	header("Location: ./files/$a");
    }

    if ($poptions == "Make-p.pov") {
        header("location: pov.php");
    }

    if ($poptions == "View-p.jpg") {
        header("location: p.jpg");
    }

    if ($poptions == "New") {
        $c=1;
        $b=1;
        while ($b == "1") {
            $pfilen="picture" . $c . ".tob";
            if (file_exists("./files/$pfilen")=="0") {
                $b=2;
            } else {
                $c=$c+1;
            }
        }
        $fp = fopen("./files/$pfilen","w");
        fclose($fp);
        chmod("./files/$pfilen",0666);
        $_SESSION[pfilez] = $pfilen;
        $poptions="View";
        header("Location: index.php");
    }

    if ($poptions == "Delete") {
        if ($pfile = $_SESSION[pfilez]) {
            unlink("./files/$pfile");
            $ff = str_replace(".tob",".setup",$pfile);
            if (file_exists("./files/$ff")) unlink("./files/$ff");
            $poptions = "View";
            $b = opendir("./files");
            $plist = array();
            while($file = readdir($b)) if (ereg("tob",$file)) array_push($plist,$file);
            sort($plist);
            $_SESSION[pfilez] = $plist[0];
        }
        header("Location: index.php");
    }
    if ($poptions == "View-.png") header("Location: drawimage.php");
    if ($poptions == "Changelog") header("Location: changelog.htm");
    if ($poptions == "Overview") header("Location: overview.htm");
    if ($poptions == "Tutorial") header("Location: tutorial.htm");
    }
// End of the File Managing Form

// Start of HTML and 1st Form
// **************************************************************

echo "<html><title>PHPCAD by William L. Berggren 2002(c)</title>\n";
echo "<body bgcolor='777777' link='000000' vlink='000000' alink='000000'>\n";

if ($xx=='' AND $yy=='' AND $xx != "0") $boxa = 'Pick a square or point!';
if ($xx OR $yy) $boxa = "Ptr#1: x=$xx y=$yy";
if ($xx=='0' AND $yy=='0') $boxa = 'Ptr#1: x=0 y=0';

if ($u=='' AND $v=='' and $u != "0") $boxb = "Pointer#2 is empty!";
if ($u OR $v) $boxb = "Ptr#2: u=$u v=$v";
if ($u=='0' AND $v=='0') $boxb = 'Ptr#2: x=0 y=0';
// Start of First Form - File Management

echo "<form method='GET' action='$PHP_SELF'>\n";
// pfile will return new file selection pfilez
echo "<select name='pfile'>\n";
echo "<option>" . $pfilez . "</option>\n";
foreach($plist as $items) {
    if ($items != $pfilez) echo "<option>" . $items . "</option>\n";
}
echo "</select>\n";

//poptions will return options
$olist= array("View","Make-p.pov","View-p.jpg","Edit-.setup","Make-movies",
"View-.tob","View-.setup","View-.png","New","Delete","Changelog","Overview","Tutorial");
echo "<select name='poptions'>\n";
foreach($olist as $items) echo "<option>" . $items . "</option>\n";
echo "</select>\n";
echo "<input  name='formsent' Type='hidden' value='sent'>\n";
echo "<input value='Submit' type='submit'>\n";
echo "<input value='$boxa' readonly size=19 align='top'>";
echo "<input value='$boxb' readonly size=19 align='top'>";
echo "</form>";

/**************************************************************
 * End of First Form The File Selector/Manager
 *
 *
 * Start of Second Form - The Editor
 **************************************************************/

include "second.php";

/**************************************************************
 * End of 2nd Form Form
 *
 * Start of Server-Side Image Map
 *************************************************************/

// Draws Help on Screen
if ($PDir=='Help') {
    echo "<iframe src='help.php?PObj=$PObj'";
    echo "vscrolling='yes' hscrolling=no width=500";
    echo " height=100 frameborder=0></iframe>\n<br>";
}
// Use grid size in .setup to determine image map coordinates
// Draw picture pfilez and use server-side imagemap.
// echo "<a href='index.php?$xx?$yy?$pfilez'>";
$zimage=$_SESSION[pfilez];
echo "<a href='index.php'>";
echo "<img border=0 src='drawimage.php?zimage=$zimage'";
//echo "<img border=0 src='drawimage.php'";
echo "ismap alt='zzz'></a><br>\n";

    $bbbbb="";
    $b = opendir("./functions");
    $inclist = array();
    while($file = readdir($b)) {
        if (ereg("inc$",$file)) array_push($inclist,$file);
    }
    sort($inclist);
    foreach ($inclist as $incname) {
        $zzz = file("./functions/$incname");
        foreach ($zzz as $lineitem) {
            if (substr_count($lineitem,"B")>15) $ptr="b";
            if (substr_count($lineitem,"C")>15) $ptr="c";
            if ($ptr=="B") $bbbbb=$bbbbb . $lineitem;
            if ($ptr=="b") $ptr="B";
        }
    }

?>
</body></html>
Return current item: PHP Cad and Drawing Program