<?
if($action=="Preview") {
//echo $action;
require"./upload_csv.php";
exit;
}
session_name("adminid");
session_register('adminses');
if (!($adminses=='on')){
echo"Please autentificate before!! ERROR - not auth!!!";
exit;}
if ($adminses<>'on'){ echo "Autentificate before!!!"; exit;}
require("./conf.php");
echo "$title
<font size=+1 align='left' color='#000088'><b>Admin Tools:</b></font> Upload *.csv file<p>";
mysql_connect("$host_name","$db_user","$db_password");
mysql_select_db("$db_name");
if ($c=="")
{
echo "<center>
<form method=\"post\" action=\"upload_csv.php\" enctype=\"multipart/form-data\">
<table border=0 width=450 cellpading=1 cellspacing=1 bgcolor='#000000'><td>
Input category name - </td><td>
<input type=\"text\" name=\"category\" size=\"20\" maxlength=\"30\"></td></tr>
<td>Select *.csv file -</td><td>
<input NAME=\"userfile\" type=\"file\" size=\"20\" maxlength=\"50\"></td></tr></table><p>
<input type=\"hidden\" name=\"c\" value=\"upload\">
<input type=\"hidden\" name=\"first\" value=\"yes\">
<input type=\"submit\" value=\"Submit\">
</form>";
}
if ($c=="upload")
{
if ($category=="") {echo "<font color='#880000' size=+1>
Error - Please input category name!!!<br><a href=\"./upload.php\">Try again</a></font>";
echo "$bottom";
exit;}
if ($userfile=="")
{echo "<font color='#990000' size=+1>Please input *.csv file<br>
<a href=\"./upload.php\">Try again</a></font> $bottom";
exit;}
echo "<form method=\"post\" action=\"upload.php\" enctype=\"multipart/form-data\">
<input type='hidden' name='c' value='image'>
<input type='hidden' name='countline' value='$countline'>
<table border=1 width=100% cellpading=1 cellspacing=0>";
$bbb="INSERT INTO $table_prod ( ";
for ($ii=1;$ii<=$edit_fild_count;$ii++) {
$tempcol[$ii]=${"col$ii"};
if ($tempcol[$ii] <> "--None--")
{
if ( $tempcol[$ii] == "User_ID") $tempcol[$ii] ="userid";
if ( $tempcol[$ii] == "Describe") $tempcol[$ii] ="describes";
$tempcol[$ii]=strtolower ($tempcol[$ii]);
$bbb=$bbb." ".$tempcol[$ii].",";
}
}
//$bbb=substr($bbb,0,-1);
$bbb=$bbb." category) VALUES ( ";
echo "breake1 $countline";
for ($j=1;$j<=$countline;$j++)
{
$aaa="";
$aaa1="UPDATE $table_prod SET ";
$ccdel="celdel".$j;
if (${$ccdel}<>"del"){
for ($i=1;$i<=$edit_fild_count;$i++)
{
$name="$j#$i";
if ( $tempcol[$i] == "--None--"){ }else{
$aaa=$aaa." '".${$name}."',";
if ( $tempcol[$i] == "userid") {
$ccc="WHERE (category='$category' AND userid='".${$name}."')";
$userid=${$name};}
$aaa1=" ".$aaa1.$tempcol[$i]."='".${$name}."',";
}
}
$aaa1=substr($aaa1,0,-1);;
$aaa1=$aaa1." ".$ccc;
$aaa=$bbb.$aaa."'".$category."')";
echo"<input type='hidden' name='a$j' value='$userid'>\n";
$sql=$aaa1;
$ddd1=mysql_query("SELECT * FROM $table_prod WHERE category='$category' AND userid='$userid'");
$dq1=mysql_num_rows($ddd1);
if ($dq1==1){
$dd=mysql_query("$sql");
if ($dd)
{echo "<tr><td>Entry $j UDATED in table!<br> $tmp1</td>";
echo "<td>Userid $userid </td><td>Old image: <img src='./img.php?userid=$userid&category=$category' width='20' height='20'>";
echo " </td><td>NEW image - <input NAME=\"sm$userid\" type=\"file\" size=\"20\" maxlength=\"50\"></td>\n".
"</tr>";
}else
{echo "<td>".mysql_errno().": ".mysql_error()."</td></tr>";}
}
else
{
$sql=$aaa;
if (mysql_query("$sql"))
{echo "<tr><td>Entry $j inserted!</td>";
echo "<td>Userid $userid</td><td>No photo:</td><td>NEW image - <input NAME=\"sm$userid\" type=\"file\" size=\"20\" maxlength=\"50\"></td>\n".
"</tr>";
}
else {echo "<tr><td><font color=red>Entry $i NOT inserted!</font>$sql</td>"; echo mysql_errno().": ".mysql_error()."<BR><td></td><tr>";}
}
}
}
echo
"</table><input type=\"submit\" value=\"Submit\">".
"<input type='hidden' name='endid' value='$countline'>
<input type='hidden' name='category' value='$category'></form> ";
echo "<input type='button' value='Close window' onclick='javascript:window.close();'>";
}
if ($c=="image")
{
echo "<a href=\"./upload.php\">Add new *.csv file</a><br>";
if ($upd!=='1'){
$fromid++;}
if ($version=='1'){
require("./upl_img.php");}
else
{require("./pay.php");}
echo "<p><input type='button' value='Close window' onclick='javascript:window.close();'>";
}
echo "$bottom";
?>