<?php
/*
   Copyright © 2001-2005 THINKDING.COM - All Rights Reserved
         ALL COPYRIGHT INFORMATION MUST REMAIN INTACT          
             AND MAY NOT BE MODIFIED IN ANY WAY               

Disclaimer of Warranty: THE SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND WITHOUT ANY WARRANTIES 
AS TO PERFORMANCE, MERCHANTABILITY, FITNESS OR OTHER PURPOSES, WHETHER EXPRESSED OR IMPLIED. ALL EXPRESSED OR IMPLIED 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR 
PURPOSE ARE DISCLAIMED. THE LICENSEE MUST ASSUME THE ENTIRE RISK OF USING THE SOFTWARE. IN NO CASE SHALL THINKDING LLC 
OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, CONSEQUENTIAL, OR OTHER DAMAGES 
OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH 
DAMAGES ARE BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT, NEGLIGENCE, STRICT TORT, OR ANY 
OTHER LEGAL THEORY. THIS IS TRUE EVEN IF THINKDING LLC OR ITS CONTRIBUTORS IS ADVISED OF THE POSSIBILITY OF SUCH 
DAMAGES. IN NO CASE WILL THE LIABILITY OF THINKDING LLC OR ITS CONTRIBUTORS EXCEED THE AMOUNT OF THE LICENSE FEE PAID 
BY LICENSEE TO THINKDING LLC. ANY LIABILITY OF THINKDING LLC OR ITS CONTRIBUTORS IS LIMITED EXCLUSIVELY TO PRODUCT 
REPLACEMENT OR REFUND OF THE PURCHASE PRICE. THINKDING LLC OR ITS CONTRIBUTORS IS NOT LIABLE FOR ANY CONTENT DISPLAYED 
ON A WEBSITE POWERED BY THINKDING LLC SOFTWARE. THIS LICENSE SHALL BE GOVERNED BY THE LAWS OF THE STATE OF PENNSYLVANIA.
*/

////////// START CONFIGURATION

define('DBHOST','localhost');     // address to mysql database
define('DBUSER','username');      // username to database
define('DBPASS','password');      // password to database
define('DBNAME','database');      // name of database
define('TABLE','search_data');    // database table to use - table type should be MyISAM

////////// END CONFIGURATION

while(list($key,$val)=each($_REQUEST)) {
$
$key $val;
}

$dbhost DBHOST;
$dbuser DBUSER;
$dbpass DBPASS;
$dbname DBNAME;
$table TABLE;

// import_request_variables ("gP", "_");          // REMOVE COMMENT ONLY IF NEEDED
// Read more at http://www.php.net/manual/en/function.import-request-variables.php

@mysql_connect($dbhost,$dbuser,$dbpass) or die("Unable to connect to database");
@
mysql_select_db("$dbname") or die("Unable to select database");

$search_size = array();
$search_date = array();
$cnt count($search_title);
$msg "";
$indb = array();

for (
$i=0$i<$cnt$i++) {
    
$search_title[$i] = trim($search_title[$i]);
    
$search_description[$i] = trim($search_description[$i]);
    
$search_keywords[$i] = trim($search_keywords[$i]);
    
$search_url[$i] = trim($search_url[$i]);

    if ((
strlen($search_title[$i])>0) && (strlen($search_description[$i])>0) && (strlen($search_keywords[$i])>0) && (strlen($search_url[$i])>4)) {
        if (!
ereg("^http://",$search_url[$i])) {
            
$search_url[$i] = "http://".$search_url[$i];
        }
        
$fp = @fopen($search_url[$i], "r");
        if ((!
$fp) || (!is_resource($fp))) {
            
$search_size[$i] = 0;
        }
        else {
            
$contents "";
            while(!
feof($fp)) {
                
$contents .= fread($fp1024);
            }
            
$search_size[$i] = strlen($contents);
            if (
$search_size[$i]<1024) {
                
$search_size[$i] = 0;
            }
        }
        if (!
get_magic_quotes_gpc()) {
            
$search_title[$i] = addslashes($search_title[$i]);
            
$search_description[$i] = addslashes($search_description[$i]);
            
$search_keywords[$i] = addslashes($search_keywords[$i]);
            
$search_url[$i] = addslashes($search_url[$i]);
        }
        
$search_size[$i] = (int) round(($search_size[$i])/1024);
        if (
$search_size[$i] == 0) {
            
$search_size[$i] = "";
        }
        else {
            
$search_size[$i] = $search_size[$i]."k";
        }
        
$search_date[$i] = date("j M Y");
        
$search_title[$i] = addslashes(stripslashes(substr($search_title[$i],0,300)));
        
$search_description[$i] = addslashes(stripslashes(substr($search_description[$i],0,300)));
        
$search_keywords[$i] = addslashes(stripslashes(substr($search_keywords[$i],0,300)));
        
$search_url[$i] = addslashes(stripslashes(substr($search_url[$i],0,300)));
        
$search_url[$i] = str_replace(" ","+",$search_url[$i]);
        
$sqlquery "INSERT INTO $table VALUES('$search_title[$i]','$search_description[$i]','$search_keywords[$i]','$search_url[$i]','$search_size[$i]','$search_date[$i]')";
        if(
mysql_query($sqlquery)) {
            
$indb[$i] = "inyes";
        }
        else {
            
$j $i 1;
            
$msg .= "Problem with entry $j : MySQL insert query failed<br>";
            
$indb[$i] = "inno";
        }
    }
    else {
        
$j $i 1;
        
$msg .= "Problem with entry $j : At least one blank field<br>";
        
$indb[$i] = "inno";
    }
}

@
mysql_close();

if (
strlen($msg)<1) {
    
$msg .= "No problems encountered<br>";
}

echo <<<END
<HTML>
<TITLE>ThinkDing :: Add Entries</TITLE>
<BODY BGCOLOR="#FFFFFF">
<center>
<table border="0" width="700">
    <tr>
        <td align="center">
            <font face="verdana">
            <b>Synopsis of entries:</b><br><br>
            $msg
            </font>
        </td>
    </tr>
    <tr>
        <td align="center">
            <font face="verdana"><br>
            <b>The following information was entered into the database:</b><br>
END;


$num_innos array_count_values($indb);
if (
$num_innos[inno] == $cnt) {
    echo 
"<br>No entries were inserted into the database";
}
else {
    for (
$i=0$i<$cnt$i++) {
        
$search_title[$i] = stripslashes($search_title[$i]);
        
$search_description[$i] = stripslashes($search_description[$i]);
        
$search_keywords[$i] = stripslashes($search_keywords[$i]);
        
$search_url[$i] = stripslashes($search_url[$i]);
        if (
$indb[$i] == "inyes") {
            
$j $i 1;
            if (
eregi("^[-][ ]",$search_size[$i])) {
                
$search_size[$i] = str_replace("- ","",$search_size[$i]);
            }
            if (
strlen($search_size[$i]) < 1) {
                
$search_size[$i] = "Small or not determined : No size inserted for this entry";
            }
echo <<<END
            <br><table width="700">
                <tr>
                    <td colspan="2" bgcolor="#eaeaea"><b>Entry $j</b></td>
                </tr>
                <tr>
                    <td width="175">TITLE : </td>
                    <td width="525">$search_title
[$i]</td>
                </tr>
                <tr>
                    <td>DESCRIPTION : </td>
                    <td>$search_description
[$i]</td>
                </tr>
                <tr>
                    <td>KEYWORDS : </td>
                    <td>$search_keywords
[$i]</td>
                </tr>
                <tr>
                    <td>URL : </td>
                    <td>$search_url
[$i]</td>
                </tr>
                <tr>
                    <td>SIZE: </td>
                    <td>$search_size
[$i]</td>
                </tr>
                <tr>
                    <td>DATE: </td>
                    <td>$search_date
[$i]</td>
                </tr>
            </table>
END;

        }
    }
}

echo <<<END
            </font>
        </td>
    </tr>
    <tr>
        <td align="center">
            <font face="verdana"><br><br><a href="entryform.php?enum=$cnt">Add More</a></font>
        </td>
    </tr>
</table>
</center>
</BODY>
</HTML>
END;

?>