public function __construct(Oedipus_Scene $scene, $name)
 {
     parent::__construct('form', NULL);
     $method = 'POST';
     $this->set_attribute_str('name', $name);
     $this->set_attribute_str('method', $method);
     $this->set_attribute_str('class', 'scene-form');
     $this->input_lis = array();
     $this->scene = $scene;
     # action
     $this_action = $this->get_scene_editor_form_action_url();
     $this->set_action($this_action);
     //                # cancel
     //                $this_cancel = $this->get_scene_editor_form_cancel_url();
     //                $this->set_cancel_location($this_cancel);
     # Hidden Inputs
     $this->add_hidden_input('scene_id', $scene->get_id());
     /*
      *If we're on the edit_scene section of Drama Page,
      * pass this on to set the return to correctly
      */
     if (isset($_GET['edit_scene'])) {
         $this->add_hidden_input('return_to_get', 'edit_scene');
     }
     $this->set_submit_text('Save');
 }
 public static function get_frame_tree_div(Oedipus_Scene $scene)
 {
     $div = new HTMLTags_Div();
     $div->set_attribute_str('class', 'frame-tree');
     $html = self::get_tree_ul(self::get_root_frame_id_for_scene_id($scene->get_id()), $scene->get_id(), $scene->is_editable());
     //                print_r($html);exit;
     $div->append($html);
     return $div;
 }
 public function __construct($drama_id, Oedipus_Scene $scene)
 {
     parent::__construct('add-scene-note');
     # Note Text Input
     $this->add_textarea_with_value('note_text', '', 'Note');
     # action
     $this_action = $this->get_scene_note_editor_form_action_url();
     $this->set_action($this_action);
     # Hidden Inputs
     $this->add_hidden_input('drama_id', $drama_id);
     $this->add_hidden_input('scene_id', $scene->get_id());
     $this->add_hidden_input('add_note', 1);
 }
 public function add_scene(Oedipus_Scene $scene)
 {
     //                $this->scenes[$scene->get_name()] = $scene;
     $this->scenes[$scene->get_id()] = $scene;
 }
    public function get_scene_by_id($scene_id)
    {
        $dbh = DB::m();
        $query = <<<SQL
SELECT 
\t*
\tFROM
\t\toedipus_scenes
\tWHERE
\t\tid = {$scene_id}
SQL;
        //                                print_r($query);exit;
        $result = mysql_query($query, $dbh);
        $row = mysql_fetch_array($result);
        //                                                print_r($row);exit;
        $scene = new Oedipus_Scene($row['id'], $row['name'], $row['added'], $row['act_id']);
        //                                                print_r($scene);exit;
        // Add the scenes to this Act
        // Get all frames for this drama
        $frames_query = <<<SQL
SELECT 
\t*
\tFROM
\t\toedipus_frames
\tWHERE
\t\tscene_id = {$scene_id}
SQL;
        //                print_r($frames_query);exit;
        $frames_result = mysql_query($frames_query, $dbh);
        //                print_r($frames_result);exit;
        // Add the frames to the drama object
        //
        if ($frames_result) {
            while ($frame_result = mysql_fetch_array($frames_result)) {
                //                                                print_r($frame_result);exit;
                $frame_id = $frame_result['id'];
                $frame = self::get_frame_by_id($frame_id);
                $scene->add_frame($frame);
            }
        }
        //                                                print_r($scene);exit;
        return $scene;
    }
    public static function add_note_to_scene(Oedipus_Scene $scene, $note_text)
    {
        // ADD NOTE TO DATABASE
        $dbh = DB::m();
        $note_sql = <<<SQL
INSERT INTO
\toedipus_notes
SET
\tnote_text = '{$note_text}',
\tadded = NOW()
SQL;
        //                print_r($sql);exit;
        $note_result = mysql_query($note_sql, $dbh);
        $note_id = mysql_insert_id($dbh);
        // ADD LINK TO DATABASE
        $scene_id = $scene->get_id();
        $link_sql = <<<SQL
INSERT INTO
\toedipus_scene_to_note_links
SET
\tscene_id = '{$scene_id}',
\tnote_id = '{$note_id}'
SQL;
        //                                print_r($link_sql);exit;
        $link_result = mysql_query($link_sql, $dbh);
        $link_id = mysql_insert_id($dbh);
        return new Oedipus_Note($note_id, $note_text, date());
    }
 protected function get_scene_div(Oedipus_Scene $scene)
 {
     /*
      *Pass Editing Priviliges
      */
     if ($this->get_drama()->is_editable()) {
         $scene->make_editable();
     }
     if (isset($_GET['frame_id'])) {
         /*
          * Return the normal frame
          */
         return new Oedipus_FrameViewSceneDiv($scene, $_GET['frame_id']);
     }
     /*
      * Return the Tree
      */
     return new Oedipus_TreeViewSceneDiv($scene);
 }
    public function add_child_frame_as_duplicate_of_parent(Oedipus_Scene $scene, $parent_frame_id)
    {
        $parent_frame = $scene->get_frame($parent_frame_id);
        $frame_name = Oedipus_DramaHelper::get_incremented_name($parent_frame->get_name());
        //print_r($frame_name);exit;
        $scene_id = $scene->get_id();
        // ADD TABLE TO DATABASE
        $dbh = DB::m();
        $sql = <<<SQL
INSERT INTO
\toedipus_frames
SET
\tname = '{$frame_name}',
\tscene_id = {$scene_id},
\tadded = NOW()
SQL;
        //print_r($sql);exit;
        $result = mysql_query($sql, $dbh);
        $frame_id = mysql_insert_id($dbh);
        /*
         *Set Frame Name
         */
        $characters = array();
        $parent_characters = array();
        $i = 0;
        foreach ($parent_frame->get_characters() as $parent_character) {
            // ADD Duplicate ACTOR tO DATABASE
            $character_name = $parent_character->get_name();
            $character_color = $parent_character->get_color();
            $sql2 = <<<SQL
INSERT INTO
\toedipus_characters
SET
\tname = '{$character_name}',
\tcolor = '{$character_color}',
\tframe_id = {$frame_id},
\tadded = NOW()
SQL;
            //                print_r($sql);exit;
            $result2 = mysql_query($sql2, $dbh);
            $character_id = mysql_insert_id($dbh);
            $character = new Oedipus_Character($character_id, $character_name, $character_color);
            $characters[$i] = $character;
            $parent_characters[$i] = $parent_character;
            $i++;
        }
        //print_r($parent_characters);exit;
        $i = 0;
        foreach ($parent_characters[$i]->get_options() as $parent_option) {
            $parent_si = $parent_option->get_stated_intention();
            //print_r($parent_si);exit;
            // ADD DEFAULT stated_intention tO DATABASE
            $stated_intention_position = $parent_si->get_tile();
            $stated_intention_doubt = $parent_si->get_doubt();
            $sql3 = <<<SQL
INSERT INTO
\toedipus_stated_intentions
SET
\tposition = '{$stated_intention_position}',
\tdoubt = '{$stated_intention_doubt}'
SQL;
            //print_r($sql3);exit;
            $result3 = mysql_query($sql3, $dbh);
            $stated_intention_id = mysql_insert_id($dbh);
            // ADD DEFAULT option tO DATABASE
            $character_id = $characters[$i]->get_id();
            $option_name = $parent_option->get_name();
            $sql4 = <<<SQL
INSERT INTO
\toedipus_options
SET
\tname = '{$option_name}',
\tcharacter_id = {$character_id},
\tstated_intention_id = {$stated_intention_id},
\tadded = NOW()
SQL;
            //                print_r($sql);exit;
            $result4 = mysql_query($sql4, $dbh);
            $option_id = mysql_insert_id($dbh);
            $stated_intention = new Oedipus_StatedIntention($stated_intention_id, $stated_intention_position, $stated_intention_doubt);
            $characters_option = new Oedipus_Option($option_id, $option_name, $stated_intention);
            $characters[$i]->add_option($characters_option);
            $i++;
        }
        // Create default positions
        foreach ($characters as $character) {
            foreach ($character->get_options() as $option) {
                $positions = array();
                foreach ($characters as $position_character) {
                    // ADD DEFAULT position tO DATABASE
                    $position_position = '1';
                    $position_doubt = '';
                    $option_id = $option->get_id();
                    $character_id = $position_character->get_id();
                    $sql5 = <<<SQL
INSERT INTO
\toedipus_positions
SET
\tposition = '{$position_position}',
\tdoubt = '{$position_doubt}',
\toption_id = {$option_id},
\tcharacter_id = {$character_id}
SQL;
                    //                                        print_r($sql5);exit;
                    $result5 = mysql_query($sql5, $dbh);
                    $position_id = mysql_insert_id($dbh);
                    $positions[$position_character->get_name()] = new Oedipus_Position($position_id, $position_position, $position_doubt, $position_character);
                }
                $option->add_positions($positions);
            }
        }
        $frame = new Oedipus_Frame($frame_id, $frame_name, date(), $scene_id, $characters);
        //__construct($id, $name, $added, $scene_id, $characters
        // Add Frame to Tree
        Oedipus_FrameTreeHelper::add_frame_to_tree($frame, $parent_frame_id);
        return $frame;
    }