<?php
#####################################
# ShopCMS: Скрипт интернет-магазина
# Copyright © by ADGroup
#
http://shopcms.ru
#####################################
// *****************************************************************************
// Purpose gets all discussion
// Inputs $navigatorParams - item
// "offset" - count row from begin to place being shown
// "CountRowOnPage" - count row on page to show on page
// Remarks
// Returns
// returns array of discussion
// $count_row is set to count(discussion)
function discGetAllAnswer( $callBackParam, &$count_row, $navigatorParams = null )
{
$data = array();
$orderClause = "";
if ( isset($callBackParam["sort"]) )
{
$orderClause = " order by ".xEscSQL($callBackParam["sort"]);
if ( isset($callBackParam["direction"]) )
{
if ( $callBackParam["direction"] == "ASC" )
$orderClause .= " ASC ";
else
$orderClause .= " DESC ";
}
}
if (!strlen($orderClause)) $orderClause = " order by date desc";
$q = db_query("select answerID, name, text, date, parent, moder from ".
ANSWER_TABLE." where parent=0 ".$orderClause );
if ( $navigatorParams != null )
{
$offset = $navigatorParams["offset"];
$CountRowOnPage = $navigatorParams["CountRowOnPage"];
}
else
{
$offset = 0;
$CountRowOnPage = 0;
}
$i=0;
while( $row = db_fetch_row($q) )
{
if ( ($i >= $offset && $i < $offset + $CountRowOnPage) ||
$navigatorParams == null )
{
$row["date"] = date("d.m.Y", $row["date"] );
$w = db_query("select count(answerID) as count from ".ANSWER_TABLE." where parent=".$row['answerID']." order by answerID");
if ($w !== false)
{
while ($r = db_fetch_row($w))
{
$row['count'] = $r['count'];
}
}
$w = db_query("select count(moder) as count_moder from ".ANSWER_TABLE." where parent=".$row['answerID']." and moder=0 order by answerID");
if ($w !== false)
{
while ($r = db_fetch_row($w))
{
$row['count_moder'] = $r['count_moder'];
}
}
$data[] = $row;
}
$i ++;
}
$count_row = $i;
return $data;
}
function discGetAllAnswerUser( $from = 0, $per_page=15 )
{
$data = array();
$q = db_query("select answerID, name, text, date, parent, moder from ".
ANSWER_TABLE." where moder=1 and parent=0 order by answerID desc limit ".$from.",".$per_page );
$i=0;
while( $row = db_fetch_row($q) )
{
if ( ($i >= $offset && $i < $offset + $CountRowOnPage) ||
$navigatorParams == null )
{
$row["date"] = date("d.m.Y", $row["date"] );
$w = db_query("select count(answerID) as count from ".ANSWER_TABLE." where parent=".$row['answerID']." and moder=1 order by answerID" );
if ($w !== false)
{
while ($r = db_fetch_row($w))
{
$row['count'] = $r['count'];
}
}
$data[] = $row;
}
$i ++;
}
$count_row = $i;
return $data;
}
function discGetAnswer( $answerID)
{
$q = db_query("select answerID, text, date, name, parent, moder from ".
ANSWER_TABLE.
" where answerID=".(int)$answerID);
if ($row = db_fetch_row( $q )){
$row["date"] = date("d.m.Y", $row["date"] );
return $row;
}
return false;
}
function discGetAnswerUser( $answerID)
{
$q = db_query("select answerID, text, date, name, parent, moder from ".
ANSWER_TABLE.
" where answerID=".(int)$answerID);
if ($row = db_fetch_row( $q )){
if ($row['moder'] == 0) return false;
$row["date"] = date("d.m.Y", $row["date"] );
return $row;
}
return false;
}
function discGetAllAnswers( $answerID)
{
$q = db_query("select answerID, text, date, name, email, parent, moder from ".
ANSWER_TABLE.
" where parent=".(int)$answerID);
$res = array();
while ($row = db_fetch_row( $q ))
{$row["date"] = date("d.m.Y", $row["date"] );
$res[] = $row;
}
return $res;
}
function discGetAllAnswersUser( $answerID)
{
$q = db_query("select answerID, text, date, name, email, parent, moder from ".
ANSWER_TABLE.
" where moder=1 and parent=".(int)$answerID);
$res = array();
while ($row = db_fetch_row( $q ))
{$row["date"] = date("d.m.Y", $row["date"] );
$res[] = $row;
}
return $res;
}
function discAddAnswer( $answerID, $name, $text, $email="", $moder=1)
{
if (!strlen($name) || !strlen($text)) return false;
db_query("insert into ".ANSWER_TABLE.
"(parent, name, text,email, date, moder) ".
"values( ".(int)$answerID.", '".xToText($name)."', '".xToText($text)."','".xToText($email)."', ".date("U").",".$moder.")");
}
function discEditAnswerDonello( $answerID, $answer )
{
if( strlen(trim($answer)) > 5 ) db_query("UPDATE ".ANSWER_TABLE." SET text='".xToText($answer)."' WHERE answerID=".(int)$answerID." ");
}
function discDeleteAnswer( $DID )
{
db_query( "delete from ".ANSWER_TABLE." where answerID=".(int)$DID );
db_query( "delete from ".ANSWER_TABLE." where parent=".(int)$DID );
}
function discModerAnswer( $DID )
{
db_query( "update ".ANSWER_TABLE." set moder=1 where answerID=".(int)$DID );
}
?>