Jump to content

Recommended Posts

Sorry I am a newbie at all of this.  I don't even know what an array is? but here is the code for the page anyway.  Thanks for the help.

 

 

<?php

require_once("inc/session.php");

require_once("inc/isotope.php");

require_once("inc/formgen.php");

require_once("inc/csv.php");

require_once("inc/validation.php");

require_once("inc/email.php");

 

global $dbc;

global $PROCESS;

global $total_lead_cost;

 

function clearMailData($data)

{

$from = urldecode($data);

$from = addslashes($from); 

$from = htmlspecialchars($from);

return $from;

}

 

if (isset($_GET['act']))

{

    switch ($_GET['act'])

    {

        case 'failed' :

        ob_end_clean();

        $PAGE['body']="The data you have entered is invalid.  Please try again.\n";

        $tl=isotope_load(array(),"templates/default.itt");

        echo isotope_exec($tl,'leadpage',$PAGE);

        exit();       

        break;

        case 'succes' :

        ob_end_clean();

        $PAGE['body']="Thank you for your submission.\n";

        $tl=isotope_load(array(),"templates/default.itt");

        echo isotope_exec($tl,'leadpage',$PAGE);

        exit();       

        break;       

    }

}

 

function fail($p=null) {

    global $dbc;

    $sql = 'select http_failed from campaign where id = '.$_POST['campaign'];

    $rv=mysql_query($sql,$dbc);

    $ar=mysql_fetch_array($rv);   

    if (strlen(trim($ar['http_failed']))!=0)

    {

    header("Location: ".$ar['http_failed']);

    }

    else

    {   

ob_end_clean();

$PAGE['body']="The data you have entered is invalid. Please try again. $p\n";

$tl=isotope_load(array(),"templates/default.itt");

echo isotope_exec($tl,'leadpage',$PAGE);

    }

exit();   

}

 

function isSendMail($camp_id,$user_id,$form_ans=null)

{

  global $dbc, $is_any_ans, $total_lead_cost;

  if ($total_lead_cost==null) $total_lead_cost = 0;

  $query = "select any_matches_leads_email from setup";

  $rv=mysql_query($query,$dbc);

  $ar=mysql_fetch_array($rv);

  $query = "SELECT c.answers, cc.filter, c.template, c.answers_cots

            FROM campaign c, customer_campaign cc

            WHERE c.id = cc.cid

            AND cc.usid = $user_id

            AND c.id = $camp_id";

  $rv=mysql_query($query,$dbc);

  if(mysql_num_rows($rv)!=1) fail();

  $ar=mysql_fetch_array($rv); 

  $arr_anws = explode(',',$ar['answers']);

  $arr_answers_cots = explode(',',$ar['answers_cots']);

  $vv = explode(',',$ar['template']);

  $need_eq = 0;

  $filter  = $ar['filter']; 

  $filter  = explode(',',$filter);   

 

  foreach ($filter as $key => $value)

  {

  $t = $value;

  $filter[$key] = array();

  $filter[$key]['value'] = $t;

  $filter[$key]['is_exact'] = '0';

  }

 

  $count_answer = count($filter);

  foreach ($vv as $key => $value)

  {

  $ts = explode('::',$value);

  if ($ts[3]==1) {

    $need_eq++;

    $filter[$key]['is_exact'] = '1';

  }

  }

  $count_eq = 0;

  $form_ans = array();

  foreach ($_POST as $key => $value)

  {

  if (strstr($key,'ans_')) $form_ans[] = $_POST[$key];

  }

  foreach ($form_ans as $key => $value)

  {

  foreach ($value as $key2 => $value2)

  {

    $form_ans[$key][$key2] = str_replace("\x0D",'',$value2);

  }

  }

 

  foreach ($arr_answers_cots as $key => $value)

  {

  $arr_answers_cots[$key] = explode("\\n",$value);

  foreach ($arr_answers_cots[$key] as $key2 => $value2)

  {

    $arr_answers_cots[$key][$key2] = str_replace("\\r","",$value2);

  }

  }

 

  foreach ($arr_anws as $key => $value)

  {

  $arr_anws[$key] = explode("\\n",$value);

  foreach ($arr_anws[$key] as $key2 => $value2)

  {

    $arr_anws[$key][$key2] = str_replace("\\r","",$value2);

  }

  }

 

 

  foreach ($filter as $key => $value)

  {

  $filter[$key]['value'] = explode('\n',$value['value']);

  }

 

  foreach($form_ans as $key => $value)

  {

  $tp = 0;

  foreach ($value as $key2 => $value2)

  {

    if (isset($filter[$key]['value']) and !is_array($filter[$key]['value']) and (in_array($value2,$filter[$key]['value']) and $filter[$key]['is_exact']=='1') or (strlen(trim($filter[$key]['value'][0]))==0) ) $tp++;

    foreach ($arr_anws[$key] as $k => $v)

    if ($v==$value2) $total_lead_cost += $arr_answers_cots[$key][$k];

  }

  if ($tp!=0) $count_eq++;

  }

  if ($count_eq>=$need_eq)

  {

      return true;

  }

  else

  {

      return false;

  }

}

 

function getQuelCost($id_camp)

