Jump to content

Greywacke

Members
  • Posts

    19
  • Joined

  • Last visited

Everything posted by Greywacke

  1. ok success at last! i've managed to get the scvript working by modifying it as follows: // top level variables var service = -1; var ajaxloading = 0; var sid = 0; // javascript xml reading section var services = xmldoc.getElementsByTagName("service"); var arr10 = new Array(); servicearr = new Array(); for (var x = 0; x < services.length; x++) { if (services[x].attributes.getNamedItem("sid") && services[x].attributes.getNamedItem("desc") && services[x].attributes.getNamedItem("selected") && indexOf.call(servicearr,services[x].attributes.getNamedItem("sid").nodeValue)==-1) { var arr = new Array(); var aa = 0; var arr1 = new Array(); arr[0] = services[x].attributes.getNamedItem("sid").nodeValue; arr[1] = services[x].attributes.getNamedItem("desc").nodeValue; arr[2] = services[x].attributes.getNamedItem("selected").nodeValue; var i = 1; for (var c = 0; c < services[x].childNodes.length; c++) { if (services[x].childNodes[c].nodeName == "attribute" && services[x].childNodes[c].attributes.getNamedItem("id").nodeValue != undefined) { var arr2 = new Array(); arr2[0] = services[x].childNodes[c].attributes.getNamedItem("id").nodeValue; arr2[1] = services[x].childNodes[c].attributes.getNamedItem("desc").nodeValue; arr2[2] = services[x].childNodes[c].attributes.getNamedItem("val").nodeValue; arr2[3] = services[x].childNodes[c].attributes.getNamedItem("ord").nodeValue; arr2[4] = (services[x].childNodes[c].attributes.getNamedItem("ptr").nodeValue!="")?services[x].childNodes[c].attributes.getNamedItem("ptr").nodeValue:""; arr1[aa] = arr2.join(";;;"); aa++; } } arr[3] = arr1.join(";.;"); // service attributes //salert(arr); if (arr.length) { addrecord("menu_services", arr); if (arr[2]!="") document.getElementById("menu_services").selectedIndex = service; servicearr.push(arr[0]); svc = true; } } } // populating function function addrecord(id, arr) { //salert(id); //salert(arr); var opt0 = document.createElement("option"); opt0.text = arr[1]; // value 1 text service name opt0.value = arr[0] + "|;|" + // value 0 service id arr[2] + "|;|" + // save selection flag ("selected" or "") arr[3]; // save the value 3 attribute keys/values/order array string var sel = document.getElementById(id); // get the select element try { sel.add(opt0, null); // standards compliant; doesn't work in IE } catch(ex) { sel.add(opt0); // IE only } if (arr[2]!="") { sid = parseInt(arr[0]); service = sel.options.length - 1; } } as can be seen, the function sets the service top level variable to the index to be marked as selected. once the dropdown is populated by the options in the xml reader, it sets the selectedIndex if the current options arr[2] value was noticed to != "" sincerely - Pierre "Greywacke" du Toit.
  2. in an ongoing attempt to resolve this on my own while i await generous assistance from the other javascripting forum users - the ajax_attributes.js portions get updated continuously, the xml is perfect. selecting the xml and attributes is perfect. handling it in javascript is not... *facepalms* the script has sofar been updated as follows... // top level "global" variables set at top of script var sid = 0; var servicearr = new Array(); // plannned future top level variables for reading and storing the attribute ancestrees var pss = "0"; var ddcnt = 0; var keys = new Array(new Array(),new Array()); // parse services var services = xmldoc.getElementsByTagName("service"); var arr10 = new Array(); servicearr = new Array(); for (var x = 0; x < services.length; x++) { if (services[x].attributes.getNamedItem("sid") && services[x].attributes.getNamedItem("desc") && services[x].attributes.getNamedItem("selected") && indexOf.call(servicearr,services[x].attributes.getNamedItem("sid").nodeValue)==-1) { var arr = new Array(); var aa = 0; var arr1 = new Array(); arr[0] = services[x].attributes.getNamedItem("sid").nodeValue; arr[1] = services[x].attributes.getNamedItem("desc").nodeValue; arr[2] = services[x].attributes.getNamedItem("selected").nodeValue; var i = 1; for (var c = 0; c < services[x].childNodes.length; c++) { if (services[x].childNodes[c].nodeName == "attribute" && services[x].childNodes[c].attributes.getNamedItem("id").nodeValue != undefined) { var arr2 = new Array(); arr2[0] = services[x].childNodes[c].attributes.getNamedItem("id").nodeValue; arr2[1] = services[x].childNodes[c].attributes.getNamedItem("desc").nodeValue; arr2[2] = services[x].childNodes[c].attributes.getNamedItem("val").nodeValue; arr2[3] = services[x].childNodes[c].attributes.getNamedItem("ord").nodeValue; arr2[4] = (services[x].childNodes[c].attributes.getNamedItem("ptr").nodeValue!="")?services[x].childNodes[c].attributes.getNamedItem("ptr").nodeValue:""; arr1[aa] = arr2.join(";;;"); aa++; } } arr[3] = arr1.join(";.;"); // service attributes //salert(arr); if (arr.length) { addrecord("menu_services", arr); servicearr.push(arr[0]); svc = true; } } } as for the xml - it is still without errors, and is still generated as follows. <root> <service sid="10" desc="Accounting Bookkeeping" selected="">...</service> <service sid="1" desc="Bakkie Canopy" selected="selected">...</service> <service sid="3" desc="Bakkie Canopy Accessories" selected=""></service> <service sid="2" desc="Bakkie Linings & Rubberizing" selected=""></service> <service sid="15" desc="Broadband Internet" selected="">...</service> <service sid="5" desc="Business Phone Systems" selected="">...</service> <service sid="9" desc="Company Registrations" selected="">...</service> <service sid="11" desc="Conference Venues" selected="">...</service> <service sid="8" desc="Debt Collection Agencies" selected="">...</service> <service sid="17" desc="Office Coffee" selected="">...</service> <service sid="7" desc="Office Colour Printers" selected="">...</service> <service sid="12" desc="Office Furniture" selected="">...</service> <service sid="13" desc="Office Movers" selected="">...</service> <service sid="14" desc="Office Network Cabling" selected="">...</service> <service sid="6" desc="Office Printers & Copiers" selected="">...</service> <service sid="16" desc="Office Water" selected="">...</service> <service sid="4" desc="Placeholder" selected=""></service> <sql/> </root> obviously, this abbreviated excerpt comes from google chrome's view of the file, which has the following header info: <?xml version="1.0" encoding="utf-8"?> if nobody wants to help then it's also fine - i am getting there as fast as possible under the current circuimstances - unfortunately it makes for a stressful job where i do not get paid till it is complete sincerely - Pierre "Greywacke" du Toit.
  3. hi all! first let me be clear - the ajax skeletal of the script is not the issue here. I have been working through night to ensure those portions are all functioning properly. i successfully load an xml document with the value of selected for each service, eiter displayed as selected or a blank string. however - when i attempt to select the selected service (in memory) in the dropdown after refreshing the xml, it selects nothing... could an bright sparks perhaps assist me in locating and resolving the issue? below is the relevant javascript portions: // parse services xml (this works perfectly so please do not think it is at fault if "unable to see the forest for the lemons") var services = xmldoc.getElementsByTagName("service"); var arr10 = new Array(); servicearr = new Array(); for (var x = 0; x < services.length; x++) { if (services[x].attributes.getNamedItem("sid") && services[x].attributes.getNamedItem("desc") && services[x].attributes.getNamedItem("selected") && indexOf.call(servicearr,services[x].attributes.getNamedItem("sid").nodeValue)==-1) { var arr = new Array(); var aa = 0; var arr1 = new Array(); arr[0] = services[x].attributes.getNamedItem("sid").nodeValue; arr[1] = services[x].attributes.getNamedItem("desc").nodeValue; arr[2] = services[x].attributes.getNamedItem("selected").nodeValue; var i = 1; for (var c = 0; c < services[x].childNodes.length; c++) { if (services[x].childNodes[c].nodeName == "attribute" && services[x].childNodes[c].attributes.getNamedItem("id").nodeValue != undefined) { var arr2 = new Array(); arr2[0] = services[x].childNodes[c].attributes.getNamedItem("id").nodeValue; arr2[1] = services[x].childNodes[c].attributes.getNamedItem("desc").nodeValue; arr2[2] = services[x].childNodes[c].attributes.getNamedItem("val").nodeValue; arr2[3] = services[x].childNodes[c].attributes.getNamedItem("ord").nodeValue; arr2[4] = (services[x].childNodes[c].attributes.getNamedItem("ptr").nodeValue!="")?services[x].childNodes[c].attributes.getNamedItem("ptr").nodeValue:""; arr1[aa] = arr2.join(";;;"); aa++; } } arr[3] = arr1.join(";.;"); // service attributes //salert(arr); if (arr.length) { addrecord("menu_services", arr); servicearr.push(arr[0]); svc = true; } } } // single addrecord function function addrecord(id, arr) { salert(id); salert(arr[0]); salert(arr[1]); salert(arr[2]); var opt0 = document.createElement("option"); //salert(arr[i]); opt0.text = arr[1]; // value 1 text service name opt0.value = arr[0] + "|;|" + // value 0 service id arr[2] + "|;|" + // save selection flag ("selected" or "") arr[3]; // save the value 3 attribute keys/values/order array string opt0.selected = (arr[2]=="selected")?true:false; var sel = document.getElementById(id); try { sel.add(opt0, null); // standards compliant; doesn't work in IE } catch(ex) { sel.add(opt0); // IE only } if (arr[2] == "selected") { sid = arr[0]; // save sid if selected! //sel.selectedIndex = sel.options.length-1; } } to prove that the xml loads correctly - here is an excerpt with the Bakky Canopy service... <root> <service sid="10" desc="Accounting Bookkeeping" selected="">...</service> <service sid="1" desc="Bakkie Canopy" selected="selected">...</service> <service sid="3" desc="Bakkie Canopy Accessories" selected=""></service> <service sid="2" desc="Bakkie Linings & Rubberizing" selected=""></service> <service sid="15" desc="Broadband Internet" selected="">...</service> <service sid="5" desc="Business Phone Systems" selected="">...</service> <service sid="9" desc="Company Registrations" selected="">...</service> <service sid="11" desc="Conference Venues" selected="">...</service> <service sid="8" desc="Debt Collection Agencies" selected="">...</service> <service sid="17" desc="Office Coffee" selected="">...</service> <service sid="7" desc="Office Colour Printers" selected="">...</service> <service sid="12" desc="Office Furniture" selected="">...</service> <service sid="13" desc="Office Movers" selected="">...</service> <service sid="14" desc="Office Network Cabling" selected="">...</service> <service sid="6" desc="Office Printers & Copiers" selected="">...</service> <service sid="16" desc="Office Water" selected="">...</service> <service sid="4" desc="Placeholder" selected=""></service> <sql/> </root> as can be seen in the xml and javascript - the service id 1 should load as default selected service id... i am hereby requesting javascripters with great insightto see what i do not - the services all load, but none are selected in the html web form. many thanks in advance to the one (or more) whom with crystal clarity, can resolve this. sincerely - Pierre "Greywacke" du Toit
  4. ok awesome thanks jazzman1! XD by replacing the unescaped caret and dollar signs with [\r\n]*, the regex query now works strange that it always did then not anymore though...
  5. ok i understand but the m switch at the end allows one to do multiline selections (eg over \r\n characters... your string does not have them... this is making me think that i need to remove the caret and $ from the beginnning and end of the substrings, in order to get the correct selection?
  6. when searching for the following regex string in notepad++ - it gets the matches on the correct places of the document parsed (performatix.php) ^\$conn \= mysql_connect\("([a-zA-Z._0-9\-]+)", "([a-zA-Z_0-9]+)", "([a-zA-Z_0-9]+)"\);$|^mysql_select_db\("([a-zA-Z_0-9]+)", \$conn\);$|^date_default_timezone_set\([\'"]([A-Za-z0-9\/+\-]+)[\'"]\);$|^\$GLOBALS\["dtmstyle"\] \= "([^"]+)";$|^\$GLOBALS\["dtlast"\] \= ([0|1]);$|^\$GLOBALS\["prod_prodmode"\] \= ([0|1]); \/\/ [a-z ]+$|^\$GLOBALS\["prod_prodmail"\] \= "([^@]+@[^"]+)";$|^\$GLOBALS\["curl"\] \= ([0|1]);$|^\$GLOBALS\["conn_timeout"\] \= ([0-9]+);$|^\$GLOBALS\["post_timeout"\] \= ([0-9]+);$|^\$GLOBALS\["ssl_enabled"\] \= ([0|1]);$ however - when i try to match within php using preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER), i keep getting the array of empty arrays. 11 in length though... in notepad++ it matches on the = in the strings, wether escaped or not. is there something i am missing here? 0o
  7. those are | separated derivatives, thus the preg_mach_all does a or between them (see the | between the preg pattern lines, at the start of each line? the escaped = is due to what a server admin said (who does not really know preg though, but i am certain something is limiting the array return values... sofar it seems to be a php directive that is limiting the results returned. as far as i am aware, an unescaped $ means "end of line" in a preg pattern, as ^ means start of line... the m switch at the end, is for multiline regex... as g usually is used for global matching.
  8. there is currently an issue on server - that it won't print multidimentional arrays deeper than depth 1. for example $arr returns the following (when using var_export() as opposed to print_r()): array ( 0 => array ( ), 1 => array ( ), 2 => array ( ), 3 => array ( ), 4 => array ( ), 5 => array ( ), 6 => array ( ), 7 => array ( ), 8 => array ( ), 9 => array ( ), 10 => array ( ), 11 => array ( ), 12 => array ( ), 13 => array ( ), ) for $pattern: $pattern = '/^\$conn = mysql_connect\("([a-zA-Z._0-9\-]+)", "([a-zA-Z_0-9]+)", "([a-zA-Z_0-9]+)"\);$'. '|^mysql_select_db\("([a-zA-Z_0-9]+)", \$conn\);$'. '|^date_default_timezone_set\([\'"]([A-Za-z0-9\/+\-]+)[\'"]\);$'. '|^\$GLOBALS\["dtmstyle"\] \= "([^"]+)";$'. '|^\$GLOBALS\["dtlast"\] \= ([0|1]);$'. '|^\$GLOBALS\["prod_prodmode"\] \= ([0|1]); \/\/ [a-z ]+$'. '|^\$GLOBALS\["prod_prodmail"\] \= "([^@]+@[^"]+)";$'. '|^\$GLOBALS\["curl"\] \= ([0|1]);$'. '|^\$GLOBALS\["conn_timeout"\] \= ([0-9]+);$'. '|^\$GLOBALS\["post_timeout"\] \= ([0-9]+);$'. '|^\$GLOBALS\["ssl_enabled"\] \= ([0|1]);$/m'; $connstr is a bit too long though, to put here - plus it contains quite a bit of confidential information. but 13 matches means its matching the strings - i just have to locate the ini setting to get the max array depth set on php 5.3.10... Suhosin's settings are all fine. sincerely, Pierre du Toit.
  9. ok with the following code <?php include("production/includes/content/performatix.php"); header("Cache-Control: no-store"); header("Content-type: text/xml; charset=utf-8"); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; echo "<root>\n"; function getdbconfig($file = "") { if ($_GLOBALS["ssl_enabled"] == 1 && ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) || $_GLOBALS["ssl_enabled"] == 0) { $pattern = '/^\$conn = mysql_connect\("([a-zA-Z._0-9\-]+)", "([a-zA-Z_0-9]+)", "([a-zA-Z_0-9]+)"\);$'. '|^mysql_select_db\("([a-zA-Z_0-9]+)", \$conn\);$'. '|^date_default_timezone_set\([\'"]([A-Za-z0-9\/+\-]+)[\'"]\);$'. '|^\$GLOBALS\["dtmstyle"\] = "([^"]+)";$'. '|^\$GLOBALS\["dtlast"\] = ([0|1]);$'. '|^\$GLOBALS\["prod_prodmode"\] = ([0|1]); \/\/ [a-z ]+$'. '|^\$GLOBALS\["prod_prodmail"\] = "([^@]+@[^"]+)";$'. '|^\$GLOBALS\["curl"\] = ([0|1]);$'. '|^\$GLOBALS\["conn_timeout"\] = ([0-9]+);$'. '|^\$GLOBALS\["post_timeout"\] = ([0-9]+);$'. '|^\$GLOBALS\["ssl_enabled"\] = ([0|1]);$/m'; $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); $arr = array(); if (preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER)!==false) { echo " <sql>".print_r($arr,true)."</sql>\n"; echo " <conn dbsrvr=\"".$arr[1][6]."\" dbname=\"".$arr[4][7]."\" user=\"".$arr[2][6]."\" pass=\"".$arr[3][6]."\" php_tz=\"".$arr[5][10]."\" php_dtf=\"".$arr[6][8]."\" php_dta=\"".$arr[7][9]."\" pt_on=\"".$arr[8][0]."\" pt_mail=\"".$arr[9][1]."\" curl=\"".$arr[10][2]."\" cto=\"".$arr[11][3]."\" pto=\"".$arr[12][4]."\" ssl=\"".$arr[13][5]."\" />\n"; echo " <sql>".xmlentities(print_r($connstr,true))."</sql>\n"; } else { echo " <error>NO PREG MATCH FOUND!</error>\n"; } } else { $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; header("Location: $redirect"); } } getdbconfig("production/includes/content/performatix.php"); echo "</root>"; ?> i've managed to get the following: <?xml version="1.0" encoding="utf-8"?> <root> <sql>Array ( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) [3] => Array ( ) [4] => Array ( ) [5] => Array ( ) [6] => Array ( ) [7] => Array ( ) [8] => Array ( ) [9] => Array ( ) [10] => Array ( ) [11] => Array ( ) [12] => Array ( ) [13] => Array ( ) ) </sql> <conn dbsrvr="" dbname="" user="" pass="" php_tz="" php_dtf="" php_dta="" pt_on="" pt_mail="" curl="" cto="" pto="" ssl="" /> <sql><?php\r\n/*\r\nMYSQL CONNECTION INCLUDE\r\nVersion 2.2.5\r\n*/\r\n// set error log files\r\nmb_internal_encoding("UTF-8");\r\nini_set('log_errors', 1);\r\nini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');\r\nini_set('html_errors', 0);\r\nini_set('display_errors', 0); // has to be off so lead managers do not return invalid xml!\r\n$GLOBALS["prod_prodmode"] = 0; // enable to send to production test email\r\n$GLOBALS["prod_prodmail"] = "*****@*****.***";\r\n$GLOBALS["curl"] = 1;\r\n$GLOBALS["conn_timeout"] = 15;\r\n$GLOBALS["post_timeout"] = 30;\r\n$GLOBALS["ssl_enabled"] = 0;\r\n$sql = array();\r\n$urlencode = false;\r\nerror_reporting(E_ALL);\r\n//$conn = mysql_connect("*****", "*****", "*****");\r\n$conn = mysql_connect("*****", "*****", "*****");\r\nif (!$conn) {\r\n $err = "ERROR #".mysql_errno()."Could not connect: ".mysql_error()." in ".$doc." on Line ".$line;\r\n array_push($GLOBALS["sql"],$err."\n");\r\n} else {\r\n mysql_query("SET NAMES utf8;",$conn);\r\n}\r\nfunction mysql_query_errors($sql, $conn, $doc, $line, $expret = false) {\r\n $line--;\r\n $err = "";\r\n $result = false;\r\n global $conn;\r\n $msc = microtime(true);\r\n $result = mysql_query($sql,$conn);\r\n $msc = microtime(true)-$msc;\r\n if (mysql_errno()) {\r\n $err = "ERROR #".mysql_errno().": ".mysql_error()." in ".$doc." on Line ".$line;\r\n array_push($GLOBALS["sql"],$sql."\n",$err."\n",'$_SESSION = '.print_r($_SESSION,true),print_r($_POST,true),"Line ".$line." in ".$doc." executed in ".$msc." seconds.\n");\r\n } elseif ($expret === true) {\r\n if ($msc >= 1) {\r\n $err = "NOTICE #0505: The query in ".$doc." on line ".$line--." executed in ".$msc." milliseconds.";\r\n } elseif (is_null($result)) {\r\n $err = "NOTICE #0504: A null value was returned by the query defined in ".$doc." on line ".$line--;\r\n } elseif (!isset($result)) {\r\n $err = "NOTICE #0503: An undefined value was returned by the query defined in ".$doc." on line ".$line--;\r\n } elseif ($result === false) {\r\n $err = "NOTICE #0502: A false value was returned by the query defined in ".$doc." on line ".$line--;\r\n } elseif ($result === true) {\r\n $err = "NOTICE #0501: A true value was returned by the query defined in ".$doc." on line ".$line--;\r\n } elseif (mysql_num_rows($result) < 1) {\r\n $err = "NOTICE #0500: An empty result set was returned by the query defined in ".$doc." on line ".$line--;\r\n }\r\n array_push($GLOBALS["sql"],$sql."\n",$err."\n",'$_SESSION = '.print_r($_SESSION,true),"\$_POST = ".print_r($_POST,true),"Line ".$line." in ".$doc." executed in ".$msc." seconds.\n");\r\n }\r\n return $result;\r\n}\r\nfunction getFile($filename) {\r\n $return = '';\r\n if (@filesize($filename)) {\r\n if ($fp = fopen($filename,'r')) {\r\n $return = fread($fp, filesize($filename));\r\n fclose($fp);\r\n return $return;\r\n } else {\r\n return false;\r\n }\r\n } else {\r\n return file_get_contents($filename);\r\n }\r\n}\r\nfunction do_post_request($url, $data, $options = array()) {\r\n $old = ini_set('default_socket_timeout', $GLOBALS["conn_timeout"]);\r\n $params = array('http' => array(\r\n 'method' => 'post',\r\n 'content' => (is_array($data))?http_build_query($data):$data\r\n )\r\n );\r\n if(isset($options['Referer']) && isset($options['User-Agent']) && isset($options['Username']) && isset($options['Password'])) {\r\n $params['http']['authorisation'] = $options['Username'].':'.$options['Password'];\r\n $params['http']['user-agent'] = $options['User-Agent'];\r\n $params['http']['referer'] = $options['Referer'];\r\n }\r\n $ctx = stream_context_create($params);\r\n $fp = @fopen($url, 'rb', false, $ctx);\r\n ini_set('default_socket_timeout', $old);\r\n stream_set_timeout($fp, $GLOBALS["post_timeout"]);\r\n if (!$fp) {\r\n trigger_error("Problem with ".$url.", ".$php_errormsg);\r\n }\r\n $response = @stream_get_contents($fp);\r\n $info = stream_get_meta_data($fp);\r\n fclose($fp);\r\n if ($info['timed_out']) {\r\n return 'Connection timed out!';\r\n } else {\r\n if ($response === false) {\r\n trigger_error("Problem reading data from ".$url.", ".$php_errormsg);\r\n }\r\n return $response;\r\n }\r\n}\r\nfunction curl_post($url, $post = array(), array $options = array()) {\r\n $user_agent='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36';\r\n \r\n $defaults = array(\r\n CURLOPT_POST => 1,\r\n CURLOPT_USERAGENT => $user_agent,\r\n CURLOPT_HEADER => 0,\r\n CURLOPT_VERBOSE => 1,\r\n CURLOPT_TIMEOUT => $GLOBALS["post_timeout"],\r\n CURLOPT_CONNECTTIMEOUT => $GLOBALS["conn_timeout"],\r\n CURLOPT_FRESH_CONNECT => 1,\r\n CURLOPT_RETURNTRANSFER => 1,\r\n CURLOPT_FORBID_REUSE => 0,\r\n CURLOPT_URL => $url,\r\n CURLOPT_POSTFIELDS => (is_array($post))?http_build_query($post):$post,\r\n CURLOPT_ENCODING => "", // handle all encodings\r\n CURLOPT_AUTOREFERER => true, // set referer on redirect\r\n CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect\r\n CURLOPT_TIMEOUT => 120, // timeout on response\r\n CURLOPT_MAXREDIRS => 10, // stop after 10 redirects\r\n );\r\n $opts = array();\r\n if(isset($options['Referer']) && isset($options['User-Agent']) && isset($options['Username']) && isset($options['Password'])) {\r\n $opts = array(\r\n CURLOPT_USERPWD => $options['Username'].':'.$options['Password'],\r\n CURLOPT_USERAGENT => $options['User-Agent'],\r\n CURLOPT_REFERER => $options['Referer']\r\n );\r\n }\r\n \r\n $ch = curl_init();\r\n curl_setopt_array($ch, ($opts + $defaults));\r\n $content = curl_exec($ch);\r\n $err = curl_errno($ch);\r\n $errmsg = curl_error($ch);\r\n $header = curl_getinfo($ch);\r\n curl_close($ch);\r\n \r\n $header['errno'] = $err;\r\n $header['errmsg'] = $errmsg;\r\n $header['content'] = $content;\r\n return $header;\r\n}\r\nfunction get_web_page($method="GET", $url="http://www.google.com/") {\r\n $user_agent='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36';\r\n\r\n $options = array(\r\n CURLOPT_HTTPAUTH => CURLAUTH_BASIC, // set authtype\r\n CURLOPT_USERPWD => "quomoto:qu0m0t0", // set htaccess details\r\n CURLOPT_CUSTOMREQUEST => $method, // set request type post or get\r\n CURLOPT_POST => ($method=="GET")?false:true, // set to GET (false) or POST (true)\r\n CURLOPT_USERAGENT => $user_agent, // set user agent\r\n CURLOPT_COOKIEFILE => "cookie.txt", // set cookie file\r\n CURLOPT_COOKIEJAR => "cookie.txt", // set cookie jar\r\n CURLOPT_RETURNTRANSFER => true, // return web page\r\n CURLOPT_HEADER => true, // don't return headers\r\n CURLOPT_FOLLOWLOCATION => true, // follow redirects\r\n CURLOPT_ENCODING => "", // handle all encodings\r\n CURLOPT_AUTOREFERER => true, // set referer on redirect\r\n CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect\r\n CURLOPT_TIMEOUT => 120, // timeout on response\r\n CURLOPT_MAXREDIRS => 10, // stop after 10 redirects\r\n );\r\n\r\n $ch = curl_init($url);\r\n curl_setopt_array($ch, $options);\r\n $content = curl_exec($ch);\r\n $err = curl_errno($ch);\r\n $errmsg = curl_error($ch);\r\n $header = curl_getinfo($ch);\r\n curl_close($ch);\r\n\r\n $header['errno'] = $err;\r\n $header['errmsg'] = $errmsg;\r\n $header['content'] = $content;\r\n return $header;\r\n}\r\n// Make OnePage CRM API call\r\nfunction make_api_call($url, $http_method, $post_data = array(), $uid = null, $key = null, $v3 = false) {\r\n $full_url = 'https://app.onepagecrm.com/api/'.$url;\r\n $ch = curl_init($full_url);\r\n //curl_setopt($ch, CURLOPT_TIMEOUT, 0);\r\n //curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);\r\n curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\r\n curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_method);\r\n $timestamp = time();\r\n $auth_data = array($uid, $timestamp, $http_method, sha1($full_url));\r\n // For POST and PUT methods we have to calculate request body hash\r\n if($http_method == 'POST' || $http_method == 'PUT'){\r\n $post_query = http_build_query($post_data);\r\n curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);\r\n $auth_data[] = sha1($post_query);\r\n }\r\n // Auth headers\r\n if($uid != null){ // We are logged in\r\n $hash = hash_hmac('sha256', implode('.', $auth_data), $key);\r\n curl_setopt($ch, CURLOPT_HTTPHEADER, array(\r\n "X-OnePageCRM-UID: $uid",\r\n "X-OnePageCRM-TS: $timestamp",\r\n "X-OnePageCRM-Auth: $hash"\r\n ));\r\n }\r\n $result = json_decode(curl_exec($ch));\r\n if($ret = curl_errno($ch)) {\r\n $info = curl_getinfo($ch);\r\n return 'CURL ERROR '.$ret.': '.curl_error($ch).' \r'.print_r($info,true);\r\n }\r\n curl_close($ch);\r\n if($result->status > 99){\r\n return print_r("API call error {$result->status} - {$result->message}\n",true);\r\n }\r\n return $result;\r\n}\r\nfunction xmlentities($value) {\r\n //replace $value's invalid xml characters with entities and unicode characters\r\n // used with Hex NCR's (Hexadecimal Numeric Character Representations).\r\n $patterns = array(\r\n '/&/', // ampersand symbol\r\n '/\r/', // carriage return\r\n '/\n/', // line feed\r\n '/</', // less than symbol\r\n '/>/', // greater than symbol\r\n '/"/', // double quotation mark\r\n '//', // SOH symbol\r\n '/©/', // (c) copyright symbols\r\n '/ë/', // e with diaresis\r\n '/è/', // e with grave\r\n '/é/', // e with acute\r\n '/"/', // left slanting double quotation mark\r\n '/"/' // right slanting double quotation mark\r\n );\r\n $replacements = array(\r\n '&amp;',\r\n '\r',\r\n '\n',\r\n '&lt;',\r\n '&gt;',\r\n '&quot;',\r\n '',\r\n '&#x00A9;',\r\n '&#x00EB;',\r\n '&#x00E8;',\r\n '&#x00E9;',\r\n '&#x201C;',\r\n '&#x201D;'\r\n );\r\n $value = utf8_encode_deep($value); // convert string to unicode to replace characters\r\n $value = preg_replace($patterns, $replacements, $value);\r\n return $value;\r\n}\r\nfunction utf8_encode_deep($input) {\r\n if (is_string($input)) {\r\n $input = mb_convert_encoding($input, 'UTF-8');\r\n //$input = utf8_encode($input);\r\n } else if (is_array($input)) {\r\n foreach ($input as &$value) {\r\n $value = utf8_encode_deep($value);\r\n }\r\n unset($value);\r\n } else if (is_object($input)) {\r\n $vars = array_keys(get_object_vars($input));\r\n foreach ($vars as $var) {\r\n $input->$var = utf8_encode_deep($input->$var);\r\n }\r\n }\r\n return $input;\r\n}\r\nfunction idflags($input) {\r\n global $conn;\r\n foreach ($input as $in) {\r\n // use to explode by first space if found, to get flag values\r\n $in = preg_split("/ |&nbsp;/",$in,2,PREG_SPLIT_NO_EMPTY);\r\n // print result array\r\n // print_r($in);\r\n // build and return the values to replace with\r\n // state & country variable texts\r\n switch (strip_tags($in[0])) {\r\n // lead form flags\r\n case "SOURCE":\r\n return ($GLOBALS["formfromname"])?$GLOBALS["formfromname"]:$GLOBALS["source"];\r\n break;\r\n case "FORMFROMNAME":\r\n return ($GLOBALS["usedefault"])?$GLOBALS["defaultfromname"]:$GLOBALS["formfromname"];\r\n break;\r\n case "FORMFROMCAPS":\r\n return ($GLOBALS["usedefault"])?strtoupper($GLOBALS["defaultfromname"]):strtoupper($GLOBALS["formfromname"]);\r\n break;\r\n case "FORMFROMABBREV":\r\n if (preg_match_all("/[A-Z]+/",($GLOBALS["usedefault"])?$GLOBALS["defaultname"]:$GLOBALS["formname"],$matches)) {\r\n return implode("",$matches[0]);\r\n } else {\r\n return "NA";\r\n }\r\n break;\r\n // mail configurable flags\r\n case "COUNTRY":\r\n return $GLOBALS["country"];\r\n break;\r\n case "STATE":\r\n return $GLOBALS["state"];\r\n break;\r\n case "DISTANCE":\r\n return number_format($GLOBALS["recipient"][14],0);\r\n break;\r\n case "TAFURL":\r\n return ($GLOBALS["usedefault"])?$GLOBALS["defurl"]:$GLOBALS["tafurl"];\r\n break;\r\n case "TAFIMG":\r\n return ($GLOBALS["usedefault"])?$GLOBALS["defimg"]:$GLOBALS["tafimg"];\r\n break;\r\n case "LOGO":\r\n return ($GLOBALS["usedefault"])?$GLOBALS["defaultlogo"]:$GLOBALS["formlogo"];\r\n break;\r\n case "FORMNAME":\r\n return ($GLOBALS["usedefault"])?$GLOBALS["defaultname"]:$GLOBALS["formname"];\r\n break;\r\n case "CRONLRSUBJECT":\r\n if ($GLOBALS["limit"]=="UPPER") {\r\n return "%CONFIGTEXT Cron | Supplier | Notification | Header | Low%";\r\n } elseif ($GLOBALS["limit"]=="LOWER") {\r\n return "%CONFIGTEXT Cron | Supplier | Notification | Header | Very Low%";\r\n }\r\n break;\r\n case "CRONSTATESUBJECT":\r\n if ($GLOBALS["limit"]=="MONTHLY") {\r\n if ($GLOBALS["recipient"][10] == 0) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Header | Monthly | Premium%";\r\n } else {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Header | Monthly | Freemium%";\r\n }\r\n } elseif ($GLOBALS["limit"]=="WEEKLY") {\r\n if ($GLOBALS["recipient"][10] == 0) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Header | Weekly | Premium%";\r\n } else {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Header | Weekly | Trial%";\r\n }\r\n } elseif ($GLOBALS["limit"]=="MANUAL") {\r\n if ($GLOBALS["recipient"][10] == 0) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Header | Monthly | Premium%";\r\n } else {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Header | Monthly | Freemium%";\r\n }\r\n }\r\n break;\r\n case "CRONSTATEMESSAGE":\r\n if ($GLOBALS["limit"]=="MONTHLY") {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Monthly | Premium%";\r\n } elseif ($GLOBALS["limit"]=="WEEKLY") {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Weekly | Premium%";\r\n } elseif ($GLOBALS["limit"]=="MANUAL") {\r\n if (strlen($_POST["textarea_transactionmessage"]) > 0) {\r\n return preg_replace(array("/\n\r/","/\n/"),"<br />\n",xmlentities($_POST["textarea_transactionmessage"]));\r\n } else {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Weekly | Premium%";\r\n }\r\n }\r\n break;\r\n case "CRONSTATEFMESSAGE":\r\n if ($GLOBALS["limit"]=="MONTHLY") {\r\n if ($GLOBALS["recipient"][10] == 4) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Monthly | Freemium%";\r\n } elseif ($GLOBALS["recipient"][10] == 2) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Monthly | Trial%";\r\n }\r\n } elseif ($GLOBALS["limit"]=="WEEKLY") {\r\n if ($GLOBALS["recipient"][10] == 4) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Weekly | Freemium%";\r\n } elseif ($GLOBALS["recipient"][10] == 2) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Weekly | Trial%";\r\n }\r\n } elseif ($GLOBALS["limit"]=="MANUAL") {\r\n if (strlen($_POST["textarea_transactionmessage"]) > 0) {\r\n return preg_replace(array("/\n\r/","/\n/"),"<br />\n",xmlentities($_POST["textarea_transactionmessage"]));\r\n } else {\r\n if ($GLOBALS["recipient"][10] == 4) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Monthly | Freemium%";\r\n } elseif ($GLOBALS["recipient"][10] == 2) {\r\n return "%CONFIGTEXT Cron | Supplier | Statement | Message | Monthly | Trial%";\r\n }\r\n }\r\n }\r\n break;\r\n case "LEADSLIST":\r\n return $GLOBALS["transactions"];\r\n break;\r\n case "LIMITMESSAGE":\r\n if ($GLOBALS["limit"]=="UPPER") {\r\n return "%CONFIGTEXT Cron | Supplier | Notification | Message | Low%";\r\n } elseif ($GLOBALS["limit"]=="LOWER") {\r\n return "%CONFIGTEXT Cron | Supplier | Notification | Message | Very Low%";\r\n }\r\n break;\r\n case "RESPONSESIGNATURE":\r\n return "%CONFIGTEXT Email | Consumer | Message | Signature%";\r\n break;\r\n case "PREMIUMSUBJECT":\r\n return "%CONFIGTEXT Email | Supplier | Premium | Header%";\r\n break;\r\n case "PREMIUMINTRO":\r\n return "%CONFIGTEXT Email | Supplier | Premium | Message | Intro%";\r\n break;\r\n case "PREMIUMSIGNATURE":\r\n return "%CONFIGTEXT Email | Supplier | Premium | Message | Signature%";\r\n break;\r\n case "FREEMIUMSUBJECT":\r\n return "%CONFIGTEXT Email | Supplier | Freemium | Header%";\r\n break;\r\n case "FREEMIUMINTRO":\r\n return "%CONFIGTEXT Email | Supplier | Freemium | Message | Intro%";\r\n break;\r\n case "FREEMIUMSIGNATURE":\r\n return "%CONFIGTEXT Email | Supplier | Freemium | Message | Signature%";\r\n break;\r\n case "RESPONSEMESSAGES":\r\n $msg = ((implode("",$GLOBALS["suppliers"]))?" %CONFIGTEXT Email | Consumer | Message | Intro Premium%":"").\r\n ((implode("",$GLOBALS["supplierp"]))?" %CONFIGTEXT Email | Consumer | Message | Intro Freemium%":"");\r\n return $msg;\r\n break;\r\n // lead value determination flags\r\n case "LVDKEYWEIGHT":\r\n return round(floatval($GLOBALS["lvdkeyarr"][$in[1]])/1*100,3);\r\n break;\r\n case "LVDVALUEWEIGHT":\r\n return round(floatval($GLOBALS["lvdvalarr"][$in[1]])/10*100,3);\r\n break;\r\n case "LVDSCORE":\r\n $GLOBALS["lvdkeyarr"] = array();\r\n $GLOBALS["lvdvalarr"] = array();\r\n $GLOBALS["calc"] = 1;\r\n $GLOBALS["lvdtot"] = 0.000;\r\n foreach ($GLOBALS["attribsarr"] as $key => $value) {\r\n $glue = '/ \| /';\r\n if (preg_match($glue,$value)>0) {\r\n $values = preg_split($glue, $value);\r\n //array_push($GLOBALS["sql"],$values);\r\n $x = 0;\r\n $constraint = "";\r\n foreach ($values as $val) {\r\n $constraint .= (($x>=1)?" OR ":"")."SA0.text_AttributeValue = \"".mysql_escape_string($val)."\" AND SA0.text_AttributeDescription = \"".mysql_escape_string($key)."\"";\r\n $x++;\r\n }\r\n $tsql = "SELECT \r\n LVD.double_AttributeKeyWeighting, \r\n SA0.double_AttributeValueWeighting, \r\n SA0.text_AttributeDescription, \r\n SA0.text_AttributeValue \r\n FROM \r\n 3_serviceattributes SA0 \r\n LEFT JOIN \r\n 42_leadvaluedetermination LVD \r\n ON LVD.bigint_AttributeID = (\r\n SELECT \r\n SA1.bigint_AttributeID \r\n FROM \r\n 3_serviceattributes SA1 \r\n WHERE \r\n SA1.text_AttributeDescription = SA0.text_AttributeDescription AND \r\n SA1.bigint_AttributeServiceID = SA0.bigint_AttributeServiceID \r\n ORDER BY \r\n SA1.bigint_AttributeID ASC LIMIT 1\r\n ) \r\n WHERE LVD.double_AttributeKeyWeighting > 0 \r\n AND SA0.double_AttributeValueWeighting > 0 \r\n AND SA0.bigint_AttributeServiceID = ".$GLOBALS["service"]." \r\n AND (\r\n ".$constraint." \r\n ) \r\n ORDER BY SA0.double_AttributeValueWeighting DESC LIMIT 1;";\r\n //array_push($GLOBALS["sql"],$tsql);\r\n $result = mysql_query_errors($tsql, $conn, __FILE__, __LINE__);\r\n if ($result) {\r\n if ($row = mysql_fetch_array($result)) {\r\n $GLOBALS["lvdkeyarr"][$key] = floatval($row["double_AttributeKeyWeighting"]);\r\n $GLOBALS["lvdvalarr"][$value] = floatval($row["double_AttributeValueWeighting"]);\r\n }\r\n }\r\n $GLOBALS["lvdtot"] += round($GLOBALS["lvdkeyarr"][$key]*$GLOBALS["lvdvalarr"][$value],3);\r\n } else {\r\n $tsql = "SELECT \r\n LVD.double_AttributeKeyWeighting, \r\n SA0.double_AttributeValueWeighting, \r\n SA0.text_AttributeDescription, \r\n SA0.text_AttributeValue \r\n FROM \r\n 3_serviceattributes SA0 \r\n LEFT JOIN \r\n 42_leadvaluedetermination LVD \r\n ON LVD.bigint_AttributeID = (\r\n SELECT \r\n SA1.bigint_AttributeID \r\n FROM \r\n 3_serviceattributes SA1 \r\n WHERE \r\n SA1.text_AttributeDescription = SA0.text_AttributeDescription AND \r\n SA1.bigint_AttributeServiceID = SA0.bigint_AttributeServiceID \r\n ORDER BY \r\n SA1.bigint_AttributeID ASC LIMIT 1\r\n ) \r\n WHERE LVD.double_AttributeKeyWeighting > 0 \r\n AND SA0.double_AttributeValueWeighting > 0 \r\n AND SA0.bigint_AttributeServiceID = ".$GLOBALS["service"]." \r\n AND (\r\n SA0.text_AttributeDescription = \"".mysql_escape_string($key)."\" \r\n AND SA0.text_AttributeValue = \"".mysql_escape_string($value)."\"\r\n ) \r\n ORDER BY SA0.double_AttributeValueWeighting DESC LIMIT 1;";\r\n $result = mysql_query_errors($tsql, $conn, __FILE__, __LINE__);\r\n if ($result) {\r\n if ($row = mysql_fetch_array($result)) {\r\n $GLOBALS["lvdkeyarr"][$key] = floatval($row["double_AttributeKeyWeighting"]);\r\n $GLOBALS["lvdvalarr"][$value] = floatval($row["double_AttributeValueWeighting"]);\r\n }\r\n }\r\n $GLOBALS["lvdtot"] += round($GLOBALS["lvdkeyarr"][$key]*$GLOBALS["lvdvalarr"][$value],3);\r\n }\r\n $i++;\r\n }\r\n $GLOBALS["lvdtot"] = round($GLOBALS["lvdtot"]/10,3);\r\n $GLOBALS["calc"] = 0;\r\n return $GLOBALS["lvdtot"];\r\n break;\r\n // % lead share variable = (premium/freemium leads sent for this service in last 30 days + 1) / (number of leads_matched table records that match supplier_id in last 30 days) * 100\r\n case "LEADSHARE":\r\n if ($GLOBALS["status"] = 0) { // PREMIUM LEAD SHARE\r\n $tsql = "SELECT (\r\n (\r\n COUNT(\r\n SELECT * FROM 27_leadssent LS \r\n LEFT JOIN 25_serviceleads SL ON (LS.bigint_LeadID = SL.bigint_LeadID) \r\n WHERE \r\n SL.bigint_SupplierID = ".$GLOBALS["recipient"][6]." \r\n AND SL.timestamp_LeadCreated > DATE_SUB(CURDATE(), INTERVAL 30 DAY)\r\n )\r\n + 1\r\n ) / (\r\n COUNT(\r\n SELECT * FROM 43_leadsmatched LM \r\n WHERE CONCAT(',',".$GLOBALS["recipient"][6].",',') LIKE CONCAT(',',LM.text_PremiumSupplierIDs,',') \r\n AND LM.timestamp_LastUpdated > DATE_SUB(CURDATE(), INTERVAL 30 DAY)\r\n )\r\n * 100\r\n )\r\n ) AS `lead_share`;";\r\n $result = mysql_query_errors($tsql, $conn, __FILE__, __LINE__);\r\n } elseif ($GLOBALS["status"] = 2 || // TRIAL LEAD SHARE\r\n $GLOBALS["status"] = 4) { // FREEMIUM LEAD SHARE\r\n $tsql = "SELECT (\r\n (\r\n COUNT(\r\n SELECT * FROM 13_prospectleadsent PS \r\n LEFT JOIN 10_serviceprospects SP ON (PS.bigint_ProspectID = SP.bigint_ProspectID) \r\n WHERE \r\n SP.bigint_SupplierID = ".$GLOBALS["recipient"][6]." \r\n AND SP.timestamp_ProspectCreated > DATE_SUB(CURDATE(), INTERVAL 30 DAY)\r\n )\r\n + 1\r\n ) / (\r\n COUNT(\r\n SELECT * FROM 43_leadsmatched LM \r\n WHERE CONCAT(',',".$GLOBALS["recipient"][6].",',') LIKE CONCAT(',',LM.text_FreemiumSupplierIDs,',') \r\n AND LM.timestamp_LastUpdated > DATE_SUB(CURDATE(), INTERVAL 30 DAY)\r\n )\r\n * 100\r\n )\r\n ) AS `lead_share`;";\r\n $result = mysql_query_errors($tsql, $conn, __FILE__, __LINE__);\r\n }\r\n if ($result) {\r\n if ($row = mysql_fetch_array($result)) {\r\n return $row["lead_share"];\r\n }\r\n }\r\n break;\r\n // attribute flags\r\n case "ATTRIBUTE":\r\n return $GLOBALS["attribsarr"][$in[1]];\r\n break;\r\n // survey flags\r\n case "SURVEYHEADER":\r\n return "%CONFIGTEXT Email | Consumer | Survey | Header%";\r\n break;\r\n case "SURVEYINTRO":\r\n return "%CONFIGTEXT Email | Consumer | Survey | Intro%";\r\n break;\r\n case "SURVEYSIGNATURE":\r\n return "%CONFIGTEXT Email | Consumer | Survey | Signature%";\r\n break;\r\n case "SURVEYTYPE":\r\n return (!$$GLOBALS["urlencode"])?xmlentities($GLOBALS["surveytype"]):urlencode($GLOBALS["surveytype"]);\r\n break;\r\n case "SURVEYURL":\r\n return $GLOBALS["surveyurl"];\r\n break;\r\n case "SURVEYQUESTIONS":\r\n return $GLOBALS["surveyquestions"];\r\n break;\r\n case "SURVEYQCOUNT":\r\n return $GLOBALS["qcnt"];\r\n break;\r\n case "SURVEYTHANKYOU":\r\n return "%CONFIGTEXT Intellisource | Survey Manager | Thank you! Note%";\r\n break;\r\n // consumer flags\r\n case "CONSUMERNAME":\r\n $GLOBALS["consumerfullname"] = str_replace(", "," ",$GLOBALS["consumerfullname"]);\r\n return (!$GLOBALS["urlencode"])?xmlentities($GLOBALS["consumerfullname"]):urlencode($GLOBALS["consumerfullname"]);\r\n break;\r\n case "CONSUMERFIRSTNAME":\r\n $GLOBALS["consumerfullname"] = str_replace(", "," ",$GLOBALS["consumerfullname"]);\r\n $str = (!$GLOBALS["urlencode"])?xmlentities($GLOBALS["consumerfullname"]):urlencode($GLOBALS["consumerfullname"]);\r\n $del = array(' ', '.');\r\n $arr = explode($del[0], str_replace($del, $del[0], $str),2);\r\n return (count($arr)>1)?$arr[0]:"";\r\n break;\r\n case "CONSUMERLASTNAME":\r\n $GLOBALS["consumerfullname"] = str_replace(", "," ",$GLOBALS["consumerfullname"]);\r\n $str = (!$GLOBALS["urlencode"])?xmlentities($GLOBALS["consumerfullname"]):urlencode($GLOBALS["consumerfullname"]);\r\n $del = array(' ', '.');\r\n $arr = explode($del[0], str_replace($del, $del[0], $str),2);\r\n return (count($arr)>1)?$arr[1]:"";\r\n break;\r\n case "CONSUMEREMAIL":\r\n return $GLOBALS["consumeremail"];\r\n break;\r\n case "CONSUMERCELL":\r\n return $GLOBALS["consumercell"];\r\n case "POSTALCODE":\r\n $arr = explode(", ",xmlentities($GLOBALS["city_town"]));\r\n return $arr[1];\r\n break;\r\n case "CONSUMERCITY":\r\n $arr = explode(", ",xmlentities($GLOBALS["city_town"]));\r\n return $arr[0];\r\n break;\r\n case "MESSAGE":\r\n return (!$GLOBALS["urlencode"])?xmlentities($GLOBALS["message"]):urlencode($GLOBALS["message"]);\r\n break;\r\n // expected by date\r\n case "EXPECTEDBY":\r\n //echo $GLOBALS["exby"]."\n";\r\n $expected = (is_array($GLOBALS["exby"]))?$GLOBALS["exby"]:explode(" ",date($GLOBALS["dtmstyle"],strtotime($GLOBALS["exby"])));\r\n //print_r(explode(" ",date($GLOBALS["dtmstyle"],strtotime($GLOBALS["exby"]))));\r\n return $expected[$GLOBALS["dtlast"]];\r\n break;\r\n // supplier flags\r\n case "OPUSERID":\r\n return $GLOBALS["user_id"];\r\n break;\r\n case "SUPPLIERNAME":\r\n return xmlentities($GLOBALS["recipient"][1]);\r\n break;\r\n case "CONTACTFNAME":\r\n $fname = explode(" ",$GLOBALS["recipient"][0]);\r\n return xmlentities($fname[0]);\r\n case "CONTACTNAME":\r\n return xmlentities($GLOBALS["recipient"][0]);\r\n break;\r\n case "ACCMGR":\r\n return xmlentities($GLOBALS["recipient"][11]);\r\n break;\r\n case "ACCMGRMAIL":\r\n return $GLOBALS["recipient"][12];\r\n break;\r\n case "PAYGBALANCE":\r\n if ($GLOBALS["leadid"]) {\r\n return $GLOBALS["newbalance"];\r\n } else {\r\n return $GLOBALS["balance"];\r\n }\r\n case "INVOICEAMOUNT":\r\n return $GLOBALS["recipient"][13];\r\n break;\r\n // lead flags\r\n case "LEADS360":\r\n return str_replace(".","",$GLOBALS["leads360"].((strlen($GLOBALS["opret"])>2048)?" &amp; OnePage Lead ID = ".$GLOBALS["opret"]:""));\r\n break;\r\n case "LEADREFERENCE":\r\n if ($GLOBALS["prospecting"]) {\r\n return ($GLOBALS["leadid2"] + 9001100).$GLOBALS["ordinal"];\r\n } elseif (isset($GLOBALS["reference"])) {\r\n return $GLOBALS["reference"];\r\n } else {\r\n return ($GLOBALS["leadid"] + 11001000).$GLOBALS["ordinal"];\r\n }\r\n break;\r\n case "MESSAGENO":\r\n return ordinalSuffix($GLOBALS["messageno"]);\r\n break;\r\n case "LEADSUCCESS":\r\n if ($GLOBALS["leadsuccess"]) {\r\n return "SENT ";\r\n } else {\r\n return "UNSENT";\r\n }\r\n break;\r\n case "LEADCREATED":\r\n return $GLOBALS["leadcreated"];\r\n break;\r\n case "LEADCATEGORY":\r\n return $GLOBALS["cat"];\r\n break;\r\n case "PAYGCOST":\r\n return $GLOBALS["servicecost"];\r\n break;\r\n case "DUPLICATES":\r\n if ($GLOBALS["prospecting"]) {\r\n return $GLOBALS["lappend"];\r\n } else {\r\n return $GLOBALS["append"];\r\n }\r\n break;\r\n // other flags\r\n case "PROSPECTMESSAGE":\r\n return $GLOBALS["pmsg"];\r\n break;\r\n case "SUPPLIERLIST":\r\n return join("",$GLOBALS["suppliers"]);\r\n break;\r\n case "PROSPECTLIST":\r\n return join("",$GLOBALS["supplierp"]);\r\n break;\r\n case "SERVICENAME":\r\n return (!$GLOBALS["urlencode"])?xmlentities($GLOBALS["servicename"]):urlencode($GLOBALS["servicename"]);\r\n break;\r\n case "REGIONNAME":\r\n return $GLOBALS["regionname"];\r\n break;\r\n // cronjob flags\r\n case "FROMDATE":\r\n return date($GLOBALS["dtmstyle"],strtotime($GLOBALS["f"]));\r\n break;\r\n case "TODATE":\r\n return date($GLOBALS["dtmstyle"],strtotime($GLOBALS["t"]));\r\n break;\r\n case "YEAR":\r\n return date("Y",now());\r\n break;\r\n case "COPYRIGHT":\r\n \r\n break;\r\n // configurable text flags ADD PARENT REGIONS OR INTO SELECT.\r\n case "CONFIGTEXT":\r\n $supplier = getconstraints(($GLOBALS["recipient"][6])?$GLOBALS["recipient"][6]:0,1);\r\n $regions = getconstraints(($GLOBALS["region"])?$GLOBALS["region"]:0,0);\r\n $service = getconstraints(($GLOBALS["service"])?$GLOBALS["service"]:0,2);\r\n $constraints = array();\r\n if (count($supplier)) array_push($constraints,(count($supplier)>1)?"(".implode(" OR ",$supplier).")":$supplier[0]);\r\n if (count($regions)) array_push($constraints,(count($regions)>1)?"(".implode(" OR ",$regions).")":$regions[0]);\r\n if (count($service)) array_push($constraints,(count($service)>1)?"(".implode(" OR ",$service).")":$service[0]);\r\n $tsql = "SELECT * \r\n FROM \r\n 18_configurabletexts \r\n WHERE \r\n 18_configurabletexts.text_TextDescription = \"".$in[1]."\" AND \r\n (".implode(" AND ",$constraints).");";\r\n $result = mysql_query_errors($tsql, $conn, __FILE__, __LINE__ );\r\n if ($result) {\r\n if ($row = mysql_fetch_array($result)) {\r\n return $row["text_TextFullContent"];\r\n }\r\n }\r\n }\r\n }\r\n}\r\nfunction populateflags($str,$urlencode=false,$usedefault=false) {\r\n // replace flags used in string (parse entire template contents' as string), populating flags individually and sometimes recursively in callback function.\r\n $GLOBALS["urlencode"] = $urlencode;\r\n $GLOBALS["usedefault"] = $usedefault;\r\n while (preg_match_all("/%([A-Z]+[^%]*)%/",$str,$arr)) {\r\n $str = preg_replace_callback("/%([A-Z]+[^%]*)%/","idflags",$str);\r\n }\r\n return $str;\r\n}\r\nfunction formattribs($str = "") {\r\n // split attributes string by html tags and space padded =, returning array\r\n $str = preg_replace("/[\n\r]+/","//",$str);\r\n $ret = preg_split("/<[^>]+>/",$str,-1,PREG_SPLIT_NO_EMPTY);\r\n $attr = array();\r\n foreach ($ret as $value) {\r\n $val = explode(" = ",$value);\r\n $attr[$val[0]] = $val[1];\r\n }\r\n return $attr;\r\n}\r\nfunction ordinalSuffix($num) {\r\n if (substr($num,-2, 2) == 11 || substr($num,-2, 2) == 12 || substr($num,-2, 2) == 13) $suffix = "th ";\r\n else if (substr($num,-1, 1) == 1) $suffix = "st ";\r\n else if (substr($num,-1, 1) == 2) $suffix = "nd";\r\n else if (substr($num,-1, 1) == 3) $suffix = "rd ";\r\n else $suffix = "th ";\r\n return $num.$suffix;\r\n}\r\nfunction getSubText($body, $tagstart, $tagend) {\r\n $startpos = strpos($body, $tagstart) + strlen($tagstart);\r\n $sublen = strpos($body,$tagend) - $startpos;\r\n return substr($body,$startpos,$sublen);\r\n}\r\nfunction getconstraints($child,$constraint,$rarray = array()) {\r\n global $conn;\r\n mysql_select_db("*****", $conn);\r\n if (!$child) $child = 0;\r\n switch ($constraint) {\r\n case 1:\r\n // return supplier level constraint\r\n if (intval($child) > 0) array_push($rarray,"18_configurabletexts.bigint_SupplierID = ".intval($child));\r\n array_push($rarray,"18_configurabletexts.bigint_SupplierID = 0");\r\n $return = $rarray;\r\n break;\r\n case 2:\r\n // return service level constraint\r\n if (intval($child) > 0) array_push($rarray,"18_configurabletexts.bigint_ServiceID = ".intval($child));\r\n array_push($rarray,"18_configurabletexts.bigint_ServiceID = 0");\r\n $return = $rarray;\r\n break;\r\n default:\r\n // return parental region constraints for use in getsuppliers function\r\n if (intval($child) == 0) {\r\n array_push($rarray,"18_configurabletexts.bigint_RegionID = 0");\r\n $return = $rarray;\r\n //print_r($return);\r\n } else {\r\n array_push($rarray,"18_configurabletexts.bigint_RegionID = ".intval($child));\r\n $sql = "SELECT bigint_ParentRegionID FROM 1_regions WHERE bigint_RegionID = ".intval($child).";";\r\n $result = mysql_query_errors($sql , $conn, __FILE__, __LINE__);\r\n if ($result) {\r\n if ($row = mysql_fetch_array($result)) {\r\n $return = getconstraints($row["bigint_ParentRegionID"],$constraint,$rarray);\r\n }\r\n mysql_free_result($result);\r\n }\r\n }\r\n }\r\n return $return;\r\n}\r\n//http://www.php.net/manual/en/function.html-entity-decode.php\r\nfunction html_entity_decode_utf8( $string, $convert_single_quotes = false ) {\r\n static $trans_tbl;\r\n //replace numeric entities\r\n $string = preg_replace('~&#x0*([0-9a-f]+);~ei', '_code2utf8(hexdec("\\1"))', $string);\r\n $string = preg_replace('~&#0*([0-9]+);~e', '_code2utf8(\\1)', $string);\r\n //replace literal entities\r\n if (!isset($trans_tbl))\r\n {\r\n $trans_tbl=array();\r\n foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)\r\n $trans_tbl[$key] = utf8_encode($val);\r\n }\r\n $decode = strtr($string, $trans_tbl);\r\n if($convert_single_quotes) $decode = str_replace("'", "\'", $decode);\r\n\r\n return $decode;\r\n}\r\n//Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv)\r\nfunction _code2utf8( $num ) {\r\n if($num < 0) return '';\r\n if($num < 128) return chr($num);\r\n\r\n //Removing / Replacing Windows Illegals Characters\r\n if($num < 160)\r\n {\r\n switch ($num)\r\n {\r\n case 128: $num=8364; break;\r\n case 129: $num=160; break; //(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160\r\n case 130: $num=8218; break;\r\n case 131: $num=402; break;\r\n case 132: $num=8222; break;\r\n case 133: $num=8230; break;\r\n case 134: $num=8224; break;\r\n case 135: $num=8225; break;\r\n case 136: $num=710; break;\r\n case 137: $num=8240; break;\r\n case 138: $num=352; break;\r\n case 139: $num=8249; break;\r\n case 140: $num=338; break;\r\n case 141: $num=160; break; //(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160\r\n case 142: $num=381; break;\r\n case 143: $num=160; break; //(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160\r\n case 144: $num=160; break; //(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160\r\n case 145: $num=8216; break;\r\n case 146: $num=8217; break;\r\n case 147: $num=8220; break;\r\n case 148: $num=8221; break;\r\n case 149: $num=8226; break;\r\n case 150: $num=8211; break;\r\n case 151: $num=8212; break;\r\n case 152: $num=732; break;\r\n case 153: $num=8482; break;\r\n case 154: $num=353; break;\r\n case 155: $num=8250; break;\r\n case 156: $num=339; break;\r\n case 157: $num=160; break; //(Rayo:) #129 using no relevant sign, thus, mapped to the saved-space #160\r\n case 158: $num=382; break;\r\n case 159: $num=376; break;\r\n }\r\n }\r\n if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);\r\n if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);\r\n if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);\r\n return '';\r\n}\r\nfunction objectToArray($d) {\r\n if (is_object($d)) {\r\n // Gets the properties of the given object\r\n // with get_object_vars function\r\n $d = get_object_vars($d);\r\n }\r\n if (is_array($d)) {\r\n /*\r\n * Return array converted to object\r\n * Using __FUNCTION__ (Magic constant)\r\n * for recursive call\r\n */\r\n return array_map(__FUNCTION__, $d);\r\n } else {\r\n // Return array\r\n return $d;\r\n }\r\n}\r\nfunction arrayToObject($d) {\r\n if (is_array($d)) {\r\n /*\r\n * Return array converted to object\r\n * Using __FUNCTION__ (Magic constant)\r\n * for recursive call\r\n */\r\n return (object) array_map(__FUNCTION__, $d);\r\n }\r\n else {\r\n // Return object\r\n return $d;\r\n }\r\n}\r\nfunction gettypes($array) {\r\n $types = "";\r\n foreach ($array as $id=>$element) {\r\n $types .= (($id>0)?",":"").$element->{"type"};\r\n }\r\n return $types;\r\n}\r\nfunction getkeys($array) {\r\n $keys = "";\r\n $id = 0;\r\n foreach (get_object_vars($array[0]) as $property=>$value) {\r\n $keys .= (($id>0)?",":"").$property;\r\n $id++;\r\n }\r\n return $keys;\r\n}\r\nfunction opconvert($array,$types=NULL,$levels=1) {\r\n $manual = (!empty($types))?"true":"false";\r\n if ($manual=="true") {\r\n $types = gettypes($array);\r\n $keys = getkeys($array);\r\n }\r\n switch ($levels) {\r\n case 1: // pre-formatted array passed\r\n return implode(",",$array);\r\n break;\r\n case 2: // unformatted hash passed\r\n $i = 0;\r\n $out = array();\r\n $type = explode(",",$types);\r\n $keys = explode(",",$keys);\r\n array_push($GLOBALS["sql"],\r\n "\$keys = ".print_r($keys,true),\r\n "\$manual = ".print_r($manual,true),\r\n "\$types = ".print_r($types,true),\r\n "\$type = ".print_r($type,true)\r\n );\r\n foreach ($array as $key=>$value) {\r\n $value = objectToArray($value);\r\n if ($manual=="true") {\r\n $out[$key] = $value["type"]."|".$value[$keys[$i+1]];\r\n } else {\r\n $out[$key] = $type[$i]."|".$value;\r\n }\r\n array_push($GLOBALS["sql"],\r\n "\$key = ".print_r($key,true),\r\n "\$value = ".print_r($value,true),\r\n "\$out[\$key] = ".print_r($out[$key],true)\r\n );\r\n $i++;\r\n }\r\n return implode(",",$out);\r\n break;\r\n }\r\n}\r\nmysql_select_db("performatix", $conn);\r\n$GLOBALS["dtmstyle"] = "Y/m/d H:i:s";\r\n$GLOBALS["dtlast"] = 0;\r\ndate_default_timezone_set("Africa/Johannesburg");\r\n$tzsql = "SET `time_zone` = '".date('P')."'";\r\nmysql_query_errors($tzsql, $conn, __FILE__, __LINE__);\r\n?></sql> </root> my problem is that print_r, when returning - does not return all the levels of the matched array. any ideas? by the way - any sensitive data has been starred out. thanks in advance, Pierre du Toit
  10. PS: the phpinfo() function returns the following for the environment: sincerely, Pierre "Greywacke" du Toit
  11. hi there everyone! i currently have, in my php document (which generates various xml depending on post and querystring request values) - the following function: function getdbconfig($file = "") { if ($_GLOBALS["ssl_enabled"] == 1 && ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) || $_GLOBALS["ssl_enabled"] == 0) { $pattern = '/^\$conn = mysql_connect\("([a-zA-Z._0-9\-]+)", "([a-zA-Z_0-9]+)", "([a-zA-Z_0-9]+)"\);$'. '|^mysql_select_db\("([a-zA-Z_0-9]+)", \$conn\);$'. '|^date_default_timezone_set\([\'"]([A-Za-z0-9\/+\-]+)[\'"]\);$'. '|^\$GLOBALS\["dtmstyle"\] = "([^"]+)";$'. '|^\$GLOBALS\["dtlast"\] = ([0|1]);$'. '|^\$GLOBALS\["prod_prodmode"\] = ([0|1]);$'. '|^\$GLOBALS\["prod_prodmail"\] = "([^@]+@[^"]+)";$'. '|^\$GLOBALS\["curl"\] = ([0|1]);$'. '|^\$GLOBALS\["conn_timeout"\] = ([0-9]+);$'. '|^\$GLOBALS\["post_timeout"\] = ([0-9]+);$'. '|^\$GLOBALS\["ssl_enabled"\] = ([0|1]);$/m'; $connstr = file_get_contents($file, FILE_USE_INCLUDE_PATH); echo "<sql>".$connstr."</sql>\n"; $arr = array(); if (preg_match_all($pattern,$connstr,$arr,PREG_PATTERN_ORDER)) { echo "<sql>".print_r($arr,true)."</sql>\n"; array_push($GLOBALS["sql"],print_r($arr,true)); echo " <conn dbsrvr=\"".$arr[1][6]."\" dbname=\"".$arr[4][7]."\" user=\"".$arr[2][6]."\" pass=\"".$arr[3][6]."\" php_tz=\"".$arr[5][10]."\" php_dtf=\"".$arr[6][8]."\" php_dta=\"".$arr[7][9]."\" pt_on=\"".$arr[8][0]."\" pt_mail=\"".$arr[9][1]."\" curl=\"".$arr[10][2]."\" cto=\"".$arr[11][3]."\" pto=\"".$arr[12][4]."\" ssl=\"".$arr[13][5]."\" />\n"; } } else { $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; header("Location: $redirect"); } } however - there is something wrong somewhere in the outer if statements, as i get nothing printed! the global variables should post the following, according to the currently parsed file contents: <?xml version="1.0" encoding="utf-8"?> <root> <conn dbsrvr="localhost" dbname="*****" user="*****" pass="*****" php_tz="Africa/Johannesburg" php_dtf="Y/m/d H:i:s" php_dta="0" pt_on="0" pt_mail="greywacke@outlook.com" curl="1" cto="15" pto="30" ssl="0" /> <sql></sql> </root> please note - private information such as database names, usernames and passwords were replaced with ***** can anyone help me out please, in resolving this issue? (to get the regular expression values printed!) any comments, questions and/or suggestions are welcome! sincerely, Pierre du Toit.
  12. ok the mailer was moved to the end of the cron, thus not happening while the database populated. at the end of the cron, the services (in an outer query) then the data (in an inner query) is now retrieved from the database, and the mails sent, per service - successfully. thanks for the help, i am trying to get into the mindset of commenting in my code.
  13. ok sorry jazzman, i've had a look at he code and on lines 10 and 16 the collections do not even exist. it is supposed to be $_GET not $get. $f = $get["f"]; $t = $get["t"]; will see what needs to change next. sorry for asking, but did you read the logic summary of the cron?
  14. populating the table 48_untappedpotentials works so far - but only for yesterday. it does not populate the other days requested...
  15. hi - the sql is working 100% - just the flow of code is not exactly as i expected when i developed it last night. here's the cronjob: <?PHP /* CANOPYXCHANGE DAILY UNTAPPED POTENTIALS CALCULATION Version 2.2.5 */ $errmsg = array(); chdir(__DIR__); include("../includes/content/performatix.php"); include("../includes/mailer/phpmailer 5.2.1/class.phpmailer.php"); // include PHPMailer class $f = $get["f"]; if (!is_numeric($f)) { $f = 1; } else { $f = intval($f); } $t = $get["t"]; if (!is_numeric($t)) { $t = 0; } else { $t = intval($t); } for ($i = $f; $i > $t; $i--) { echo "-".$i."days \r\n"; $osql = "SELECT SC.bigint_ServiceID, # Service R.bigint_RegionID, # Region SA1.bigint_AttributeID, # Primary Attribute Value SC.text_ServiceManagerContact, SC.`text_ServiceManagerE-mail`, SC.text_TechSupportContact, SC.`text_TechSupportE-mail`, SC.text_ServiceDescription, R.text_RegionDescription, SA1.text_AttributeValue, SUM(PLS.double_PotentialCost) AS double_ProspectsCostTotal, COUNT(DISTINCT SP.bigint_ProspectID, PLS.smallint_ProspectOrdinal) AS bigint_ProspectsSentCount, TRUNCATE(SUM(PLS.double_PotentialCost)/COUNT(DISTINCT SP.bigint_ProspectID, PLS.smallint_ProspectOrdinal), 2) AS double_AvgCostPerProspect, DATE_ADD(CURDATE(),INTERVAL -".$i." DAY) AS date_DateStamp FROM 2_servicescatalogue SC JOIN 1_regions R ON ( R.bigint_ParentRegionID BETWEEN 1 AND 7 ) JOIN 3_serviceattributes SA0 ON ( SC.bigint_PrimaryAttributeKey = SA0.bigint_AttributeID AND SC.bigint_ServiceID = SA0.bigint_AttributeServiceID ) JOIN 3_serviceattributes SA1 ON ( SA0.text_AttributeDescription = SA1.text_AttributeDescription AND SA0.bigint_AttributeServiceID = SA1.bigint_AttributeServiceID ) JOIN 10_serviceprospects SP ON ( DATE(SP.timestamp_ProspectCreated) = DATE_ADD(CURDATE(),INTERVAL -".$i." DAY) AND SC.bigint_ServiceID = SP.bigint_ServiceID AND R.bigint_RegionID = SP.bigint_RegionID AND SP.text_LeadAttributes LIKE IF( SA1.bigint_AttributeID = 0, '%', CONCAT( '%', SA1.text_AttributeDescription, ' = ', SA1.text_AttributeValue, '%' ) ) ) JOIN 13_prospectleadsent PLS ON (SP.bigint_ProspectID = PLS.bigint_ProspectID) GROUP BY SC.bigint_ServiceID, R.bigint_RegionID, SA1.bigint_AttributeID ORDER BY SC.text_ServiceDescription ASC, R.text_RegionDescription ASC, SA1.text_AttributeValue ASC;"; $oresult = mysql_query_errors($osql, $conn , __FILE__ , __LINE__,true); $oservice = 0; $n = 0; $service = array(); $servicename = array(); $region = array(); $regionname = array(); $attid = array(); $attvalue = array(); $pct = array(); $psc = array(); $acpp = array(); $ds = array(); $summary = ""; if ($oresult) { while ($orow = mysql_fetch_array($oresult)) { global $formname, $logo, $formfromname, $formfrommail, $smgn, $smge, $tcsn, $tcse, $datestamp, $summary, $cmpid, $cmpname, $cmpsource, $apicreds, $time, $now; $smgn = $orow["text_ServiceManagerContact"]; $smge = $orow["text_ServiceManagerE-mail"]; $tcsn = $orow["text_TechSupportContact"]; $tcse = $orow["text_TechSupportE-mail"]; $service[$n] = $orow["bigint_ServiceID"]; $servicename[$n] = $orow["text_ServiceDescription"]; $region[$n] = $orow["bigint_RegionID"]; $regionname[$n] = $orow["text_RegionDescription"]; $attid[$n] = $orow["bigint_AttributeID"]; $attvalue[$n] = $orow["text_AttributeValue"]; $pct[$n] = floatval($orow["double_ProspectsCostTotal"]); $psc[$n] = $orow["bigint_ProspectsSentCount"]; $acpp[$n] = floatval($orow["double_AvgCostPerProspect"]); $ds[$n] = $orow["date_DateStamp"]; $tsql = "INSERT INTO 48_untappedpotentials ( bigint_ServiceID, bigint_RegionID, bigint_PrimAttValue, double_ProspectsCostTotal, bigint_ProspectsSentCount, double_AvgCostPerProspect, date_DateStamp ) VALUES ( ".$service[$n].", ".$region[$n].", ".$attid[$n].", ".$pct[$n].", ".$psc[$n].", ".$acpp[$n].", \"".$ds[$n]."\" ) ON DUPLICATE KEY UPDATE bigint_ServiceID = ".$service[$n].", bigint_RegionID = ".$region[$n].", bigint_PrimAttValue = ".$attid[$n].", double_ProspectsCostTotal = ".$pct[$n].", bigint_ProspectsSentCount = ".$psc[$n].", double_AvgCostPerProspect = ".$acpp[$n].", date_DateStamp = \"".$ds[$n]."\";"; $tresult = mysql_query_errors($tsql, $conn , __FILE__ , __LINE__,true); if ($oservice != $service[$n] && $n != 0) { $tsql0 = "SELECT * FROM 32_webformconfigs WC WHERE WC.tinyint_FormDefault = 1 AND WC.bigint_FormService = ".$service[0].";"; $tresult0 = mysql_query_errors($tsql0, $conn, __FILE__, __LINE__ , true ); $trow0 = mysql_fetch_array($tresult0); $formid = $trow0["bigint_FormID"]; $formname = $trow0["text_FormName"]; $copy = $formname; $logo = "http://quomoto.co/templates/fs_quomoto/images/quomoto_logo.png"; //$trow0["text_FormLogo"]; $formfromname = $trow0["text_FormMailerFromName"]; $formfrommail = $trow0["text_FormMailerFromAddress"]; echo "$servicename[0] \$ds[0] = ".print_r($ds[0],true)."\r\n"; $summary .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">". "<thead>". "<tr>". "<th>Service Description</th>". "<th>Region Description</th>". "<th>Primary Attribute Value</th>". "<th>Total Prospects Cost</th>". "<th>Total Prospects Sent</th>". "<th>Average Cost Per Prospect</th>". "</tr>". "</thead>". "<tbody>"; for ($a = 0; $a < count($service)-1; $a++) { $summary .= "<tr class=\"minus\">"; $summary .= "<td>".$servicename[$a]."</td>"; $summary .= "<td>".$regionname[$a]."</td>"; $summary .= "<td>".$attvalue[$n]."</td>"; $summary .= "<td>".$pct[$a]."</td>"; $summary .= "<td>".$psc[$a]."</td>"; $summary .= "<td>".$acpp[$a]."</td>"; $summary .= "</tr>"; } $summary .= "</tbody>". "</table>"; // mail to service manager if records found if (strlen($summary)>0) { $body = getFile("../templat/untappedpotentials.html"); // load mail template $mail = new PHPMailer(); // create a new object $body = str_replace("%LOGO%",$logo,$body); // insert logo url $body = str_replace("%DATESTAMP%",$ds[0],$body); // insert current datestamp $body = str_replace("%SUMMARY%",$summary,$body); // insert summary of yesterdays campaign transactions $body = str_replace("%FORMNAME%",$formname,$body); // insert form name $body = str_replace("%COPYRIGHT%",$copy,$body); // insert copyright owner $body = str_replace("%YEAR%",date("Y"),$body); // insert copyright year $body = populateflags($body); require("../includes/mailer/phpmailer 5.2.1/mailer_auth.php"); // include mailer auth $mail->From = $formfrommail; // set from email $mail->FromName = $formfromname; // set from name $mail->Subject = getSubText($body,"<title>","</title>"); // set subject to template page title $mail->AddAddress($smge,$smgn); // bcc jaap the response $mail->AddBCC("jaap@quomoto.co","Jaap Venter"); // bcc the svcmgr the notification $mail->AddBCC($tcse,$tcsn); // bcc tech support the notification $mail->ClearAttachments(); // clears attachments $mail->MsgHTML($body); // set HTML Body $mail->AltBody = strip_tags(html_entity_decode(getSubText($body, // set Text Body "<body>","</body>"))); $mail->IsHTML(true); // set send as HTML if(!$mail->Send()) { // if attempt sending failed array_push($errmsg,"FAILURE: ".$smge.", ".$smgn. // save error report " (".trim(strip_tags($mail->ErrorInfo)).")"); $failure++; // increment failures count } else { array_push($errmsg,"SUCCESS: ".$smge.", ".$smgn); // save success report $success++; // increment success count } } $n = 0; $service = array(); $servicename = array(); $region = array(); $regionname = array(); $attid = array(); $attvalue = array(); $pct = array(); $psc = array(); $acpp = array(); $ds = array(); $summary = ""; $service[$n] = $orow["bigint_ServiceID"]; $servicename[$n] = $orow["text_ServiceDescription"]; $region[$n] = $orow["bigint_RegionID"]; $regionname[$n] = $orow["text_RegionDescription"]; $attid[$n] = $orow["bigint_AttributeID"]; $attvalue[$n] = $orow["text_AttributeValue"]; $pct[$n] = floatval($orow["double_ProspectsCostTotal"]); $psc[$n] = $orow["bigint_ProspectsSentCount"]; $acpp[$n] = floatval($orow["double_AvgCostPerProspect"]); $ds[$n] = $orow["date_DateStamp"]; $tsql0 = "SELECT * FROM 32_webformconfigs WC WHERE WC.tinyint_FormDefault = 1 AND WC.bigint_FormService = ".$service[$n].";"; $tresult0 = mysql_query_errors($tsql0, $conn, __FILE__, __LINE__ , true ); $trow0 = mysql_fetch_array($tresult0); $formid = $trow0["bigint_FormID"]; $formname = $trow0["text_FormName"]; $copy = $formname; $logo = "http://quomoto.co/templates/fs_quomoto/images/quomoto_logo.png"; //$trow0["text_FormLogo"]; $formfromname = $trow0["text_FormMailerFromName"]; $formfrommail = $trow0["text_FormMailerFromAddress"]; echo "$servicename[0] \$ds[0] = ".print_r($ds[0],true)."\r\n"; } $n++; } } echo "SQL, ARR, LMX & CAT DEBUGGING INFO:\r\n\r\n\$sql = ".print_r($sql,true)."\r\n". "SUCCESS COUNT = ".intval($success)."\r\n". "FAILURE COUNT = ".intval($failure)."\r\n". "\$ERRMSG = ".print_r($errmsg,true); } mysql_close($conn); ?> > however - when executed it does not print all the days, i am running as "cronjob_untappedpotentials.php?f=38&t=0" so it should decrement from 38 down to 0. > then in the resultset, send an email out per distinct service. > what is wrong with the logic in my code? apologies, i was rather overworked when i developed this. i think the actual question is - how does the current execution differ from the intention of execution? 0o sincerely, Pierre du Toit.
  16. thanks alot Psycho and Barand for your valued input! i have made all the joins as JOIN now instead of LEFT JOIN - and the performance increase on the query is quite alot! it now takes seconds to execute - merely by switching the JOIN types which is quite feasible. as for Barand's suggestion - I see what you have said and it holds value too - however, i would need to discuss it with my client - thanks alot! the query has changed as follows (also due to extra requirements in getting exactly what my client wanted): SELECT SC.text_ServiceDescription, R.text_RegionDescription, SA1.text_AttributeValue, GROUP_CONCAT(DISTINCT S.text_SupplierName SEPARATOR ', ') AS text_SupplierNames, IFNULL(SW.smallint_SuppliersWanted,0) AS bigint_SuppliersWantedAmount, COUNT(DISTINCT S.bigint_SupplierID) AS bigint_PremiumCustomersCount, ROUND(AVG(T.bigint_TransactionAmount)/COUNT(DISTINCT LS.bigint_LeadID, LS.smallint_LeadOrdinal),2) AS bigint_AvgCostPerLead, ROUND(COUNT(DISTINCT LS.bigint_LeadID, LS.smallint_LeadOrdinal),2) AS bigint_AvgNumLeadsGen FROM 4_servicesuppliers SS JOIN 2_servicescatalogue SC ON (SS.bigint_ServiceID = SC.bigint_ServiceID) JOIN 1_regions R ON (SS.bigint_RegionID = R.bigint_RegionID OR SS.bigint_RegionID = R.bigint_ParentRegionID) JOIN 5_suppliers S ON (SS.bigint_SupplierID = S.bigint_SupplierID) JOIN 11_supplierswanted SW ON (SS.bigint_ServiceID = SW.bigint_ServiceID AND R.bigint_RegionID = SW.bigint_RegionID) JOIN 3_serviceattributes SA0 ON (SC.bigint_PrimaryAttributeKey = SA0.bigint_AttributeID AND SC.bigint_ServiceID = SA0.bigint_AttributeServiceID) JOIN 3_serviceattributes SA1 ON (SA0.text_AttributeDescription = SA1.text_AttributeDescription AND SC.bigint_ServiceID = SA1.bigint_AttributeServiceID) JOIN 25_serviceleads SL ON (SC.bigint_ServiceID = SL.bigint_ServiceID AND SL.text_LeadAttributes LIKE CONCAT("%",SA0.text_AttributeDescription," = ",SA1.text_AttributeValue,"%")) JOIN 27_leadssent LS ON (SL.bigint_LeadID = LS.bigint_LeadID) JOIN 19_consumers C ON (SL.bigint_ConsumerID = C.bigint_ConsumerID AND R.bigint_RegionID = C.bigint_ConsumerRegion) JOIN 8_transactions T ON (SL.bigint_LeadID = T.bigint_LeadID AND LS.smallint_LeadOrdinal = T.smallint_LeadOrdinal) WHERE S.smallint_SupplierStatus = 0 AND IFNULL(SW.smallint_SuppliersWanted,0) > 0 AND SL.timestamp_LeadCreated >= DATE_SUB(CURDATE(),INTERVAL 30 DAY) AND SL.text_LeadAttributes LIKE CONCAT("%",SA1.text_AttributeDescription," = ",SA1.text_AttributeValue,"%") AND LS.text_Duplicates = "" GROUP BY SS.bigint_ServiceID, SW.bigint_RegionID, SA1.text_AttributeValue ORDER BY SS.bigint_ServiceID ASC, R.bigint_RegionID ASC; as for the indexes being created - they have, just a pity they are not supported on text fields in the current storage engine (which was required for some server software we had to install). the database was designed in MyISAM back when that was the best option to use for the tables - but is now using InnoDB. sincerely, Pierre "Greywacke" du Toit.
  17. hi there, i have the following query, which is supposed to return the valid sales lead counts and average the costs and count the leads during the past 30 days. SELECT SC.text_ServiceDescription, R.text_RegionDescription, GROUP_CONCAT(DISTINCT S.text_SupplierName SEPARATOR ', ') AS text_SupplierNames, IFNULL(SW.smallint_SuppliersWanted,0) AS bigint_SuppliersWantedAmount, COUNT(DISTINCT S.bigint_SupplierID) AS bigint_PremiumCustomersCount, ROUND(AVG(T.bigint_TransactionAmount),2) AS bigint_AvgCostPerLead, ROUND(COUNT(DISTINCT LS.bigint_LeadID, LS.smallint_LeadOrdinal),2) AS bigint_AvgNumLeadsGen FROM 4_servicesuppliers SS LEFT JOIN 2_servicescatalogue SC ON (SS.bigint_ServiceID = SC.bigint_ServiceID) LEFT JOIN 1_regions R ON (SS.bigint_RegionID = R.bigint_RegionID OR SS.bigint_RegionID = R.bigint_ParentRegionID) LEFT JOIN 5_suppliers S ON (SS.bigint_SupplierID = S.bigint_SupplierID) LEFT JOIN 11_supplierswanted SW ON (SS.bigint_ServiceID = SW.bigint_ServiceID AND R.bigint_RegionID = SW.bigint_RegionID) LEFT JOIN 3_serviceattributes SA0 ON (SC.bigint_PrimaryAttributeKey = SA0.bigint_AttributeID AND SC.bigint_ServiceID = SA0.bigint_AttributeServiceID) LEFT JOIN 3_serviceattributes SA1 ON (SA0.text_AttributeDescription = SA1.text_AttributeDescription AND SC.bigint_ServiceID = SA1.bigint_AttributeServiceID) LEFT JOIN 25_serviceleads SL ON (SC.bigint_ServiceID = SL.bigint_ServiceID AND SL.text_LeadAttributes LIKE CONCAT("%",SA1.text_AttributeDescription," = ",SA1.text_AttributeValue,"%")) LEFT JOIN 27_leadssent LS ON (SL.bigint_LeadID = LS.bigint_LeadID) LEFT JOIN 8_transactions T ON (SL.bigint_LeadID = T.bigint_LeadID AND LS.smallint_LeadOrdinal = T.smallint_LeadOrdinal) WHERE S.smallint_SupplierStatus = 0 AND IFNULL(SW.smallint_SuppliersWanted,0) > 0 AND SL.timestamp_LeadCreated >= DATE_SUB(CURDATE(),INTERVAL 30 DAY) AND SL.text_LeadAttributes LIKE CONCAT("%",SA1.text_AttributeDescription," = ",SA1.text_AttributeValue,"%") AND LS.text_Duplicates = "" GROUP BY SS.bigint_ServiceID, SW.bigint_RegionID ORDER BY SS.bigint_ServiceID ASC, R.bigint_RegionID ASC; however - this query takes forever to execute, even longer than the system timeout in phpmyadmin! also via php... in php i have a microtimer attached which times the query above, at 1568.6739211082 seconds. how can i optimize the query above, especially with regard to the 25_serviceleads, 27_leadssent and 8_transactions JOIN's? i have uploaded the sql digest for the tables above to this message, to recreate this issue (removing the email addresses of course - as we do not condone spam ) to: http://performatix.co/Untapped_Potential_Income.zip please respond if you authentically know your mysql (especially the joins!) - you are welcome to assist. i have not been able to do the course myself yet - what i do know - is all as result of a lifelong hobby. sincerely, Pierre "Greywacke" du Toit.
  18. sorry for the late reply, yes all other mails work on the host - i posted here because i cannot see "the forest for the flowers", i only see trees... why i posted here to see if there are any errors in the coding... syntax is fine though, dreamweaver picks up on that very reliably...
  19. hi there, the following is an excerpt from our lead manager on performatix, being POST requested securely from url: http://performatix.co/production/scripts/ajax_leads.php?q=2&m=2013-11-11%2000%3A00%3A00%20to%202013-11-12%2023%3A59%3A59%26c%3D1384258729921. the post data sent is just the full lead id & ordinal as well as supplier id forwarding to. the issue is with getting the lead cost - if a new method of calculating the price named lead value determination is used. this function follows the code below. //... case 2: // resend lead $cat = ""; // set default category to blank string $fixedcost = 0.00; $dynamiccost = 0.00; $servicecost = 0.00; $fullid = explode(';',$_POST["list_leads"]); $leadid = $fullid[0]; $ordinal = $fullid[1]; $supplierid = $_POST["menu_forward"]; $charge = 0; $dynarr = array(); $smgn = ""; $smge = ""; $tcsn = ""; $tcse = ""; $tsql = "SELECT SL.bigint_LeadID, LS.smallint_LeadOrdinal FROM 25_serviceleads SL JOIN 27_leadssent LS ON ( SL.bigint_LeadID = LS.bigint_LeadID AND LS.bigint_SupplierID = ".$supplierid." ) WHERE LS.bigint_LeadID = ".$leadid.";"; $result = mysql_query_errors( $tsql, $conn, __FILE__ , __LINE__, true); if ($result) { if ($row = mysql_fetch_array($result)) { // just resend if not new supplier $charge = false; mysql_free_result($result); } else { // insert and charge if new supplier // get new ordinal $osql = "SELECT smallint_LeadOrdinal + 1 AS smallint_LeadOrdinal FROM 27_leadssent WHERE bigint_LeadID = ".$leadid." ORDER BY smallint_LeadOrdinal DESC LIMIT 1;"; $oresult = mysql_query_errors( $osql , $conn , __FILE__ , __LINE__, true); if ($oresult) { if ($orow = mysql_fetch_array($oresult)) { $ordinal = $orow["smallint_LeadOrdinal"] + 1; } } if (!$ordinal) $ordinal++; $sql1 = "INSERT INTO 27_leadssent (bigint_LeadID, smallint_LeadOrdinal, bigint_SupplierID, text_Duplicates, tinyint_LeadSent) VALUES (".$leadid.", ".$ordinal.", ".$supplierid.", \"\", 0);"; $result1 = mysql_query_errors( $sql1 , $conn , __FILE__ , __LINE__, true); // charge for lead sent if send successfully $charge = true; } $tsql = "SELECT SL.bigint_LeadID, LS.smallint_LeadOrdinal, SL.bigint_FormID, S.bigint_ZipCodeID, orgs.Latitude AS oLatitude, orgs.Longitude AS oLongitude, zips.Latitude, zips.Longitude, C.bigint_ConsumerRegion, C.text_ConsumerCountry, SL.bigint_ServiceID, CONCAT_WS( \";\", C.text_ConsumerName, C.`text_ConsumerE-Mail`, C.text_ConsumerPhone, C.text_ConsumerCity ) AS text_Consumer, LS.text_Duplicates, SL.text_LeadAttributes, SL.timestamp_ExpectedBy, SL.text_LeadMessage, R.text_RegionDescription, SC.*, LS.bigint_SupplierID, S.text_SupplierName, S.text_ContactFirstName, S.text_ContactSurname, S.`text_ContactE-mail`, S.bigint_CurrentBalance, S.tinyint_VariablePricingEnabled, S.text_AccMgr, S.`text_AccMgrE-mail`, S.text_OnePageData, LS.double_LeadValueScoring FROM 25_serviceleads SL LEFT JOIN 19_consumers C ON SL.bigint_ConsumerID = C.bigint_ConsumerID LEFT JOIN 27_leadssent LS ON SL.bigint_LeadID = LS.bigint_LeadID LEFT JOIN 1_regions R ON R.bigint_RegionID = C.bigint_ConsumerRegion LEFT JOIN 2_servicescatalogue SC ON SC.bigint_ServiceID = SL.bigint_ServiceID LEFT JOIN 5_suppliers S ON S.bigint_SupplierID = LS.bigint_SupplierID LEFT JOIN 30_fivedigitcommercial AS zips ON LPAD(S.bigint_ZipCodeID,5,'0') LIKE zips.ZIPCode LEFT JOIN 30_fivedigitcommercial AS orgs ON LPAD(C.bigint_ConsumerRegion,5,'0') LIKE orgs.ZIPCode AND zips.CityType='D' AND orgs.CityType='D' WHERE LS.bigint_LeadID = ".$leadid." AND LS.smallint_LeadOrdinal = ".$ordinal.";"; $result = mysql_query_errors( $tsql , $conn , __FILE__ , __LINE__, true); if ($result) { if ($row = mysql_fetch_array($result)) { global $service, $servicecost, $cat, $recipient, $append, $exby, $attribsarr, $formname, $consumerfullname, $consumeremail, $consumercell, $city_town, $message, $regionname, $leadid, $ordinal, $country, $leads360, $formfromname, $formfrommail, $sql, $errmsg; if ($row["bigint_ZipCodeID"]>0) { require_once("../private/DistanceWizard.php"); $unit = Measurement::MILES; // our desired unit of measure $distanceWizard = new DistanceWizard(); // create new distance wizard class // Create the coordinate of the origin ZIP code. $originCoord = new Coordinate($row['oLatitude'], $row['oLongitude']); // Get the relative ZIP code's coordinate. $relativeCoord = new Coordinate($row['Latitude'], $row['Longitude']); // Calculate the distance. $distance = $distanceWizard->CalculateDistance( $originCoord, $relativeCoord, $unit ); } $recipient = array( xmlentities($row["text_ContactFirstName"]." ".$row["text_ContactSurname"]), // 0 $row["text_SupplierName"], // 1 $row["text_ContactE-mail"], // 2 $row["bigint_CurrentBalance"], // 3 $row["bigint_ContactTel"], // 4 $row["text_SupplierAddress"], // 5 $row["bigint_SupplierID"], // 6 $row["text_GoogleMapsURL"], // 7 (($row["text_VTigerData"])?$row["text_VTigerData"]:" ; ; "), // 8 $row["tinyint_VariablePricingEnabled"], // 9 $row["smallint_SupplierStatus"], // 10 $row["text_AccMgr"], // 11 $row["text_AccMgrE-mail"], // 12 $row["bigint_CreditInvoice"], // 13 $distance, // 14 $row["bigint_ZipCodeID"], // 15 (($row["text_OnePageData"])?$row["text_OnePageData"]:";;") // 16 ); $append = $row["text_Duplicates"]; $service = $row["bigint_ServiceID"]; $exby = $row["timestamp_ExpectedBy"]; $attribsarr = formattribs($row["text_LeadAttributes"]); $formid = $row["bigint_FormID"]; $tsql0 = "SELECT * FROM 32_webformconfigs WHERE bigint_FormID = ".$formid.";"; $tresult0 = mysql_query_errors($tsql0, $conn, __FILE__, __LINE__); $trow0 = mysql_fetch_array($tresult0); $formname = $trow0["text_FormName"]; $formlogo = $trow0["text_FormLogo"]; $formfromname = $trow0["text_FormMailerFromName"]; $formfrommail = $trow0["text_FormMailerFromAddress"]; $redirect = $trow0["text_Redirect"]; $tafurl = $trow0["text_WebFormTAFUrl"]; $tafimg = $trow0["text_WebFormTAFImage"]; if ($GLOBALS["lvdenabled"]==1) { $GLOBALS["lvdenabled"] = $trow0["tinyint_LeadScoringEnabled"]; $GLOBALS["lvdtot"] = 0.000; $fixedcost = $trow0["bigint_CostPerLead"]; } else { $catid = getCategory(); } $servicecost = getCost($recipient[9]); // calculate service cost $newbalance = (($append!="")?$recipient[3]:$recipient[3]-$servicecost); // generate new balance $consumerinfo = explode(";",$row["text_Consumer"]); $consumerfullname = $consumerinfo[0]; $consumeremail = $consumerinfo[1]; $consumercell = $consumerinfo[2]; $city_town = $consumerinfo[3]; $country = $row["text_ConsumerCountry"]; $servicename = $row["text_ServiceDescription"]; $message = $row["text_LeadMessage"]; $regionname = $row["text_RegionDescription"]; $body = getFile("../templat/lead.html"); // load mail template $mail = new PHPMailer(); // create a new object $leads360 = "Available to %FORMFROMNAME% Premium eSales customers."; $leads360 = leads360Integration($recipient[6]); // submit leads 360 / retail connection requests $opret = onePageIntegration($recipient[16]); // submit onepage crm request $smgn = $orow["text_ServiceManagerContact"]; $smge = $orow["text_ServiceManagerE-mail"]; $tcsn = $orow["text_TechSupportContact"]; $tcse = $orow["text_TechSupportE-mail"]; $body = populateflags($body); // populate flags require("../includes/mailer/phpmailer 5.2.1/mailer_auth.php"); // include mailer auth $mail->From = $formfrommail; // set from mail $mail->FromName = $formfromname; // set from name $mail->Subject = html_entity_decode(getSubText($body,"<title>","</title>")); // set subject to template page title and append text $mail->AddReplyTo($consumeremail,$consumerfullname); // add the consumer to the replyto list $mail->ClearAttachments(); // clears attachments $mail->MsgHTML($body); // set HTML Body $mail->AltBody = strip_tags(html_entity_decode(getSubText($body,"<body>","</body>"))); // set Text Body $mail->AddAddress(($GLOBAL["prod_prodmode"])?$GLOBAL["prod_prodmail"]: // add recipient $recipient[2], html_entity_decode_utf8($recipient[0])); $mail->AddBCC($recipient[12],$recipient[11]); // bcc the accmgr the notification $mail->AddBCC($tcse,$tcsn); // bcc tech support the notification $mail->IsHTML(true); // set send as HTML if(!$mail->Send()) { // if attempt sending failed $response = "FAILURE: ".$recipient[0].", ".$recipient[2]." (".$mail->ErrorInfo.")"; // save error report } else { // successfully sent, subtract credits and report success. $response = "SUCCESS: ".$recipient[0].", ".$recipient[2]; // save success report & Call Leads 360 Integration if ($charge) { if ($newbalance != $recipient[3] && $append == "") { // if different supplier AND original lead deducted $sql2 = "UPDATE 5_suppliers SET bigint_CurrentBalance = ".$newbalance." WHERE bigint_SupplierID = ".$supplierid.";"; $result2 = mysql_query_errors( $sql2 , $conn , __FILE__ , __LINE__, true); $sql3 = "INSERT INTO 8_transactions (bigint_SupplierID, text_TransactionEvent, bigint_LeadID, smallint_LeadOrdinal, bigint_TransactionAmount, bigint_TransactionBalance) VALUES (".$recipient[6].",\"Lead #".($leadid + 11001000).$ordinal." Sent\", ".$leadid.",".$ordinal.",".$servicecost.",".$newbalance.");"; $result3 = mysql_query_errors( $sql3 , $conn , __FILE__ , __LINE__, true); } } $sql4 = "UPDATE 27_leadssent SET tinyint_LeadSent = 1, text_OnePageID = CONCAT(text_OnePageID, IF(LENGTH(text_OnePageID)>0,\", \",\"\"), \"".mysql_escape_string($opret)."\") WHERE bigint_LeadID = ".$leadid." AND bigint_SupplierID = ".$supplierid." AND smallint_LeadOrdinal = ".$ordinal.";"; $result4 = mysql_query_errors( $sql4 , $conn , __FILE__ , __LINE__, true); } if (implode("",$sql)!="") { $mail = new PHPMailer(); // create a new object $extended = array("\$mailadds (premium) = ".print_r($mailadds,true),"\$_SERVER = ".print_r($_SERVER,true),"gethostbyaddr(\$_SERVER['REMOTE_ADDR']) = ".gethostbyaddr($_SERVER['REMOTE_ADDR'])); // extended user info $body = "SQL, ARR, LMX & CAT DEBUGGING INFO:\r\n\r\n\$extended = ".print_r($extended,true)."\r\n\r\n\$SQL = ".print_r($GLOBALS["sql"],true)."\n\$ATTRIBSARR = ".print_r($attribsarr,true)."\r\n\$LVDENABLED = ".print_r($GLOBALS['lvdenabled'],true)."\r\n\r\n\$LVDKEYARR = ".print_r($GLOBALS['lvdkeyarr'],true)."\r\n\$LVDVALARR = ".print_r($GLOBALS['lvdvalarr'],true)."\r\n\$FIXEDCOST = ".print_r($GLOBALS['fixedcost'],true)."\r\n\$DYNAMICCOST = ".print_r($GLOBALS['dynamiccost'],true)."\r\n\r\n\$LVDTOT = ".print_r($GLOBALS['lvdtot'],true)."\r\n\r\n\$SERVICECOST = ".print_r($GLOBALS['servicecost'],true)."\r\n\r\n\$DYNARR = ".print_r($dynarr,true)."\r\n\$USERARR = ".print_r($userarr,true)."\r\n\$ERRMSG = ".print_r($errmsg,true); // create message body $mail->From = $formfrommail; // set from email $mail->FromName = $formfromname; // set from name $mail->Subject = "SQL Debugging & Other Errors"; // set subject to template page title $mail->AddAddress($smge,$smgn); // bcc jaap the response $mail->AddBCC($smge,$smgn); // bcc the svcmgr the notification $mail->AddBCC($tcse,$tcsn); // bcc tech support the notification $mail->ClearAttachments(); // clears attachments $mail->Body = $body; // set Text Body if(!$mail->Send()) { // if attempt sending failed array_push($errmsg,"DEBUG FAILURE: ".$smge.", ".$smgn." & ".$tcse.", ".$tcsn. // save error report " (".trim(strip_tags($mail->ErrorInfo)).")"); $failure++; // increment failures count } else { array_push($errmsg,"DEBUG SUCCESS: ".$smge.", ".$smgn." & ".$tcse.", ".$tcsn); // save success report $success++; // increment success count } } } } } $country = (isset($_POST["filter_country"]))?$_POST["filter_country"]:""; $state = (isset($_POST["filter_state"]))?$_POST["filter_state"]:""; $county = (isset($_POST["filter_county"]))?$_POST["filter_county"]:""; $zip = (isset($_POST["filter_zip"]))?$_POST["filter_zip"]:""; $supplrs = (isset($_POST["filter_suppliers"]))?$_POST["filter_suppliers"]:""; $search = (isset($_POST["filter_search"]))?$_POST["filter_search"]:""; switch ($o) { case 1: // by supplier getleads("LS.bigint_SupplierID", "S", "text_SupplierName", $country, $state, $county, $zip, $supplrs, $search); break; case 2: // by region getleads("C.bigint_ConsumerRegion", "R", "text_RegionDescription", $country, $state, $county, $zip, $supplrs, $search); break; default: // by service getleads("SL.bigint_ServiceID", "SC", "text_ServiceDescription", $country, $state, $county, $zip, $supplrs, $search); } getfsuppliers(); break; //... below is the getCost function which determines the cost of the lead. function getCost($varcost) { if ($GLOBALS['lvdenabled']==1) { $GLOBALS["lvdtot"] = populateflags("%LVDSCORE%"); while (!isset($GLOBALS["calc"]) || $GLOBALS["calc"] == 1) { usleep(1000); } $GLOBALS["servicecost"] = round($GLOBALS["fixedcost"]*$GLOBALS["lvdtot"],2); return $GLOBALS["servicecost"]; } else { if ($GLOBALS["append"]!="") { return 0; } elseif (intval($varcost) == 1) { return $GLOBALS["dynamiccost"]; } else { return $GLOBALS["fixedcost"]; } } } in an effort to determine what is wrong with the implementation - i tried to get a debugging mailer going, but unfortunately this does not mail out anything - doesn't even display it's own status. would someone be so kind as to assist in getting the debugging mailer working? thank you, Pierre "Greywacke" du Toit.
×
×
  • 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.