Subversion-Projekte lars-tiefland.medien

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?
        Class Artist
        {
                var $id;
                var $name;
                var $fname;
                var $pic;
                var $p_del;

                function __construct($id=0)
                {
                        global $db, $prefix, $db_meld;
                        if ($id)
                        {
                                $sql="SELECT * FROM $prefix"."artist WHERE artist_id=$id";
                                $res=$db->query($sql);
                                if (DB::isError($res))
                                {
                                        $db_meld=$res->getUserInfo();
                                }
                                else
                                {
                                        $row=$res->fetchRow();
                                        $this->id=$id;
                                        $this->name=stripslashes($row["artist_name"]);
                                        $this->fname=stripslashes($row["artist_fname"]);
                                        $this->pic =($row["artist_pic"])?$row["artist_pic"]:"nopic.jpg";
                                }
                        }
                        else
                        {
                                $this->id=0;
                                $this->name="";
                                $this->fname="";
                                $this->pic="";
                        }
                        return $this;
                }
                function Artist($id=0)
                {
                        $this->__construct($id);
                }

                function update($a_name, $a_pic, $a_fname, $p_del)
                {
                        $this->name=$a_name;
                        $this->fname=$a_fname;
                        $this->pic=$a_pic;
                        $this->p_del=$p_del;
                }

                function save($mode="save")
                {
                        global $db, $prefix;
                        switch ($mode)
                        {
                                case "save":
                                        $sql="INSERT INTO $prefix"."artist (artist_name, artist_fname, artist_pic) VALUES ('$this->name', '$this->fname', '$this->pic')";
                                        break;
                                case "update":
                                        $pic_sql="";
                                        if ($this->pic || $this->p_del)
                                        {
                                                $pic_sql=", artist_pic='$this->pic'";
                                        }
                                        $sql="UPDATE $prefix"."artist SET artist_name='$this->name', artist_fname='$this->fname'".$pic_sql." WHERE artist_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"."artist";
                        if ($anz > 0)
                        {
                                $res=$db->limitquery($sql,$start,$anz);
                                $id=0;
                                $ret=array(array());
                                while ($row=$res->fetchRow())
                                {
                                        $ret[$id]["link_id"]=$row["artist_id"];
                                        $ret[$id]["a_name"]=($row["artist_id"]==1)?$common["various"]:stripslashes($row["artist_name"]);
                                        $ret[$id]["a_fname"]=stripslashes($row["artist_fname"]);
                                        $ret[$id]["a_pic"] =stripslashes(($row["artist_pic"])?$row["artist_pic"]:"nopic.jpg");
                                        $id++;
                                }
                                return $ret;
                        }
                        else
                        {
                                $res=$db->query($sql);
                                return $res->numRows();
                        }
                }

                function getArtists()
                {
                        global $db, $prefix, $common;
                        $sql="SELECT * FROM $prefix"."artist ORDER BY artist_name";
                        $res=$db->query($sql);
                        $ret["-1"]=$common["please_select"];
                        while ($row=$res->fetchRow())
                        {
                                $artist_id=$row["artist_id"];
                                $artist=new Artist($artist_id);
                                $ret[$artist_id]=stripslashes("$artist->fname $artist->name");
                        }
                        $ret["1"]=$common["various"];
                        return $ret;
                }
        }
?>