<?
/*
/*****************************************
* *
* Индустриални информационни системи *
* *
* Пример за търсене, обработка и печат *
* на данни от mssql таблица *
* Преподавател: Алдениз Рашидов *
* *
*****************************************/
/*
Неободимо е да са създадени две таблици "USERS_TYPES" и "USERS_temp" в БД "EXP" :
CREATE TABLE USERS_TYPES (USERTYPE int PRIMARY KEY NOT NULL, USERTYPENAME varchar (50) NULL)
CREATE TABLE USERS_temp (login varchar (20) PRIMARY KEY NOT NULL, password varchar (20) NULL ,usertype int NULL)
*/
@MSSQL_CONNECT("MSSQLSERVER","potrebitel","parola");
@mssql_select_db("EXP");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Content-Type" Content="text/html; charset=windows-1251">
<meta http-equiv="content-language" content="bg">
<meta name="author" content="Aldeniz Rashidov">
<title>Упражнение</title>
<STYLE>
.TED31 {BORDER-left:inset black 0.5pt; border-top:inset 0pt; BORDER-bottom:inset black 0.5pt; BORDER-right:inset black 0pt; }
BODY {
margin-bottom : 0px;margin-left : 0px;margin-right : 0px;margin-top : 22px; marginheight : 0px; marginwidth: 0px;
<? if ($prints==0) { ?>
background: #E1E1E1;bgcolor: #E1E1E1;
<? } else { ?>
background: #FFFFFF;bgcolor: #FFFFFF;
<? } ?>
}
Font { font: 10px Arial,Verdana, sans-serif;}
TD {font: 11px Arial, sans-serif;}
th {
font-size: 11px;font-weight:normal; height: 25px;
<? if ($prints==0) { ?>
background-color:#c0c0e0;
<? } else { ?>
background-color:#FFFFFF;
<? } ?>
}
.forumline {border: 2px #006699 solid; background-color: #FFFFFF;}
<? if ($prints==0) { ?>
td.row1 {background-color: #EFEFEF; }
td.row2 {background-color:#DEE3E7; }
td.row3 {background-color:#FE7f7f; }
<? } ?>
.button{
font: 11px Arial;
color: #000000;
text-decoration: none;
border: 1px solid;
background: #FFFFFF;
text-transform: none;
}
.INP1{
text-decoration: none;
border: 1px #006699 solid;
background: #FFFFFF;
font-size:11px;
height: 20px;
};
a { text-decoration: none; }
a:hover { color: white; };
.fontas {font-size: 12px; color: brown;}
.fontas1 {
font-size: 12px;
<? if ($prints==0) { ?>
color: white;
<? } else { ?>
color: brown;
<? } ?>
}
.fixing{
font-size: 10px;
width:16px; height:15px;
text-align: center;
border: 1px solid #8cD7ff;
margin: 2px;
background-color:#efffef;
cursor: hand;
}
</STYLE>
<SCRIPT TYPE ="text/javascript" LANGUAGE="JavaScript">
function Flag(q) { b='a['+q+']'; document.logined.elements[b].value=1; }
function Proverka()
{
b='login[0]';if(document.logined.elements[b].value=="") { alert("Моля въведете име!"); return false; }
b='password[0]';if(document.logined.elements[b].value=="") { alert("Моля въведете парола!"); return false; }
b='tip[0]';if(document.logined.elements[b].value=="") { alert("Моля въведете вид потребител!"); return false; }
return true;
}
function Go(f) { document.logined.flag.value=f; document.logined.submit(); }
function Goto(f) {if (f<0) f=0; document.logined.Start.value=f; document.logined.submit(); }
function Gotos(f) {
document.logined.flag.value=0;
if (document.logined.orders_old.value==document.logined.orders.value) document.logined.orders_old.value=-1;
else document.logined.orders_old.value=document.logined.orders.value;
document.logined.orders.value=f; document.logined.submit();
}
function Search(f) {document.logined.flag.value=4; document.logined.orders.value=f; document.logined.submit();}
function Edit() {if (document.logined.edit.value==1) document.logined.edit.value=0; else document.logined.edit.value=1; document.logined.submit(); }
function Pr() {document.logined.prints.value=1; document.logined.target="_blank"; document.logined.submit(); document.logined.target="_self"; document.logined.prints.value=0; }
</SCRIPT>
</head>
<?
$status="";
if ($flag==1) {
$query="insert into LOGIN..USERS_temp values ('$login[0]','$password[0]',$tip[0])";
$Start=0; if ($orders==0) $Start=ceil(($redove/$ITEMS));
$result=@mssql_query($query); if ($result==0) $status="добавяне";
}
if ($flag==2) {
for($m=1;$m<=$redove;$m++)
if($a[$m]==1) {
$query="update LOGIN..USERS_temp set password='$password[$m]', usertype='$tip[$m]' where login='$login[$m]'";
$result=@mssql_query($query); if ($result==0) $status="подновяване";
}
}
if ($flag==3) {
for($m=1;$m<=$redove;$m++)
if($dels[$m]==1) {
$query="delete LOGIN..USERS_temp where login='$login[$m]' ";
if ($redove<=$Start*$ITEMS) $Start--;
$result=@mssql_query($query); if ($result==0) $status="изтриване";
}
}
// =============================== zaiavki
$query1 = "select usertype,usertypename from login..users_types order by 2";
$result1 = @MSSQL_QUERY($query1);
if ($orders_old==$orders) $asc="desc"; else $asc="asc";
$ord=""; if ($orders<>0) $ord=" ORDER BY $orders $asc";
$query="SELECT login,password,login..users_temp.usertype,usertypename from login..users_temp,login..users_types where login..users_types.usertype=login..users_temp.usertype $ord";
$result=@mssql_query($query);
$numrows=@mssql_num_rows($result);
$Max=9; //max broi na stranicite
$ITEMS=4; // broi vizualizirani itemsi
$search=-1;
if ($flag==1) {
$y=0; while ($y<$numrows) { if (@mssql_result($result,$y,0)==$login[0]) break; $y++; }
$Start=floor($y/$ITEMS); $search=$y;
}
if ($flag==4) {
$search=-1; $y=0;
while ($y<$numrows) {
$yy=0;
if (($orders==1) and preg_match("/$login[0]/i", @mssql_result($result,$y,0))) break;
if (($orders==2) and preg_match("/$password[0]/i", @mssql_result($result,$y,1))) break;
if (($orders==4) and preg_match("/$tip[0]/i", @mssql_result($result,$y,2))) break;
$y++; $yy=1;
}
if ($yy==0) { $Start=floor($y/$ITEMS); $search=$y; }
}
$flag=0;
$updown=' solid brown;border-left: 4px solid #c0c0e0;border-right: 4px solid #c0c0e0;font-size: 0px; line-height: 0%; width: 0px;"></span>';
$lefright='8px solid black; margin-bottom:0px; border-bottom: 4px solid #efffef;border-top: 4px solid #efffef;font-size: 0px; line-height: 0%; width: 0px;"></span>';
$up='<span style="border-top: 8px '.$updown; $down='<span style="border-bottom: 8px '.$updown;;
$left='<span style=" margin-left:2px; border-left:'.$lefright; $right='<span style=" margin-right:2px; border-right:'.$lefright;
echo "<body ><form target='_self' action='".basename($_SERVER['REQUEST_URI'])."' name='logined' METHOD=POST>";
echo "<input type='hidden' name='Start' value=$Start>";
echo "<input type='hidden' name='PHPSESSID' value=$PHPSESSID>";
echo "<input type='hidden' name='koef' value=$koef>";
echo "<input type='hidden' name='orders' value=$orders>";
echo "<input type='hidden' name='orders_old' value=$orders_old>";
echo "<input type='hidden' name='redove' value=$numrows>";
echo "<input type='hidden' name='flag' value='0'> ";
echo "<input type='hidden' name='edit' value='$edit'> ";
echo "<input type='hidden' name='prints' value='$prints'> ";
echo "<center><b><font style='font-weight:bold;font-size:10pt;'>Пример за търсене, обработка и печат на данни от таблица</font></b></center><br>";
echo "<div id=red1 align='center'>";
if ($status!="") echo "Възникнала е грешка при ".$status."<br>";
if ($prints==1) $cl="ted31"; else $cl=""; //class za td i th
echo "<table border=0 rules=none>";
//========================================================== =
$br=$Start*$ITEMS; if ($br>=$numrows) { $Start--; $br=$Start*$ITEMS; }
if ($Start<0) {$Start=0; $br=0;}
$Total=round($numrows/$ITEMS); if (($numrows/$ITEMS!=round($numrows/$ITEMS)) && ($numrows/$ITEMS>round($numrows/$ITEMS)) ) $Total++;
$Half = Round($Max/2); $Begin = ($Start+1) - $Half;$End = ($Start+1) + $Half;
if ($Begin <= 1) { $End = $End - $Begin + 1; $Begin = 1; }
if ($End >= $Total) {$Begin = $Begin - ($End - $Total); If ($Begin < 1) $Begin = 1; $End = $Total; }
$Begin--; $End--;
if ($prints==0) {
echo "<tr>";
if ($edit==0) $editor="Редакция"; else $editor="Преглед";
echo "<td align='left'><input type='button' class='button' style='height: 20px; width: 60px;' value='$editor' Onclick='javascript: Edit($edit);'></td>";
echo "<td align='center' nowrap>";
echo "<a href='javascript: Goto(".($Start-1).")'><span class='fixing'> $right</span></a>";
for ($i=$Begin;$i<=$End;$i++) {
if ($i==$Start) $color="red"; else $color="";
echo "<a href='javascript: Goto(".($i).")'><span style='color:$color' class='fixing'>".($i+1)."</span></a>";
}
echo "<a href='javascript: Goto(".($Start+1).")'><span class='fixing'>$left </span></a>";
echo "</td>";
echo "<td align='right'><input type='button' class='button' style='height: 20px; width: 60px;' value='Печат' Onclick='javascript: Pr();'></td>";
echo "</tr>";
}
//==========================================================
echo "<tr><td colspan=3>";
//======
//echo '<table border="1" width="100%" class="style2" cellspacing="0" cellpadding="0" bordercolor="#000000" bordercolorlight="#ffffff" align=center>';
if ($prints==1) echo '<table style="BORDER-right:inset 0.5pt;BORDER-top:inset 1pt;" cellpadding="5" cellspacing="0" bordercolor="#000000" align="center">'; else
echo "<table cellpadding=3 cellspacing=1 align='center' class='forumline'>";
//========================================================== titulen red
echo "<tr>";
echo "<th class=$cl align='center' nowrap >#</font></th>";
if ($orders_old==$orders) $znak0=$down; else $znak0=$up; if ($prints==1) $znak0="";
if ($orders==1) {$znak=$znak0; $stil="fontas1";} else { $znak=""; $stil="fontas"; }
echo "<th class=$cl align='center' nowrap ><a class='$stil' href='javascript:Gotos(1)'>Име</a> $znak</th>";
if ($orders==2) {$znak=$znak0; $stil="fontas1";} else { $znak=""; $stil="fontas"; }
echo "<th class=$cl align='center' nowrap ><a class='$stil' href='javascript:Gotos(2)'>Парола</a> $znak</th>";
if ($orders==4) {$znak=$znak0; $stil="fontas1";} else { $znak=""; $stil="fontas"; }
echo "<th class=$cl align='center' nowrap ><a class='$stil' href='javascript:Gotos(4)'>Вид</a> $znak</th>";
if ($edit==1 and $prints==0)echo "<th align='center' nowrap ><input type='button' class='button' style='height: 20px; width: 60px;' value='Изтрий' Onclick='javascript: Go(3);'></th>";
echo "</tr>";
//======
$u=1; $nomer=$br+1; $ii=0; @mssql_data_seek($result,$br);
while ($br<=$numrows) {
$ii++; if ($ii>$ITEMS) $br=$numrows;
if ($br==$numrows and $prints==1) break;
if ($br==$numrows) {
$u=0; // novi danni
if ($numrows!=0) {
echo "<tr>";
echo "<th class='row1' align='center' > </th>";
echo "<th class='row1' align='center' ><a href='javascript:Search(1)'><img src='lupa.gif' border=0></a></th>";
echo "<th class='row1' align='center' ><a href='javascript:Search(2)'><img src='lupa.gif' border=0></a></th>";
echo "<th class='row1' align='center' ><a href='javascript:Search(4)'><img src='lupa.gif' border=0></a></th>";
if ($edit==1 and $prints==0) echo "<th class='row1' ><input type='button' style='height: 20px; width: 60px' class='button' value='Поднови' Onclick='javascript: Go(2);'></th>";
echo "</tr>";
}
unset($row);
} else $row=@mssql_fetch_row($result);
if ($search!=-1 and $br==$search) $class="row3"; else $class="row2"; if ($prints==1) $class= $cl ;
echo "<tr>";
if ($br==$numrows) echo "<td class='$class' align='right'> "; else echo "<td class='$class' align='right'>".$nomer++.".";
echo "<input type='hidden' name='a[$u]' value='0'>";
echo "</td>";
// =============================== login
echo "<td class='$class' align='right'>";
if ($br==$numrows) echo "<input class='INP1' type='text' style='height: 19px; font-size: 10px; width: 60px' name='login[$u]' value='$row[0]' OnChange='javascript: Flag($u);'>";
else echo "<input type='hidden' style='width:40px' name='login[$u]' value='$row[0]'>$row[0]</td>";
// =============================== parola
echo "<td class='$class' align='right'>";
if (($edit==0 and $br!=$numrows) or ($prints==1)) echo $row[1]; else echo "<input class='INP1' type='password' style='height: 19px; font-size: 10px; width: 60px' name='password[$u]' value='$row[1]' OnChange='javascript: Flag($u);'>";
echo "</td>";
// =============================== tip
echo "<td class='$class' align='left'>";
if (($edit==0 and $br!=$numrows) or ($prints==1)) echo $row[3]; else {
echo "<SELECT class='INP1' NAME = 'tip[$u]' class='INP1' style='width:400px' OnChange='javascript: Flag($u);'>";
@mssql_data_seek($result1,0);
if ($br==$numrows) echo "<option selected value=''></option>";
while (list($a,$b) = mssql_fetch_row($result1)) {
if ($row[2]==$a) $sel='selected'; else $sel='';
echo "<option $sel value='$a'>$b</option>";
}
echo "</select>";
}
echo "</td>";
// ===============================
if ($edit==1 and $prints==0) {
if ($br==$numrows) echo "<td class='$class' align='center'><input style='height: 20px; width: 60px' class='button' type='button' value='Добави' Onclick='javascript: if (Proverka()) Go(1);'></td>";
else echo "<td class='$class' align='center'><input type='checkbox' name='dels[$u]' value=1></td>";
}
echo "</tr>";
$u++; $br++;
}
echo "</table>";
echo "</td></tr></table>";
echo "</div>";
echo " </form></body>";
?>
</html>