{

  global $dbc;

 

  $is_eq = false;     

  $query = "SELECT c.answers, c.statements

            FROM campaign c

            WHERE c.id = $id_camp";

  $rv=mysql_query($query,$dbc);

  if(mysql_num_rows($rv)!=1) fail();

  $ar=mysql_fetch_array($rv); 

 

  $v_list_statements = explode("\\n",$ar['statements']);

  foreach ($v_list_statements as $key => $value)

  {

  $v_list_statements[$key] = str_replace("\\r","",$v_list_statements[$key]);

  $v_list_statements[$key] = str_replace("\\","",$v_list_statements[$key]);

  $v_list_statements[$key] = str_replace("\r","",$v_list_statements[$key]); 

  }

 

  $form_ans = array();

  foreach ($_POST as $key => $value)

  {

  if (strstr($key,'ans_')) $form_ans[] = $_POST[$key];

  }

  foreach ($form_ans as $key => $value)

  {

  foreach ($value as $key2 => $value2)

  {

    $form_ans[$key][$key2] = str_replace("\x0D",'',$value2);

  }

  }

 

  $v_list_answer = csvtoarray($ar['answers']);

 

  foreach ($v_list_answer as $key => $value)

  { 

  $v_list_answer[$key] = explode("\r\n",$value);

  if (is_array($value))

  {

    foreach ($value as $key2 => $value2)

    {

    $v_list_answer[$key2] = str_replace("\\r","",$v_list_answer[$key2]);

    $v_list_answer[$key2] = str_replace("\\","",$v_list_answer[$key2]);

    $v_list_answer[$key2] = str_replace("\r","",$v_list_answer[$key2]); 

    }

  }

  }

 

  foreach ($v_list_answer as $key => $value ) $v_list_answer[$key] = array_flip($value);

  $tt = 0;

  foreach ($v_list_answer as $key => $value)

  {

  foreach ($value as $key2 => $value2)

  {

    $v_list_answer[$key][$key2] = $value2 + 1;

    $tt++;

  }

  }

 

  foreach ($form_ans as $key => $value)

  {

  foreach ($value as $key2 => $value2)

  {

    $form_ans[$key][$key2] = $v_list_answer[$key][$value2];

  }

  }

  $tt = $form_ans;   

  foreach ($v_list_statements as $key => $value)

  {

  $subject = $value;

  list($rules,$cost) = explode("=",$subject);

    if (preg_match_all('/\d+:[A-Za-z0-9"]+/', $rules, $matches)) {

        foreach($matches[0] as $match){

            list($key2, $value2) = explode(":", $match,2);

            $rules = str_replace($match, 'in_array('.$value2.', $tt['.($key2-1).'])', $rules);

        }

        $rules = str_replace("and", "&&", $rules);

        $subject = str_replace("or", "||", $rules);

    }

    if (strlen($subject)>10) eval(" \$is_eq = ( $subject ); ");

    if ($is_eq)

    {

    return $cost;

    }

  }

}

 

ob_start();

 

//print "!<br>";

 

$cid=(int)$_POST['campaign'];

if(md5("ILCVF568234".$cid)!=$_POST['cvfid']) fail();

 

//print "!!<br>";

                               

if (isset($_POST['email']) and !valemail($_POST['email'])) fail();

if (isset($_POST['name1']) and !valtext($_POST['name1'])) fail();

if (isset($_POST['name2']) and !valtext($_POST['name2'])) fail();

if (isset($_POST['address']) and !valtext($_POST['address'])) fail();

if (isset($_POST['city']) and !valtext($_POST['city'])) fail();

if (isset($_POST['state']) and !valtext($_POST['state'])) fail('STATE');

if (isset($_POST['zip']) and !valzip($_POST['zip'])) fail();

if (isset($_POST['country']) and !valnum($_POST['country'],1,267)) fail();

if (isset($_POST['phone']) and !valphone($_POST['phone'])) fail();

if (isset($_POST['fax']) and !valphone($_POST['fax'])) fail();

 

//print "!!!<br>";

$query = "SELECT C.answers,AF.selltimes FROM campaign C

LEFT JOIN account_affiliate AF ON AF.usid=C.usid

WHERE id='$cid' AND active=1 AND deleted=0 AND approved=1

AND C.usid=AF.usid";

//print "$query<br>";

$rv=mysql_query($query,$dbc);

if(mysql_num_rows($rv)!=1) fail();

$ar=mysql_fetch_array($rv);

//print "!!!!<br>";

 

 

$ar1=csvtoarray($ar['answers']);

 

foreach ($_POST as $k => $v)

{

if (strstr($k,'ans_'))

{

$vls=array_map("trim",explode("\n",$ar1[$k]));

if($ar1[$k] && !in_array(trim($v),$vls)) fail();

}

 

 

$ans='';

 

foreach ($_POST as $k => $v)

{

if (strstr($k,'ans_'))

{

  if (is_array($_POST[$k]) and count($_POST[$k])>1)

  {

  foreach ($_POST[$k] as $k2 => $v2) $ans.=$v2.';:;';

  $ans = substr($ans,0,strlen($ans)-3).',';

  }

  else

  {

  $ans.=arraytocsv($v).',';     

  }

}

}

$ans = substr($ans,0,strlen($ans)-1);

 

$ref=$_SERVER["HTTP_REFERER"];

$v_selltime =  $ar['selltimes'];

$insvals = "$cid,'". $_SERVER['REMOTE_ADDR']."','".$v_selltime."','".

clearMailData($ref)."', ";

    (isset($_POST['email'])) ? ( $insvals .= " '".clearMailData($_POST['email'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['name1'])) ? ( $insvals .= " '".clearMailData($_POST['name1'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['name2'])) ? ( $insvals .= " '".clearMailData($_POST['name2'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['address'])) ? ( $insvals .= " '".clearMailData($_POST['address'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['city'])) ? ( $insvals .= " '".clearMailData($_POST['city'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['postcode'])) ? ( $insvals .= " '".clearMailData($_POST['postcode'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['state'])) ? ( $insvals .= " '".clearMailData($_POST['state'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['country'])) ? ( $insvals .=" '".clearMailData($_POST['country'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['phone'])) ? ( $insvals .= " '".clearMailData($_POST['phone'])."'," ) : ( $insvals .= "''," );

    (isset($_POST['fax'])) ? ( $insvals .= " '".clearMailData($_POST['fax'])."'," ) : ( $insvals .= "''," );   

    $insvals .= "'".clearMailData($ans)."'";

   

$selltimes=$ar['selltimes'];

 

$query = "SELECT value FROM filter_keywords WHERE active=1";

$rv=mysql_query($query,$dbc);

$a2=array();

$valid=1;

for($i=0; $i<mysql_num_rows($rv); $i++) {

$ar=mysql_fetch_array($rv);

if(strpos($insvals,trim($ar['value']))!=FALSE) $valid=0;

}

      $count_sold = 0;

      $sql = "SELECT start_point_sold FROM shedule s, campaign c WHERE c.ref_shedule = s.id_shedule AND c.id =".clearMailData($_POST['campaign']);

      $rv=mysql_query($sql,$dbc);

      $ar=mysql_fetch_array($rv);     

      if (strlen(trim($ar['start_point_sold']))!=0) $count_sold = $ar['start_point_sold'];

 

      $sql = "SELECT ref_categ FROM campaign WHERE id =".clearMailData($_POST['campaign']);

      $rv=mysql_query($sql,$dbc);

      $ar=mysql_fetch_array($rv);     

      $ref_categ = $ar['ref_categ'];     

 

      /*===============================================*/

        $query = "SELECT answers, template

        FROM campaign

        WHERE id='".$_POST['campaign']."'";

        $rv=mysql_query($query,$dbc);

        $ar=mysql_fetch_array($rv);

 

        $ar1=csvtoarray($ar['template']);

        $ar2=csvtoarray($ar['answers']);

 

     

$query = "INSERT INTO lead (cid,ipaddr,ttl,refer,email,inf_name1,

inf_name2,inf_addr,inf_city,inf_zip,inf_state,inf_country,

inf_phone,inf_fax,answers,valid,camp_id,status,sold,ref_category) VALUES ($insvals, '$valid','".clearMailData($_POST['campaign'])."','L',$count_sold,$ref_categ)";

mysql_query($query,$dbc);

$lid=mysql_insert_id($dbc);

 

 

if($valid) {

   

    $list_show_fields = array();

    $sql = "select fields_show from campaign where id = ".clearMailData($_POST['campaign']);

    $rv=mysql_query($sql,$dbc);   

    $v_list_show_fields = mysql_fetch_array($rv);

    $list_show_fields = explode(',',$v_list_show_fields['fields_show']);

    $send_contact = array();

   

    if (isset($_POST['email']))

    {       

    ( in_array('email',$list_show_fields )) ?

    ( $send_contact['f_email'] = "Email : ".clearMailData($_POST['email']) ) :

    ( $send_contact['f_email'] = '' );

    }

   

    if (isset($_POST['name1']))

    {

    ( in_array('first_name',$list_show_fields) ) ?

    ( $send_contact['f_first_name'] = "First Name : ".clearMailData($_POST['name1']) ) :

    ( $send_contact['f_first_name'] = '' );

    }

    if (isset($_POST['name2']))

    {

    ( in_array('last_name',$list_show_fields) ) ?

    ( $send_contact['f_last_name'] = "Last Name : ".clearMailData($_POST['name2']) ) :

    ( $send_contact['f_last_name'] = '' );

    }

    if (isset($_POST['address']))

    {

    ( in_array('address',$list_show_fields) ) ?

    ( $send_contact['f_address'] = "Address : ".clearMailData($_POST['address']) ) :

    ( $send_contact['f_address'] = '' );

    }

    if (isset($_POST['city']))

    {

    ( in_array('city',$list_show_fields) ) ?

    ( $send_contact['f_city'] = "City : ".clearMailData($_POST['city']) ) :

    ( $send_contact['f_city'] = '' );       

    }

    if (isset($_POST['state']))

    {

    ( in_array('state',$list_show_fields) ) ?

    ( $send_contact['f_state'] = "State : ".clearMailData($_POST['state']) ) :

    ( $send_contact['f_state'] = '' );

    }

    if (isset($_POST['zip']))

    {

    ( in_array('zip',$list_show_fields) ) ?

    ( $send_contact['f_zip'] = "Zip : ".clearMailData($_POST['zip']) ) :

    ( $send_contact['f_zip'] );

    }

    if (isset($_POST['phone']))

    {

    ( in_array('phone',$list_show_fields) ) ?

    ( $send_contact['f_phone'] = "Phone : ".clearMailData($_POST['phone']) ) :

    ( $send_contact['f_phone'] = '' );   

    }

    if (isset($_POST['fax']))

    {

    ( in_array('fax',$list_show_fields) ) ?

    ( $send_contact['f_fax'] = "Fax : ".clearMailData($_POST['fax']) ) :

    ( $send_contact['f_fax'] = '' );   

    }

    if (isset($_POST['country']))

    {

$rv=mysql_query("SELECT name FROM country where id = ".clearMailData($_POST['country']),$dbc);

$country=mysql_fetch_array($rv);           

    ( in_array('coutry',$list_show_fields) ) ?

    ( $send_contact['f_country'] = "Country : ".$country['name'] ) :

    ( $send_contact['f_country'] = '' );   

    }   

    for ($i=0;$i<count($ar1);$i++)

    {

    $s = explode('::',$ar1[$i]);

    $send_contact['question'.($i+1)] = $s[0];   

    $ts = '';

    foreach ($_POST['ans_'.$i] as $k => $v) $ts .= "$v,";

    $ss = $ts;

    $send_contact['answer'.($i+1)] = substr($ss,0,strlen($ss)-1);   

    }

 

    email_lead($lid,"Thank you for registering","newlead");

 

// TODO block this into runlead(), lpd, filts....               

    $sql = "SELECT C.answers,AF.selltimes, C.min_cost as min_cost, C.max_cost as max_cost FROM campaign C, account_affiliate AF

    WHERE id='$cid' AND active=1 AND deleted=0 AND approved=1

    AND C.usid=AF.usid";

   

    $rv=mysql_query($sql,$dbc);

$ar=mysql_fetch_array($rv);   

    $ttp = $ar;

    $total_solds = $v_selltime; // $ar['selltimes'];

             

    $query="SELECT AC.usid AS cuid, AF.usid AS afuid, C.cost as afcost, C.cost*AF.ratio*AC.ratio AS ccost

    FROM account_customer AC, customer_campaign CC, campaign C, account_affiliate AF

    LEFT JOIN customer_lead CL ON CL.lid='$lid' AND CL.usid=AC.usid

    WHERE CC.usid=AC.usid AND CC.cid='$cid' AND C.id=CC.cid

    AND AC.pause=0

            AND AC.pauseuntil<now()

    AND C.active=1

            AND C.deleted=0

            AND C.approved=1

            AND AF.usid=C.usid

            AND C.cost*AF.ratio*AC.ratio<=AC.balance

    ORDER BY AC.lastcust";   

    $rv=mysql_query($query,$dbc);

    $l_cost = $ar['ccost'];

   

    if (mysql_num_rows($rv)!=0) mysql_query("UPDATE lead SET sold = 0 WHERE id='$lid'",$dbc);

for($i=0; $i<mysql_num_rows($rv); $i++) {

$ar=mysql_fetch_array($rv);

 

        $sql = "select sold, status from lead where id='$lid'";

        $rv1=mysql_query($sql,$dbc);

    $ar1=mysql_fetch_array($rv1);   

        if ($ar1['sold']<$total_solds)

        {

//          print "<pre>";

//          print_r($_POST);

//          print "</pre>";

           

 

                if (isset($_POST['ans']))

                {

                $total_lead_cost = $l_cost;

                if (isSendMail($cid,$ar['cuid'],$_POST['ans']))

                {

                   

                  $l_cost = getQuelCost($_POST['campaign']);

                  $l_cost = $l_cost + 0;                                     

                   

                  if ($total_lead_cost>=0) $l_cost = $l_cost + $total_lead_cost;                   

                 

                  if ($l_cost<$ttp['min_cost']) $l_cost = $ttp['min_cost'];

                  if ($l_cost>$ttp['max_cost']) $l_cost = $ttp['max_cost'];

                  if (config_get("autoresponse"))

                  {                   

                  email_account($ar['cuid'],"New lead","newlead",$send_contact);

                  }

                  else

                  {

                  email_account($ar['cuid'],"New lead","deliverlead",$send_contact);                     

                  }                 

          mysql_query("INSERT INTO customer_lead (usid,lid,cost,pay,sold_as) VALUES ('".$ar['cuid']."','$lid','".$l_cost."','".

      $ar['afcost']."','".$ar1['status']."')",$dbc);

          mysql_query("UPDATE account_customer SET balance=balance-'".addslashes($l_cost)."', lastcust='$lid'

      WHERE usid='".$ar['cuid']."'",$dbc);                 

                }

                }

                else

                { 

                $total_lead_cost = $l_cost;

                if (isSendMail($cid,$ar['cuid']))

                {

                  $l_cost = getQuelCost($_POST['campaign']);

                  $l_cost = $l_cost + 0;                                     

                   

                  if ($total_lead_cost>=0) $l_cost = $l_cost + $total_lead_cost;                   

                 

                  if ($l_cost<$ttp['min_cost']) $l_cost = $ttp['min_cost'];

                  if ($l_cost>$ttp['max_cost']) $l_cost = $ttp['max_cost'];

                 

                  if(config_get("autoresponse"))

                  {                                         

                  email_account($ar['cuid'],"New lead","newlead",$send_contact);

                  }

                  else

                  {

                  email_account($ar['cuid'],"New lead","deliverlead",$send_contact);

                  }

          mysql_query("INSERT INTO customer_lead (usid,lid,cost,pay,sold_as) VALUES ('".$ar['cuid']."','$lid','".$l_cost."','".

      $ar['afcost']."','".$ar1['status']."')",$dbc);

          mysql_query("UPDATE account_customer SET balance=balance-'".addslashes($l_cost)."', lastcust='$lid'

      WHERE usid='".$ar['cuid']."'",$dbc);                 

                }           

                }       

    if(config_get("autoresponse"))

            {

    email_lead_cuc($lid,"Thank you for registering",$ar['cuid'],$cid);

            }

            /*

    mysql_query("UPDATE account_customer SET balance=balance-'".

    addslashes($ar['ccost'])."', lastcust='$lid'

    WHERE usid='".$ar['cuid']."'",$dbc);

            */   

    mysql_query("UPDATE campaign SET total_generate=total_generate+1 WHERE id='".$_POST['campaign']."'",$dbc);           

               

    mysql_query("UPDATE account_affiliate SET balance=balance+'".

    addslashes($ar['afcost'])."',totleads=totleads+1,

    leads=leads+1

    WHERE usid='".$ar['afuid']."'",$dbc);

    mysql_query("UPDATE lead SET ttl=ttl-1, sold = sold + 1 WHERE id='$lid'",$dbc);

        }

}

// TODO up to here.

}

 

$query = 'select http_succes from campaign where id = '.clearMailData($_POST['campaign']);

$rv=mysql_query($query,$dbc);

$ar=mysql_fetch_array($rv);   

if (strlen(trim($ar['http_succes']))!=0)

{

    echo "

      <html>

      <head>

      <script type=\"text/javascript\">

      <!--

      window.location = '".$ar['http_succes']."';

      -->

      </script>     

      </head>

      <body></body></html>";

    exit;   

}

else

{   

echo "Thank you for your submission.\n";       

}

 

$PAGE['body']=ob_get_contents();

ob_end_clean();

 

$tl=isotope_load(array(),"templates/default.itt");

echo isotope_exec($tl,'leadpage',$PAGE);

 

?>

Link to comment
https://forums.phpfreaks.com/topic/82753-help-with-this-error/#findComment-420903
Share on other sites

Here is the actual error and the line that it is on:

Warning: Invalid argument supplied for foreach() in /home/endlesse/public_html/ileads/addlead.php on line 442

 

<?php
require_once("inc/session.php");
require_once("inc/isotope.php");
require_once("inc/formgen.php");
require_once("inc/csv.php");
require_once("inc/validation.php");
require_once("inc/email.php");

global $dbc;
global $PROCESS;
global $total_lead_cost;

function clearMailData($data)
{
$from = urldecode($data);
$from = addslashes($from);  
$from = htmlspecialchars($from);
return $from;
}

if (isset($_GET['act']))
{
    switch ($_GET['act'])
    {
        case 'failed' : 
        ob_end_clean();
        $PAGE['body']="The data you have entered is invalid.  Please try again.\n";
        $tl=isotope_load(array(),"templates/default.itt");
        echo isotope_exec($tl,'leadpage',$PAGE);
        exit();         
         break;
        case 'succes' : 
        ob_end_clean();
        $PAGE['body']="Thank you for your submission.\n";
        $tl=isotope_load(array(),"templates/default.itt");
        echo isotope_exec($tl,'leadpage',$PAGE);
        exit();         
         break;         
    }
}

function fail($p=null) {
    global $dbc;
    $sql = 'select http_failed from campaign where id = '.$_POST['campaign'];
    $rv=mysql_query($sql,$dbc);
    $ar=mysql_fetch_array($rv);    
    if (strlen(trim($ar['http_failed']))!=0)
    {
     header("Location: ".$ar['http_failed']);
    }
    else
    {    
 ob_end_clean();
 $PAGE['body']="The data you have entered is invalid. Please try again. $p\n";
 $tl=isotope_load(array(),"templates/default.itt");
 echo isotope_exec($tl,'leadpage',$PAGE);
    }
exit();    
}

function isSendMail($camp_id,$user_id,$form_ans=null)
{
  global $dbc, $is_any_ans, $total_lead_cost;
  if ($total_lead_cost==null) $total_lead_cost = 0;
  $query = "select any_matches_leads_email from setup";
  $rv=mysql_query($query,$dbc);
  $ar=mysql_fetch_array($rv);
  $query = "SELECT c.answers, cc.filter, c.template, c.answers_cots
            FROM campaign c, customer_campaign cc
            WHERE c.id = cc.cid
            AND cc.usid = $user_id
            AND c.id = $camp_id";
  $rv=mysql_query($query,$dbc);
  if(mysql_num_rows($rv)!=1) fail();
  $ar=mysql_fetch_array($rv);  
  $arr_anws = explode(',',$ar['answers']);
  $arr_answers_cots = explode(',',$ar['answers_cots']);
  $vv = explode(',',$ar['template']);
  $need_eq = 0;
  $filter  = $ar['filter'];  
  $filter  = explode(',',$filter);    
  
  foreach ($filter as $key => $value)
  {
   $t = $value;
   $filter[$key] = array();
   $filter[$key]['value'] = $t;
   $filter[$key]['is_exact'] = '0';
  }
  
  $count_answer = count($filter);
  foreach ($vv as $key => $value)
  {
   $ts = explode('::',$value);
   if ($ts[3]==1) { 
    $need_eq++;
    $filter[$key]['is_exact'] = '1';
   }
  }
  $count_eq = 0;
  $form_ans = array();
  foreach ($_POST as $key => $value)
  {
   if (strstr($key,'ans_')) $form_ans[] = $_POST[$key];
  }
  foreach ($form_ans as $key => $value)
  {
   foreach ($value as $key2 => $value2)
   {
    $form_ans[$key][$key2] = str_replace("\x0D",'',$value2);
   }
  }
  
  foreach ($arr_answers_cots as $key => $value)
  {
   $arr_answers_cots[$key] = explode("\\n",$value);
   foreach ($arr_answers_cots[$key] as $key2 => $value2)
   {
    $arr_answers_cots[$key][$key2] = str_replace("\\r","",$value2);
   }
  }

  foreach ($arr_anws as $key => $value)
  {
   $arr_anws[$key] = explode("\\n",$value);
   foreach ($arr_anws[$key] as $key2 => $value2)
   {
    $arr_anws[$key][$key2] = str_replace("\\r","",$value2);
   }
  }
  
  
  foreach ($filter as $key => $value)
  {
   $filter[$key]['value'] = explode('\n',$value['value']);
  }
  
  foreach($form_ans as $key => $value)
  {
   $tp = 0;
   foreach ($value as $key2 => $value2)
   {
    if (isset($filter[$key]['value']) and !is_array($filter[$key]['value']) and (in_array($value2,$filter[$key]['value']) and $filter[$key]['is_exact']=='1') or (strlen(trim($filter[$key]['value'][0]))==0) ) $tp++;
    foreach ($arr_anws[$key] as $k => $v)
     if ($v==$value2) $total_lead_cost += $arr_answers_cots[$key][$k];
   }
   if ($tp!=0) $count_eq++;
  }
  if ($count_eq>=$need_eq) 
  {
      return true;
  }
  else
  {
      return false;
  }
}

function getQuelCost($id_camp)
{
  global $dbc;
  
  $is_eq = false;      
  $query = "SELECT c.answers, c.statements
            FROM campaign c
            WHERE c.id = $id_camp";
  $rv=mysql_query($query,$dbc);
  if(mysql_num_rows($rv)!=1) fail();
  $ar=mysql_fetch_array($rv);  
  
  $v_list_statements = explode("\\n",$ar['statements']);
  foreach ($v_list_statements as $key => $value)
  {
   $v_list_statements[$key] = str_replace("\\r","",$v_list_statements[$key]);
   $v_list_statements[$key] = str_replace("\\","",$v_list_statements[$key]); 
   $v_list_statements[$key] = str_replace("\r","",$v_list_statements[$key]);  
  }

  $form_ans = array();
  foreach ($_POST as $key => $value)
  {
   if (strstr($key,'ans_')) $form_ans[] = $_POST[$key];
  }
  foreach ($form_ans as $key => $value)
  {
   foreach ($value as $key2 => $value2)
   {
    $form_ans[$key][$key2] = str_replace("\x0D",'',$value2);
   }
  }
  
  $v_list_answer = csvtoarray($ar['answers']);

  foreach ($v_list_answer as $key => $value)
  {  
   $v_list_answer[$key] = explode("\r\n",$value);
   if (is_array($value))
   {
    foreach ($value as $key2 => $value2)
    {
     $v_list_answer[$key2] = str_replace("\\r","",$v_list_answer[$key2]);
     $v_list_answer[$key2] = str_replace("\\","",$v_list_answer[$key2]); 
     $v_list_answer[$key2] = str_replace("\r","",$v_list_answer[$key2]);  
    }
   }
  }
  
  foreach ($v_list_answer as $key => $value ) $v_list_answer[$key] = array_flip($value);
  $tt = 0;
  foreach ($v_list_answer as $key => $value)
  {
   foreach ($value as $key2 => $value2) 
   {
    $v_list_answer[$key][$key2] = $value2 + 1;
    $tt++;
   }
  }
  
  foreach ($form_ans as $key => $value)
  {
   foreach ($value as $key2 => $value2)
   {
    $form_ans[$key][$key2] = $v_list_answer[$key][$value2];
   }
  }
  $tt = $form_ans;    
  foreach ($v_list_statements as $key => $value)
  {
   $subject = $value;
   list($rules,$cost) = explode("=",$subject);
    if (preg_match_all('/\d+:[A-Za-z0-9"]+/', $rules, $matches)) {
        foreach($matches[0] as $match){
            list($key2, $value2) = explode(":", $match,2);
            $rules = str_replace($match, 'in_array('.$value2.', $tt['.($key2-1).'])', $rules);
        }
        $rules = str_replace("and", "&&", $rules);
        $subject = str_replace("or", "||", $rules);
    }
    if (strlen($subject)>10) eval(" \$is_eq = ( $subject ); ");
    if ($is_eq)
    {
     return $cost;
    }
  }
}

ob_start();

//print "!<br>";

$cid=(int)$_POST['campaign'];
if(md5("ILCVF568234".$cid)!=$_POST['cvfid']) fail();

//print "!!<br>";
                                 
if (isset($_POST['email']) and !valemail($_POST['email'])) fail();
if (isset($_POST['name1']) and !valtext($_POST['name1'])) fail();
if (isset($_POST['name2']) and !valtext($_POST['name2'])) fail();
if (isset($_POST['address']) and !valtext($_POST['address'])) fail();
if (isset($_POST['city']) and !valtext($_POST['city'])) fail();
if (isset($_POST['state']) and !valtext($_POST['state'])) fail('STATE');
if (isset($_POST['zip']) and !valzip($_POST['zip'])) fail();
if (isset($_POST['country']) and !valnum($_POST['country'],1,267)) fail();
if (isset($_POST['phone']) and !valphone($_POST['phone'])) fail();
if (isset($_POST['fax']) and !valphone($_POST['fax'])) fail();

//print "!!!<br>";
$query = "SELECT C.answers,AF.selltimes FROM campaign C
LEFT JOIN account_affiliate AF ON AF.usid=C.usid
WHERE id='$cid' AND active=1 AND deleted=0 AND approved=1
AND C.usid=AF.usid";
//print "$query<br>";
$rv=mysql_query($query,$dbc);
if(mysql_num_rows($rv)!=1) fail();
$ar=mysql_fetch_array($rv);
//print "!!!!<br>";


$ar1=csvtoarray($ar['answers']);

foreach ($_POST as $k => $v)
{
if (strstr($k,'ans_')) 
{
$vls=array_map("trim",explode("\n",$ar1[$k]));
if($ar1[$k] && !in_array(trim($v),$vls)) fail();
}  
}


$ans='';

foreach ($_POST as $k => $v)
{
if (strstr($k,'ans_')) 
{
  if (is_array($_POST[$k]) and count($_POST[$k])>1)
  {
   foreach ($_POST[$k] as $k2 => $v2) $ans.=$v2.';:;';
   $ans = substr($ans,0,strlen($ans)-3).',';
  }
  else
  {
   $ans.=arraytocsv($v).',';      
  }
}
}
$ans = substr($ans,0,strlen($ans)-1);

$ref=$_SERVER["HTTP_REFERER"];
$v_selltime =  $ar['selltimes'];
$insvals = "$cid,'". $_SERVER['REMOTE_ADDR']."','".$v_selltime."','".
clearMailData($ref)."', ";
    (isset($_POST['email'])) ? ( $insvals .= " '".clearMailData($_POST['email'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['name1'])) ? ( $insvals .= " '".clearMailData($_POST['name1'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['name2'])) ? ( $insvals .= " '".clearMailData($_POST['name2'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['address'])) ? ( $insvals .= " '".clearMailData($_POST['address'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['city'])) ? ( $insvals .= " '".clearMailData($_POST['city'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['postcode'])) ? ( $insvals .= " '".clearMailData($_POST['postcode'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['state'])) ? ( $insvals .= " '".clearMailData($_POST['state'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['country'])) ? ( $insvals .=" '".clearMailData($_POST['country'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['phone'])) ? ( $insvals .= " '".clearMailData($_POST['phone'])."'," ) : ( $insvals .= "''," );
    (isset($_POST['fax'])) ? ( $insvals .= " '".clearMailData($_POST['fax'])."'," ) : ( $insvals .= "''," );    
    $insvals .= "'".clearMailData($ans)."'";
    
$selltimes=$ar['selltimes'];

$query = "SELECT value FROM filter_keywords WHERE active=1";
$rv=mysql_query($query,$dbc);
$a2=array();
$valid=1;
for($i=0; $i<mysql_num_rows($rv); $i++) {
$ar=mysql_fetch_array($rv);
if(strpos($insvals,trim($ar['value']))!=FALSE) $valid=0;
}
       $count_sold = 0;
       $sql = "SELECT start_point_sold FROM shedule s, campaign c WHERE c.ref_shedule = s.id_shedule AND c.id =".clearMailData($_POST['campaign']);
       $rv=mysql_query($sql,$dbc);
       $ar=mysql_fetch_array($rv);       
       if (strlen(trim($ar['start_point_sold']))!=0) $count_sold = $ar['start_point_sold'];

       $sql = "SELECT ref_categ FROM campaign WHERE id =".clearMailData($_POST['campaign']);
       $rv=mysql_query($sql,$dbc);
       $ar=mysql_fetch_array($rv);       
       $ref_categ = $ar['ref_categ'];       

       /*===============================================*/
        $query = "SELECT answers, template
        FROM campaign
        WHERE id='".$_POST['campaign']."'";
        $rv=mysql_query($query,$dbc);
        $ar=mysql_fetch_array($rv);

        $ar1=csvtoarray($ar['template']);
        $ar2=csvtoarray($ar['answers']);

       
$query = "INSERT INTO lead (cid,ipaddr,ttl,refer,email,inf_name1,
inf_name2,inf_addr,inf_city,inf_zip,inf_state,inf_country,
inf_phone,inf_fax,answers,valid,camp_id,status,sold,ref_category) VALUES ($insvals, '$valid','".clearMailData($_POST['campaign'])."','L',$count_sold,$ref_categ)";
mysql_query($query,$dbc);
$lid=mysql_insert_id($dbc);


if($valid) {
    
    $list_show_fields = array();
    $sql = "select fields_show from campaign where id = ".clearMailData($_POST['campaign']);
    $rv=mysql_query($sql,$dbc);    
    $v_list_show_fields = mysql_fetch_array($rv);
    $list_show_fields = explode(',',$v_list_show_fields['fields_show']);
    $send_contact = array();
    
    if (isset($_POST['email']))
    {        
     ( in_array('email',$list_show_fields )) ? 
     ( $send_contact['f_email'] = "Email : ".clearMailData($_POST['email']) ) :
     ( $send_contact['f_email'] = '' );
    }
    
    if (isset($_POST['name1']))
    {
     ( in_array('first_name',$list_show_fields) ) ? 
     ( $send_contact['f_first_name'] = "First Name : ".clearMailData($_POST['name1']) ) :
     ( $send_contact['f_first_name'] = '' );
    }
    if (isset($_POST['name2']))
    {
     ( in_array('last_name',$list_show_fields) ) ? 
     ( $send_contact['f_last_name'] = "Last Name : ".clearMailData($_POST['name2']) ) :
     ( $send_contact['f_last_name'] = '' );
    }
    if (isset($_POST['address'])) 
    {
     ( in_array('address',$list_show_fields) ) ? 
     ( $send_contact['f_address'] = "Address : ".clearMailData($_POST['address']) ) :
     ( $send_contact['f_address'] = '' );
    }
    if (isset($_POST['city'])) 
    {
     ( in_array('city',$list_show_fields) ) ? 
     ( $send_contact['f_city'] = "City : ".clearMailData($_POST['city']) ) :
     ( $send_contact['f_city'] = '' );        
    }
    if (isset($_POST['state'])) 
    {
     ( in_array('state',$list_show_fields) ) ? 
     ( $send_contact['f_state'] = "State : ".clearMailData($_POST['state']) ) :
     ( $send_contact['f_state'] = '' );
    }
    if (isset($_POST['zip'])) 
    {
     ( in_array('zip',$list_show_fields) ) ? 
     ( $send_contact['f_zip'] = "Zip : ".clearMailData($_POST['zip']) ) :
     ( $send_contact['f_zip'] );
    }
    if (isset($_POST['phone'])) 
    {
     ( in_array('phone',$list_show_fields) ) ? 
     ( $send_contact['f_phone'] = "Phone : ".clearMailData($_POST['phone']) ) :
     ( $send_contact['f_phone'] = '' );     
    }
    if (isset($_POST['fax'])) 
    {
     ( in_array('fax',$list_show_fields) ) ? 
     ( $send_contact['f_fax'] = "Fax : ".clearMailData($_POST['fax']) ) :
     ( $send_contact['f_fax'] = '' );     
    }
    if (isset($_POST['country']))
    {
 $rv=mysql_query("SELECT name FROM country where id = ".clearMailData($_POST['country']),$dbc);
 $country=mysql_fetch_array($rv);            
     ( in_array('coutry',$list_show_fields) ) ? 
     ( $send_contact['f_country'] = "Country : ".$country['name'] ) :
     ( $send_contact['f_country'] = '' );     
    }    
    for ($i=0;$i<count($ar1);$i++)
    {
     $s = explode('::',$ar1[$i]);
     $send_contact['question'.($i+1)] = $s[0];     
     $ts = '';
     foreach ($_POST['ans_'.$i] as $k => $v) $ts .= "$v,";
     $ss = $ts;
     $send_contact['answer'.($i+1)] = substr($ss,0,strlen($ss)-1);     
    }

    email_lead($lid,"Thank you for registering","newlead");

// TODO block this into runlead(), lpd, filts....                
    $sql = "SELECT C.answers,AF.selltimes, C.min_cost as min_cost, C.max_cost as max_cost FROM campaign C, account_affiliate AF
    WHERE id='$cid' AND active=1 AND deleted=0 AND approved=1
    AND C.usid=AF.usid";
    
    $rv=mysql_query($sql,$dbc);
$ar=mysql_fetch_array($rv);    
    $ttp = $ar;
    $total_solds = $v_selltime; // $ar['selltimes'];
              
    $query="SELECT AC.usid AS cuid, AF.usid AS afuid, C.cost as afcost,	C.cost*AF.ratio*AC.ratio AS ccost
	    FROM account_customer AC, customer_campaign CC, campaign C, account_affiliate AF
	    LEFT JOIN customer_lead CL ON CL.lid='$lid' AND CL.usid=AC.usid
	    WHERE CC.usid=AC.usid AND CC.cid='$cid' AND C.id=CC.cid
	    AND AC.pause=0 
            AND AC.pauseuntil<now()
	    AND C.active=1 
            AND C.deleted=0 
            AND C.approved=1
            AND AF.usid=C.usid
            AND C.cost*AF.ratio*AC.ratio<=AC.balance
	    ORDER BY AC.lastcust";    
    $rv=mysql_query($query,$dbc);
    $l_cost = $ar['ccost'];
    
    if (mysql_num_rows($rv)!=0) mysql_query("UPDATE lead SET sold = 0 WHERE id='$lid'",$dbc); 
for($i=0; $i<mysql_num_rows($rv); $i++) {
	$ar=mysql_fetch_array($rv);

        $sql = "select sold, status from lead where id='$lid'";
        $rv1=mysql_query($sql,$dbc);
    $ar1=mysql_fetch_array($rv1);    
        if ($ar1['sold']<$total_solds)
        {
//          print "<pre>";
//          print_r($_POST);
//          print "</pre>";
            

                if (isset($_POST['ans']))
                {
                 $total_lead_cost = $l_cost;
                 if (isSendMail($cid,$ar['cuid'],$_POST['ans'])) 
                 {
                     
                  $l_cost = getQuelCost($_POST['campaign']);
                  $l_cost = $l_cost + 0;                                      
                     
                  if ($total_lead_cost>=0) $l_cost = $l_cost + $total_lead_cost;                     
                  
                  if ($l_cost<$ttp['min_cost']) $l_cost = $ttp['min_cost'];
                  if ($l_cost>$ttp['max_cost']) $l_cost = $ttp['max_cost'];
                  if (config_get("autoresponse"))
                  {                     
                   email_account($ar['cuid'],"New lead","newlead",$send_contact);
                  }
                  else
                  {
                   email_account($ar['cuid'],"New lead","deliverlead",$send_contact);                      
                  }                  
	          mysql_query("INSERT INTO customer_lead (usid,lid,cost,pay,sold_as) VALUES ('".$ar['cuid']."','$lid','".$l_cost."','".
		       $ar['afcost']."','".$ar1['status']."')",$dbc);
	          mysql_query("UPDATE account_customer SET balance=balance-'".addslashes($l_cost)."', lastcust='$lid'
		       WHERE usid='".$ar['cuid']."'",$dbc);                  
                 }
                }
                else
                {   
                 $total_lead_cost = $l_cost;
                 if (isSendMail($cid,$ar['cuid'])) 
                 {
                  $l_cost = getQuelCost($_POST['campaign']);
                  $l_cost = $l_cost + 0;                                      
                     
                  if ($total_lead_cost>=0) $l_cost = $l_cost + $total_lead_cost;                     
                  
                  if ($l_cost<$ttp['min_cost']) $l_cost = $ttp['min_cost'];
                  if ($l_cost>$ttp['max_cost']) $l_cost = $ttp['max_cost'];
                  
                  if(config_get("autoresponse"))
                  {                                          
                   email_account($ar['cuid'],"New lead","newlead",$send_contact);
                  }
                  else
                  {
                   email_account($ar['cuid'],"New lead","deliverlead",$send_contact);
                  }
	          mysql_query("INSERT INTO customer_lead (usid,lid,cost,pay,sold_as) VALUES ('".$ar['cuid']."','$lid','".$l_cost."','".
		       $ar['afcost']."','".$ar1['status']."')",$dbc);
	          mysql_query("UPDATE account_customer SET balance=balance-'".addslashes($l_cost)."', lastcust='$lid'
		       WHERE usid='".$ar['cuid']."'",$dbc);                  
                 }            
                }        
	    if(config_get("autoresponse"))
            {
		    email_lead_cuc($lid,"Thank you for registering",$ar['cuid'],$cid);
            }
            /*
	    mysql_query("UPDATE account_customer SET balance=balance-'".
		    addslashes($ar['ccost'])."', lastcust='$lid'
		    WHERE usid='".$ar['cuid']."'",$dbc);
            */    
	    mysql_query("UPDATE campaign SET total_generate=total_generate+1 WHERE id='".$_POST['campaign']."'",$dbc);            
                
	    mysql_query("UPDATE account_affiliate SET balance=balance+'".
		    addslashes($ar['afcost'])."',totleads=totleads+1,
		    leads=leads+1
		    WHERE usid='".$ar['afuid']."'",$dbc);
	    mysql_query("UPDATE lead SET ttl=ttl-1, sold = sold + 1 WHERE id='$lid'",$dbc);
        }
}
// TODO up to here.
}

$query = 'select http_succes from campaign where id = '.clearMailData($_POST['campaign']);
$rv=mysql_query($query,$dbc);
$ar=mysql_fetch_array($rv);    
if (strlen(trim($ar['http_succes']))!=0)
{
     echo "
      <html>
      <head>
      <script type=\"text/javascript\">
      <!--
       window.location = '".$ar['http_succes']."';
       -->
      </script>      
      </head>
      <body></body></html>";
     exit;     
}
else
{    
echo "Thank you for your submission.\n";        
}

$PAGE['body']=ob_get_contents();
ob_end_clean();

$tl=isotope_load(array(),"templates/default.itt");
echo isotope_exec($tl,'leadpage',$PAGE);

?>

Link to comment
https://forums.phpfreaks.com/topic/82753-help-with-this-error/#findComment-421000
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.