Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 70.98 KB | None | 0 0
  1. <?
  2.  
  3.   function adderror ($error)
  4.   {
  5.     global $errormessage;
  6.     $errormessage .= '<li>' . $error;
  7.   }
  8.  
  9.   function makehostingpayment ($func_domainid, $paidamount, $fees, $invoice = '', $gateway = '', $transid = '')
  10.   {
  11.     global $CONFIG;
  12.     $query = '' . 'SELECT * FROM tblhosting WHERE id=\'' . $func_domainid . '\'';
  13.     $result = mysql_query ($query);
  14.     $data = mysql_fetch_array ($result);
  15.     $userid = $data['userid'];
  16.     $billingcycle = $data['billingcycle'];
  17.     $domain = $data['domain'];
  18.     $packageid = $data['packageid'];
  19.     $regdate = $data['regdate'];
  20.     $nextduedate = $data['nextduedate'];
  21.     $status = $data['domainstatus'];
  22.     $server = $data['server'];
  23.     $paymentmethod = $data['paymentmethod'];
  24.     if ($gateway)
  25.     {
  26.       $paymentmethod = $gateway;
  27.     }
  28.  
  29.     if ($nextduedate == $regdate)
  30.     {
  31.       $amount = $data['firstpaymentamount'];
  32.     }
  33.     else
  34.     {
  35.       $amount = $data['amount'];
  36.     }
  37.  
  38.     $year = substr ($nextduedate, 0, 4);
  39.     $month = substr ($nextduedate, 5, 2);
  40.     $day = substr ($nextduedate, 8, 2);
  41.     $query = '' . 'SELECT * FROM tblproducts WHERE id=\'' . $packageid . '\'';
  42.     $result = mysql_query ($query);
  43.     $data = mysql_fetch_array ($result);
  44.     $producttype = $data['type'];
  45.     $package = $data['name'];
  46.     $proratabilling = $data['proratabilling'];
  47.     $proratadate = $data['proratadate'];
  48.     $proratachargenextmonth = $data['proratachargenextmonth'];
  49.     $tax = $data['tax'];
  50.     if (($tax AND $CONFIG['TaxEnabled']))
  51.     {
  52.       if (!function_exists ('getClientsDetails'))
  53.       {
  54.         require dirname (__FILE__) . '/clientfunctions.php';
  55.       }
  56.  
  57.       $clientsdetails = getclientsdetails ($userid);
  58.       $state = $clientsdetails['state'];
  59.       $country = $clientsdetails['country'];
  60.       $taxrate = gettaxrate ($state, $country);
  61.     }
  62.  
  63.     if (($regdate == $nextduedate AND $proratabilling))
  64.     {
  65.       if ($billingcycle == 'Monthly')
  66.       {
  67.         $proratamonths = 1;
  68.       }
  69.       else
  70.       {
  71.         if ($billingcycle == 'Quarterly')
  72.         {
  73.           $proratamonths = 3;
  74.         }
  75.         else
  76.         {
  77.           if ($billingcycle == 'Semi-Annually')
  78.           {
  79.             $proratamonths = 6;
  80.           }
  81.           else
  82.           {
  83.             if ($billingcycle == 'Annually')
  84.             {
  85.               $proratamonths = 12;
  86.             }
  87.             else
  88.             {
  89.               if ($billingcycle == 'Biennially')
  90.               {
  91.                 $proratamonths = 24;
  92.               }
  93.             }
  94.           }
  95.         }
  96.       }
  97.  
  98.       if ($billingcycle != 'Monthly')
  99.       {
  100.         $proratachargenextmonth = 0;
  101.       }
  102.  
  103.       $orderyear = substr ($regdate, 0, 4);
  104.       $ordermonth = substr ($regdate, 5, 2);
  105.       $orderday = substr ($regdate, 8, 2);
  106.       if ($orderday < $proratadate)
  107.       {
  108.         $proratamonth = $ordermonth;
  109.       }
  110.       else
  111.       {
  112.         $proratamonth = $ordermonth + 1;
  113.       }
  114.  
  115.       $days = (strtotime (date ('Y-m-d', mktime (0, 0, 0, $proratamonth, $proratadate, $orderyear))) - strtotime (date ('Y-m-d'))) / (60 * 60 * 24);
  116.       $totaldays = 30;
  117.       $proratadateuntil = date ('Y-m-d', mktime (0, 0, 0, $proratamonth, $proratadate, $orderyear));
  118.       if (($proratachargenextmonth <= $orderday AND $days < 31))
  119.       {
  120.         $proratadateuntil = date ('Y-m-d', mktime (0, 0, 0, $proratamonth + $proratamonths, $proratadate, $orderyear));
  121.       }
  122.     }
  123.  
  124.     if ($billingcycle == 'Monthly')
  125.     {
  126.       $new_time = mktime (0, 0, 0, $month + 1, $day, $year);
  127.       $day = date ('d', $new_time);
  128.       $month = date ('m', $new_time);
  129.       $year = date ('Y', $new_time);
  130.     }
  131.     else
  132.     {
  133.       if ($billingcycle == 'Quarterly')
  134.       {
  135.         $new_time = mktime (0, 0, 0, $month + 3, $day, $year);
  136.         $day = date ('d', $new_time);
  137.         $month = date ('m', $new_time);
  138.         $year = date ('Y', $new_time);
  139.       }
  140.       else
  141.       {
  142.         if ($billingcycle == 'Semi-Annually')
  143.         {
  144.           $new_time = mktime (0, 0, 0, $month + 6, $day, $year);
  145.           $day = date ('d', $new_time);
  146.           $month = date ('m', $new_time);
  147.           $year = date ('Y', $new_time);
  148.         }
  149.         else
  150.         {
  151.           if ($billingcycle == 'Annually')
  152.           {
  153.             $new_time = mktime (0, 0, 0, $month, $day, $year + 1);
  154.             $day = date ('d', $new_time);
  155.             $month = date ('m', $new_time);
  156.             $year = date ('Y', $new_time);
  157.           }
  158.           else
  159.           {
  160.             if ($billingcycle == 'Biennially')
  161.             {
  162.               $new_time = mktime (0, 0, 0, $month, $day, $year + 2);
  163.               $day = date ('d', $new_time);
  164.               $month = date ('m', $new_time);
  165.               $year = date ('Y', $new_time);
  166.             }
  167.             else
  168.             {
  169.               if ($billingcycle == 'One Time')
  170.               {
  171.                 $day = '00';
  172.                 $month = '00';
  173.                 $year = '0000';
  174.               }
  175.             }
  176.           }
  177.         }
  178.       }
  179.     }
  180.  
  181.     $nextduedate = $year . '-' . $month . '-' . $day;
  182.     if ($proratadateuntil)
  183.     {
  184.       $nextduedate = $proratadateuntil;
  185.     }
  186.  
  187.     $query = '' . 'UPDATE tblhosting SET nextduedate=\'' . $nextduedate . '\',nextinvoicedate=\'' . $nextduedate . '\' WHERE id=\'' . $func_domainid . '\'';
  188.     $result = mysql_query ($query);
  189.     if ($producttype == 'hostingaccount')
  190.     {
  191.       $productdescription = '' . 'Hosting Payment (' . $package . ' Package) - ' . $domain;
  192.     }
  193.     else
  194.     {
  195.       if ($producttype == 'reselleraccount')
  196.       {
  197.         $productdescription = '' . 'Reseller Payment (' . $package . ' Package) - ' . $domain;
  198.       }
  199.       else
  200.       {
  201.         if ($producttype == 'server')
  202.         {
  203.           $productdescription = '' . 'Server Payment (' . $package . ') - ' . $domain;
  204.         }
  205.         else
  206.         {
  207.           $productdescription = '' . 'Product/Service Payment (' . $package . ')';
  208.         }
  209.       }
  210.     }
  211.  
  212.     if ($invoice == '')
  213.     {
  214.       if (!$paidamount)
  215.       {
  216.         $newtaxrate = $taxrate / 100 + 1;
  217.         $paidamount = $amount * $newtaxrate;
  218.       }
  219.  
  220.       accountin ($userid, $productdescription, $paidamount, $fees, $paymentmethod, $transid);
  221.       sendmessage ('Subscription Payment Confirmation', $func_domainid, $nextduedate);
  222.     }
  223.  
  224.     logactivity ('' . 'Updated Next Due Date for Account (Hosting ID: ' . $func_domainid . ')');
  225.     if (!function_exists ('getServerType'))
  226.     {
  227.       require_once dirname (__FILE__) . '/serverfunctions.php';
  228.     }
  229.  
  230.     $servertype = getservertype ($server);
  231.     if ($status == 'Pending')
  232.     {
  233.       $query = '' . 'SELECT * FROM tblproducts WHERE id=\'' . $packageid . '\'';
  234.       $result = mysql_query ($query);
  235.       $data = mysql_fetch_array ($result);
  236.       $autosetup = $data['autosetup'];
  237.       if ($autosetup == 'payment')
  238.       {
  239.         global $silent;
  240.         if ($server != '')
  241.         {
  242.           require_once dirname (__FILE__) . '/../modules/servers/' . $servertype . '/' . $servertype . '.php';
  243.           $result = servercreateaccount ($func_domainid);
  244.           if ($result == 'success')
  245.           {
  246.             sendmessage ('defaultnewacc', $func_domainid);
  247.             sendadminnotification ('admin', 'WHMCS Automatic Setup Notification', '' . '<p>The order placed for ' . $domain . ' has received its first payment and has been automatically setup</p><p>Client ID: ' . $userid . '<br>Product/Service: ' . $package . '<br>Domain: ' . $domain . '</p>');
  248.             logactivity ('' . 'Automatic Account Setup on First Payment Successful (Hosting Account ID: ' . $func_domainid . ')');
  249.           }
  250.           else
  251.           {
  252.             sendadminnotification ('admin', 'WHMCS Automatic Setup Notification', '' . '<p>The order placed for ' . $domain . ' has received its first payment but an error occured and the account could not be automatically setup on the server</p><p>Client ID: ' . $userid . '<br>Product/Service: ' . $package . '<br>Domain: ' . $domain . '<br>Error: ' . $result . '</p>');
  253.             logactivity ('' . 'Automatic Account Setup on First Payment Failed (Hosting Account ID: ' . $func_domainid . ' Error: ' . $result . ')');
  254.           }
  255.         }
  256.       }
  257.     }
  258.  
  259.     if ($status == 'Suspended')
  260.     {
  261.       global $CONFIG;
  262.       if ($CONFIG['AutoUnsuspend'] == 'on')
  263.       {
  264.         if ($server != '')
  265.         {
  266.           if (!function_exists ('getServerType'))
  267.           {
  268.             require_once dirname (__FILE__) . '/serverfunctions.php';
  269.           }
  270.  
  271.           require_once dirname (__FILE__) . '/../modules/servers/' . $servertype . '/' . $servertype . '.php';
  272.           serverunsuspendaccount ($func_domainid);
  273.           sendadminnotification ('admin', 'WHMCS Automatic Unsuspension Notification', '' . '<p>The order placed for ' . $domain . ' has received its next payment and has been automatically unsuspended</p><p>Client ID: ' . $userid . '<br>Product/Service: ' . $package . '<br>Domain: ' . $domain . '</p>');
  274.           logactivity ('' . 'Automatic Unsuspension on Payment Performed (Hosting ID: ' . $func_domainid . ')');
  275.         }
  276.       }
  277.     }
  278.  
  279.     affiliatepayment ('', $func_domainid);
  280.   }
  281.  
  282.   function makedomainpayment ($func_domainid, $paidamount, $fees, $invoice = '', $gateway = '', $transid = '')
  283.   {
  284.     global $CONFIG;
  285.     $query = '' . 'SELECT * FROM tbldomains WHERE id=\'' . $func_domainid . '\'';
  286.     $result = mysql_query ($query);
  287.     $data = mysql_fetch_array ($result);
  288.     $userid = $data['userid'];
  289.     $domaintype = $data['type'];
  290.     $orderid = $data['orderid'];
  291.     $registrationperiod = $data['registrationperiod'];
  292.     $registrationdate = $data['registrationdate'];
  293.     $nextduedate = $data['nextduedate'];
  294.     $amount = $data['amount'];
  295.     $domain = $data['domain'];
  296.     $paymentmethod = $data['paymentmethod'];
  297.     $registrar = $data['registrar'];
  298.     $year = substr ($nextduedate, 0, 4);
  299.     $month = substr ($nextduedate, 5, 2);
  300.     $day = substr ($nextduedate, 8, 2);
  301.     $year = $year + $registrationperiod;
  302.     $newnextduedate = $year . $month . $day;
  303.     $query = '' . 'UPDATE tbldomains SET nextduedate=\'' . $newnextduedate . '\' WHERE id=\'' . $func_domainid . '\'';
  304.     $result = mysql_query ($query);
  305.     if ($gateway)
  306.     {
  307.       $paymentmethod = $gateway;
  308.     }
  309.  
  310.     if ($CONFIG['TaxEnabled'])
  311.     {
  312.       if (!function_exists ('getClientsDetails'))
  313.       {
  314.         require dirname (__FILE__) . '/clientfunctions.php';
  315.       }
  316.  
  317.       $clientsdetails = getclientsdetails ($userid);
  318.       $state = $clientsdetails['state'];
  319.       $country = $clientsdetails['country'];
  320.       $taxrate = gettaxrate ($state, $country);
  321.       $tax = 1;
  322.     }
  323.  
  324.     if ($invoice == '')
  325.     {
  326.       if (!$paidamount)
  327.       {
  328.         $newtaxrate = $taxrate / 100 + 1;
  329.         $paidamount = $amount * $newtaxrate;
  330.       }
  331.  
  332.       accountin ($userid, '' . 'Domain Payment - ' . $domain, $paidamount, $fees, $paymentmethod, $transid);
  333.       sendmessage ('Domain Subscription Payment Confirmation', $func_domainid);
  334.     }
  335.  
  336.     logactivity ('' . 'Updated Next Due Date for Domain (Domain ID: ' . $func_domainid . ')');
  337.     $domainparts = explode ('.', $domain, 2);
  338.     $sld = $domainparts[0];
  339.     $tld = $domainparts[1];
  340.     $table = 'tbldomainpricing';
  341.     $fields = 'autoreg';
  342.     $where = '' . 'extension=\'.' . $tld . '\'';
  343.     $result = select_query ($table, $fields, $where);
  344.     $data = mysql_fetch_array ($result);
  345.     $autoreg = $data['autoreg'];
  346.     if ($autoreg)
  347.     {
  348.       require_once dirname (__FILE__) . '/registrarfunctions.php';
  349.       $params['domainid'] = $func_domainid;
  350.       $params['sld'] = $sld;
  351.       $params['tld'] = $tld;
  352.       if ($nextduedate <= $registrationdate)
  353.       {
  354.         $table = 'tbldomains';
  355.         $fields = '';
  356.         $fields = array ('registrar' => $autoreg);
  357.         $where = '' . 'id=\'' . $func_domainid . '\'';
  358.         update_query ($table, $fields, $where);
  359.         $params['registrar'] = $autoreg;
  360.         if ($domaintype == 'Register')
  361.         {
  362.           $result = regregisterdomain ($params);
  363.           $emailmessage = 'Domain Registration Confirmation';
  364.         }
  365.         else
  366.         {
  367.           if ($domaintype == 'Transfer')
  368.           {
  369.             $result = regtransferdomain ($params);
  370.             $emailmessage = 'Domain Transfer Initiated';
  371.           }
  372.         }
  373.  
  374.         $result = $result['error'];
  375.         if ($result)
  376.         {
  377.           sendadminnotification ('admin', 'WHMCS Automatic Domain Registration Failure Notification', '' . '<p>The order placed for ' . $domain . ' has received its first payment and has been automatically submitted to the registrar</p><p>Client ID: ' . $userid . '<br>Domain: ' . $domain . '<br>Error: ' . $result . '</p>');
  378.           return null;
  379.         }
  380.  
  381.         sendmessage ($emailmessage, $func_domainid);
  382.         sendadminnotification ('admin', 'WHMCS Automatic Domain Registration Success Notification', '' . '<p>The order placed for ' . $domain . ' has received its first payment and has been automatically submitted to the registrar</p><p>Client ID: ' . $userid . '<br>Domain: ' . $domain . '</p>');
  383.         return null;
  384.       }
  385.  
  386.       $params['registrar'] = $registrar;
  387.       $result = regrenewdomain ($params);
  388.       $result = $result['error'];
  389.       if ($result)
  390.       {
  391.         sendadminnotification ('admin', 'WHMCS Automatic Domain Renewal Failure Notification', '' . '<p>The invoice for the renewal of ' . $domain . ' has been paid and the renewal request has been automatically submitted to the registrar</p><p>Client ID: ' . $userid . '<br>Domain: ' . $domain . '<br>Error: ' . $result . '</p>');
  392.         return null;
  393.       }
  394.  
  395.       sendmessage ('Domain Renewal Confirmation', $func_domainid);
  396.       sendadminnotification ('admin', 'WHMCS Automatic Domain Renewal Success Notification', '' . '<p>The invoice for the renewal of ' . $domain . ' has been paid and the renewal request has been automatically submitted to the registrar</p><p>Client ID: ' . $userid . '<br>Domain: ' . $domain . '</p>');
  397.     }
  398.  
  399.   }
  400.  
  401.   function accountin ($userid, $description, $amount, $fees, $gateway = '', $transid = '', $invoiceid = '', $date = '')
  402.   {
  403.     if ($date)
  404.     {
  405.       $date = '\'' . tomysqldate ($date) . '\'';
  406.     }
  407.     else
  408.     {
  409.       $date = 'now()';
  410.     }
  411.  
  412.     $query = '' . 'INSERT INTO tblaccounts (userid,gateway,date,description,amountin,fees,amountout,transid,invoiceid) VALUES (\'' . $userid . '\',\'' . $gateway . '\',' . $date . ',\'' . $description . '\',\'' . $amount . '\',\'' . $fees . '\',\'0.00\',\'' . $transid . '\',\'' . $invoiceid . '\')';
  413.     $result = mysql_query ($query);
  414.   }
  415.  
  416.   function accountout ($userid, $description, $amount)
  417.   {
  418.     $query = '' . 'INSERT INTO tblaccounts (userid,date,description,amountin,fees,amountout) VALUES (\'' . $userid . '\',now(),\'' . $description . '\',\'0.00\',\'0.00\',\'' . $amount . '\')';
  419.     $result = mysql_query ($query);
  420.   }
  421.  
  422.   function sendmessage ($func_messagename, $func_id, $extra = '')
  423.   {
  424.     global $silent;
  425.     global $CONFIG;
  426.     global $_LANG;
  427.     global $encryption_key;
  428.     $wordreplace_numbers = array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  429.     $wordreplace_words = array ('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
  430.     if ($func_messagename == 'defaultnewacc')
  431.     {
  432.       $query = '' . 'SELECT tblproducts.welcomeemail FROM tblproducts INNER JOIN tblhosting ON tblhosting.packageid=tblproducts.id WHERE tblhosting.id=\'' . $func_id . '\'';
  433.       $result = mysql_query ($query);
  434.       $data = mysql_fetch_array ($result);
  435.       $query = 'SELECT name FROM tblemailtemplates WHERE id=\'' . $data['welcomeemail'] . '\'';
  436.       $result = mysql_query ($query);
  437.       $data = mysql_fetch_array ($result);
  438.       $func_messagename = $data['name'];
  439.     }
  440.  
  441.     $query = '' . 'SELECT * FROM tblemailtemplates WHERE name=\'' . $func_messagename . '\' AND language=\'\'';
  442.     $result = mysql_query ($query);
  443.     $data = mysql_fetch_array ($result);
  444.     $type = $data['type'];
  445.     $subject = $data['subject'];
  446.     $message = $data['message'];
  447.     $fromname = $data['fromname'];
  448.     $fromemail = $data['fromemail'];
  449.     $disabled = $data['disabled'];
  450.     $copyto = $data['copyto'];
  451.     $plaintext = $data['plaintext'];
  452.     if (($type != 'support' AND !$func_id))
  453.     {
  454.       return false;
  455.     }
  456.  
  457.     if ($disabled)
  458.     {
  459.       if (!$silent)
  460.       {
  461.         echo '' . '<p>This email message has been disabled (' . $subject . ')</p>';
  462.       }
  463.  
  464.       return false;
  465.     }
  466.  
  467.     if ($type == 'invoice')
  468.     {
  469.       $query = '' . 'SELECT tblinvoices.*,tblpaymentgateways.value FROM tblinvoices INNER JOIN tblpaymentgateways ON tblpaymentgateways.gateway=tblinvoices.paymentmethod WHERE tblpaymentgateways.setting=\'name\' AND tblinvoices.id=\'' . $func_id . '\'';
  470.       $result = mysql_query ($query);
  471.       $data = mysql_fetch_array ($result);
  472.       $id = $data['id'];
  473.       $invoicenum = $data['invoicenum'];
  474.       $userid = $data['userid'];
  475.       $date = $data['date'];
  476.       $duedate = $data['duedate'];
  477.       $datepaid = $data['datepaid'];
  478.       if ($datepaid != '0000-00-00 00:00:00')
  479.       {
  480.         $datepaid = frommysqldate ($datepaid);
  481.       }
  482.       else
  483.       {
  484.         $datepaid = '-';
  485.       }
  486.  
  487.       $subtotal = $data['subtotal'];
  488.       $credit = $data['credit'];
  489.       $total = $data['total'];
  490.       $status = $data['status'];
  491.       $randomstring = $data['randomstring'];
  492.       $gateway = $data['paymentmethod'];
  493.       $taxrate = $data['taxrate'];
  494.       $tax = $data['tax'];
  495.       $paymentmethod = $data['value'];
  496.       $date = frommysqldate ($date);
  497.       $duedate = frommysqldate ($duedate);
  498.       if (!$invoicenum)
  499.       {
  500.         $invoicenum = $id;
  501.       }
  502.  
  503.       $query = '' . 'SELECT SUM(amountin) FROM tblaccounts WHERE invoiceid=\'' . $id . '\'';
  504.       $result = mysql_query ($query);
  505.       $data = mysql_fetch_array ($result);
  506.       $amountpaid = $data[0];
  507.       $query = '' . 'SELECT * FROM tblaccounts WHERE invoiceid=\'' . $id . '\' ORDER BY id DESC';
  508.       $result = mysql_query ($query);
  509.       $data = mysql_fetch_array ($result);
  510.       $lastpaymentamount = $data['amountin'];
  511.       $transactionid = $data['transid'];
  512.       $invoicedescription = '';
  513.       $query = '' . 'SELECT * FROM tblinvoiceitems WHERE invoiceid=\'' . $func_id . '\'';
  514.       $result = mysql_query ($query);
  515.       while ($data = mysql_fetch_array ($result))
  516.       {
  517.         $description = $data['description'];
  518.         $amount = $data['amount'];
  519.         $invoicedescription .= '' . $description . ' ' . $CONFIG['CurrencySymbol'] . $amount . ' ' . $CONFIG['Currency'] . '<br>
  520. ';
  521.       }
  522.  
  523.       $invoicedescription .= '------------------------------------------------------<br>
  524. ';
  525.       $invoicedescription .= $_LANG['invoicessubtotal'] . ': ' . $CONFIG['CurrencySymbol'] . $subtotal . ' ' . $CONFIG['Currency'] . '<br>
  526. ';
  527.       $invoicedescription .= $_LANG['invoicescredit'] . ': ' . $CONFIG['CurrencySymbol'] . $credit . ' ' . $CONFIG['Currency'] . '<br>
  528. ';
  529.       if (($CONFIG['TaxEnabled'] AND $taxrate))
  530.       {
  531.         $invoicedescription .= $taxrate . '% ' . $_LANG['invoicestax'] . ': ' . $CONFIG['CurrencySymbol'] . $tax . ' ' . $CONFIG['Currency'] . '<br>
  532. ';
  533.       }
  534.  
  535.       $invoicedescription .= $_LANG['invoicestotal'] . ': ' . $CONFIG['CurrencySymbol'] . $total . ' ' . $CONFIG['Currency'] . '';
  536.       if ($gateway)
  537.       {
  538.         if (!function_exists ('paymentMethodsSelection'))
  539.         {
  540.           require_once dirname (__FILE__) . '/gatewayfunctions.php';
  541.         }
  542.  
  543.         require_once dirname (__FILE__) . '/../modules/gateways/' . $gateway . '.php';
  544.         $params = getvariables ('' . $gateway);
  545.         $params['description'] = $CONFIG['CompanyName'] . ' - ' . $_LANG['invoicestitle'] . ' ' . $id;
  546.         $params['amount'] = $total;
  547.         $params['invoiceid'] = $id;
  548.         if ($CONFIG['SystemSSLURL'])
  549.         {
  550.           $params['systemurl'] = $CONFIG['SystemSSLURL'];
  551.         }
  552.         else
  553.         {
  554.           $params['systemurl'] = $CONFIG['SystemURL'];
  555.         }
  556.  
  557.         $params['returnurl'] = $params['systemurl'] . '/viewinvoice.php?id=' . $id;
  558.         $params['clientdetails'] = $clientsdetails;
  559.         eval ('$paymentbutton=' . $gateway . '_link($params);');
  560.       }
  561.  
  562.       $email_merge_fields['InvoiceID'] = $id;
  563.       $email_merge_fields['InvoiceNo'] = $invoicenum;
  564.       $email_merge_fields['InvoiceNum'] = $invoicenum;
  565.       $email_merge_fields['InvoiceDate'] = $date;
  566.       $email_merge_fields['DueDate'] = $duedate;
  567.       $email_merge_fields['DatePaid'] = $datepaid;
  568.       $email_merge_fields['Description'] = $invoicedescription;
  569.       $email_merge_fields['AmountPaid'] = $CONFIG['CurrencySymbol'] . ('' . $amountpaid . ' ') . $CONFIG['Currency'];
  570.       $email_merge_fields['AmountDue'] = $CONFIG['CurrencySymbol'] . ('' . $total . ' ') . $CONFIG['Currency'];
  571.       $email_merge_fields['SubTotal'] = $CONFIG['CurrencySymbol'] . ('' . $subtotal . ' ') . $CONFIG['Currency'];
  572.       $email_merge_fields['Credit'] = $CONFIG['CurrencySymbol'] . ('' . $credit . ' ') . $CONFIG['Currency'];
  573.       $email_merge_fields['Tax'] = $CONFIG['CurrencySymbol'] . ('' . $tax . ' ') . $CONFIG['Currency'];
  574.       $email_merge_fields['TaxRate'] = $taxrate . '%';
  575.       $email_merge_fields['Total'] = $CONFIG['CurrencySymbol'] . ('' . $total . ' ') . $CONFIG['Currency'];
  576.       $email_merge_fields['Status'] = $status;
  577.       $email_merge_fields['LastPaymentAmount'] = $lastpaymentamount;
  578.       $email_merge_fields['TransactionID'] = $transactionid;
  579.       $email_merge_fields['PayButton'] = $paymentbutton;
  580.       $email_merge_fields['PaymentMethod'] = $paymentmethod;
  581.       $email_merge_fields['InvoiceLink'] = '<a href="' . $CONFIG['SystemURL'] . ('' . '/viewinvoice.php?id=' . $id . '">') . $CONFIG['SystemURL'] . ('' . '/viewinvoice.php?id=' . $id . '</a>');
  582.       $query = '' . 'SELECT SUM(total) FROM tblinvoices WHERE userid=\'' . $userid . '\' AND status=\'Unpaid\'';
  583.       $result = mysql_query ($query);
  584.       $data = mysql_fetch_array ($result);
  585.       $alldueinvoices = $data[0];
  586.       $email_merge_fields['PreviousBalance'] = $CONFIG['CurrencySymbol'] . format_as_currency ($alldueinvoices - $total) . ' ' . $CONFIG['Currency'];
  587.       $email_merge_fields['AllDueInvoices'] = $CONFIG['CurrencySymbol'] . format_as_currency ($alldueinvoices) . ' ' . $CONFIG['Currency'];
  588.       $query = '' . 'SELECT amountin FROM tblaccounts WHERE userid=\'' . $userid . '\' ORDER BY id DESC';
  589.       $result = mysql_query ($query);
  590.       $data = mysql_fetch_array ($result);
  591.       $lastpaymentamount = $data[0];
  592.       $email_merge_fields['LastPaymentAmount'] = $CONFIG['CurrencySymbol'] . format_as_currency ($lastpaymentamount) . ' ' . $CONFIG['Currency'];
  593.       if (((($func_messagename == 'Invoice Created' OR $func_messagename == 'Credit Card Invoice Created') OR $func_messagename == 'Invoice Payment Confirmation') OR $func_messagename == 'Credit Card Payment Confirmation'))
  594.       {
  595.         if ($CONFIG['EnablePDFInvoices'])
  596.         {
  597.           require_once dirname (__FILE__) . '/countries.php';
  598.           if (strtoupper ($CONFIG['Charset']) == 'UTF-8')
  599.           {
  600.             require dirname (__FILE__) . '/tcpdf' . substr (phpversion (), 0, 1) . '.php';
  601.           }
  602.           else
  603.           {
  604.             require dirname (__FILE__) . '/fpdf.php';
  605.           }
  606.  
  607.           $attachmentfilename = $invoicenum . '.pdf';
  608.           $attachmentdata = pdfinvoice ($id);
  609.         }
  610.       }
  611.     }
  612.     else
  613.     {
  614.       if ($type == 'addon')
  615.       {
  616.         $query = '' . 'SELECT tblhostingaddons.*,tblpaymentgateways.value FROM tblhostingaddons INNER JOIN tblpaymentgateways ON tblpaymentgateways.gateway=tblhostingaddons.paymentmethod WHERE tblpaymentgateways.setting=\'name\' AND tblhostingaddons.id=\'' . $func_id . '\'';
  617.         $result = mysql_query ($query);
  618.         $data = mysql_fetch_array ($result);
  619.         $id = $data['id'];
  620.         $hostingid = $data['hostingid'];
  621.         $regdate = $data['regdate'];
  622.         $name = $data['name'];
  623.         $setupfee = $data['setupfee'];
  624.         $recurring = $data['recurring'];
  625.         $billingcycle = $data['billingcycle'];
  626.         $free = $data['free'];
  627.         $paymentmethod = $data['value'];
  628.         $status = $data['status'];
  629.         $nextduedate = $data['nextduedate'];
  630.         $regdate = frommysqldate ($regdate);
  631.         $nextduedate = frommysqldate ($nextduedate);
  632.         $query = '' . 'SELECT * FROM tblhosting WHERE id=\'' . $hostingid . '\'';
  633.         $result = mysql_query ($query);
  634.         $data = mysql_fetch_array ($result);
  635.         $userid = $data['userid'];
  636.         $domain = $data['domain'];
  637.         $package = $data['package'];
  638.         $email_merge_fields['RegDate'] = $regdate;
  639.         $email_merge_fields['Product'] = $package;
  640.         $email_merge_fields['Domain'] = $domain;
  641.         $email_merge_fields['AddonName'] = $name;
  642.         $email_merge_fields['SetupFee'] = $CONFIG['CurrencySymbol'] . ('' . $setupfee . ' ') . $CONFIG['Currency'];
  643.         $email_merge_fields['Amount'] = $CONFIG['CurrencySymbol'] . ('' . $recurring . ' ') . $CONFIG['Currency'];
  644.         $email_merge_fields['BillingCycle'] = $billingcycle;
  645.         $email_merge_fields['PaymentMethod'] = $paymentmethod;
  646.         $email_merge_fields['NextDueDate'] = $nextduedate;
  647.         $email_merge_fields['Status'] = $status;
  648.       }
  649.       else
  650.       {
  651.         if ($type == 'support')
  652.         {
  653.           $query = '' . 'SELECT * FROM tbltickets WHERE id=\'' . $func_id . '\'';
  654.           $result = mysql_query ($query);
  655.           $data = mysql_fetch_array ($result);
  656.           $id = $data['id'];
  657.           $deptid = $data['did'];
  658.           $tid = $data['tid'];
  659.           $c = $data['c'];
  660.           $userid = $data['userid'];
  661.           $date = $data['date'];
  662.           $title = $data['title'];
  663.           $tmessage = $data['message'];
  664.           $status = $data['status'];
  665.           $urgency = $data['urgency'];
  666.           $attachment = $data['attachment'];
  667.           if ($urgency == 'Low')
  668.           {
  669.             $urgency = $_LANG['supportticketsticketurgencylow'];
  670.           }
  671.           else
  672.           {
  673.             if ($urgency == 'Medium')
  674.             {
  675.               $urgency = $_LANG['supportticketsticketurgencymedium'];
  676.             }
  677.             else
  678.             {
  679.               if ($urgency == 'High')
  680.               {
  681.                 $urgency = $_LANG['supportticketsticketurgencyhigh'];
  682.               }
  683.             }
  684.           }
  685.  
  686.           if ($status == 'Open')
  687.           {
  688.             $status = $_LANG['supportticketsstatusopen'];
  689.           }
  690.           else
  691.           {
  692.             if ($status == 'Answered')
  693.             {
  694.               $status = $_LANG['supportticketsstatusanswered'];
  695.             }
  696.             else
  697.             {
  698.               if ($status == 'On Hold')
  699.               {
  700.                 $status = $_LANG['supportticketsstatusonhold'];
  701.               }
  702.               else
  703.               {
  704.                 if ($status == 'In Progress')
  705.                 {
  706.                   $status = $_LANG['supportticketsstatusinprogress'];
  707.                 }
  708.                 else
  709.                 {
  710.                   if ($status == 'Customer-Reply')
  711.                   {
  712.                     $status = $_LANG['supportticketsstatuscustomerreply'];
  713.                   }
  714.                   else
  715.                   {
  716.                     if ($status == 'Closed')
  717.                     {
  718.                       $status = $_LANG['supportticketsstatusclosed'];
  719.                     }
  720.                   }
  721.                 }
  722.               }
  723.             }
  724.           }
  725.  
  726.           if ($userid == '0000000000')
  727.           {
  728.             $firstname = $data['name'];
  729.             $email = $data['email'];
  730.           }
  731.  
  732.           $query = '' . 'SELECT * FROM tblticketdepartments WHERE id=\'' . $deptid . '\'';
  733.           $result = mysql_query ($query);
  734.           $data = mysql_fetch_array ($result);
  735.           $fromname = $CONFIG['CompanyName'] . ' ' . $data['name'];
  736.           $fromemail = $data['email'];
  737.           if ($extra != '')
  738.           {
  739.             $query = '' . 'SELECT * FROM tblticketreplies WHERE id=\'' . $extra . '\'';
  740.             $result = mysql_query ($query);
  741.             $data = mysql_fetch_array ($result);
  742.             $tmessage = $data['message'];
  743.             $attachment = $data['attachment'];
  744.           }
  745.  
  746.           if ($attachment)
  747.           {
  748.             global $attachments_dir;
  749.             $attachdir = $attachments_dir;
  750.             if (substr ($attachdir, 0, 1) != '/')
  751.             {
  752.               $attachdir = dirname (__FILE__) . '/../' . $attachdir;
  753.             }
  754.  
  755.             $attachmentfilename = substr ($attachment, 7);
  756.             $attachmentdata = file_get_contents ($attachdir . $attachment);
  757.           }
  758.  
  759.           $date = frommysqldate ($date);
  760.           $subject = '' . '[Ticket ID: ' . $tid . '] ' . $title;
  761.           $email_merge_fields['TicketID'] = $tid;
  762.           $email_merge_fields['DateOpened'] = $date;
  763.           $email_merge_fields['Subject'] = $title;
  764.           $email_merge_fields['Message'] = $tmessage;
  765.           $email_merge_fields['Status'] = $status;
  766.           $email_merge_fields['Priority'] = $urgency;
  767.           $email_merge_fields['TicketURL'] = $CONFIG['SystemURL'] . ('' . '/viewticket.php?tid=' . $tid . '&c=' . $c);
  768.           $email_merge_fields['TicketLink'] = '<a href="' . $CONFIG['SystemURL'] . ('' . '/viewticket.php?tid=' . $tid . '&c=' . $c . '">') . $CONFIG['SystemURL'] . ('' . '/viewticket.php?tid=' . $tid . '&c=' . $c . '</a>');
  769.         }
  770.         else
  771.         {
  772.           if ($type == 'domain')
  773.           {
  774.             $query = '' . 'SELECT * FROM tbldomains WHERE id=\'' . $func_id . '\'';
  775.             $result = mysql_query ($query);
  776.             $data = mysql_fetch_array ($result);
  777.             $id = $data['id'];
  778.             $userid = $data['userid'];
  779.             $orderid = $data['orderid'];
  780.             $registrationdate = $data['registrationdate'];
  781.             $status = $data['status'];
  782.             $domain = $data['domain'];
  783.             $firstpaymentamount = $data['firstpaymentamount'];
  784.             $recurringamount = $data['recurringamount'];
  785.             $registrar = $data['registrar'];
  786.             $registrationperiod = $data['registrationperiod'];
  787.             $expirydate = $data['expirydate'];
  788.             $nextduedate = $data['nextduedate'];
  789.             $registrationdate = frommysqldate ($registrationdate);
  790.             $expirydate = frommysqldate ($expirydate);
  791.             $nextduedate = frommysqldate ($nextduedate);
  792.             $email_merge_fields['OrderID'] = $orderid;
  793.             $email_merge_fields['OrderIDWords'] = str_replace ($wordreplace_numbers, $wordreplace_words, $orderid);
  794.             $email_merge_fields['RegDate'] = $registrationdate;
  795.             $email_merge_fields['Status'] = $status;
  796.             $email_merge_fields['Domain'] = $domain;
  797.             $email_merge_fields['Amount'] = $CONFIG['CurrencySymbol'] . ('' . $firstpaymentamount . ' ') . $CONFIG['Currency'];
  798.             $email_merge_fields['FirstPaymentAmount'] = $CONFIG['CurrencySymbol'] . ('' . $firstpaymentamount . ' ') . $CONFIG['Currency'];
  799.             $email_merge_fields['RecurringAmount'] = $CONFIG['CurrencySymbol'] . ('' . $recurringamount . ' ') . $CONFIG['Currency'];
  800.             $email_merge_fields['Registrar'] = $registrar;
  801.             $email_merge_fields['RegPeriod'] = $registrationperiod . ' ' . $_LANG['orderyears'];
  802.             $email_merge_fields['ExpiryDate'] = $expirydate;
  803.             $email_merge_fields['NextDueDate'] = $nextduedate;
  804.             $email_merge_fields['DaysUntilExpiry'] = $extra;
  805.           }
  806.           else
  807.           {
  808.             if ($type == 'product')
  809.             {
  810.               $query = '' . 'SELECT tblhosting.*,tblproducts.name,tblpaymentgateways.value FROM tblhosting INNER JOIN tblproducts ON tblproducts.id=tblhosting.packageid INNER JOIN tblpaymentgateways ON tblpaymentgateways.gateway=tblhosting.paymentmethod WHERE tblpaymentgateways.setting=\'name\' AND tblhosting.id=\'' . $func_id . '\'';
  811.               $result = mysql_query ($query);
  812.               $data = mysql_fetch_array ($result);
  813.               $id = $data['id'];
  814.               $userid = $data['userid'];
  815.               $orderid = $data['orderid'];
  816.               $regdate = $data['regdate'];
  817.               $nextduedate = $data['nextduedate'];
  818.               $orderno = $data['orderno'];
  819.               $domain = $data['domain'];
  820.               $server = $data['server'];
  821.               $package = $data['name'];
  822.               $packageid = $data['packageid'];
  823.               $upgrades = $data['upgrades'];
  824.               $gateway = $data['paymentmethod'];
  825.               $paymentmethod = $data['value'];
  826.               if ($regdate == $nextduedate)
  827.               {
  828.                 $amount = $data['firstpaymentamount'];
  829.               }
  830.               else
  831.               {
  832.                 $amount = $data['amount'];
  833.               }
  834.  
  835.               $firstpaymentamount = $data['firstpaymentamount'];
  836.               $recurringamount = $data['amount'];
  837.               if ($func_messagename == 'Hosting Payment Confirmation')
  838.               {
  839.                 if ($extra != '')
  840.                 {
  841.                   $nextduedate = $extra;
  842.                 }
  843.  
  844.                 if ($nextduedate == '0000-00-00')
  845.                 {
  846.                   $nextduedate = '-';
  847.                 }
  848.               }
  849.  
  850.               $billingcycle = $data['billingcycle'];
  851.               $domainstatus = $data['domainstatus'];
  852.               $username = $data['username'];
  853.               $password = decrypt ($data['password'], $encryption_key);
  854.               $rootpassword = decrypt ($data['rootpassword'], $encryption_key);
  855.               $dedicatedip = $data['dedicatedip'];
  856.               $assignedips = nl2br ($data['assignedips']);
  857.               $dedi_ns1 = $data['ns1'];
  858.               $dedi_ns2 = $data['ns2'];
  859.               $regdate = frommysqldate ($regdate);
  860.               if ($nextduedate != '-')
  861.               {
  862.                 $nextduedate = frommysqldate ($nextduedate);
  863.               }
  864.  
  865.               $query3 = '' . 'SELECT * FROM tblservers WHERE id=\'' . $server . '\'';
  866.               $result3 = mysql_query ($query3);
  867.               $data3 = mysql_fetch_array ($result3);
  868.               $servername = $data3['name'];
  869.               $serverip = $data3['ipaddress'];
  870.               $ns1 = $data3['nameserver1'];
  871.               $ns1ip = $data3['nameserver1ip'];
  872.               $ns2 = $data3['nameserver2'];
  873.               $ns2ip = $data3['nameserver2ip'];
  874.               $ns3 = $data3['nameserver3'];
  875.               $ns3ip = $data3['nameserver3ip'];
  876.               $ns4 = $data3['nameserver4'];
  877.               $ns4ip = $data3['nameserver4ip'];
  878.               $configoptions = '';
  879.               $query4 = '' . 'SELECT tblproductconfigoptions.optionname AS confoption,tblproductconfigoptionssub.optionname,tblproductconfigoptionssub.price FROM tblhostingconfigoptions INNER JOIN tblproductconfigoptions ON tblproductconfigoptions.id=tblhostingconfigoptions.configid INNER JOIN tblproductconfigoptionssub ON tblproductconfigoptionssub.id=tblhostingconfigoptions.optionid WHERE relid=\'' . $func_id . '\' ORDER BY tblproductconfigoptions.`order`,tblproductconfigoptions.id ASC';
  880.               $result4 = mysql_query ($query4);
  881.               while ($data4 = mysql_fetch_array ($result4))
  882.               {
  883.                 $confoption = $data4['confoption'];
  884.                 if (strpos ($confoption, '|'))
  885.                 {
  886.                   $confoption = explode ('|', $confoption);
  887.                   $confoption = trim ($confoption[1]);
  888.                 }
  889.  
  890.                 $optionname = $data4['optionname'];
  891.                 if (strpos ($optionname, '|'))
  892.                 {
  893.                   $optionname = explode ('|', $optionname);
  894.                   $optionname = trim ($optionname[1]);
  895.                 }
  896.  
  897.                 $price = $data4['price'];
  898.                 $configoptions .= '' . $confoption . ': ' . $optionname . ' ' . $CONFIG['CurrencySymbol'] . $price . '<br>
  899. ';
  900.               }
  901.  
  902.               $email_merge_fields['OrderID'] = $orderid;
  903.               $email_merge_fields['OrderIDWords'] = str_replace ($wordreplace_numbers, $wordreplace_words, $orderid);
  904.               $email_merge_fields['ProductID'] = ltrim ($id, 0);
  905.               $email_merge_fields['RegDate'] = $regdate;
  906.               $email_merge_fields['Domain'] = $domain;
  907.               $email_merge_fields['ServerName'] = $servername;
  908.               $email_merge_fields['ServerIP'] = $serverip;
  909.               $email_merge_fields['DedicatedIP'] = $dedicatedip;
  910.               $email_merge_fields['AssignedIPs'] = $assignedips;
  911.               if ($dedi_ns1 != '')
  912.               {
  913.                 $email_merge_fields['Nameserver1'] = $dedi_ns1;
  914.                 $email_merge_fields['Nameserver2'] = $dedi_ns2;
  915.               }
  916.               else
  917.               {
  918.                 $email_merge_fields['Nameserver1'] = $ns1;
  919.                 $email_merge_fields['Nameserver2'] = $ns2;
  920.                 $email_merge_fields['Nameserver3'] = $ns3;
  921.                 $email_merge_fields['Nameserver4'] = $ns4;
  922.               }
  923.  
  924.               $email_merge_fields['Nameserver1IP'] = $ns1ip;
  925.               $email_merge_fields['Nameserver2IP'] = $ns2ip;
  926.               $email_merge_fields['Nameserver3IP'] = $ns3ip;
  927.               $email_merge_fields['Nameserver4IP'] = $ns4ip;
  928.               $email_merge_fields['Product'] = $package;
  929.               $email_merge_fields['Package'] = $package;
  930.               $email_merge_fields['ConfigOptions'] = $configoptions;
  931.               $email_merge_fields['Domain'] = $domain;
  932.               $email_merge_fields['PaymentMethod'] = $paymentmethod;
  933.               $email_merge_fields['Amount'] = $CONFIG['CurrencySymbol'] . ('' . $amount . ' ') . $CONFIG['Currency'];
  934.               $email_merge_fields['FirstPaymentAmount'] = $CONFIG['CurrencySymbol'] . ('' . $firstpaymentamount . ' ') . $CONFIG['Currency'];
  935.               $email_merge_fields['RecurringAmount'] = $CONFIG['CurrencySymbol'] . ('' . $recurringamount . ' ') . $CONFIG['Currency'];
  936.               $email_merge_fields['BillingCycle'] = $billingcycle;
  937.               $email_merge_fields['NextDueDate'] = $nextduedate;
  938.               $email_merge_fields['Status'] = $domainstatus;
  939.               $email_merge_fields['Username'] = $username;
  940.               $email_merge_fields['Password'] = $password;
  941.               $email_merge_fields['CpanelUsername'] = $username;
  942.               $email_merge_fields['CpanelPassword'] = $password;
  943.               $email_merge_fields['RootUsername'] = $username;
  944.               $email_merge_fields['RootPassword'] = $rootpassword;
  945.               include_once dirname (__FILE__) . '/customfieldfunctions.php';
  946.               $customfields = getcustomfields ('product', $packageid, $func_id, '', '');
  947.               foreach ($customfields as $customfield)
  948.               {
  949.                 $email_merge_fields['ProductCustom-' . $customfield['name']] = $customfield['value'];
  950.               }
  951.  
  952.               if ($func_messagename == 'Order Confirmation')
  953.               {
  954.                 $userid = $func_id;
  955.                 foreach ($extra as $k => $v)
  956.                 {
  957.                   $email_merge_fields[$k] = $v;
  958.                 }
  959.               }
  960.             }
  961.             else
  962.             {
  963.               if ($type == 'affiliate')
  964.               {
  965.                 $query = '' . 'SELECT * FROM tblaffiliates WHERE id=\'' . $func_id . '\'';
  966.                 $result = mysql_query ($query);
  967.                 $data = mysql_fetch_array ($result);
  968.                 $id = $data['id'];
  969.                 $userid = $data['clientid'];
  970.                 $visitors = $data['visitors'];
  971.                 $balance = $data['balance'];
  972.                 $withdrawn = $data['withdrawn'];
  973.                 $referralstable .= '<table cellspacing=1 bgcolor=#cccccc width=100%><tr bgcolor=#efefef style="text-align:center;font-weight:bold;"><td>' . $_LANG['orderproduct'] . '</td><td>' . $_LANG['orderbillingcycle'] . '</td><td>' . $_LANG['affiliatescommision'] . '</td></tr>';
  974.                 $query = '' . 'SELECT * FROM tblaffiliatesaccounts WHERE affiliateid=\'' . $id . '\' ORDER BY id ASC';
  975.                 $result = mysql_query ($query);
  976.                 while ($data = mysql_fetch_array ($result))
  977.                 {
  978.                   $package = $data['package'];
  979.                   $billingcycle = $data['billingcycle'];
  980.                   $amount = $data['amount'];
  981.                   $commission = $data['commission'];
  982.                   $referralstable .= '' . '<tr bgcolor=#ffffff style="text-align:center;"><td>' . $package . '</td><td>' . $billingcycle . '</td><td>' . $CONFIG['CurrencySymbol'] . $commission . '</td></tr>';
  983.                 }
  984.  
  985.                 if ($status == '')
  986.                 {
  987.                   $referralstable .= '<tr bgcolor=#ffffff><td colspan=3 align=center>No Referral Signups</td></tr>';
  988.                 }
  989.  
  990.                 $referralstable .= '</table>';
  991.                 $email_merge_fields['TotalVisitors'] = $visitors;
  992.                 $email_merge_fields['CurrentBalance'] = $CONFIG['CurrencySymbol'] . $balance . ' ' . $CONFIG['Currency'];
  993.                 $email_merge_fields['AmountWithdrawn'] = $CONFIG['CurrencySymbol'] . $withdrawn . ' ' . $CONFIG['Currency'];
  994.                 $email_merge_fields['ReferralsTable'] = $referralstable;
  995.                 $email_merge_fields['ReferralLink'] = $CONFIG['SystemURL'] . ('' . '/aff.php?aff=' . $id);
  996.               }
  997.             }
  998.           }
  999.         }
  1000.       }
  1001.     }
  1002.  
  1003.     if ($type == 'general')
  1004.     {
  1005.       $userid = $func_id;
  1006.     }
  1007.  
  1008.     $query2 = '' . 'SELECT * FROM tblclients WHERE id=\'' . $userid . '\'';
  1009.     $result2 = mysql_query ($query2);
  1010.     $data2 = mysql_fetch_array ($result2);
  1011.     if ((!$firstname AND !$email))
  1012.     {
  1013.       $firstname = $data2['firstname'];
  1014.       $email = $data2['email'];
  1015.     }
  1016.  
  1017.     $lastname = $data2['lastname'];
  1018.     $companyname = $data2['companyname'];
  1019.     $address1 = $data2['address1'];
  1020.     $address2 = $data2['address2'];
  1021.     $city = $data2['city'];
  1022.     $state = $data2['state'];
  1023.     $postcode = $data2['postcode'];
  1024.     $country = $data2['country'];
  1025.     $phonenumber = $data2['phonenumber'];
  1026.     $language = $data2['language'];
  1027.     $credit = $data2['credit'];
  1028.     $password = decrypt ($data2['password'], $encryption_key);
  1029.     if ($companyname == '')
  1030.     {
  1031.       $fname = '' . $firstname . ' ' . $lastname;
  1032.     }
  1033.     else
  1034.     {
  1035.       $fname = '' . $firstname . ' ' . $lastname . ' (' . $companyname . ')';
  1036.     }
  1037.  
  1038.     if (!$email)
  1039.     {
  1040.       return false;
  1041.     }
  1042.  
  1043.     $query = '' . 'SELECT * FROM tblemailtemplates WHERE name=\'' . $func_messagename . '\' AND language=\'' . $language . '\'';
  1044.     $result = mysql_query ($query);
  1045.     $data = mysql_fetch_array ($result);
  1046.     if ((substr ($subject, 0, 10) != '[Ticket ID' AND $data['subject']))
  1047.     {
  1048.       $subject = $data['subject'];
  1049.     }
  1050.  
  1051.     if ($data['message'])
  1052.     {
  1053.       $message = $data['message'];
  1054.     }
  1055.  
  1056.     $email_merge_fields['CustomerID'] = ltrim ($userid, 0);
  1057.     $email_merge_fields['CustomerName'] = $fname;
  1058.     $email_merge_fields['CustomerFirstName'] = $firstname;
  1059.     $email_merge_fields['CompanyName'] = $companyname;
  1060.     $email_merge_fields['CustomerEmail'] = $email;
  1061.     $email_merge_fields['Address1'] = $address1;
  1062.     $email_merge_fields['Address2'] = $address2;
  1063.     $email_merge_fields['City'] = $city;
  1064.     $email_merge_fields['State'] = $state;
  1065.     $email_merge_fields['Postcode'] = $postcode;
  1066.     $email_merge_fields['Country'] = $country;
  1067.     $email_merge_fields['PhoneNumber'] = $phonenumber;
  1068.     $email_merge_fields['MAPassword'] = $password;
  1069.     $email_merge_fields['CAPassword'] = $password;
  1070.     $email_merge_fields['CreditBalance'] = $credit;
  1071.     include_once dirname (__FILE__) . '/customfieldfunctions.php';
  1072.     $customfields = getcustomfields ('client', '', $userid, 'on', '');
  1073.     foreach ($customfields as $customfield)
  1074.     {
  1075.       $email_merge_fields['Custom-' . $customfield['name']] = $customfield['value'];
  1076.     }
  1077.  
  1078.     $email_merge_fields['CompanyName'] = $CONFIG['CompanyName'];
  1079.     $email_merge_fields['ClientAreaLink'] = '<a href="' . $CONFIG['SystemURL'] . '">' . $CONFIG['SystemURL'] . '</a>';
  1080.     $email_merge_fields['Signature'] = nl2br ($CONFIG['Signature']);
  1081.     if ($fromname == '')
  1082.     {
  1083.       $fromname = $CONFIG['CompanyName'];
  1084.     }
  1085.  
  1086.     if ($fromemail == '')
  1087.     {
  1088.       $fromemail = $CONFIG['Email'];
  1089.     }
  1090.  
  1091.     foreach ($email_merge_fields as $mergefield => $mergevalue)
  1092.     {
  1093.       $subject = str_replace ((('' . '[') . $mergefield . ']'), $mergevalue, $subject);
  1094.       $message = str_replace ((('' . '[') . $mergefield . ']'), $mergevalue, $message);
  1095.     }
  1096.  
  1097.     $mail = new PHPMailer ();
  1098.     if ($CONFIG['MailType'] == 'mail')
  1099.     {
  1100.       $mail->Mailer = 'mail';
  1101.       $mail->From = $fromemail;
  1102.       $mail->FromName = $fromname;
  1103.     }
  1104.     else
  1105.     {
  1106.       if ($CONFIG['MailType'] == 'smtp')
  1107.       {
  1108.         $mail->IsSMTP ();
  1109.         $mail->Host = $CONFIG['SMTPHost'];
  1110.         $mail->SMTPAuth = true;
  1111.         $mail->Port = $CONFIG['SMTPPort'];
  1112.         $mail->Username = $CONFIG['SMTPUsername'];
  1113.         $mail->Password = $CONFIG['SMTPPassword'];
  1114.         $mail->From = $CONFIG['SMTPUsername'];
  1115.         $mail->FromName = $fromname;
  1116.         $mail->Sender = $mail->Username;
  1117.         $mail->AddReplyTo ($fromemail, $fromname);
  1118.       }
  1119.     }
  1120.  
  1121.     $mail->CharSet = $CONFIG['Charset'];
  1122.     if ($CONFIG['BCCMessages'] != '')
  1123.     {
  1124.       $bcc = $CONFIG['BCCMessages'] . ',';
  1125.       $bcc = explode (',', $bcc);
  1126.       foreach ($bcc as $value)
  1127.       {
  1128.         if ($value != '')
  1129.         {
  1130.           $mail->AddBCC ($value);
  1131.           continue;
  1132.         }
  1133.       }
  1134.     }
  1135.  
  1136.     $mail->AddAddress ($email, $firstname . ' ' . $lastname);
  1137.     $query = '' . 'SELECT * FROM tblcontacts WHERE userid=\'' . $userid . '\' AND ' . $type . 'emails=\'1\'';
  1138.     $result = mysql_query ($query);
  1139.     while ($data = mysql_fetch_array ($result))
  1140.     {
  1141.       $mail->AddAddress ($data['email'], $data['firstname'] . ' ' . $data['lastname']);
  1142.     }
  1143.  
  1144.     if ($copyto)
  1145.     {
  1146.       if ($CONFIG['MailType'] == 'mail')
  1147.       {
  1148.         $mail->AddBCC ($copyto, $CONFIG['CompanyName']);
  1149.       }
  1150.       else
  1151.       {
  1152.         $mail->AddCC ($copyto, $CONFIG['CompanyName']);
  1153.       }
  1154.     }
  1155.  
  1156.     $mail->Subject = stripslashes ($subject);
  1157.     if ($plaintext)
  1158.     {
  1159.       $message = stripslashes ($message);
  1160.       $message = strip_tags ($message);
  1161.       $mail->Body = $message;
  1162.       $message = nl2br ($message);
  1163.     }
  1164.     else
  1165.     {
  1166.       $message = stripslashes ($message);
  1167.       $message_text = str_replace ('<p>', '', $message);
  1168.       $message_text = str_replace ('</p>', '
  1169.  
  1170. ', $message_text);
  1171.       $message_text = str_replace ('<br>', '
  1172. ', $message_text);
  1173.       $message_text = str_replace ('<br />', '
  1174. ', $message_text);
  1175.       $message_text = strip_tags ($message_text);
  1176.       if ($CONFIG['LogoURL'] != '')
  1177.       {
  1178.         $message = '<p><a href="' . $CONFIG['Domain'] . '" target="_blank"><img src="' . $CONFIG['LogoURL'] . '" alt="' . $CONFIG['CompanyName'] . '" border="0"></a></p><font style="font-family:Verdana;font-size:11px">' . $message;
  1179.       }
  1180.       else
  1181.       {
  1182.         $message = '<font style="font-family:Verdana;font-size:11px">' . $message;
  1183.       }
  1184.  
  1185.       $mail->Body = $message;
  1186.       $mail->AltBody = $message_text;
  1187.     }
  1188.  
  1189.     if ($attachmentfilename)
  1190.     {
  1191.       $mail->AddStringAttachment ($attachmentdata, $attachmentfilename);
  1192.     }
  1193.  
  1194.     global $smtp_debug;
  1195.     if ($smtp_debug == 'on')
  1196.     {
  1197.       $mail->SMTPDebug = true;
  1198.     }
  1199.  
  1200.     if (CLIENTAREA == '1')
  1201.     {
  1202.       $silent = 'true';
  1203.     }
  1204.  
  1205.     if (!$mail->Send ())
  1206.     {
  1207.       if ($silent != 'true')
  1208.       {
  1209.         echo '' . '<p>There has been an error sending the email (' . $subject . ')</p>';
  1210.       }
  1211.     }
  1212.     else
  1213.     {
  1214.       if ($silent != 'true')
  1215.       {
  1216.         echo '' . '<p>Email Sent Successfully to <a href="clientssummary.php?userid=' . $userid . '">' . $firstname . ' ' . $lastname . '</a></p>';
  1217.       }
  1218.  
  1219.       $subject = addslashes ($subject);
  1220.       $message = addslashes ($message);
  1221.       $query = '' . 'INSERT INTO tblemails (userid,subject,message,date) VALUES (\'' . $userid . '\',\'' . $subject . '\',\'' . $message . '\',now())';
  1222.       $result = mysql_query ($query);
  1223.       logactivity ('' . 'Email Sent to ' . $firstname . ' ' . $lastname . ' (' . $subject . ')');
  1224.     }
  1225.  
  1226.     $mail->ClearAddresses ();
  1227.   }
  1228.  
  1229.   function sendadminnotification ($to = 'admin', $subject, $adminmessage, $deptid = '')
  1230.   {
  1231.     global $CONFIG;
  1232.     if ($CONFIG['LogoURL'] != '')
  1233.     {
  1234.       $message = '<p><a href="' . $CONFIG['Domain'] . '" target="_blank"><img src="' . $CONFIG['LogoURL'] . '" alt="' . $CONFIG['CompanyName'] . '" border="0"></a></p>';
  1235.     }
  1236.  
  1237.     $message .= '' . '<font style="font-family:Verdana;font-size:11px"><p>' . $adminmessage . '</p><p><a href="' . $CONFIG['SystemURL'] . '/admin/">' . $CONFIG['SystemURL'] . '/admin/</a></p>';
  1238.     $mail = new PHPMailer ();
  1239.     $mail->From = $CONFIG['SystemEmailsFromEmail'];
  1240.     $mail->FromName = $CONFIG['SystemEmailsFromName'];
  1241.     $mail->Subject = stripslashes ($subject);
  1242.     $mail->CharSet = $CONFIG['Charset'];
  1243.     if ($CONFIG['MailType'] == 'mail')
  1244.     {
  1245.       $mail->Mailer = 'mail';
  1246.     }
  1247.     else
  1248.     {
  1249.       if ($CONFIG['MailType'] == 'smtp')
  1250.       {
  1251.         $mail->IsSMTP ();
  1252.         $mail->Host = $CONFIG['SMTPHost'];
  1253.         $mail->SMTPAuth = true;
  1254.         $mail->Port = $CONFIG['SMTPPort'];
  1255.         $mail->Username = $CONFIG['SMTPUsername'];
  1256.         $mail->Password = $CONFIG['SMTPPassword'];
  1257.         $mail->From = $CONFIG['SystemEmailsFromEmail'];
  1258.         $mail->FromName = $CONFIG['SystemEmailsFromName'];
  1259.         $mail->Sender = $CONFIG['SMTPUsername'];
  1260.         $mail->AddReplyTo ($CONFIG['SystemEmailsFromEmail'], $CONFIG['SystemEmailsFromName']);
  1261.       }
  1262.     }
  1263.  
  1264.     $message = stripslashes ($message);
  1265.     $message_text = str_replace ('</p>', '
  1266.  
  1267. ', $message);
  1268.     $message_text = str_replace ('<br>', '
  1269. ', $message_text);
  1270.     $message_text = strip_tags ($message_text);
  1271.     $mail->Body = $message;
  1272.     $mail->AltBody = $message_text;
  1273.     $mailquery = 'SELECT * FROM tbladmins WHERE ';
  1274.     if ($deptid != '')
  1275.     {
  1276.       $query = '' . 'SELECT * FROM tblticketdepartments WHERE id=\'' . $deptid . '\'';
  1277.       $result = mysql_query ($query);
  1278.       $data = mysql_fetch_array ($result);
  1279.       $mail->From = $data['email'];
  1280.       $deptid = str_pad ($deptid, 3, '0', STR_PAD_LEFT);
  1281.       $mailquery .= '' . 'ticketnotifications=\'on\' AND supportdepts LIKE \'%,' . $deptid . ',%\'';
  1282.     }
  1283.     else
  1284.     {
  1285.       $mailquery .= '(userlevel=\'3\'';
  1286.       if ($to == 'support')
  1287.       {
  1288.         $mailquery .= ' OR userlevel=\'1\'';
  1289.       }
  1290.       else
  1291.       {
  1292.         if ($to == 'sales')
  1293.         {
  1294.           $mailquery .= ' OR userlevel=\'2\'';
  1295.         }
  1296.       }
  1297.  
  1298.       $mailquery .= ')';
  1299.       if ($subject == 'WHMCS New Order Notification')
  1300.       {
  1301.         $mailquery .= ' AND ordernotifications=\'on\'';
  1302.       }
  1303.     }
  1304.  
  1305.     $mailresult = mysql_query ($mailquery);
  1306.     $i = 0;
  1307.     while ($maildata = mysql_fetch_array ($mailresult))
  1308.     {
  1309.       $mail->AddAddress ($maildata['email']);
  1310.     }
  1311.  
  1312.     $mail->Send ();
  1313.     $mail->ClearAddresses ();
  1314.   }
  1315.  
  1316.   function tomysqldate ($date)
  1317.   {
  1318.     global $CONFIG;
  1319.     if ($CONFIG['DateFormat'] == 'DD/MM/YYYY')
  1320.     {
  1321.       $day = substr ($date, 0, 2);
  1322.       $month = substr ($date, 3, 2);
  1323.       $year = substr ($date, 6, 4);
  1324.       $hours = substr ($date, 10, 2);
  1325.       $minutes = substr ($date, 13, 2);
  1326.       $seconds = substr ($date, 16, 2);
  1327.     }
  1328.     else
  1329.     {
  1330.       if ($CONFIG['DateFormat'] == 'MM/DD/YYYY')
  1331.       {
  1332.         $day = substr ($date, 3, 2);
  1333.         $month = substr ($date, 0, 2);
  1334.         $year = substr ($date, 6, 4);
  1335.         $hours = substr ($date, 10, 2);
  1336.         $minutes = substr ($date, 13, 2);
  1337.         $seconds = substr ($date, 16, 2);
  1338.       }
  1339.       else
  1340.       {
  1341.         if ($CONFIG['DateFormat'] == 'YYYY/MM/DD')
  1342.         {
  1343.           $day = substr ($date, 8, 2);
  1344.           $month = substr ($date, 5, 2);
  1345.           $year = substr ($date, 0, 4);
  1346.           $hours = substr ($date, 10, 2);
  1347.           $minutes = substr ($date, 13, 2);
  1348.           $seconds = substr ($date, 16, 2);
  1349.         }
  1350.       }
  1351.     }
  1352.  
  1353.     $date = $year . $month . $day . $hours . $minutes . $seconds;
  1354.     return $date;
  1355.   }
  1356.  
  1357.   function frommysqldate ($date, $format = '')
  1358.   {
  1359.     global $CONFIG;
  1360.     global $timeoffset;
  1361.     $year = substr ($date, 0, 4);
  1362.     $month = substr ($date, 5, 2);
  1363.     $day = substr ($date, 8, 2);
  1364.     $hours = substr ($date, 11, 2);
  1365.     $minutes = substr ($date, 14, 2);
  1366.     $seconds = substr ($date, 17, 2);
  1367.     if ($timeoffset)
  1368.     {
  1369.       $hours = $hours + $timeoffset;
  1370.       $new_time = mktime ($hours, $minutes, $seconds, $month, $day, $year);
  1371.       $year = date ('Y', $new_time);
  1372.       $month = date ('m', $new_time);
  1373.       $day = date ('d', $new_time);
  1374.       $hours = date ('H', $new_time);
  1375.       $minutes = date ('i', $new_time);
  1376.       $seconds = date ('s', $new_time);
  1377.     }
  1378.  
  1379.     if ($CONFIG['DateFormat'] == 'DD/MM/YYYY')
  1380.     {
  1381.       $date = '' . $day . '/' . $month . '/' . $year;
  1382.     }
  1383.     else
  1384.     {
  1385.       if ($CONFIG['DateFormat'] == 'MM/DD/YYYY')
  1386.       {
  1387.         $date = '' . $month . '/' . $day . '/' . $year;
  1388.       }
  1389.       else
  1390.       {
  1391.         if ($CONFIG['DateFormat'] == 'YYYY/MM/DD')
  1392.         {
  1393.           $date = '' . $year . '/' . $month . '/' . $day;
  1394.         }
  1395.       }
  1396.     }
  1397.  
  1398.     if ($format == 'time')
  1399.     {
  1400.       $date .= '' . ' ' . $hours . ':' . $minutes;
  1401.     }
  1402.  
  1403.     return $date;
  1404.   }
  1405.  
  1406.   function gettodaysdate ()
  1407.   {
  1408.     global $CONFIG;
  1409.     if ($CONFIG['DateFormat'] == 'DD/MM/YYYY')
  1410.     {
  1411.       $date = date ('d') . '/' . date ('m') . '/' . date ('Y');
  1412.     }
  1413.     else
  1414.     {
  1415.       if ($CONFIG['DateFormat'] == 'MM/DD/YYYY')
  1416.       {
  1417.         $date = date ('m') . '/' . date ('d') . '/' . date ('Y');
  1418.       }
  1419.       else
  1420.       {
  1421.         if ($CONFIG['DateFormat'] == 'YYYY/MM/DD')
  1422.         {
  1423.           $date = date ('Y') . '/' . date ('m') . '/' . date ('d');
  1424.         }
  1425.       }
  1426.     }
  1427.  
  1428.     return $date;
  1429.   }
  1430.  
  1431.   function makeaddonpayment ($func_addonid, $paidamount, $func_fees, $invoice = '', $gateway = '', $transid = '')
  1432.   {
  1433.     global $CONFIG;
  1434.     $query = '' . 'SELECT * FROM tblhostingaddons WHERE id=\'' . $func_addonid . '\'';
  1435.     $result = mysql_query ($query);
  1436.     $data = mysql_fetch_array ($result);
  1437.     $id = $data['id'];
  1438.     $hostingid = $data['hostingid'];
  1439.     $regdate = $data['regdate'];
  1440.     $name = $data['name'];
  1441.     $setupfee = $data['setupfee'];
  1442.     $recurring = $data['recurring'];
  1443.     $billingcycle = $data['billingcycle'];
  1444.     $free = $data['free'];
  1445.     $status = $data['status'];
  1446.     $nextduedate = $data['nextduedate'];
  1447.     $paymentmethod = $data['paymentmethod'];
  1448.     if ($regdate == $nextduedate)
  1449.     {
  1450.       $amount = $setupfee + $recurring;
  1451.     }
  1452.     else
  1453.     {
  1454.       $amount = $recurring;
  1455.     }
  1456.  
  1457.     if ($gateway)
  1458.     {
  1459.       $paymentmethod = $gateway;
  1460.     }
  1461.  
  1462.     $query = '' . 'SELECT * FROM tblhosting WHERE id=\'' . $hostingid . '\'';
  1463.     $result = mysql_query ($query);
  1464.     $data = mysql_fetch_array ($result);
  1465.     $userid = $data['userid'];
  1466.     $domain = $data['domain'];
  1467.     if (substr ($regdate, 0, 8) == substr ($nextduedate, 0, 8))
  1468.     {
  1469.       $recurring = $setupfee;
  1470.     }
  1471.  
  1472.     $year = substr ($nextduedate, 0, 4);
  1473.     $month = substr ($nextduedate, 5, 2);
  1474.     $day = substr ($nextduedate, 8, 2);
  1475.     if ($billingcycle == 'Monthly')
  1476.     {
  1477.       $new_time = mktime (0, 0, 0, $month + 1, $day, $year);
  1478.       $day = date ('d', $new_time);
  1479.       $month = date ('m', $new_time);
  1480.       $year = date ('Y', $new_time);
  1481.     }
  1482.     else
  1483.     {
  1484.       if ($billingcycle == 'Quarterly')
  1485.       {
  1486.         $new_time = mktime (0, 0, 0, $month + 3, $day, $year);
  1487.         $day = date ('d', $new_time);
  1488.         $month = date ('m', $new_time);
  1489.         $year = date ('Y', $new_time);
  1490.       }
  1491.       else
  1492.       {
  1493.         if ($billingcycle == 'Semi-Annually')
  1494.         {
  1495.           $new_time = mktime (0, 0, 0, $month + 6, $day, $year);
  1496.           $day = date ('d', $new_time);
  1497.           $month = date ('m', $new_time);
  1498.           $year = date ('Y', $new_time);
  1499.         }
  1500.         else
  1501.         {
  1502.           if ($billingcycle == 'Annually')
  1503.           {
  1504.             $new_time = mktime (0, 0, 0, $month, $day, $year + 1);
  1505.             $day = date ('d', $new_time);
  1506.             $month = date ('m', $new_time);
  1507.             $year = date ('Y', $new_time);
  1508.           }
  1509.           else
  1510.           {
  1511.             if ($billingcycle == 'Biennially')
  1512.             {
  1513.               $new_time = mktime (0, 0, 0, $month, $day, $year + 2);
  1514.               $day = date ('d', $new_time);
  1515.               $month = date ('m', $new_time);
  1516.               $year = date ('Y', $new_time);
  1517.             }
  1518.             else
  1519.             {
  1520.               if ($billingcycle == 'One Time')
  1521.               {
  1522.                 $day = '00';
  1523.                 $month = '00';
  1524.                 $year = '0000';
  1525.               }
  1526.             }
  1527.           }
  1528.         }
  1529.       }
  1530.     }
  1531.  
  1532.     $nextduedate = $year . $month . $day;
  1533.     $query = '' . 'UPDATE tblhostingaddons SET nextduedate=\'' . $nextduedate . '\' WHERE id=\'' . $func_addonid . '\'';
  1534.     $result = mysql_query ($query);
  1535.     logactivity ('' . 'Updated Next Due Date for Hosting Addon (ID: ' . $func_addonid . ')');
  1536.     if ($CONFIG['TaxEnabled'])
  1537.     {
  1538.       $clientsdetails = getclientsdetails ($userid);
  1539.       $state = $clientsdetails['state'];
  1540.       $country = $clientsdetails['country'];
  1541.       $taxrate = gettaxrate ($state, $country);
  1542.       $tax = 1;
  1543.     }
  1544.  
  1545.     if ($invoice == '')
  1546.     {
  1547.       if (!$paidamount)
  1548.       {
  1549.         $newtaxrate = $taxrate / 100 + 1;
  1550.         $paidamount = $amount * $newtaxrate;
  1551.       }
  1552.  
  1553.       accountin ($userid, '' . 'Addon Payment (' . $domain . ') - ' . $name, $paidamount, $fees, $paymentmethod, $transid);
  1554.       sendmessage ('Addon Subscription Payment Confirmation', $func_addonid);
  1555.     }
  1556.  
  1557.   }
  1558.  
  1559.   function affiliatepayment ($affaccid, $hostingid)
  1560.   {
  1561.     global $CONFIG;
  1562.     if ($affaccid != '')
  1563.     {
  1564.       $query = '' . 'SELECT * FROM tblaffiliatesaccounts WHERE id=\'' . $affaccid . '\'';
  1565.     }
  1566.     else
  1567.     {
  1568.       $query = '' . 'SELECT * FROM tblaffiliatesaccounts WHERE relid=\'' . $hostingid . '\'';
  1569.     }
  1570.  
  1571.     $result = mysql_query ($query);
  1572.     $data = mysql_fetch_array ($result);
  1573.     $affaccid = $data['id'];
  1574.     $affid = $data['affiliateid'];
  1575.     $amount = $data['amount'];
  1576.     $lastpaid = $data['lastpaid'];
  1577.     $commission = $data['commission'];
  1578.     $relid = $data['relid'];
  1579.     $query = '' . 'SELECT tblproducts.*,tblhosting.amount FROM tblproducts INNER JOIN tblhosting ON tblhosting.packageid=tblproducts.id WHERE tblhosting.id=\'' . $relid . '\'';
  1580.     $result = mysql_query ($query);
  1581.     $data = mysql_fetch_array ($result);
  1582.     $affiliateonetime = $data['affiliateonetime'];
  1583.     if ($affiliateonetime == 'on')
  1584.     {
  1585.       if ($lastpaid == '0000-00-00')
  1586.       {
  1587.         $payout = true;
  1588.       }
  1589.       else
  1590.       {
  1591.         $error = 'This product is setup for a one time affiliate payment only and the commission has already been paid';
  1592.       }
  1593.     }
  1594.     else
  1595.     {
  1596.       $payout = true;
  1597.     }
  1598.  
  1599.     if (($affaccid AND $payout))
  1600.     {
  1601.       if ($CONFIG['AffiliatesDelayCommission'])
  1602.       {
  1603.         $clearingdate = date ('Y-m-d', mktime (0, 0, 0, date ('m'), date ('d') + $CONFIG['AffiliatesDelayCommission'], date ('Y')));
  1604.         $query = '' . 'INSERT INTO tblaffiliatespending (affaccid,amount,clearingdate) VALUES (\'' . $affaccid . '\',\'' . $commission . '\',\'' . $clearingdate . '\')';
  1605.         $result = mysql_query ($query);
  1606.       }
  1607.       else
  1608.       {
  1609.         $query = '' . 'UPDATE tblaffiliates SET balance=balance+' . $commission . ' WHERE id=\'' . $affid . '\'';
  1610.         $result = mysql_query ($query);
  1611.         $query = '' . 'UPDATE tblaffiliatesaccounts SET lastpaid=now() WHERE id=\'' . $affaccid . '\'';
  1612.         $result = mysql_query ($query);
  1613.         $query = '' . 'INSERT INTO tblaffiliateshistory (affiliateid,date,affaccid,amount) VALUES (\'' . $affid . '\',now(),\'' . $affaccid . '\',\'' . $commission . '\')';
  1614.         $result = mysql_query ($query);
  1615.       }
  1616.     }
  1617.  
  1618.     return $error;
  1619.   }
  1620.  
  1621.   function calculateaffiliatecommission ($affid, $relid)
  1622.   {
  1623.     global $CONFIG;
  1624.     $query = '' . 'SELECT tblproducts.*,tblhosting.amount,tblhosting.firstpaymentamount FROM tblproducts INNER JOIN tblhosting ON tblhosting.packageid=tblproducts.id WHERE tblhosting.id=\'' . $relid . '\'';
  1625.     $result = mysql_query ($query);
  1626.     $data = mysql_fetch_array ($result);
  1627.     $firstpaymentamount = $data['firstpaymentamount'];
  1628.     $amount = $data['amount'];
  1629.     $affiliateonetime = $data['affiliateonetime'];
  1630.     $affiliatepaytype = $data['affiliatepaytype'];
  1631.     $affiliatepayamount = $data['affiliatepayamount'];
  1632.     if ($affiliatepaytype)
  1633.     {
  1634.       if ($affiliatepaytype == 'percentage')
  1635.       {
  1636.         $percentage = $affiliatepayamount;
  1637.       }
  1638.       else
  1639.       {
  1640.         $fixedamount = $affiliatepayamount;
  1641.       }
  1642.     }
  1643.     else
  1644.     {
  1645.       $query = '' . 'SELECT * FROM tblaffiliates WHERE id=\'' . $affid . '\'';
  1646.       $result = mysql_query ($query);
  1647.       $data = mysql_fetch_array ($result);
  1648.       $paytype = $data['paytype'];
  1649.       $payamount = $data['payamount'];
  1650.       if ($paytype)
  1651.       {
  1652.         if ($paytype == 'percentage')
  1653.         {
  1654.           $percentage = $payamount;
  1655.         }
  1656.         else
  1657.         {
  1658.           $fixedamount = $payamount;
  1659.         }
  1660.       }
  1661.       else
  1662.       {
  1663.         $percentage = $CONFIG['AffiliateEarningPercent'];
  1664.       }
  1665.     }
  1666.  
  1667.     if ($fixedamount)
  1668.     {
  1669.       $commission = $fixedamount;
  1670.     }
  1671.     else
  1672.     {
  1673.       $commission = $amount * ($percentage / 100);
  1674.     }
  1675.  
  1676.     $commission = number_format ($commission, 2, '.', '');
  1677.     return $commission;
  1678.   }
  1679.  
  1680.   function logactivity ($description)
  1681.   {
  1682.     global $CONFIG;
  1683.     if ($_SESSION['adminusername'] == '')
  1684.     {
  1685.       $username = 'System';
  1686.     }
  1687.     else
  1688.     {
  1689.       $username = $_SESSION['adminusername'];
  1690.     }
  1691.  
  1692.     $query = '' . 'INSERT INTO tblactivitylog (date,description,user) VALUES (now(),\'' . $description . '\',\'' . $username . '\')';
  1693.     $result = mysql_query ($query);
  1694.     $query = 'SELECT * FROM tblactivitylog ORDER BY id DESC LIMIT ' . $CONFIG['ActivityLimit'] . ',99999';
  1695.     $result = mysql_query ($query);
  1696.     while ($data = mysql_fetch_array ($result))
  1697.     {
  1698.       $result2 = mysql_query ('DELETE FROM tblactivitylog WHERE id=\'' . $data['id'] . '\'');
  1699.     }
  1700.  
  1701.   }
  1702.  
  1703.   function generateuniqueid ($type = '')
  1704.   {
  1705.     $z = 0;
  1706.     if ($type == '')
  1707.     {
  1708.       $length = 10;
  1709.     }
  1710.     else
  1711.     {
  1712.       $length = 6;
  1713.     }
  1714.  
  1715.     while ($z <= 0)
  1716.     {
  1717.       $seedsfirst = '123456789';
  1718.       $seeds = '0123456789';
  1719.       $str = null;
  1720.       $seeds_count = strlen ($seeds) - 1;
  1721.       $i = 0;
  1722.       while ($i < $length)
  1723.       {
  1724.         if ($i == 0)
  1725.         {
  1726.           $str .= $seedsfirst[rand (0, $seeds_count - 1)];
  1727.         }
  1728.         else
  1729.         {
  1730.           $str .= $seeds[rand (0, $seeds_count)];
  1731.         }
  1732.  
  1733.         ++$i;
  1734.       }
  1735.  
  1736.       if ($type == '')
  1737.       {
  1738.         $query = '' . 'SELECT ordernum FROM tblorders WHERE ordernum=\'' . $str . '\'';
  1739.         $result = mysql_query ($query);
  1740.         $data = mysql_fetch_array ($result);
  1741.         $id = $data['id'];
  1742.         if ($id == '')
  1743.         {
  1744.           $z = 1;
  1745.           continue;
  1746.         }
  1747.  
  1748.         continue;
  1749.       }
  1750.       else
  1751.       {
  1752.         if ($type == 'tickets')
  1753.         {
  1754.           $query = '' . 'SELECT id FROM tbltickets WHERE tid=\'' . $str . '\'';
  1755.           $result = mysql_query ($query);
  1756.           $data = mysql_fetch_array ($result);
  1757.           $id = $data['id'];
  1758.           if ($id == '')
  1759.           {
  1760.             $z = 1;
  1761.             continue;
  1762.           }
  1763.  
  1764.           continue;
  1765.         }
  1766.  
  1767.         continue;
  1768.       }
  1769.     }
  1770.  
  1771.     return $str;
  1772.   }
  1773.  
  1774.   function getlicenseinformation ()
  1775.   {
  1776.     global $license;
  1777.     $url = 'http://www.whmcs.com/license/index.php';
  1778.     $query_string = 'licensekey=' . $license;
  1779.     $ch = curl_init ();
  1780.     curl_setopt ($ch, CURLOPT_URL, $url);
  1781.     curl_setopt ($ch, CURLOPT_POST, 1);
  1782.     curl_setopt ($ch, CURLOPT_TIMEOUT, 3);
  1783.     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  1784.     curl_setopt ($ch, CURLOPT_POSTFIELDS, $query_string);
  1785.     $filecontents = curl_exec ($ch);
  1786.     curl_close ($ch);
  1787.     preg_match ('/\\<registeredto\\>(.*?)\\<\\/registeredto\\>/', $filecontents, $registeredto);
  1788.     preg_match ('/\\<pid\\>(.*?)\\<\\/pid\\>/', $filecontents, $pid);
  1789.     preg_match ('/\\<type\\>(.*?)\\<\\/type\\>/', $filecontents, $type);
  1790.     preg_match ('/\\<domain\\>(.*?)\\<\\/domain\\>/', $filecontents, $domain);
  1791.     preg_match ('/\\<ip\\>(.*?)\\<\\/ip\\>/', $filecontents, $ip);
  1792.     preg_match ('/\\<created\\>(.*?)\\<\\/created\\>/', $filecontents, $created);
  1793.     preg_match ('/\\<expires\\>(.*?)\\<\\/expires\\>/', $filecontents, $expires);
  1794.     preg_match ('/\\<latestversion\\>(.*?)\\<\\/latestversion\\>/', $filecontents, $latestversion);
  1795.     $registeredto = $registeredto[1];
  1796.     $pid = $pid[1];
  1797.     $type = $type[1];
  1798.     $domain = $domain[1];
  1799.     $ip = $ip[1];
  1800.     $created = $created[1];
  1801.     $expires = $expires[1];
  1802.     $latestversion = $latestversion[1];
  1803.     $licenseinfo['registeredto'] = $registeredto;
  1804.     $licenseinfo['pid'] = $pid;
  1805.     $licenseinfo['type'] = $type;
  1806.     $licenseinfo['domain'] = $domain;
  1807.     $licenseinfo['ip'] = $ip;
  1808.     $licenseinfo['created'] = $created;
  1809.     $licenseinfo['expires'] = $expires;
  1810.     $licenseinfo['latestversion'] = $latestversion;
  1811.     return $licenseinfo;
  1812.   }
  1813.  
  1814.   function titlecase ($string)
  1815.   {
  1816.     $len = strlen ($string);
  1817.     $i = 0;
  1818.     $last = '';
  1819.     $new = '';
  1820.     $string = strtoupper ($string);
  1821.     while ($i < $len)
  1822.     {
  1823.       $char = substr ($string, $i, 1);
  1824.       if (ereg ('[A-Z]', $last))
  1825.       {
  1826.         $new .= strtolower ($char);
  1827.       }
  1828.       else
  1829.       {
  1830.         $new .= strtoupper ($char);
  1831.       }
  1832.  
  1833.       $last = $char;
  1834.       ++$i;
  1835.     }
  1836.  
  1837.     return $new;
  1838.   }
  1839.  
  1840.   function server_addr ()
  1841.   {
  1842.     return ($_SERVER['SERVER_ADDR'] ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']);
  1843.   }
  1844.  
  1845.   function path_translated ()
  1846.   {
  1847.     if ($_SERVER['PATH_TRANSLATED'])
  1848.     {
  1849.       return substr ($_SERVER['PATH_TRANSLATED'], 0, @strrpos ($_SERVER['PATH_TRANSLATED'], '/'));
  1850.     }
  1851.  
  1852.     if ($_SERVER['SCRIPT_FILENAME'])
  1853.     {
  1854.       return substr ($_SERVER['SCRIPT_FILENAME'], 0, @strrpos ($_SERVER['SCRIPT_FILENAME'], '/'));
  1855.     }
  1856.  
  1857.     return substr ($_SERVER['ORIG_PATH_TRANSLATED'], 0, @strrpos ($_SERVER['ORIG_PATH_TRANSLATED'], '\\'));
  1858.   }
  1859.  
  1860.   function encrypt ($string, $key = '')
  1861.   {
  1862.     if (!$key)
  1863.     {
  1864.       global $encryption_key;
  1865.       $key = $encryption_key;
  1866.     }
  1867.  
  1868.     $result = '';
  1869.     $i = 0;
  1870.     while ($i < strlen ($string))
  1871.     {
  1872.       $char = substr ($string, $i, 1);
  1873.       $keychar = substr ($key, $i % strlen ($key) - 1, 1);
  1874.       $char = chr (ord ($char) + ord ($keychar));
  1875.       $result .= $char;
  1876.       ++$i;
  1877.     }
  1878.  
  1879.     return base64_encode ($result);
  1880.   }
  1881.  
  1882.   function decrypt ($string, $key = '')
  1883.   {
  1884.     if (!$key)
  1885.     {
  1886.       global $encryption_key;
  1887.       $key = $encryption_key;
  1888.     }
  1889.  
  1890.     $result = '';
  1891.     $string = base64_decode ($string);
  1892.     $i = 0;
  1893.     while ($i < strlen ($string))
  1894.     {
  1895.       $char = substr ($string, $i, 1);
  1896.       $keychar = substr ($key, $i % strlen ($key) - 1, 1);
  1897.       $char = chr (ord ($char) - ord ($keychar));
  1898.       $result .= $char;
  1899.       ++$i;
  1900.     }
  1901.  
  1902.     return $result;
  1903.   }
  1904.  
  1905.   function sanitize ($str)
  1906.   {
  1907.     $str = strip_tags ($str);
  1908.     $str = htmlspecialchars ($str, ENT_NOQUOTES);
  1909.     $str = stripslashes ($str);
  1910.     return $str;
  1911.   }
  1912.  
  1913.   function xmltoarray ($rawxml)
  1914.   {
  1915.     $xml_parser = xml_parser_create ();
  1916.     xml_parse_into_struct ($xml_parser, $rawxml, $vals, $index);
  1917.     xml_parser_free ($xml_parser);
  1918.     $params = array ();
  1919.     $level = array ();
  1920.     foreach ($vals as $xml_elem)
  1921.     {
  1922.       if ($xml_elem['type'] == 'open')
  1923.       {
  1924.         $level[$xml_elem['level']] = $xml_elem['tag'];
  1925.       }
  1926.  
  1927.       if ($xml_elem['type'] == 'complete')
  1928.       {
  1929.         $start_level = 1;
  1930.         $php_stmt = '$params';
  1931.         while ($start_level < $xml_elem['level'])
  1932.         {
  1933.           $php_stmt .= '[$level[' . $start_level . ']]';
  1934.           ++$start_level;
  1935.         }
  1936.  
  1937.         $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
  1938.         eval ($php_stmt);
  1939.         continue;
  1940.       }
  1941.     }
  1942.  
  1943.     return $params;
  1944.   }
  1945.  
  1946.   function format_as_currency ($amount)
  1947.   {
  1948.     $amount += 9.99999999999999954748112e-07;
  1949.     $amount = round ($amount, 2);
  1950.     $amount = sprintf ('%01.2f', $amount);
  1951.     return $amount;
  1952.   }
  1953.  
  1954.   function xencrypt ($ckey, $string)
  1955.   {
  1956.     $string = base64_encode ($string);
  1957.     $keys = array ();
  1958.     $c_key = base64_encode (sha1 (md5 ($ckey)));
  1959.     $c_key = substr ($c_key, 0, round (ord ($ckey[0]) / 5));
  1960.     $c2_key = base64_encode (md5 (sha1 ($ckey)));
  1961.     $last = strlen ($ckey) - 1;
  1962.     $c2_key = substr ($c2_key, 1, round (ord ($ckey[$last]) / 7));
  1963.     $c3_key = base64_encode (sha1 (md5 ($c_key) . md5 ($c2_key)));
  1964.     $mid = round ($last / 2);
  1965.     $c3_key = substr ($c3_key, 1, round (ord ($ckey[$mid]) / 9));
  1966.     $c_key = $c_key . $c2_key . $c3_key;
  1967.     $c_key = base64_encode ($c_key);
  1968.     $i = 0;
  1969.     while ($i < strlen ($c_key))
  1970.     {
  1971.       $keys[] = $c_key[$i];
  1972.       ++$i;
  1973.     }
  1974.  
  1975.     $i = 0;
  1976.     while ($i < strlen ($string))
  1977.     {
  1978.       $id = $i % count ($keys);
  1979.       $ord = ord ($string[$i]);
  1980.       ($ord = $ord OR ord ($keys[$id]));
  1981.       ++$id;
  1982.       ($ord = $ord AND ord ($keys[$id]));
  1983.       ++$id;
  1984.       $ord = $ord XOR ord ($keys[$id]);
  1985.       ++$id;
  1986.       $ord = $ord + ord ($keys[$id]);
  1987.       $string[$i] = chr ($ord);
  1988.       ++$i;
  1989.     }
  1990.  
  1991.     return base64_encode ($string);
  1992.   }
  1993.  
  1994.   function xdecrypt ($ckey, $string)
  1995.   {
  1996.     $string = base64_decode ($string);
  1997.     $keys = array ();
  1998.     $c_key = base64_encode (sha1 (md5 ($ckey)));
  1999.     $c_key = substr ($c_key, 0, round (ord ($ckey[0]) / 5));
  2000.     $c2_key = base64_encode (md5 (sha1 ($ckey)));
  2001.     $last = strlen ($ckey) - 1;
  2002.     $c2_key = substr ($c2_key, 1, round (ord ($ckey[$last]) / 7));
  2003.     $c3_key = base64_encode (sha1 (md5 ($c_key) . md5 ($c2_key)));
  2004.     $mid = round ($last / 2);
  2005.     $c3_key = substr ($c3_key, 1, round (ord ($ckey[$mid]) / 9));
  2006.     $c_key = $c_key . $c2_key . $c3_key;
  2007.     $c_key = base64_encode ($c_key);
  2008.     $i = 0;
  2009.     while ($i < strlen ($c_key))
  2010.     {
  2011.       $keys[] = $c_key[$i];
  2012.       ++$i;
  2013.     }
  2014.  
  2015.     $i = 0;
  2016.     while ($i < strlen ($string))
  2017.     {
  2018.       $id = $i % count ($keys);
  2019.       $ord = ord ($string[$i]);
  2020.       $ord = $ord XOR ord ($keys[$id]);
  2021.       ++$id;
  2022.       ($ord = $ord AND ord ($keys[$id]));
  2023.       ++$id;
  2024.       ($ord = $ord OR ord ($keys[$id]));
  2025.       ++$id;
  2026.       $ord = $ord - ord ($keys[$id]);
  2027.       $string[$i] = chr ($ord);
  2028.       ++$i;
  2029.     }
  2030.  
  2031.     return base64_decode ($string);
  2032.   }
  2033.  
  2034.   require dirname (__FILE__) . '/class.phpmailer.php';
  2035.   if (!@function_exists ('file_get_contents'))
  2036.   {
  2037.     function file_get_contents ($url)
  2038.     {
  2039.       return implode ('', @file ($url));
  2040.     }
  2041.   }
  2042.  
  2043. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement