Документ взят из кэша поисковой машины. Адрес оригинального документа : http://genphys.phys.msu.su/mikromag/script/phorum.php3
Дата изменения: Mon Nov 1 03:19:53 2010
Дата индексирования: Mon Oct 1 22:10:58 2012
Кодировка: Windows-1251

require("./auth.php3");

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
//header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
//header("Cache-Control: no-cache, must-revalidate");
//header("Pragma: no-cache");
error_reporting(15);
//////////////////
// за работу форумов
//

define("DBName","mikromag");
define("HostName","localhost");
define("UserName","counter");
define("Password","counter");

if(!mysql_connect(HostName,UserName,Password))
{ echo "Ошибка! Не могу соединиться с базой ".DBName."!
"; exit; }


//******************
//* combines the two above functions for ease of use
//* in some circumstances
function pDateTime($unixtime)
{ $year= substr($unixtime,0,4);
$month=substr($unixtime,4,2);
$day=substr($unixtime,6,2);
$hour=substr($unixtime,8,2);
$min=substr($unixtime,10,2);
$sec=substr($unixtime,12,2);

$res=$day."-".$month."-".$year." ".$hour.":".$min.":".$sec;
return $res;
}

//**************
//* make some changes for all element of array
//* if some element of aray is array1 - make the same changes for all elements of array1
function obrMas($mas)
{
for(@reset($mas);
@$key=key($mas);
next($mas))
{
$elem = $mas[$key];
if (is_array($elem)==true)
{
obrMas($elem);
}
else
{
$t = addslashes($mas[$key]);
$t=strip_tags($t);
//$this=htmlspecialchars($this);
$t=trim($t);
$mas[$key] = $t;
}
}
}

@obrMas($HTTP_GET_VARS);
@obrMas($HTTP_POST_VARS);

//*****************************
// return 0 - error !=0 OK
function ftake_id_on_login($login,$password)
{
$s="select * from treg where login='$login' and password='$password'";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

if (mysql_num_rows($res)!=1)
{
return 0;
}

$ff=mysql_fetch_array($res);
return $ff['id'];

}


//*************
//* main class -
class cl_phorum
{
var $login,$password,$treg_id,$action,$tem_id,$tsb_id;

//***************
//** return top of the page
function top()
{
?>




Микромаг - сервер




require("../include/top.htm");
} // top

//******************
//**return bottom of the page
function bottom()
{
?>


if (!empty($this->tsb_id))
{
echo "

Ответ на:\"$this->tek_soob_tema\"

";
}
else
{
echo "

Новое сообщение

";
}//if

?>

Тема:  


Текст сообщения






treg_id;?>>
tem_id; ?>>
tsb_id)) {echo $this->tsb_id;} else {echo "0";}?>>


}//buttom

/////////////////////////////////////

function soob()
{
$this->top();
echo "Список форумов";
echo "
tem_id\">
Новое сообщение
";
echo "
tem_id\">";
$this->tema(); echo "
";

$this->soob_koncret();
$this->spisok_soob($this->ftop_id($this->tsb_id));
$this->otvet();
$this->bottom();


}//soob

//////////////////////////

//##########
//# сохранение нового сообщения
function new_soob_sohr()
{
$s="insert into tsb (tsb_nazv, tsb_text, tsb_parent_id,tema_id,treg_id)
values('$GLOBALS[tsb_nazv]','$GLOBALS[tsb_text]',$GLOBALS[tsb_parent_id],$GLOBALS[tem_id],$GLOBALS[treg_id])";
echo $s;
$res=mysql(DBName,$s);
if (mysql_errno()<>0)
{
echo mysql_errno().": ".mysql_error()."
Ошибка записи!"; exit;
}
else
{
?>


Content="1; URL=http://genphys.phys.msu.su?action=soob&tem_id=tem_id;?>&tsb_id=">




}//if
} // new_soob_sohr

//*****************
//** list of all phorums
function spisok_phorum()
{
$this->top();

echo "

Список форумов на сервере Микромаг

";

$s="select * from tema order by tem_nazv";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

echo "
    ";
    while($ff=mysql_fetch_array($res))
    {
    echo "
  1. $ff[tem_nazv]";
    echo " Сообщений:".$this->count_under($ff['tem_id'],0);
    }
    echo "
";

echo "Новый форум может добавить только администратор сервера";

$this->bottom();
} //spisok_phoru


//**********************
//** подсчет числа сообщений под данным сообщением
function count_under($tema_id,$id)
{
$s="select count(tsb_id) as number from tsb where tem_id=$tema_id and tsb_parent_id=$id";
// echo "$s
";

$res1=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

$ff=mysql_fetch_array($res1);
$fres=$ff['number'];
// echo $fres;

if ($fres>0)
{
$s="select id from tsb where tem_id=$tema_id and tsb_parent_id=$id";
// echo "$s
";

$res1=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

while ($ff=mysql_fetch_array($res1))
{
$fres+=$this->count_under($tema_id,$ff['id']);
}
}

return $fres;

}// count_under


//*******************************
//** id верхнего сообщения для данного сообщения ($id)
function ftop_id($id)
{
$s="select * from tsb where id=$id";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

$ff=mysql_fetch_array($res);
if ($ff['tsb_parent_id']==0)
{
return $id;
}
else
{
return $this->ftop_id($ff['tsb_parent_id']);
}
}//ftop_id

//***********************************
//** all about 1 phorum
function phorum()
{
$this->top();
echo "Список форумов";
$this->tema();
$this->spisok_soob_krat();
$this->otvet();
$this->bottom();
} // phorum

//******************************
//** main topic of phorum
function tema()
{
$s="select * from tema where id=$this->tem_id";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

$ff=mysql_fetch_array($res);

echo "

".$ff['value']."

";

} // tema

//****************************
//** short list of all messages in one phorum
function spisok_soob_krat()
{
$s="select * from tsb where tema_id=".$this->tem_id." and tsb_parent_id=0 order by data";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

echo "";
} // spisok_soob_krat()

//***************************************************
//** list of all messages under message with this id
function spisok_soob_under($tsb_id)
{
$s="select * from tsb where tsb_parent_id=$tsb_id";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}
if (mysql_num_rows($res)>0)
{
echo "";
}
} //spisok_soob_under


//********************************
//** list of all messages
function spisok_soob($tsb_id)
{
$s="select * from tsb where id=$tsb_id";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

echo "";
} // spisok_soob()

//*********************
//** message
function soob_koncret()
{
echo "
";
$s="select tsb_nazv,soob,data,f,i,o from tsb,treg where tsb.treg_id=treg.id and tsb.id=$this->tsb_id";
// echo "$s
";

$res=mysql(DBName,$s);
if (mysql_errno()<>0) {echo mysql_errno().": ".mysql_error()."
Ошибка
чтения!"; exit;}

$ff=mysql_fetch_array($res);

$fio=$ff['f']." ".chr(ord($ff['i'])).".".chr(ord($ff['o'])).".";
$str_data="".pDateTime($ff['data'])."";
echo "


 $ff[tsb_nazv]  Автор: $fio от: $str_data
 $ff[soob]

";
}// soob_koncre


//***********************************
//** выводит форму для добавления сообщения
function otvet()
{
?>






} //otvet


////////////////////////
function main()
{

switch (@$this->action)
{
case 'spisok_phorum':
$this->spisok_phorum(); // список всех формумов
break;
case 'phorum':
$this->phorum(); // отдельный форум на просмотр
break;
case 'spisok_soob_krat':
$this->spisok_soob_krat(); //список сообщений отельного форума - только верхние сообщения
break;
case 'spisok_soob_poln':
$this->spisok_soob_poln(); //список сообщений отельного форума - все сообщения
break;
case 'spisok_sub_soob':
$this->spisok_sub_soob(); //список сообщений под отдельным сообщением
break;
case 'soob':
$this->soob(); //отдельное сообщение с формой для ответа
break;
case 'new_soob_form':
$this->new_soob_form(); //новое сообщение в форум - форма для ввода
break;
case 'new_soob_sohr':
$this->new_soob_sohr(); //новое сообщение в форум - сохранение
break;

default:
$this->spisok_phorum();
//$this->count_under(0,0);
break;
}//case switch
}//main


function constr()
{

@$this->action=$GLOBALS['action'];
@$this->login=$GLOBALS['PHP_AUTH_USER'];
@$this->password=$GLOBALS['PHP_AUTH_PW'];
// @$this->treg_id=f_take_id_on_login($this->login,$this->password);

// if ($this->treg_id==0) { echo "wrong login or password!";exit;}

@$this->tem_id=$GLOBALS['tem_id'];
@$this->tsb_id=$GLOBALS['tsb_id'];

if (!empty($this->tsb_id))
{
$s="select * from tsb where tsb_id=$this->tsb_id";
$res=mysql(DBName,$s);

if (mysql_errno()<>0) {
echo mysql_errno().": ".mysql_error()."
Ошибка чтения!"; exit;
} //if

$ff=mysql_fetch_array($res);
$this->tek_soob_tema=$ff['tsb_nazv'];
}
@$this->new_tema=$GLOBALS['new_tema'];
@$this->new_soob=$GLOBALS['new_soob'];
} // end constructor
}

$p=new cl_phorum;
$p->constr();
$p->main();

?>