Subversion-Projekte lars-tiefland.medien

Revision

Revision 102 | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?

    class Album
    {
        var $id;
        var $name;
        var $sampler;
        var $genre;
        var $pic;
        var $year;
        var $p_del;

        function __construct( $id = 0 )
        {
            global $db, $prefix;
            if ( $id )
            {
                $sql = "SELECT * FROM $prefix" . "boxes WHERE a_id=$id";
                $res = $db->query( $sql );
                $row = $res->fetchRow();
                $this->id = $id;
                $this->name = stripslashes( $row["a_name"] );
                $this->genre = $row["a_genre"];
                $this->year = $row["a_year"];
                $this->pic = stripslashes( ( $row["a_pic"] ) ? $row["a_pic"] :
                    "nopic.jpg" );
            }
            else
            {
                $this->id = 0;
                $this->name = "";
                $this->genre = -1;
                $this->pic = "";
                $this->year = 0;
            }
            return $this;
        }
        function Album( $id = 0 )
        {
            $this->__construct( $id );
        }

        function update( $a_name, $a_pic, $a_year, $a_genre = 0, $p_del = 0 )
        {
            $this->name = $a_name;
            $this->year = $a_year;
            $this->pic = $a_pic;
            $this->genre = $a_genre;
            $this->p_del = $p_del;
        }

        function save( $mode = "save" )
        {
            global $db, $prefix;
            switch ( $mode )
            {
                case "save":
                    $sql = "INSERT INTO $prefix" .
                        "boxes (a_name, a_pic, a_year, a_genre) VALUES ('$this->name', $this->sampler, '$this->pic', $this->year, $this->genre)";
                    break;
                case "update":
                    $pic_sql = "";
                    if ( $this->pic || $this->p_del )
                    {
                        $pic_sql = "a_pic='$this->pic',";
                    }
                    $sql = "UPDATE $prefix" . "boxes SET a_name='$this->name', " .
                        $pic_sql . " a_year=$this->year, a_genre=$this->genre WHERE a_id=$this->id";
                    break;
                case "del":
                    break;
            }
            return $db->query( $sql );
        }

        function Liste( $start = 0, $anz = 0 )
        {
            global $db, $prefix, $common;
            $sql = "SELECT * FROM $prefix" . "boxes";
            if ( $anz > 0 )
            {
                $res = $db->limitquery( $sql, $start, $anz );
                $id = 0;
                $ret = array( array() );
                while ( $row = $res->fetchRow() )
                {
                    $ret[$id]["link_id"] = $row["a_id"];
                    $ret[$id]["a_name"] = stripslashes( $row["a_name"] );
                    $ret[$id]["a_year"] = ( $row["a_year"] ) ? $row["a_year"] :
                        $common["unknown"];
                    $ret[$id]["a_pic"] = stripslashes( ( $row["a_pic"] ) ? $row["a_pic"] :
                        "nopic.jpg" );
                    $g = new Genre( $row["a_genre"] );
                    $ret[$id]["a_genre"] = $g->name;
                    $id++;
                }
                return $ret;
            }
            else
            {
                $res = $db->query( $sql );
                return $res->numRows();
            }
        }

        function getAlbums()
        {
            global $db, $prefix, $common;
            $sql = "SELECT * FROM $prefix" . "boxes ORDER BY a_name";
            $res = $db->query( $sql );
            $ret["-1"] = $common["please_select"];
            while ( $row = $res->fetchRow() )
            {
                $id = $row["a_id"];
                $ret[$id] = stripslashes( $row["a_name"] );
            }
            return $ret;
        }
    }

?>