public function is_user_id_allowed_to_view_drama($user_id, Oedipus_Drama $drama)
    {
        $user = NULL;
        $drama_id = $drama->get_id();
        if (InputValidation_NumberValidator::validate_database_id($user_id)) {
            $dbh = DB::m();
            $user_id = mysql_real_escape_string($user_id, $dbh);
            $query = <<<SQL
SELECT
\tcount(user_id) AS count
FROM
\toedipus_users_allowed_to_view_drama_links
WHERE
\toedipus_users_allowed_to_view_drama_links.user_id = {$user_id}
\tAND
\toedipus_users_allowed_to_view_drama_links.drama_id = {$drama_id}
SQL;
            $result = mysql_query($query, $dbh);
            if ($row = mysql_fetch_assoc($result)) {
                if ($row['count'] == 1) {
                    return TRUE;
                }
                return FALSE;
            }
        }
    }
 private function get_drama_tr(Oedipus_Drama $drama)
 {
     $tr = new HTMLTags_TR();
     //$tr->set_attribute_str('id', 'drama');
     $link = new HTMLTags_A($drama->get_name());
     $link->set_href($this->get_drama_page_url_for_drama($drama));
     $name_td = $this->get_td_with_id($link->get_as_string(), 'name');
     $tr->append($name_td);
     $added_td = $this->get_td_with_id($drama->get_human_readable_added(), 'added');
     $tr->append($added_td);
     return $tr;
 }
 public static function get_view_page_url(Oedipus_Drama $drama = NULL)
 {
     if (isset($drama)) {
         #			$url = new HTMLTags_URL();
         #			$url->set_file('/dramas/'. $drama->get_unique_name());
         #//                        $url->set_get_variable('oo-page', 1);
         #//                        $url->set_get_variable('page-class', 'Oedipus_DramaEditorPage');
         #
         #//                        $url->set_get_variable('drama_unique_name', );
         return PublicHTML_URLHelper::get_oo_page_url('Oedipus_DramaPage', array('drama_id' => $drama->get_id()));
         return $url;
     } else {
         return PublicHTML_URLHelper::get_oo_page_url('Oedipus_DramaPage');
     }
 }
    public function get_drama_by_id($drama_id)
    {
        $dbh = DB::m();
        $query = <<<SQL
SELECT 
\t*
\tFROM
\t\toedipus_dramas
\tWHERE
\t\tid = {$drama_id}
SQL;
        //                                print_r($query);exit;
        $result = mysql_query($query, $dbh);
        $row = mysql_fetch_array($result);
        if ($row == FALSE) {
            throw new Oedipus_DramaNotFoundException('ID ' . $drama_id);
        }
        //                                print_r($row);exit;
        $drama = new Oedipus_Drama($row['id'], $row['name'], $row['unique_name'], $row['added'], $row['status']);
        // Add the acts to this Drama
        // Get all acts for this drama
        $acts_query = <<<SQL
SELECT 
\t*
\tFROM
\t\toedipus_acts
\tWHERE
\t\tdrama_id = {$drama_id}
SQL;
        //                                print_r($acts_query);exit;
        $acts_result = mysql_query($acts_query, $dbh);
        // Add the acts to the drama object
        //
        if ($acts_result) {
            while ($act_result = mysql_fetch_array($acts_result)) {
                $act_id = $act_result['id'];
                $act = self::get_act_by_id($act_id);
                $drama->add_act($act);
            }
        }
        //                                print_r($drama);exit;
        return $drama;
    }
 public static function get_mod_rewrite_drama_page_url(Oedipus_Drama $drama = NULL)
 {
     if (isset($drama)) {
         $url = new HTMLTags_URL();
         $url->set_file('/dramas/' . $drama->get_unique_name());
         return $url;
     } else {
         return self::get_drama_page_url();
     }
 }
    public function add_table(Oedipus_Drama $drama, $table_name)
    {
        // ADD TABLE TO DATABASE
        $drama_id = $drama->get_id();
        $dbh = DB::m();
        $sql = <<<SQL
INSERT INTO
\toedipus_tables
SET
\tname = '{$table_name}',
\tdrama_id = {$drama_id},
\tadded = NOW()
SQL;
        //                print_r($sql);exit;
        $result = mysql_query($sql, $dbh);
        $table_id = mysql_insert_id($dbh);
        // ADD DEFAULT ACTOR tO DATABASE
        $actor_name = 'First Actor';
        $actor_color = 'red';
        $sql2 = <<<SQL
INSERT INTO
\toedipus_actors
SET
\tname = '{$actor_name}',
\tcolor = '{$actor_color}',
\ttable_id = {$table_id},
\tadded = NOW()
SQL;
        //                print_r($sql);exit;
        $result2 = mysql_query($sql2, $dbh);
        $actor_id = mysql_insert_id($dbh);
        $actor = new Oedipus_Actor($actor_id, $actor_name, $actor_color);
        $actors = array();
        $actors[] = $actor;
        foreach ($actors as $actor) {
            // ADD DEFAULT stated_intention tO DATABASE
            $stated_intention_position = '1';
            $stated_intention_doubt = '';
            $sql3 = <<<SQL
INSERT INTO
\toedipus_stated_intentions
SET
\tposition = '{$stated_intention_position}',
\tdoubt = '{$stated_intention_doubt}'
SQL;
            //                print_r($sql);exit;
            $result3 = mysql_query($sql3, $dbh);
            $stated_intention_id = mysql_insert_id($dbh);
            // ADD DEFAULT option tO DATABASE
            $option_name = 'First Option';
            $sql4 = <<<SQL
INSERT INTO
\toedipus_options
SET
\tname = '{$option_name}',
\tactor_id = {$actor_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);
            $actors_option = new Oedipus_Option($option_id, $option_name, $stated_intention);
            $actor->add_option($actors_option);
        }
        // Create default positions
        foreach ($actors as $actor) {
            foreach ($actor->get_options() as $option) {
                $positions = array();
                foreach ($actors as $position_actor) {
                    // ADD DEFAULT position tO DATABASE
                    $position_position = '1';
                    $position_doubt = '';
                    $option_id = $option->get_id();
                    $actor_id = $position_actor->get_id();
                    $sql5 = <<<SQL
INSERT INTO
\toedipus_positions
SET
\tposition = '{$position_position}',
\tdoubt = '{$position_doubt}',
\toption_id = {$option_id},
\tactor_id = {$actor_id}
SQL;
                    //                                                        print_r($sql5);exit;
                    $result5 = mysql_query($sql5, $dbh);
                    $position_id = mysql_insert_id($dbh);
                    $positions[$position_actor->get_name()] = new Oedipus_Position($position_id, $position_position, $position_doubt, $position_actor);
                }
                $option->add_positions($positions);
            }
        }
        $table = new Oedipus_Table($table_id, $drama_id, $table_name, $actors);
        //                print_r($table);exit;
        //
        // Update Drama Object with new Table
        //                $drama->add_table($table);
        return $table;
    }