Jump to content

Error check


LeonLatex

Recommended Posts

Please help me out here? I have had this error for weeks now, but i cant find the reason. And noe i even dont know where to look. I am totaly f*****
The error is about "session_start"

"<? php
error_reporting (E_ALL);
ini_set ('display_errors', '1');
?> "
Can the above error checker show errors even a site is opening normal?
When I open a page with session_start, an error occurs, but when I open the same page without this, the page opens without problems and appears and appears completely without error.
Ie. that all pages that contain session_start then the error will appear, as long as I have activated error check. Have for a long time suspected that this error is related to log in. So I tried to run error check directly from the log in page. I did not get any errors there, but I can not log in. On the log in page there is no session_start, but there is a "$ loggedin = $ _SESSION ['member_id'] ?? 0;" that is, this is a variable for session start. Or a global variable. So the error may be in db_inc.php as well, but I can not find the error. I do not understand what I am overlooking.

I have tried as best I can to familiarize myself with the script. It's not set up by me. That's what barand has done, so before anyone asks why I can not ask barand. Then I say as it is. I do not understand that either, he has probably told me something, but ..... Easiest is to say: So, dont even ask.

I hope anyway to get help to solve this problem. Can the "specified" error check indicate an error outside it is there?
Or, it is there, but not where it is supposed to be.
# counselless

Below is some of the scripting from the files. Name of files included. **AJAX script in the.php is deleted because there is no relations in that of mater**.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

db_inc.php

<?php
define("HOST",'****'); // Default database host.
define("USERNAME",'****');        // Deafault database username .
define("PASSWORD",'****');            // Default database password.
define("DATABASE", '****');    // Default database name.

function pdoConnect($dbname=DATABASE)
{
    $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    return $db;
}
?>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
header.php

<?php
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
?>
<?php
$disabl1 = isset($_SESSION['member_id']) ? '' : 'w3-disabled'; 
$disabl2 = isset($_SESSION['member_id']) && isset($_SESSION['isadmin']) ? '' : 'w3-disabled';  
$log_btn = isset($_SESSION['member_id']) ?  'Logg ut' : 'Logg inn'; 
?>

<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';

include $ROOT.'db_inc.php';
$pdo = pdoConnect();

$loggedin =  $_SESSION['member_id'] ?? 0;

unset( $_SESSION['member_id'], $_SESSION['isadmin']);

if ($loggedin)  {
    header("Location: {$HOST}marina.php");
    exit;
}

$msg = '';

