<?php 
/*    
 *    Copyright (c) 2010 VidiScript
 *
 *    This file is part of VidiScript.
 *
 *    VidiScript is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VidiScript is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VidiScript.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    File Name: add.php
 *    Description: Adds an outgoing link
 *    $Date: 2010-02-21 23:16:57 +0000 (Sun, 21 Feb 2010) $
 *    $Revision: 12 $
 */
global $sitepath ;
session_start() ;
if (isset($_POST['Submit'])) {
      $sitename = $_POST['sitename'] ;
      $url = $_POST['url'] ;
      $sitename = addslashes($sitename) ;
      $url = addslashes($url) ;
      if (getSetting("approval", $db) == 1) {
            echo "Checking for unique information <br><br>" ;
            if ($_POST['code'] != $_SESSION['key']) {
                  die("Error: You must enter the code correctly") ;
            }
            else {
                  echo 'You entered the Captcha correctly <br><br>' ;
            }
            $db->query("SELECT * FROM approval WHERE Url = '".$url."'") ;
            if ($db->numrows() > 0) {
                  echo "Url already Submitted" ;
                  exit ;
            }
            $db->query("SELECT * FROM traffic WHERE Url = '".$url."'") ;
            if ($db->numrows() > 0) {
                  echo "Url already Submitted" ;
                  exit ;
            }
            $db->query("SELECT * FROM approval WHERE Sitename = '".$sitename."'") ;
            if ($db->numrows() > 0) {
                  echo "Site Name Already Taken" ;
                  exit ;
            }
            $db->query("SELECT * FROM traffic WHERE Sitename = '".$sitename."'") ;
            if ($db->numrows() > 0) {
                  echo "Site Name Already Taken" ;
                  exit ;
            }
            $url = str_replace('http://', '', $url) ;
            echo "Removing http:// <br><br>" ;
            $domain = explode("/", $url) ;
            $domainK = $domain[0] ;
            echo "Checking if url is valid <br><br>" ;
            $up = @fsockopen("$domainK", 80, $errno, $errstr, 30) ;
            if ($up) {
                  echo "Everything looks good.<br><br>" ;
                  $sql = "INSERT INTO approval VALUES ('', '$sitename', '$domainK')" ;
                  mysql_query($sql) or die("Didnt work") ;
                  echo $domainK." Has been Submitted and is <b>AWAITING APPROVAL</b>" ;
            }
            else {
                  echo "Please submit a Valid Url. This Url Doesnt Exist.." ;
                  exit ;
            }
      }
      else {
            $db->query("SELECT * FROM traffic WHERE Url = '".$url."'") ;
            echo "Checking for unique information <br><br>" ;
            if ($_POST['code'] != $_SESSION['key']) {
                  die("Error: You must enter the code correctly") ;
            }
            else {
                  echo 'You entered the Captcha correctly <br><br>' ;
            }
            if ($db->numrows() > 0) {
                  echo "Url already Submitted" ;
                  exit ;
            }
            $db->query("SELECT * FROM traffic WHERE Sitename = '".$sitename."'") ;
            if ($db->numrows() > 0) {
                  echo "Site Name Already Taken" ;
                  exit ;
            }
            $url = str_replace('http://', '', $url) ;
            echo "Removing http:// <br><br>" ;
            $domain = explode("/", $url) ;
            $domainK = $domain[0] ;
            echo "Checking if url is valid <br><br>" ;
            $up = @fsockopen("$domainK", 80, $errno, $errstr, 30) ;
            if ($up) {
                  echo "Everything looks good.<br><br>" ;
                  $sql = "INSERT INTO traffic VALUES ('', '$sitename', '$domainK', '0', '0')" ;
                  mysql_query($sql) or die("Didnt work") ;
                  echo $domainK." Has been Submitted" ;
            }
            else {
                  echo "Please submit a Valid Url. This Url Doesnt Exist.." ;
                  exit ;
            }
      }
}
?>
