describe ppl_newsdb ; +------------+--------------+------+-----+------------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+------------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | regdate | date | | MUL | 0000-00-00 | | | author | varchar(40) | | | | | | message | text | | | | | | active | char(1) | YES | | Y | | | published | char(1) | | | Y | | | annotation | varchar(250) | | | | | | title | varchar(250) | | | | | +------------+--------------+------+-----+------------+----------------+ 8 rows in set (0.02 sec) */ Class SiteNews { var $id; var $regdate; var $author; var $message; var $active; var $published; var $title; var $annotation; var $year; function Load($id){ global $DB; $SQL = "select *, YEAR(regdate) as year from ppl_newsdb where id='$id'"; $res = GetObject($DB,$SQL); if( $res ){ $this->id = $res["id"]; // $this->regdate = ($res["regdate"]); // _hs // echo ""; $this->regdate = FetchDate($res["regdate"]); $this->author = ($res["author"]); $this->message = ($res["message"]); $this->annotation = ($res["annotation"]); $this->title = ($res["title"]); $this->active = $res["active"]; $this->published = $res["published"]; $this->year = $res['year']; return true; }else{ $this->id = ""; $this->regdate = ""; $this->author = ""; $this->annotation = ""; $this->title = ""; $this->message = ""; $this->active = "Y"; $this->published = "N"; $this->year = ""; return false; } } // Load($id) function Create($regdate, $author, $message, $active, $published, $title, $annotation, $NEWS_LANG){ global $DB; $ds = split('-',$regdate); $ds[0] = intval($ds[0]); // day $ds[1] = intval($ds[1]); // mon $ds[2] = intval($ds[2]); // year if($ds[0]<0 || $ds[0]>31 ) $ds[0] = 1; if($ds[1]<0 || $ds[1]>12 ) $ds[1] = 1; if($ds[2]<=0 ) $ds[2] = date("Y"); if($ds[2]<99 ) $ds[2] = 2000 + $ds[2]; if($ds[2]>9999 ) $ds[2] = date("Y"); $regdate = $ds[2] . "-" . $ds[1] . "-" . $ds[0]; $Data[regdate] = trim($regdate) ? QuoteAndSlashes($regdate) : "now()" ; $Data[author] = QuoteAndSlashes($author); $Data[message] = QuoteAndSlashes($message); $Data[active] = QuoteAndSlashes($active == "Y" ? "Y" : "N" ); $Data[published] = QuoteAndSlashes($published== "Y" ? "Y" : "N" ); $Data[title] = QuoteAndSlashes($title); $Data[NEWS_LANG] = QuoteAndSlashes($NEWS_LANG); $msgID = DBInsert($DB, $Table="ppl_newsdb", $Data); $this->Load($msgID); } // Create function Update($id, $regdate, $author, $message, $active, $published, $title, $annotation){ global $DB; $ds = split('-',$regdate); $ds[0] = intval($ds[0]); // day $ds[1] = intval($ds[1]); // mon $ds[2] = intval($ds[2]); // year if($ds[0]<0 || $ds[0]>31 ) $ds[0] = 1; if($ds[1]<0 || $ds[1]>12 ) $ds[1] = 1; if($ds[2]<=0 ) $ds[2] = date("Y"); if($ds[2]<99 ) $ds[2] = 2000 + $ds[2]; if($ds[2]>9999 ) $ds[2] = date("Y"); $regdate = $ds[2] . "-" . $ds[1] . "-" . $ds[0]; $Data['regdate'] = trim($regdate) ? QuoteAndSlashes($regdate) : "now()" ; $Data['author'] = QuoteAndSlashes($author); $Data['message'] = QuoteAndSlashes($message); $Data['active'] = QuoteAndSlashes($active == "Y" ? "Y" : "N" ); $Data['published'] = QuoteAndSlashes($published== "Y" ? "Y" : "N" ); $Data['title'] = QuoteAndSlashes($title); $Data['NEWS_LANG'] = QuoteAndSlashes($NEWS_LANG); DBUpdate($DB, $Table="ppl_newsdb", $Data, $WhereClause="id=".QuoteAndSlashes($_POST['msgID']) ); $this->Load($id); } function Lock($msgID){ global $DB; $LockD['published'] = QuoteAndSlashes("N"); DBUpdate($DB, $Table="ppl_newsdb", $LockD, $WhereClause="id=".QuoteAndSlashes($_POST['msgID']) ); } function UnLock($msgID){ global $DB; $LockD['published'] = QuoteAndSlashes("Y"); DBUpdate($DB, $Table="ppl_newsdb", $LockD, $WhereClause="id=".QuoteAndSlashes($_POST['msgID']) ); } function Delete($msgID){ global $DB; $SQL = "delete from ppl_newsdb where id=".intval($msgID); $res=DBExec($DB,$SQL); } function GetNewsYears(&$YMIN, &$YMAX){ global $DB, $SLANG; $SQL = "select max(YEAR(regdate)) as YEARMAX, min(YEAR(regdate)) as YEARMIN from ppl_newsdb where (published='Y') and (NEWS_LANG='*' or NEWS_LANG=" . QuoteAndSlashes($SLANG) . ")"; // echo ""; $Data = GetObject($DB, $SQL); $YMIN = $Data['YEARMIN']; $YMAX = $Data['YEARMAX']; } function GetStartPageNewsIDs($ForYEAR="-default-"){ global $DB, $SLANG; $ForYEAR = intval($ForYEAR); $this->GetNewsYears($YMIN, $YMAX); if( $ForYEAR="-default-" || $ForYEAR <$YMIN || $ForYEAR>$YMAX ){ // $ForYEAR = $YMAX; select any year!!! $SQL = "select id from ppl_newsdb where (active='Y') and (published='Y') and (NEWS_LANG='*' or NEWS_LANG=" . QuoteAndSlashes($SLANG) . ") order by regdate desc"; }else{ $SQL = "select id from ppl_newsdb where (active='Y') and (published='Y') and (YEAR(regdate)='$ForYEAR') and (NEWS_LANG='*' or NEWS_LANG=" . QuoteAndSlashes($SLANG) . ") order by regdate desc"; } // echo ""; return GetArray($DB,$SQL); } function GetAllNewsIDS($ForYEAR=""){ global $DB, $SLANG; $ForYEAR = intval($ForYEAR); $this->GetNewsYears($YMIN, $YMAX); if( $ForYEAR <$YMIN || $ForYEAR>$YMAX ){ $ForYEAR = $YMAX; } $SQL = "select id from ppl_newsdb where (published='Y') and (YEAR(regdate)='$ForYEAR') and (NEWS_LANG='*' or NEWS_LANG=" . QuoteAndSlashes($SLANG) . ") order by regdate desc"; return GetArray($DB,$SQL); } function GetArchiveYears(){ global $DB, $SLANG; $SQL = "select distinct YEAR(regdate) as YEAR from ppl_newsdb where (published='Y') and (NEWS_LANG='*' or NEWS_LANG=" . QuoteAndSlashes($SLANG) . ") order by YEAR desc"; return GetArray($DB,$SQL); } } ?>