Exemple #1
0
function main()
{
    try {
        BlockIfViolation();
        global $locale;
        global $returnURI;
        $PHP_SELF = $_SERVER['PHP_SELF'];
        $post = $_POST['blnPost'];
        $id = $_GET['id'];
        $movID = $_GET['movID'];
        $relationship = $_GET['relationship'];
        $m2p = new MovieToPerson($id);
        if (!$m2p->IsNew()) {
            $mov =& $m2p->Movie();
            $person =& $m2p->Person();
        } else {
            $m2p->Relationship($relationship);
            $person = new Person();
            if ($movID == "") {
                throw new Exception("Missing movID");
            }
            $mov = new Movie($movID);
        }
        $movID = $mov->ID();
        $persons = new Persons();
        $persons->LoadAll();
        $persons->Sort("FirstName");
        print "<h3><a href=movie.php?id={$movID}>" . $mov->Title() . "</a></h3>\n";
        $characterName = $m2p->CharacterName();
        $relationship = $m2p->Relationship();
        if ($post) {
            if ($_POST['btnDelete'] != '') {
                $m2p->MarkForDeletion();
                $characterName = $relationship = '';
            } else {
                $person = new Person($_POST['cboPersons']);
                $m2p->Person($person);
                $m2p->PersonID($person->ID());
                $m2p->Movie($mov);
                $m2p->CharacterName($_POST['txtCharacterName']);
                $m2p->Relationship($_POST['txtRelationship']);
                $characterName = $m2p->CharacterName();
                $relationship = $m2p->Relationship();
            }
            if (UpdateObject($m2p)) {
                ReturnURI();
            }
        }
        $firstName = $person->FirstName();
        $lastName = $person->LastName();
        ?>
        <form name=frm method=post action=<?php 
        echo $PHP_SELF . "?id={$id}&movID={$movID}&returnURI={$returnURI}";
        ?>
>
            <table border=1>
                <tr>
                    <td>
                        <?php 
        print "<select name=cboPersons>\n";
        foreach ($persons as $person) {
            $name = $person->Name();
            $id = $person->ID();
            if ($id == $m2p->PersonID()) {
                $selectTag = 'SELECTED';
            } else {
                $selectTag = '';
            }
            ?>
                                <option value=<?php 
            echo $id;
            ?>
 <?php 
            echo $selectTag;
            ?>
><?php 
            echo $name;
            ?>
</option>
                            <?php 
        }
        print "</select>\n";
        ?>
                    </td>
                </tr>
                <?php 
        if ($relationship == 's') {
            ?>
                    <tr>
                        <td><?php 
            echo GetCap('capCharacterName');
            ?>
</td>
                        <td><input type=text name=txtCharacterName value='<?php 
            echo $characterName;
            ?>
'></td>
                    </tr>
                <?php 
        }
        ?>
                <tr>
                    <td><?php 
        echo GetCap('capRelationship');
        ?>
</td>
                    <td><input type=text name=txtRelationship value=<?php 
        echo $relationship;
        ?>
></td>
                </tr>
                <tr>
                    <td> <input type=submit name=btnSubmit value=<?php 
        echo GetCap('capSubmit');
        ?>
> </td>
                    <td> <a href=<?php 
        echo "{$PHP_SELF}?movID={$movID}";
        ?>
><?php 
        echo GetCap('capNew');
        ?>
</a>
                </tr>
                <input type=hidden name=blnPost value=1>
            </table>
         </form>
        <?php 
    } catch (Exception $ex) {
        ProcessException($ex);
    }
    require_once 'tailer.php';
}