if ($_SERVER['REQUEST_METHOD']=='POST') {
    $res = $pdo->prepare("SELECT password
                               , member_id
                               , admin
                          FROM member
                          WHERE email = ?     
                         ");
    $res->execute([ $_POST['email'] ]);
    $row = $res->fetch();
    if ($row && password_verify($_POST['password'], $row['password'])) {
        $_SESSION['member_id'] = $row['member_id'];
        if ($row['admin'] == 1) {
            $_SESSION['isadmin'] = 1;
        }
        header("Location: {$HOST}members.php");
        exit;
    }
    else $msg = "<div class='w3-panel w3-red w3-padding'><p>Error: Kunne ikke logge inn!</p></div>";                     
}
?>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

marina.php

<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';

include $ROOT.'db_inc.php';
$pdo = pdoConnect();

const PAGETITLE = 'Båtplasskart og Venteliste';
const HELPBUTTON = "<span id='info_btn' class='w3-badge w3-small w3-white w3-border w3-border-white w3-right' title='Hjelp'>?</span>";
//////////////////////////////////////////////////////////////////////////
**AJAX script is deleted because there is no relations in that of mater**
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

login.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';

include $ROOT.'db_inc.php';
$pdo = pdoConnect();

$loggedin =  $_SESSION['member_id'] ?? 0;

unset( $_SESSION['member_id'], $_SESSION['isadmin']);

if ($loggedin)  {
    header("Location: {$HOST}index.php");
    exit;
}

$msg = '';

if ($_SERVER['REQUEST_METHOD']=='POST') {
    $res = $pdo->prepare("SELECT password
                               , member_id
                               , admin
                          FROM member
                          WHERE email = ?     
                         ");
    $res->execute([ $_POST['email'] ]);
    $row = $res->fetch();
    if ($row && password_verify($_POST['password'], $row['password'])) {
        $_SESSION['member_id'] = $row['member_id'];
        if ($row['admin'] == 1) {
            $_SESSION['isadmin'] = 1;
        }
        header("Location: {$HOST}index.php");
        exit;
    }
    else $msg = "<div class='w3-panel w3-red w3-padding'><p>Ugyldig innlogging</p></div>";                     
}
?>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

front.php

<div class='w3-content w3-card-4 w3-margin-top w3-padding w3-light-gray'>
        <div class="w3-content">
         <div class='w3-panel w3-blue-gray w3-center'>
            <h3>Infrormasjon og Nyheter i Brandbu Småbåtforening, Røykenvik og på Randsfjorden.</h3>
        </div>
            <div class='w3-container'>
                <h4>Registrere som medlem, legge inn båt og få tildelt båtplass.</h4>
                <p>Det er gjort så pier A, B eller C velges automatisk som visninglg av kun de ledige plasser på registreringsidens nedtrekksmeny for pier-valg/for hvilke pier man tildeles. Scriptet skiller mellom oddetall og partall på alle pierene inkl. B brygge/pier. Alt skjer  automatisk selv om det er både 3 og 3,5 meters plasser der. Dette skjer ut i fra hvilke bredde på båten som legges inn i registreringskjemaet. Det skal ikke gå ann å få større plass enn hva systemet er satt til å beregne som tilpasset for hver brygge/plass.
                <p>
                <h4>Log In</h4>
                <p>Jeg har generert e-postadresser for alle testmedlemmene. Alle e-poster har utforming "fornavn.etternavn@gmail.com". Ved en tilfeldighet har alle medlemmer valgt samme passord ("passord"). Scott Chegg er for tiden utnevnt til administrator, så for eksempel
              <ul>
                <li>Logg inn som Admin</p>
                <pre>
                      E-mail   :  scott.chegg@gmail.com
                      Passord:  password
                </pre>
                </li>
                <li>Logg inn som normalt medlem</p>
                <pre>
                      E-mail   :  peter.dowt@gmail.com
                      Passord:  password
                </pre>
                </li>
                </ul>
                <p> Gjestetilgang gis for øyeblikket menyalternativene "Båtplass" og "Innmelding" (og "Logg inn", selvfølgelig) </p>
                 <p> Bare administratorer har menyfunksjonen "Faktura" tilgjengelig. </p>
                
                <h4> Marina.php </h4>
                <p> &bull; Gjestene &ndash; kan se kartet og klikke på båter, men medlemsdata er skjult for dem. De kan ikke flytte båter. <br>
                &bull; Medlemmer &ndash; kan klikke båter og se medlemsdata. De kan heller ikke flytte båter. <br>
                &bull; Administratorer &ndash; kan klikke båter, se medlemsdata og flytte båter. </p>
                <p> Lagt til brygge C + for båter med bjelke over 3,8 meter. Disse båtene har nå sin egen venteliste. </p>
                <p> Alle ventelister utvidet til å vise de 10 første båtene i hver liste. </p>
                
                <h4> Members.php </h4>
                <p> Medlemmenes medlemsnummer vises på listen. </p>
                <p> Medlemmer kan redigere sine egne personlige data. De kan også legge til detaljer om den nye båten sin (om nødvendig).
                <ul> <li> Hvis den nye båten har samme størrelse som den gamle båten, blir båtplassen beholdt </li>
                    <li> Hvis den nye båten er mindre enn den gamle båten, blir båtplassen beholdt til slutten av medlemsåret og deretter plassert på ventelisten for en mindre båtplass </li>
                    <li> Hvis den nye båten er større enn den gamle båten, plasseres den nye båten i venteliste for bredere båtplass. </li>
                    <li> Den gamle båten fjernes i alle tilfeller. </li>
                    </ul>
                <p> Administratorer kan redigere alle medlemmers personlige data og angi / deaktivere medlemmers administratorstatus. Administratorer kan også fjerne medlemmer
                (i så fall blir båten deres også fjernet) </p>
                
                <h4> Register.php </h4>
                <p> Et for øyeblikket tilgjengelig medlemsnummer vises på skjemaet. Ved registrering tildeles medlemmet dette medlemsnummeret </p>
                
                <h4> Fakturaer </h4>
                <p> Disse viser nå medlemmets navn og medlemsnummer </p>
        </div>
        </div>
        </div>
        </div>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

index.php

<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';

const PAGETITLE = "Velkommen";
    
include $ROOT.'header.php';
    
include $ROOT.'front.php';      //For you only. Remove when not required
    
include $ROOT.'footer.php';  
?>

Edited by LeonLatex
Link to comment
Share on other sites

Stop going in and out of PHP for no reason. In the header.php file you have whitespace before you call header_start() (it's the blank line between ?> and <?php) - you can't have output before you start a session. I'm assuming that's the error you're getting because that's a lot of strangely formatted code to go through and it's been a bit of a long day.

Link to comment
Share on other sites

11 minutes ago, ginerjm said:

An error occurs.  Great.  Care to tell us what the error is?

BTW - if you reference a session var without doing the session_start first OF COURSE you will get an error there.

I thought you understood it was a session_start error when i say so. Here is a print screen of what the error is in letters. heres a screen dump:
(before you ask. I have tried "require_once". It doesent help.)


 

php_error.png

Link to comment
Share on other sites

33 minutes ago, maxxd said:

Stop going in and out of PHP for no reason. In the header.php file you have whitespace before you call header_start() (it's the blank line between ?> and <?php) - you can't have output before you start a session. I'm assuming that's the error you're getting because that's a lot of strangely formatted code to go through and it's been a bit of a long day.

O oh... Is that the reason. Got to try it. Give me 3 min. Yes, it has bean a realy long dau- 12:50 in the night here now 😮 Thanks for your suggestion.

Link to comment
Share on other sites

1 hour ago, maxxd said:

Stop going in and out of PHP for no reason. In the header.php file you have whitespace before you call header_start() (it's the blank line between ?> and <?php) - you can't have output before you start a session. I'm assuming that's the error you're getting because that's a lot of strangely formatted code to go through and it's been a bit of a long day.

No, it did not help to delete the <? Php and?> That were too many and I also made sure not to have any white space between <? Php .... and ....?> I also made sure not to have white space before them in the margin.

Link to comment
Share on other sites

What is that line supposed to be?  Don't recognize.

 

As for the php tags.  Would you believe that when I write my scripts I use a single php tag in the whole damn thing?    No need to keep leaving php and coming back in.  Read up on it.  And what they are telling you is that when you are NOT in php mode any spaces or blank lines in your script will be treated as blank html lines/code.  That is a problem when you try do to php type things a little bit later.  My scripts all begin like this:

<?php
session_start();
php code
php code
php code
..
..
..
$code=<<<heredocs
html stuff
js stuff
css stuff
 more html stuff
heredocs;
echo $code
exit();

Not even the lack of an ending php tag.  Not necessary.

Edited by ginerjm
Link to comment
Share on other sites

You won't necessarily be able to see the whitespace - depending on what IDE and character set you're using there may be an errant byte order mark in the output or there may just be too many includes to thoroughly trace. And just because you deleted opening/closing PHP tags in header.php doesn't necessarily mean that's it. For instance, you have a couple open/close tags in login.php and you don't show the full code of marina.php.

Basically, if you have unbroken blocks of PHP, don't break up the blocks. There's no need to go in and out of PHP unless you absolutely have to, and nine out of ten times you don't. Unless you're using WordPress or an old-style or homegrown framework, in which case you will have to so be aware that it's not a great way to develop and keep a close eye on your code.

Link to comment
Share on other sites

As an aside, please use the code button in the post composer to paste code (it's between the quotes and the smiley face - "<>"). It helps with formatting and as long as you select PHP in the language drop-down on the right, it'll color-code your code and make it much easier to read.

Link to comment
Share on other sites

8 hours ago, ginerjm said:

What is that line supposed to be?  Don't recognize.

 

As for the php tags.  Would you believe that when I write my scripts I use a single php tag in the whole damn thing?    No need to keep leaving php and coming back in.  Read up on it.  And what they are telling you is that when you are NOT in php mode any spaces or blank lines in your script will be treated as blank html lines/code.  That is a problem when you try do to php type things a little bit later.  My scripts all begin like this:

<?php
session_start();
php code
php code
php code
..
..
..
$code=<<<heredocs
html stuff
js stuff
css stuff
 more html stuff
heredocs;
echo $code
exit();

Not even the lack of an ending php tag.  Not necessary.

As explained, this is a script that barand has put together for me. I've probably messed it up properly, he's done a good job of getting me started again, but I have a long way to go.
So if I understand you two right. NO LINESPACE BETWEEN <? PHP and?> Will that say not abow the block or below the block to?
I know I can take shortcuts that are stupid to make it easier to read the code, both along the way and afterwards. So what I spend an enormous amount of time on now is correcting all the mistakes I have "made". So I have to go through and make sure that everything that is between opening and frying PHP is without double line breaks / white space ..
When you say this about the differences between the different IDEs that exist in the market. Do you mean that they treat the code differently or do you mean that they show the code in different colors?

5 hours ago, maxxd said:

You won't necessarily be able to see the whitespace - depending on what IDE and character set you're using there may be an errant byte order mark in the output or there may just be too many includes to thoroughly trace. And just because you deleted opening/closing PHP tags in header.php doesn't necessarily mean that's it. For instance, you have a couple open/close tags in login.php and you don't show the full code of marina.php.

Basically, if you have unbroken blocks of PHP, don't break up the blocks. There's no need to go in and out of PHP unless you absolutely have to, and nine out of ten times you don't. Unless you're using WordPress or an old-style or homegrown framework, in which case you will have to so be aware that it's not a great way to develop and keep a close eye on your code.

It's because I take shortcuts to make the code more readable to myself I break up the blocks. I am fully aware of that, but in eagerness and able to do more and in combination with the fact that I am tired, unconcentrated and just want to do a little more all the time, I do a lot of stupid things. And sometimes I can make so many changes that in the end I do not remember what I have done. I remember that I was very structured in the way I worked before, but everything is forgotten, unfortunately.
Do you mean that you do not need to close <?php
I never think I've tried before.

5 hours ago, maxxd said:

As an aside, please use the code button in the post composer to paste code (it's between the quotes and the smiley face - "<>"). It helps with formatting and as long as you select PHP in the language drop-down on the right, it'll color-code your code and make it much easier to read.

I will remeber that 🙂 I will post the complete the full script from the marina.php file. That file is loooong. I will post it below of this post.
After i have done that i have to go to bed. Its 11:00 in the morning here in norway now, so its on time to get some sleep. I haven't slept for 33-34 hours. 

Link to comment
Share on other sites

<?php
session_start();
$ROOT = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) . '/';
$HOST = 'http://' . $_SERVER['HTTP_HOST'] . '/';

if (!isset($_SESSION['isadmin'])) {
    header("Location: {$HOST}marina.php");
    exit;
}

include $ROOT.'db_inc.php';
$pdo = pdoConnect();

const PAGETITLE = 'Båtplasskart og Venteliste';
const HELPBUTTON = "<span id='info_btn' class='w3-badge w3-small w3-white w3-border w3-border-white w3-right' title='Hjelp'>?</span>";
//////////////////////////////////////////////////////////////////////////
//  HANDLE AJAX REQUEST
//
if (isset($_GET['ajax'])) {
    if ($_GET['ajax']=='getberth') {
        $res = $pdo->prepare("SELECT 
                                       m.fname 
                                     , m.lname
                                     , m.mobile
									 , m.email
                                     , b.name as bname
                                     , b.make
                                     , b.model
                                     , COALESCE(be.berth_no, '') as berth_no
                                     , CASE WHEN be.berth_no IS NULL
                                            THEN CONCAT('(Ventet siden ' , date_format(bb.date_from, '%M %D %Y') , ')')
                                            ELSE ''
                                       END as since
                                FROM member m 
                                     JOIN boat b USING (member_id)
                                     JOIN boat_berth bb ON b.boat_id = bb.boat_id
                                                        AND curdate() BETWEEN bb.date_from AND COALESCE(bb.date_until, '9999-12-31')
                                     LEFT JOIN berth be USING (berth_id) 
                                WHERE b.boat_id = ?
                              ");
        $res->execute( [ $_GET['boat'] ] );
        $row = $res->fetch();
        $today = date('Y-m-d');
        if (!isset($_SESSION['member_id'])) {
            $row['fname'] = $row['lname'] = $row['mobile'] = $row['email'] = '';      // member info redacted for non-members
        }
        $datefield = isset($_SESSION['isadmin']) ? "<label>Endret dato</label><input class='' type='date' id='reberth_date' value='$today'>" 
                                                 : "&nbsp;<input type='hidden' id='reberth_date' value='$today'>";
        
        $resp = <<<RESP
            <div class='w3-panel w3-blue-gray'>
                <h3>Båtplass ID: {$row['berth_no']} {$row['since']}
                    <span class="w3-right w3-margin-right" onclick="hideInfo();"><i class='fas fa-times'></i></span>
                </h3>
            </div>
            <div class='w3-row-padding'>
                <div class='w3-third'>
                    <label>Båtnavn</label>{$row['bname']}<br>
                    <label>Fabrikat</label>{$row['make']}<br>
                    <label>Type/Modell</label>{$row['model']}<br>
                </div>
                <div class='w3-third'>
                    <label>Eier</label>{$row['fname']} {$row['lname']}<br>
                    <label>Mobilnummer</label>{$row['mobile']}<br>
                	<label>E-mail</label>{$row['email']}
				</div>
                <div class='w3-third'>
                    $datefield
                </div>
            </div>
RESP;
        exit($resp);
    }
    
    elseif ($_GET['ajax'] == 'reberth') {
        if (!isset($_SESSION['isadmin'])) {
            exit(marina($pdo));
        }
        $pdo->beginTransaction();
        try {
            $stmt = $pdo->prepare("UPDATE boat_berth
                                          SET date_until = ? - INTERVAL 1 DAY
                                          WHERE boat_id = ? AND date_until IS NULL
                                          ");
            $stmt->execute( [ $_GET['date'], $_GET['boat'] ] );
            $stmt = $pdo->prepare("INSERT INTO boat_berth(boat_id, berth_id, date_from, date_until)
                                   VALUES (? , ?, ?, null)
                                  ");
            $stmt->execute( [ $_GET['boat'], $_GET['berth'], $_GET['date'] ] );
            $pdo->commit();
        }
        catch(PDOException $e) {
            $pdo->rollBack();
            throw $e;
        } 
        exit(marina($pdo));
    }
    
    elseif ($_GET['ajax'] == 'dispose') {
        if (!isset($_SESSION['isadmin'])) {
            exit(marina($pdo));
        }
        $pdo->beginTransaction();
        try {
            $stmt = $pdo->prepare("UPDATE boat_berth
                                          SET date_until = ?  - INTERVAL 1 DAY
                                          WHERE boat_id = ? AND date_until IS NULL
                                          ");
            $stmt->execute( [ $_GET['date'], $_GET['boat'] ] );
            $stmt = $pdo->prepare("UPDATE boat
                                         SET disposal_date = ?
                                  WHERE boat_id = ?
                                 ");
            $stmt->execute( [ $_GET['date'], $_GET['boat'] ] );
            $pdo->commit();
        }
        catch(PDOException $e) {
            $pdo->rollBack();
            throw $e;
        } 
        exit(marina($pdo));
    }
}
////////////////////////////////////////////////////////////////////

/* Shape and size of the boat graphics / illustrations */
function boat($id, $size, $rotate, $x, $y) {
    switch ($size) {
        case 1: $width = 66;
                $height = 18;
                break;
        case 2: $width = 78;
                $height = 22;
                break;
        case 3: $width = 88;
                $height = 26;
        case 4: $width = 88;
                $height = 26;
    }
	/* The graphics / illustrations of the boats are in three parts. There are bow, midships and stern.<br>
       ellipse is the shape of the bow */ 
    $cx = $width/2;
    $cy = $height/2;
    $svg = "<g transform='translate($x, $y)'>
            <g transform='rotate($rotate $cx $cy)'>\n";   
    $cx2 = $width/2;
    $rx2 = $cx2;
    $cy2 = $height/2;
    $ry2 = $cy2;
    $svg .= "<ellipse cx='$cx2' cy='$cy2' rx='$rx2' ry='$ry2' class='boat boat1' data-sel='0' data-size='$size' data-id='$id'/>\n";
    
    $cx1 = $width/10;
    $rx1 = $cx1;
    $cy1 = $height/2;
    $ry1 = $cy1;
    $svg .= "<ellipse cx='$cx1' cy='$cy1' rx='$rx1' ry='$ry1'class='boat' />\n";
    
    $rx3 = $cx1;
    $ry3 = 0;
    $rw3 = $cx2 - $cx1;
    $rh3 = $height;
    $svg .= "<rect x='$rx3' y='$ry3' width='$rw3' height='$rh3' class='boat' />\n";
    $svg .= "</g>
             </g>\n";
    return $svg; 
}

function berth($bid, $no, $size, $rotate, $boat, $x, $y)
{
    switch ($size) {
        case 1: $width = 26;
                break;
        case 2: $width = 30;
                break;
        case 3:
        case 4: $width = $rotate==180 ? 153 : 34;
                break;
    }
    $even = (intval(substr($no, -2)))%2;
    $offsets = [
                   1 => [  0 => [ 'x' => 6-$width, 'y' => 5],
                           1 => [ 'x' => 6-$width, 'y' => 28],
                        ],
               
                   2 => [  0 => [ 'x' => 6-$width, 'y' => -3],
                           1 => [ 'x' => 6-$width, 'y' => 32],
                        ],
               
                   3 => [  0 => [ 'x' => 6-$width, 'y' => -10],
                           1 => [ 'x' => 60, 'y' => 3],
                        ],
                   4 => [  0 => [ 'x' => 6-$width, 'y' => -10],
                           1 => [ 'x' => 60, 'y' => 3],
                        ]
               ];
    $height = 50;
    $ty = $height/2;
    $tx = $width/2 + 3;
    $ta = -90; 
    $svg = "<g transform='translate($x, $y)'>\n";
    if ($rotate == -90) {
        $svg .= "<path d='M 0 0 v $height h $width v -$height' fill='#000079' stroke='#C0C0C0' stroke-width='2' class='berth' 
            data-bid='$bid' data-bno='$no' data-boat='$boat' data-size='$size' />\n";
    }
    elseif ($rotate == 90) {
        $svg .= "<path d='M 0 $height  v -$height h $width v $height'  fill='#000080' stroke='#C0C0C0' stroke-width='2' class='berth'
            data-bid='$bid' data-bno='$no' data-boat='$boat' data-size='$size' />\n";
    }
    else {
        $svg .= "<path d='M 0 20  v -20 h $width v 20'  fill='#000080' stroke='#C0C0C0' stroke-width='2' class='berth'
            data-bid='$bid' data-bno='$no' data-boat='$boat' data-size='$size' />\n";
        $ty = 18;
        $tx += 30;
        $ta = 0;
    }
    
    if ($boat) {
        $svg .= boat($boat, $size, $rotate, $offsets[$size][$even]['x'], $offsets[$size][$even]['y']);
    }
    $bclass = $boat ? 'bno1' : 'bno2';
    $svg .= "<text x='$tx' y='$ty' text-anchor='middle' class='$bclass' transform='rotate( $ta $tx $ty)'>$no</text>\n";
    $svg .= "</g>\n";
    return $svg;
}

function marina($db)
{ /* Controling the piers and berths */
    $piers = [  'A' => ['x0' => 60,  // Positioning sideways of pier A
                        'y0' => 100, // Positioning up/down of pier A
                        'w'  => 988, // Length pier A
                        'h'  => 16,  // Width Pier A
                        'bw' => 26   // Berth width pier A
                       ],
                'B' => ['x0' => 198, // Positioning sideways of pier B
                        'y0' => 324, // Positioning up/down of pier B
                        'w'  => 810, // Length pier B
                        'h'  => 16,  // Width Pier B
                        'bw' => 30   // Berth width pier B
                       ],
                'C' => ['x0' => 310, // Positioning sideways of pier C
                        'y0' => 596, // Positioning up/down of pier C
                        'w'  => 612, // Length pier C
                        'h'  => 16,  // Width Pier C
                        'bw' => 34   // Berth width pier C
                       ]
             ];
    
    $svg = "<svg width='1140' height='840' viewBox='0 0 1140 840'>
            <defs>
               <radialGradient id='myGradient'>
                  <stop offset='10%' stop-color='#000000' />       
                  <stop offset='95%' stop-color='#808080' />
                </radialGradient>
               <radialGradient id='myGrad2'>
                  <stop offset='10%' stop-color='#A91723' />       
                  <stop offset='95%' stop-color='#808080' />
                </radialGradient>
 
            <style type='text/css'>
                .boat {
                    fill: #FCF8E8;
                }
                .boat1 {
                    cursor: pointer;
                }
                .pierno {
                    font-size: 20pt;
                    fill: #FFF;
                }
                .piernox {
                    font-size: 12pt;
                    fill: #FFF;
                }
                .qno {
                    font-size: 20pt;
                    fill: #CCC;
                }
                .bno1 {
                    font-size: 10pt;
                    fill: #444;
                }
                .bno2 {
                    font-size: 10pt;
                    fill: #FFF;
                }
                .title1 {
                    font-size: 30pt;
                    font-family: gabriola, cursive;
                    font-style: italic;
                    fill: #FFF;
                }
                .title2 {
                    font-size: 20pt;
                    font-family: gabriola, cursive;
                    font-style: italic;
                    fill: #FFF;
                }
            </style>
            </defs>
           ";
    $svg .= "<rect x='0' y='0' width='1140' height='800' fill='#000080' />
             <rect id='waiting-area' x='0' y='700' width='1140' height='140' fill='#808080' />
             <!--<text x='1130' y='690' fill='#808080' font-size='8pt' transform='rotate(-90 1130 690)'>&copy; 2021 Barry Andrew</text>-->
             <path d='M 0 700 h 1140' stroke='#006EFC'/>
             <text x='5' y='695' fill='#C0C0C0' font-size='20'>Første 10 på venteliste for båtplass.(+ er long-side-plasser på brygge C)</text>
             <text x='1080' y='720' text-anchor='middle' fill='#000080' font-size='18'>Slette fra</text>
             <text x='1080' y='795' text-anchor='middle' fill='#000080' font-size='18'>venteliste</text>
             ";

    // Berths
    $res = $db->query("SELECT  b.berth_id
                             , b.pier
                             , b.berth_no
                             , b.size
                             , bb.boat_id
                        FROM berth b
                             LEFT JOIN boat_berth bb ON b.berth_id = bb.berth_id
                                                     AND CURDATE() BETWEEN bb.date_from AND COALESCE(bb.date_until, '9999-12-31')
                        ORDER BY berth_no

                        ");
    
    foreach ($res as $r) {
        $px = $piers[$r['pier']]['x0'] + $piers[$r['pier']]['w'];
        $bno = intval(substr($r['berth_no'], -2));
        
        switch ($r['pier']) {
            case 'A':   
            case 'B': $y = ($bno%2 == 0) ? $piers[$r['pier']]['y0'] - 50 : $piers[$r['pier']]['y0'] + 16;
                      $x = $px - floor(($bno+1)/2) * $piers[$r['pier']]['bw'];
                      $rotate = ($bno%2 == 0) ? -90 : 90;
                      $svg .= berth($r['berth_id'], $r['berth_no'], $r['size'], $rotate, $r['boat_id'], $x, $y);
                      break;
            case 'C': 
                      if ($bno%2 == 0) {
                          $y = $piers[$r['pier']]['y0'] - 50;
                          $x = $px - floor(($bno+1)/2) * $piers[$r['pier']]['bw']; 
                          $rotate = -90;
                      }
                      else {
                          $y = $piers[$r['pier']]['y0'] + 16;
                          $x = $px - floor(($bno+1)/2) * $piers[$r['pier']]['w']/4;
                          $rotate = 180;
                      }
                      
                      $svg .= berth($r['berth_id'], $r['berth_no'], $r['size'], $rotate, $r['boat_id'], $x, $y);
                      break;
        }
    }
    
    // Jetties
    for ($j='A'; $j<='C'; $j++) {
        $x = $piers[$j]['x0'];
        $y = $piers[$j]['y0'];
        $h = $piers[$j]['h'];
        $w = $piers[$j]['w'];
        $tx = $piers[$j]['x0'] - 28;
        $ty = $piers[$j]['y0'] + 17;
        $svg .= "<rect x='$x' y='$y' width='$w' height='$h' fill='#C38E31' />\n"; /* Pier color */
        $svg .= "<text x='$tx' y='$ty' fill='#FFF' class='pierno'>$j</text>\n";
    }
	
	/* Positioning and appearance of the molo */
    $ty += 28;
    $svg .= "<text x='$tx' y='$ty' fill='#FFF' class='piernox'>+</text>\n";
    $svg .= "<path d='M 1116 0 h 16 v 200 l -130 412 h -16 l 130 -412 z' fill='#ACACAC' />" ;
    foreach ($piers as $p) {
        $svg .= gangplank($p['x0'] + $p['w'] - 6, $p['y0'] + 1, 75);
    }

    // Unberthed boats
    $res = $db->query("SELECT b.boat_id
                            , b.size
                       FROM boat b
                            JOIN boat_berth bb ON b.boat_id = bb.boat_id
                                               AND bb.berth_id IS NULL
                                               AND CURDATE() BETWEEN bb.date_from AND COALESCE(bb.date_until, '9999-12-31')
                       ORDER BY b.size, bb.date_from
                      ");
    $tx = 4;
    $ty = 725;
    
    $by = 705;
    $waiting = [];
    foreach ($res as $r) {
        $waiting[$r['size']][] = $r['boat_id'];
    }
    
    foreach ($waiting as $sz => $q) {
        switch ($sz) {
            case 1: $p = 'A'; break;
            case 2: $p = 'B'; break;
            case 3: $p = 'C'; break;
            case 4: $p = '+'; break;
        }

        $svg .= "<text x='$tx' y='$ty' fill='#FFF' class='qno'>$p</text>\n";
        $k = count($q);
        $xtra = $k > 10 ? $k - 10 : '';
        $q = array_slice($q, 0, 10);
        $bx = 30;
        foreach ($q as $id) {
            $svg .= boat($id, $sz, 180, $bx, $by);
            $bx += 92;
        }
        $ky = $ty - 6;
        if ($xtra) $svg .= "<text x='$bx' y='$ky' fill='#FFF' fill='#FFF' font-size='20'>+$xtra</text>\n";
        $ty += 32;
        $by += 32;
    }

    $svg .= "<circle id='vortex' cx='1080' cy='750' r='25' fill='url(\"#myGradient\")' />";
    $svg .= '</svg>' ;
    return $svg;
}

function gangplank($x, $y, $len)
{
    $svg = "<rect x='$x' y='$y' width='$len' height='12' fill='#E0E0E0' stroke='#666' />\n";
    for ($i=5; $i<$len; $i+=5) {
        $ix = $x + $i;
        $svg .= "<path d='M $ix $y v 12' fill='none' stroke='#666' />\n";
    }
    return $svg;
}
?>
<!DOCTYPE html>
<html lang='no'>
<head>

<title>Brandbu SmåbåtForening - Båtplasser</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<link rel='stylesheet' href='https://www.w3schools.com/w3css/4/w3.css'>
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.15.1/css/all.css'>
<link href='css/footer_marina.css' rel='stylesheet' type="text/css">
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'></script>
<script type='text/javascript'>
    $().ready(function() {
        $("#nav-marina").addClass("w3-bottombar")
        init()
        
        $("#info_btn").click( function() {
            $("#infopanel").toggle()
        })
    })
    
    function init()
    {
        $('.boat1').click(function() {
            var boat = $(this).data('id')
            $('.boat').css('fill', '#FCF8E8')
            $('.boat').attr('data-sel', 0)
            $(this).attr('data-sel', 1)
            $(this).parent().children().css('fill', '#FF0000')
            $.get(
                '',
                {'ajax':'getberth', 'boat':boat},
                function(resp) {
                    $('#query-results').html(resp)
                    $('#query-results').show()
                    location.href = '#query-results'
                },
                'TEXT'
            )
        })
        
        $('.berth').click( function() {
            var boat = $(".boat1[data-sel='1']")
            if (!boat) {
                return
            }
            else {
                var boatsize = $(boat).data('size')
                var berthsize = $(this).data('size')
                if (berthsize != boatsize) {
                    return
                }
                if ($(this).data('boat')) return;
                var boatid = $(boat).data('id')
                var berthid = $(this).data('bid')
                var date = $('#reberth_date').val()
                $.get(
                    '',
                    {'ajax':'reberth', 'boat':boatid, 'berth':berthid, 'date':date},
                    function(resp) {
                        $('.boat').attr('data-sel', 0)
                        $('#marina').html(resp)
                        init()
                    },
                    'TEXT'
                )
            }
        })
        
        $("#vortex").click( function() {
            var boat = $(".boat1[data-sel='1']")
            if (!boat) {
                return
            }
            var boatid = $(boat).data('id')
            var date = $('#reberth_date').val()
                $.get(
                    '',
                    {'ajax':'dispose', 'boat':boatid, 'date':date},
                    function(resp) {
                        $('.boat').attr('data-sel', 0)
                        $('#marina').html(resp)
                        init()
                    },
                    'TEXT'
                )
            
        })
        
    }
    function hideHelp() {
        $("#infopanel").toggle()
    }
    function hideInfo() {
        $('#query-results').hide()
        $('.boat').css('fill', '#FCF8E8')
        $('.boat').data('sel', 0)
    }
    
</script>
<style type='text/css'>
    label {
        background-color: #607d8b;
        color: white;
        border: 1px solid white;
        display: inline-block;
        padding: 4px;
        width: 130px;
        margin-right: 10px;
    }
    #query-results {
        display: none;
    }
    #vortex:hover {
        cursor: pointer;
        fill: url('#myGrad2');
    }
    #info_btn {
        cursor: pointer;
    }
    #infopanel {
        display: none;
    }
    .berth:hover {
        fill: #2e90ff;
        cursor: pointer;
    }
body {
	background-color: #000080;
}
</style>
</head>
<body>

<?php include $ROOT.'header.php' ?>

<div id="infopanel" class="w3-card-4 w3-container w3-sand">
    <div class="w3-panel w3-brown w3-center w3-padding w3-large">
        Informasjon
        <span class="w3-right w3-margin-right" onclick="hideHelp();"><i class='fas fa-times'></i></span>
    </div>
    <p>Denne siden gir en oversikt over marinaen, båtene og båtplassene i BSF marina. I tillegg vil du finne noe informasjon om Røykenvik og Randsfjorden her.</p>
        <ul>
        <li>Klikk på en båt (baug-området) for å se informasjonen om den båten/eieren i et informasjonspanel øverst på siden.</li>
        <li>Når en båt er valgt, kan du flytte den til en annen båtplass av samme størrelse ved å klikke på en tom køye.</li>
        <li>Du kan også slette båten ved å klikke på "slette fra venteliste"-knappen nederst til høyre.</li>
        <li>Disse bevegelsene brukes fra i dag. Hvis du vil at de skal brukes på en annen dato, kan du angi ønsket dato i båtens informasjonspanel</li>
        <li>De første 10 båtene (i datorekkefølge) for hver brygge som venter på at en bryggeplass skal bli tilgjengelig, vises i "venteområdet" nederst. Igjen, disse kan velges og tildeles en tilgjengelig båtplass.</li>
        </ul>
</div>

<div class='w3-container'>
    <div id='query-results' class='w3-card-4 w3-margin w3-padding w3-light-gray'>
        <!-- click response -->
    </div>
    <div id='marina' class='w3-container w3-padding w3-center' style='overflow:auto;'>
        <?=marina($pdo)?>
    </div>
</div>

	<?php include $ROOT.'footer_marina.php';  ?>
</body>
</html>

 

Link to comment
Share on other sites

4 hours ago, maxxd said:

what is it supposed to do?

It displays an interactive map of his association's marina, showing all the berths and the boats in each berth. Clicking on a boat displays details of the boat and (if the user is logged in as a member) it displays contact details of the boat owner. It also allows you move boats from one berth to another, or from the waiting lists at the bottom to an empty berth. All changes update the database. Having made a change the map is redrawn.

As you can see from the image below, it worked when it left the shop (login too, so it can display the owner details). I wrote this, and a few other pages, for Leon as a hobby project during the lockdown.

image.thumb.png.17e82d3d1a513d9d20fc0f06bfeb8899.png

If you examine the lower right-hand edge of the image you will see my name. When he put it on his site that name had been removed and he added footer proclaiming "Design and Development by...<his site>". If you look at the posted code (line 300 - about halfway down - my name is there but now commented out). I told him that as he wanted to claim all the credit for the design and developent then he should actually do it all. I then ceased communication.

Given that history, it seems strange he should be publically crediting me now he has screwed with the code and it has all gone FUBAR. Whether he intends it as blame or just to try and embarrass me into helping out, I'm not sure. But it does give me no choice but to explain publically why I am not rushing forward to help with his problems.

Edited by Barand
  • Great Answer 1
Link to comment
Share on other sites

Nice and a smart move barand, wery! As the person you are, of all, YOU, you go out public to mark me and throwing all the blame on me? It's ok. I let you do that. But...

I know you have frinds and like-minded in here on PHP Freaks. You have bean here since 2002 or something. You are well known among the other once her. PHP Freaks is a site i came over by chance, and it was a lucky shot that I did so. Here I also found "my" like-minded people. People who needed help. I did it because I've been away from the "subject programming" for over ten years (since 2010/11). Things I could do were totally gone. I had to learn everything again. There are also "several reasons" for this. Blue. a stroke in 2014. But I'm also 50 years old in January, so everything is not so good and functional anymore , by the case learning. These are things I've told barand about before he knows a lot of me and my future as a self developed and a businessman and one of the persons and owners behind the biggest webhosting and data center in Norway. That is a story back to 1998/99 (actual in 
1995, but that is a longer story).  So he knows about it, about me. There are also some other incidences as a traffic accident in 1988 with major head injuries that make memory and earning not my biggest "thing" in life. soooo ...... maxxd, then you have heard a little of the one side of the story. I never felt for explain or tell others about what happened between me and barand, or other things for that mather. And still barand is trying to put me in a place i dont belong. Remember there is always two sides of a story, two sides of whats true. Here is the rest of my version. (And i have never tried to hide that this script was something barand had done) Just go back and look up in this tread.

I never feel to put a stamp on or blame other people. I let them do their things. As long.........as long as it is not unfair and not goes over head of me or any of mine. I am concerned about justice and that everyone including myself is treated with respect. Now i feel for saying. (never thought i would go SOOOO in to discuss OT on a internet forum).

Me and barand was skyping and working on the "marian project" one nigh(i think it was in june)t, like we had done since around February. Me in Norway and him in GB. That day i had tried to do some adjustments and corrections on the site barand has made for me, and. In that matter i removed hes signature. I tried out a few things. Some were luckyly put back the way barand did it Part of the reason why barand should help me with this was that I could use it to learn / practice. That was not a agrement among us from the beginning. But along the way, it became more and more clear that this was what this project was about, and that I would be able to use it later for what it was intended for. A gift from me to my marina where I live. They have had problems for a long time with running the marina association for several years due to lack of time, and that the marina is run on a voluntary basis (unpaid).  all with manny problems, like a surgery that went wery wrong, eating heavy medications and a loss of a friend (barand knows all of this) i now felt like stating to go realy in to study and learn barands code. So the whole day i was doing this and sudenly some time in the evening/night barand showed up. And i was actualy waiting for him because i was exited see him on Skype. Like i throw all in my hands away i contacted him/or he was contacting me. I had a lot of questions to ask him. So now i forgot all about what i had done and put them back the way they was. I had the signature/copyright text in the footer file from another site i was working on. Where i forgot to change the text and implement barands information. It still had my name and e-mail, and my intension was to put in barands name and e-mail. Hard to explain and be belived. You got to know me to to understand(me).

So, over to the core of the marina.php file where all begun. I tried to learn the PHP and AJAX he set up in this file. He realy did a great job. I comment out hes signature and I commented out part of hes scripts and blocks, just to see what the diferent functions in the script(s)works/do, among other things. If I had the intention to remove it (take advantage of), then I had not just commented it away. I would totally remove it in the source code. There were many things up there that had been commented out, but that he had not seen. besides the one thing that was visually visible in the browser. Until this we had a good collaboration on both mic and writing on Skype. When he became aware of this, he totally turned on his heels and I have never seen a person turn so completely on mood, situation and not least receptivity to listen to what is an explanation. No, barry has since made his own version and locked me out. I tried then as now to explain what had happened. Both in writing by email, on Skype and on pm here at PHP Freaks. Lately I have been trying to sell the script since I do not want to finish it. I have received several stakeholders for it. There is one offer in particular from Denmark that seems to be serious enough. When I got an answer from Denmark a few days ago, I contacted barand the same day / evening and told him about it, and that I would divide the sum 50/50, but now I do not know if it works either. Since I contact Denmark, I wanted to clean up and make the code more readable. That's why I've now messed up the whole script and rendered it useless. Why would I make myself an enemy with someone I depended on to move on?
I know that with this I am in danger of not receiving help anymore here on PHP Freaks or being banned. Of course I hope we can all be friends, but ... how far are you willing to go? I also feel unfairly treated. Again, sorry for what I did that seemed like taking your credit for the work I will forever be grateful for. For that is what you accuse me of, and who have not been willing to listen to me. Sorry....
(i had a backup of the scripts/site, but deleted it when i was about delete the web root files and put in the backup).

Edited by LeonLatex
correct some line spaces
Link to comment
Share on other sites

So Barand did all the work and made a useful working script under the impression he was not only helping you with a personal project but helping someone who wanted to learn PHP. You then removed all public-facing attribution to Barand and broke the system, turned around and tried to sell the software he built and you broke, and now you offer him a 50-50 split but you can't understand why he's miffed about it?

I mean, dude...

  • Great Answer 1
Link to comment
Share on other sites

19 hours ago, LeonLatex said:

Nice and a smart move

You engineered it. When you started citing me in your posts as being responsible for the original code you gave me two undesirable options...

  • I could carry on ignoring the posts, but then I would look bad in everyone's eyes for being the one who knew the code but apparently leaving you in the lurch, or
  • I could submit to your coercion to make me carry on helping you with the project, albeit via the forum.

When on the horns of a dilemma one looks for a third option.

And should I be grateful for your selling my code without my permission and generously offering me 50%?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.