function widget_supporttickets_overview($vars)
{
    global $chart;
    $title = "Support Tickets Overview";
    $activestatuses = $replystatuses = array();
    $result = select_query("tblticketstatuses", "title,showactive,showawaiting", "showactive=1");
    while ($data = mysql_fetch_array($result)) {
        if ($data['showactive']) {
            $activestatuses[] = $data['title'];
        }
        if ($data['showawaiting']) {
            $replystatuses[] = $data['title'];
        }
    }
    $ticketcount = 0;
    $awaitingReplyByDept = array();
    if (count($replystatuses) > 0) {
        $query = "SELECT name,(SELECT COUNT(*) FROM tbltickets WHERE tbltickets.did=tblticketdepartments.id AND tbltickets.status IN (" . db_build_in_array($replystatuses) . ")) FROM tblticketdepartments ORDER BY `order` ASC";
        $result = full_query($query);
        while ($data = mysql_fetch_array($result)) {
            $awaitingReplyByDept[] = array('c' => array(array('v' => addcslashes(Sanitize::decode($data[0]), '"')), array('v' => $data[1], 'f' => $data[1])));
            $ticketcount += $data[1];
        }
    }
    $awaitingReplyByStatus = array();
    $query = "SELECT tblticketstatuses.title,(SELECT COUNT(*) FROM tbltickets WHERE tbltickets.status=tblticketstatuses.title) FROM tblticketstatuses WHERE showawaiting=1 ORDER BY sortorder ASC";
    $result = full_query($query);
    while ($data = mysql_fetch_array($result)) {
        $awaitingReplyByStatus[] = array('c' => array(array('v' => addcslashes(Sanitize::decode($data[0]), '"')), array('v' => $data[1], 'f' => $data[1])));
        $ticketcount += $data[1];
    }
    if (!$ticketcount) {
        $content = <<<EOT
<br />
<div align="center">
    There are <strong>0</strong> Tickets Currently Awaiting a Reply
</div>
<br />
EOT;
    } else {
        // Awaiting Reply by Department
        $chartData = array('cols' => array(array('label' => 'Department', 'type' => 'string'), array('label' => 'Ticket Count', 'type' => 'number')), 'rows' => $awaitingReplyByDept);
        $content = '<div id="ticketOverviewDepartments">' . $chart->drawChart('Pie', $chartData, array('title' => 'Awaiting Reply by Department', 'legendpos' => 'right'), '250px') . '</div>';
        // Awaiting Reply by Status
        $chartData = array('cols' => array(array('label' => 'Status', 'type' => 'string'), array('label' => 'Ticket Count', 'type' => 'number')), 'rows' => $awaitingReplyByStatus);
        $content .= '<div id="ticketOverviewStatuses">' . $chart->drawChart('Pie', $chartData, array('title' => 'Awaiting Reply by Status', 'legendpos' => 'right'), '250px') . '</div>';
    }
    return array('title' => $title, 'content' => $content);
}
Beispiel #2
0
 public function getUpgradeProductOptions()
 {
     $upgradepackages = $this->getUpgradePIDs();
     if (!count($upgradepackages)) {
         return array();
     }
     $array = array();
     $result = select_query("tblproducts", "id", "id IN (" . db_build_in_array($upgradepackages) . ")", "order` ASC,`name", "ASC");
     while ($data = mysql_fetch_array($result)) {
         $pid = $data['id'];
         $array[$pid] = getProductInfo($pid);
         $array[$pid]['pricing'] = getPricingInfo($pid, "", true);
     }
     return $array;
 }
Beispiel #3
0
function widget_supporttickets_overview($vars)
{
    global $_ADMINLANG;
    $title = "Support Tickets Overview";
    $activestatuses = $replystatuses = array();
    $result = select_query("tblticketstatuses", "title,showactive,showawaiting", "showactive=1");
    while ($data = mysql_fetch_array($result)) {
        if ($data['showactive']) {
            $activestatuses[] = db_escape_string($data['title']);
        }
        if ($data['showawaiting']) {
            $replystatuses[] = db_escape_string($data['title']);
        }
    }
    $ticketcount = 0;
    $chartdata = array();
    $query = "SELECT name,(SELECT COUNT(*) FROM tbltickets WHERE tbltickets.did=tblticketdepartments.id AND tbltickets.status IN (" . db_build_in_array($replystatuses) . ")) FROM tblticketdepartments ORDER BY `order` ASC";
    $result = full_query($query);
    while ($data = mysql_fetch_array($result)) {
        $chartdata[] = "['" . addslashes($data[0]) . "'," . $data[1] . "]";
        $ticketcount += $data[1];
    }
    $chartdata = implode(',', $chartdata);
    $chartdata2 = array();
    $query = "SELECT tblticketstatuses.title,(SELECT COUNT(*) FROM tbltickets WHERE tbltickets.status=tblticketstatuses.title) FROM tblticketstatuses WHERE showawaiting=1 ORDER BY sortorder ASC";
    $result = full_query($query);
    while ($data = mysql_fetch_array($result)) {
        $chartdata2[] = "['" . $data[0] . "'," . $data[1] . "]";
        $ticketcount += $data[1];
    }
    $chartdata2 = implode(',', $chartdata2);
    if (!$ticketcount) {
        $content = '<br /><div align="center">There are <strong>0</strong> Tickets Currently Awaiting a Reply</div><br />';
    } else {
        $content = <<<EOF
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawTicketChart1);
      function drawTicketChart1() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Department');
        data.addColumn('number', 'Ticket Count');
        data.addRows([
          {$chartdata}
        ]);

        var options = {
          chartArea: {left:0,top:20,width:"100%",height:"160"},
          title: 'Awaiting Reply by Department'
        };

        var chart = new google.visualization.PieChart(document.getElementById('ticketsoverview1'));
        chart.draw(data, options);
      }
      google.setOnLoadCallback(drawTicketChart2);
      function drawTicketChart2() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Status');
        data.addColumn('number', 'Ticket Count');
        data.addRows([
          {$chartdata2}
        ]);

        var options = {
          chartArea: {left:0,top:20,width:"100%",height:"160"},
          title: 'Awaiting Reply by Status'
        };

        var chart = new google.visualization.PieChart(document.getElementById('ticketsoverview2'));
        chart.draw(data, options);
      }

    </script>

    <div id="ticketsoverview1" style="float:left;width: 50%; height: 200px;"></div>
    <div id="ticketsoverview2" style="float:right;width: 50%; height: 200px;"></div>

EOF;
    }
    return array('title' => $title, 'content' => $content);
}
Beispiel #4
0
function getKBAutoSuggestionsQuery($field, $textparts, $limit, $existingkbarticles = "")
{
    $kbarticles = array();
    $where = "";
    foreach ($textparts as $textpart) {
        $where .= "" . $field . " LIKE '%" . db_escape_string($textpart) . "%' OR ";
    }
    $where = !$where ? "id!=''" : substr($where, 0, 0 - 4);
    if (is_array($existingkbarticles)) {
        $existingkbids = array();
        foreach ($existingkbarticles as $v) {
            $existingkbids[] = (int) $v['id'];
        }
        $where = "(" . $where . ")";
        if (0 < count($existingkbids)) {
            $where .= " AND id NOT IN (" . db_build_in_array($existingkbids) . ")";
        }
    }
    $result = full_query("SELECT id,parentid FROM tblknowledgebase WHERE " . $where . " ORDER BY useful DESC LIMIT 0," . (int) $limit);
    while ($data = mysql_fetch_array($result)) {
        $articleid = $data['id'];
        $parentid = $data['parentid'];
        if ($parentid) {
            $articleid = $parentid;
        }
        $result2 = full_query("SELECT tblknowledgebaselinks.categoryid FROM tblknowledgebase INNER JOIN tblknowledgebaselinks ON tblknowledgebase.id=tblknowledgebaselinks.articleid INNER JOIN tblknowledgebasecats ON tblknowledgebasecats.id=tblknowledgebaselinks.categoryid WHERE (tblknowledgebase.id=" . (int) $articleid . " OR tblknowledgebase.parentid=" . (int) $articleid . ") AND tblknowledgebasecats.hidden=''");
        $data = mysql_fetch_array($result2);
        $categoryid = $data['categoryid'];
        if ($categoryid) {
            $result2 = full_query("SELECT * FROM tblknowledgebase WHERE (id=" . (int) $articleid . " OR parentid=" . (int) $articleid . ") AND (language='" . db_escape_string($_SESSION['Language']) . "' OR language='') ORDER BY language DESC");
            $data = mysql_fetch_array($result2);
            $title = $data['title'];
            $article = $data['article'];
            $views = $data['views'];
            $kbarticles[] = array("id" => $articleid, "category" => $categoryid, "title" => $title, "article" => ticketsummary($article), "text" => $article);
        }
    }
    return $kbarticles;
}
while ($data = mysql_fetch_array($result)) {
    if ($data['showactive']) {
        $activestatuses[] = $data[0];
    }
    if ($data['showawaiting']) {
        $awaitingreplystatuses[] = $data[0];
    }
}
$deptfilter = "";
if (!$ignore_dept_assignments) {
    $result = select_query("tbladmins", "supportdepts", array("id" => $_SESSION['adminid']));
    $data = mysql_fetch_array($result);
    $supportdepts = $data[0];
    $supportdepts = explode(",", $supportdepts);
    $deptids = array();
    foreach ($supportdepts as $id) {
        if (trim($id)) {
            $deptids[] = trim($id);
            continue;
        }
    }
    if (count($deptids)) {
        $deptfilter = "WHERE tblticketdepartments.id IN (" . db_build_in_array($deptids) . ") ";
    }
}
$result = full_query("SELECT id,name,(SELECT COUNT(id) FROM tbltickets WHERE did=tblticketdepartments.id AND status IN (" . db_build_in_array($awaitingreplystatuses) . ")) AS awaitingreply,(SELECT COUNT(id) FROM tbltickets WHERE did=tblticketdepartments.id AND status IN (" . db_build_in_array($activestatuses) . ")) AS opentickets FROM tblticketdepartments " . $deptfilter . "ORDER BY name ASC");
$apiresults = array("result" => "success", "totalresults" => mysql_num_rows($result));
while ($data = mysql_fetch_array($result)) {
    $apiresults['departments']['department'][] = array("id" => $data['id'], "name" => $data['name'], "awaitingreply" => $data['awaitingreply'], "opentickets" => $data['opentickets']);
}
$responsetype = "xml";
Beispiel #6
0
 $todata = array();
 $query = "";
 if (!$type) {
     $type = "general";
 }
 $queryMadeFromEmailType = "";
 if ($type == "massmail") {
     $clientstatus = db_build_in_array($clientstatus);
     $clientgroup = db_build_in_array($clientgroup);
     $clientlanguage = db_build_in_array($clientlanguage, true);
     $productids = db_build_in_array($productids);
     $productstatus = db_build_in_array($productstatus);
     $server = db_build_in_array($server);
     $addonids = db_build_in_array($addonids);
     $addonstatus = db_build_in_array($addonstatus);
     $domainstatus = db_build_in_array($domainstatus);
     if ($emailtype == "General") {
         $type = "general";
         $query = "SELECT id,id AS userid,tblclients.firstname,tblclients.lastname,tblclients.email FROM tblclients WHERE id!=''";
         if ($clientstatus) {
             $query .= " AND tblclients.status IN (" . $clientstatus . ")";
         }
         if ($clientgroup) {
             $query .= " AND tblclients.groupid IN (" . $clientgroup . ")";
         }
         if ($clientlanguage) {
             $query .= " AND tblclients.language IN (" . $clientlanguage . ")";
         }
         if (is_array($customfield)) {
             foreach ($customfield as $k => $v) {
                 if ($v) {
Beispiel #7
0
            while ($data_resultdeptids = mysql_fetch_array($resultdeptids)) {
                $deptnames[] = $data_resultdeptids[0];
            }
        }
        if (!count($deptnames)) {
            $deptnames[] = $aInt->lang("global", "none");
        }
        $tabledata[] = array($data['firstname'] . " " . $data['lastname'], "<a href=\"mailto:" . $data['email'] . "\">" . $data['email'] . "</a>", $data['username'], $data['name'], implode(", ", $deptnames), "<a href=\"" . $PHP_SELF . "?action=manage&id=" . $data['id'] . "\"><img src=\"images/edit.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"Edit\"></a>", "<a href=\"#\" onClick=\"doDelete('" . $data['id'] . "')\"><img src=\"images/delete.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"Delete\"></a>");
    }
    echo $aInt->sortableTable(array($aInt->lang("fields", "name"), $aInt->lang("fields", "email"), $aInt->lang("fields", "username"), $aInt->lang("administrators", "adminrole"), $aInt->lang("administrators", "assigneddepts"), "", ""), $tabledata);
    echo "<h2>" . $aInt->lang("administrators", "inactive") . " </h2>";
    $tabledata = array();
    $result = select_query("tbladmins", "tbladmins.*,tbladminroles.name", array("disabled" => "1"), "firstname` ASC,`lastname", "ASC", "", "tbladminroles ON tbladmins.roleid=tbladminroles.id");
    while ($data = mysql_fetch_array($result)) {
        $departments = $deptnames = array();
        $supportdepts = db_build_in_array(explode(",", $data['supportdepts']));
        if ($supportdepts) {
            $resultdeptids = select_query("tblticketdepartments", "name", "id IN (" . $supportdepts . ")");
            while ($data_resultdeptids = mysql_fetch_array($resultdeptids)) {
                $deptnames[] = $data_resultdeptids[0];
            }
        }
        if (!count($deptnames)) {
            $deptnames[] = $aInt->lang("global", "none");
        }
        $tabledata[] = array($data['firstname'] . " " . $data['lastname'], "<a href=\"mailto:" . $data['email'] . "\">" . $data['email'] . "</a>", $data['username'], $data['name'], implode(", ", $deptnames), "<a href=\"" . $PHP_SELF . "?action=manage&id=" . $data['id'] . "\"><img src=\"images/edit.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"Edit\"></a>", "<a href=\"#\" onClick=\"doDelete('" . $data['id'] . "')\"><img src=\"images/delete.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"Delete\"></a>");
    }
    echo $aInt->sortableTable(array($aInt->lang("fields", "name"), $aInt->lang("fields", "email"), $aInt->lang("fields", "username"), $aInt->lang("administrators", "adminrole"), $aInt->lang("administrators", "assigneddepts"), "", ""), $tabledata);
} else {
    if ($action == "manage") {
        if ($id) {
Beispiel #8
0
 public function getTagCloudData()
 {
     if (!count($this->tagticketids)) {
         return array();
     }
     $tags = array();
     $result = full_query("SELECT `tag`, COUNT(*) AS `count` FROM `tbltickettags` WHERE ticketid IN (" . db_build_in_array($this->tagticketids) . ") GROUP BY `tag` ORDER BY `count` DESC");
     while ($data = mysql_fetch_assoc($result)) {
         $tags[] = $data;
     }
     return $tags;
 }
function bulkpricingupdater_output($vars)
{
    $modulelink = $vars['modulelink'];
    $step = isset($_REQUEST['step']) ? $_REQUEST['step'] : "";
    if (!$step) {
        echo "\n<p>By default, changing the pricing of products & services in the product configuration area will not affect existing clients. They remain at the prices they agreed to at the time of signing up. However, if you want to apply price increases to your existing clients too, then this addon utility allows you to do that.</p>\n<p>(Use Ctrl+Click to select more than one criteria in any of the fields)</p>\n";
        echo "\n<form method=\"post\" action=\"";
        echo $modulelink;
        echo "&step=2\">\n\n<p><b>Conditions</b></p>\n\n<table class=\"form\" width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">\n<tr><td width=\"15%\" class=\"fieldlabel\">Product</td><td class=\"fieldarea\" colspan=\"3\">";
        echo "<s";
        echo "elect name=\"productids[]\" size=\"10\" multiple=\"true\" style=\"width:600px;\">";
        $result = select_query("tblproducts", "tblproducts.id,tblproducts.gid,tblproducts.name,tblproductgroups.name AS groupname", "", "tblproductgroups`.`order` ASC,`tblproducts`.`order` ASC,`name", "ASC", "", "tblproductgroups ON tblproducts.gid=tblproductgroups.id");
        while ($data = mysql_fetch_array($result)) {
            $pid = $data['id'];
            $pname = $data['name'];
            $ptype = $data['groupname'];
            echo "<option value=\"" . $pid . "\">" . $ptype . " - " . $pname . "</option>";
        }
        $result = select_query("tbladdons", "", "", "name", "ASC");
        while ($data = mysql_fetch_array($result)) {
            $id = $data['id'];
            $name = $data['name'];
            $description = $data['description'];
            echo "<option value=\"A" . $id . "\">Addon - " . $name . "</option>";
        }
        $result = select_query("tbldomainpricing", "DISTINCT extension", "", "extension", "ASC");
        while ($data = mysql_fetch_array($result)) {
            $tld = $data['extension'];
            echo "<option value=\"D" . $tld . "\">Domain - " . $tld . "</option>";
        }
        echo "</select></td></tr>\n<tr><td class=\"fieldlabel\">Status</td><td class=\"fieldarea\">";
        echo "<s";
        echo "elect name=\"status[]\" size=\"5\" multiple=\"true\">\n<option>Pending</option>\n<option>Pending Transfer</option>\n<option selected>Active</option>\n<option selected>Suspended</option>\n<option>Terminated</option>\n<option>Cancelled</option>\n<option>Expired</option>\n<option>Fraud</option>\n</select></td><td width=\"15%\" class=\"fieldlabel\">Billing Cycle</td><td class=\"fieldarea\">";
        echo "<s";
        echo "elect name=\"billingcycle[]\" size=\"8\" multiple=\"true\">\n<option>Monthly</option>\n<option>Quarterly</option>\n<option>Semi-Annually</option>\n<option>Annually</option>\n<option>Biennially</option>\n<option>Triennially</option>\n";
        $domainyears = 1;
        while ($domainyears <= 10) {
            echo "<option value=\"" . $domainyears . "\">Domain: " . $domainyears . " Year</option>";
            ++$domainyears;
        }
        echo "</select></td></tr>\n<tr><td class=\"fieldlabel\">Currency</td><td class=\"fieldarea\">";
        echo "<s";
        echo "elect name=\"currid\">";
        $result = select_query("tblcurrencies", "id,code", "", "code", "ASC");
        while ($data = mysql_fetch_array($result)) {
            echo "<option value=\"" . $data['id'] . "\"";
            if ($data['id'] == $currency) {
                echo " selected";
            }
            echo ">" . $data['code'] . "</option>";
        }
        echo "</select></td><td class=\"fieldlabel\">Current Price</td><td class=\"fieldarea\"><input type=\"text\" name=\"currentprice\" size=\"10\" value=\"\" /> (Optional)</td></tr>\n</table>\n\n<p><b>Price</b></p>\n\n<table class=\"form\" width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">\n<tr><td width=\"20%\" class=\"fieldlabel\">New Recurring Price</td><td class=\"fieldarea\"><input type=\"text\" name=\"newprice\" size=\"10\" value=\"0.00\" /></";
        echo "td></tr>\n</table>\n\n<p align=\"center\"><input type=\"submit\" value=\"Update Pricing\" class=\"button\" /></p>\n\n</form>\n\n";
        return null;
    }
    check_token();
    $productids = $_REQUEST['productids'];
    $status = $_REQUEST['status'];
    $billingcycle = $_REQUEST['billingcycle'];
    $currid = (int) $_REQUEST['currid'];
    $currentprice = $_REQUEST['currentprice'];
    $newprice = $_REQUEST['newprice'];
    $statusmatches = db_build_in_array($status);
    $billingcyclematches = db_build_in_array($billingcycle);
    if ($currentprice) {
        $currentprice = format_as_currency($currentprice);
    }
    $newprice = format_as_currency($newprice);
    echo "<p><b>Conditions</b></p><p>Statuses: " . $statusmatches . "<br />Billing Cycles: " . $billingcyclematches;
    if ($currentprice) {
        echo "<br />Current Price: " . $currentprice;
    }
    echo "</p><p><b>Pricing Update Results</b></p><ul>";
    $currentprice = db_escape_string($currentprice);
    $newprice = db_escape_string($newprice);
    foreach ($productids as $pid) {
        $prodfirstletter = substr($pid, 0, 1);
        $prodrest = (int) substr($pid, 1);
        echo "<li>";
        if ($prodfirstletter == "A") {
            $query = "UPDATE tblhostingaddons,tblhosting SET tblhostingaddons.recurring='" . $newprice . "' WHERE tblhostingaddons.addonid='" . $prodrest . "' AND tblhostingaddons.status IN (" . $statusmatches . ") AND tblhostingaddons.billingcycle IN (" . $billingcyclematches . ") AND tblhosting.id=tblhostingaddons.hostingid AND tblhosting.userid IN (SELECT id FROM tblclients WHERE currency='" . $currid . "')";
            if ($currentprice) {
                $query .= " AND tblhostingaddons.recurring='" . $currentprice . "'";
            }
            echo "Updated Addon ID " . $prodrest;
        } else {
            if ($prodfirstletter == "D") {
                $query = "UPDATE tbldomains SET recurringamount='" . $newprice . "' WHERE domain LIKE '%" . $prodrest . "' AND status IN (" . $statusmatches . ") AND registrationperiod IN (" . $billingcyclematches . ") AND userid IN (SELECT id FROM tblclients WHERE currency='" . $currid . "')";
                if ($currentprice) {
                    $query .= " AND recurringamount='" . $currentprice . "'";
                }
                echo "Updated Domains with TLD " . $prodrest;
            } else {
                $pid = (int) $pid;
                $query = "UPDATE tblhosting SET amount='" . $newprice . "' WHERE packageid='" . $pid . "' AND domainstatus IN (" . $statusmatches . ") AND billingcycle IN (" . $billingcyclematches . ") AND userid IN (SELECT id FROM tblclients WHERE currency='" . $currid . "')";
                if ($currentprice) {
                    $query .= " AND amount='" . $currentprice . "'";
                }
                echo "Updated Product ID " . $pid;
            }
        }
        $result = full_query($query);
        $numaffected = mysql_affected_rows();
        echo " - " . $numaffected . " Affected";
        echo "</li>";
    }
}
 *
 **/
if (!defined("WHMCS")) {
    exit("This file cannot be accessed directly");
}
require_once ROOTDIR . "/includes/adminfunctions.php";
$description = "This graph shows the number of tasks incomplete compared with total number of tasks for each project";
$datefrom = fromMySQLDate(date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - 7, date("Y"))));
$dateto = fromMySQLDate(date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))));
if ($statsonly) {
    return false;
}
$chartdata = array();
$statuses = get_query_val("tbladdonmodules", "value", array("module" => "project_management", "setting" => "completedstatuses"));
$statuses = explode(",", $statuses);
$result = select_query("mod_project", "id,title", "status NOT IN (" . db_build_in_array($statuses) . ")");
while ($data = mysql_fetch_array($result)) {
    $projectid = $data['id'];
    $title = $data['title'];
    $totaltasks = get_query_val("mod_projecttasks", "COUNT(*)", array("projectid" => $projectid));
    $completedtasks = get_query_val("mod_projecttasks", "COUNT(*)", array("projectid" => $projectid, "completed" => "1"));
    $chartdata[$title] = $completedtasks;
    $chartdata2[$title] = $totaltasks;
}
$graph = new WHMCSGraph(1000, 400);
$graph->setTitle("Task Status per Project");
$graph->setBarColor("220,57,18", "51,102,204");
$graph->addData($chartdata, $chartdata2);
$graph->setLegendTitle("Completed Tasks", "Total Tasks");
$graph->setDataValues(true);
$graph->setXValuesHorizontal(true);
Beispiel #11
0
             echo $cdata['optionname'] . " => " . $cdata['subopname'] . ", ";
             continue;
         }
         if ($cdata['optiontype'] == 3) {
             echo $cdata['optionname'] . " => " . ($opid ? $aInt->lang("bundles", "enabled") : $aInt->lang("bundles", "disabled")) . ", ";
             continue;
         }
         if ($cdata['optiontype'] == 4) {
             echo $cdata['optionname'] . " => " . $opid . ", ";
             continue;
         }
     }
 }
 if ($data['addons']) {
     echo " &nbsp;&nbsp; - " . $aInt->lang("addons", "title") . ": ";
     $result = select_query("tbladdons", "name", "id IN (" . db_build_in_array($data['addons']) . ")");
     while ($data = mysql_fetch_array($result)) {
         echo $data[0] . ", ";
     }
     echo "<br />";
 }
 if ($data['tlds']) {
     echo " &nbsp;&nbsp; - " . $aInt->lang("bundles", "tldrestrictions") . ": " . implode(", ", $data['tlds']) . "<br />";
 }
 if ($data['regperiod']) {
     echo " &nbsp;&nbsp; - " . $aInt->lang("domains", "regperiod") . ": " . $data['regperiod'] . " " . $aInt->lang("domains", "years") . "<br />";
 }
 if ($data['dompriceoverride']) {
     echo " &nbsp;&nbsp; - " . $aInt->lang("bundles", "domainpriceoverride") . ": " . formatCurrency($data['domprice']) . "<br />";
 }
 if ($data['addons']) {
Beispiel #12
0
 $addonids = array();
 $result = select_query("tbladdons", "id,packages", "");
 while ($data = mysql_fetch_array($result)) {
     $id = $data['id'];
     $packages = $data['packages'];
     $packages = explode(",", $packages);
     foreach ($productids as $productid) {
         if (in_array($productid, $productids) && !in_array($id, $addonids)) {
             $addonids[] = $id;
             continue;
         }
     }
 }
 $addons = array();
 if (count($addonids)) {
     $result = select_query("tbladdons", "", "id IN (" . db_build_in_array($addonids) . ")", "weight` ASC,`name", "ASC");
     while ($data = mysql_fetch_array($result)) {
         $addonid = $data['id'];
         $packages = $data['packages'];
         $packages = explode(",", $packages);
         $name = $data['name'];
         $description = $data['description'];
         $billingcycle = $data['billingcycle'];
         $free = false;
         if ($billingcycle == "Free Account") {
             $free = true;
         } else {
             $result2 = select_query("tblpricing", "", array("type" => "addon", "currency" => $currency['id'], "relid" => $addonid));
             $data = mysql_fetch_array($result2);
             $setupfee = $data['msetupfee'];
             $recurring = $data['monthly'];
Beispiel #13
0
                }
            }
        }
    }
    $clientWhere = is_numeric($userid) && 0 < $userid ? "AND tblinvoices.userid=" . (int) $userid : "";
    if ($filterby == "Date Created") {
        $filterby = "date";
    } else {
        if ($filterby == "Due Date") {
            $filterby = "duedate";
        } else {
            $filterby = "datepaid";
            $dateto .= " 23:59:59";
        }
    }
    $statuses_in_clause = db_build_in_array($statuses);
    $paymentmethods_in_clause = db_build_in_array($paymentmethods);
    $batchpdf_where_clause = "tblinvoices." . $filterby . " >= '" . toMySQLDate($datefrom) . ("' AND tblinvoices." . $filterby . "<='") . toMySQLDate($dateto) . "' AND tblinvoices.status IN (" . $statuses_in_clause . ")" . " AND tblinvoices.paymentmethod IN (" . $paymentmethods_in_clause . ")" . $clientWhere;
    $batchpdfresult = select_query("tblinvoices", "tblinvoices.id", $batchpdf_where_clause, $orderby, "ASC", "", "tblclients ON tblclients.id=tblinvoices.userid");
    $numrows = mysql_num_rows($batchpdfresult);
    if (!$numrows) {
        redir("report=pdf_batch&noresults=1", "reports.php");
    } else {
        header("Content-Disposition: attachment; filename=\"" . $aInt->lang("reports", "pdfbatch") . " " . date("Y-m-d") . ".pdf\"");
    }
    while ($data = mysql_fetch_array($batchpdfresult)) {
        $invoice->pdfInvoicePage($data['id']);
    }
    $pdfdata = $invoice->pdfOutput();
    echo $pdfdata;
}
Beispiel #14
0
 public function getAssociatedDownloads()
 {
     if (!count($this->associated_download_ids)) {
         return array();
     }
     $downloadsarray = array();
     $result = select_query("tbldownloads", "", "id IN (" . db_build_in_array(db_escape_numarray($this->associated_download_ids)) . ")", "id", "DESC");
     while ($data = mysql_fetch_array($result)) {
         $dlid = $data['id'];
         $category = $data['category'];
         $type = $data['type'];
         $title = $data['title'];
         $description = $data['description'];
         $downloads = $data['downloads'];
         $location = $data['location'];
         $fileext = explode(".", $location);
         $fileext = end($fileext);
         $type = "zip";
         if ($fileext == "doc") {
             $type = "doc";
         }
         if ($fileext == "gif" || $fileext == "jpg" || $fileext == "jpeg" || $fileext == "png") {
             $type = "picture";
         }
         if ($fileext == "txt") {
             $type = "txt";
         }
         $type = "<img src=\"images/" . $type . ".png\" align=\"absmiddle\" alt=\"\" />";
         $downloadsarray[] = array("id" => $dlid, "catid" => $category, "type" => $type, "title" => $title, "description" => $description, "downloads" => $downloads, "link" => "dl.php?type=d&id=" . $dlid . "&serviceid=" . $this->getID());
     }
     return $downloadsarray;
 }
Beispiel #15
0
/**
 *
 * @ WHMCS FULL DECODED & NULLED
 *
 * @ Version  : 5.2.15
 * @ Author   : MTIMER
 * @ Release on : 2013-12-24
 * @ Website  : http://www.mtimer.cn
 *
 **/
function select_query($table, $fields, $where, $orderby = "", $orderbyorder = "", $limit = "", $innerjoin = "")
{
    global $CONFIG;
    global $query_count;
    global $mysql_errors;
    global $whmcsmysql;
    if (!$fields) {
        $fields = "*";
    }
    $query = "SELECT " . $fields . " FROM " . db_make_safe_field($table);
    if ($innerjoin) {
        $query .= " INNER JOIN " . db_escape_string($innerjoin) . "";
    }
    if ($where) {
        if (is_array($where)) {
            $criteria = array();
            foreach ($where as $origkey => $value) {
                $key = db_make_safe_field($origkey);
                if (is_array($value)) {
                    if ($key == "default") {
                        $key = "`default`";
                    }
                    if ($value['sqltype'] == "LIKE") {
                        $criteria[] = "" . $key . " LIKE '%" . db_escape_string($value['value']) . "%'";
                        continue;
                    }
                    if ($value['sqltype'] == "NEQ") {
                        $criteria[] = "" . $key . "!='" . db_escape_string($value['value']) . "'";
                        continue;
                    }
                    if ($value['sqltype'] == ">" && db_is_valid_amount($value['value'])) {
                        $criteria[] = "" . $key . ">" . $value['value'];
                        continue;
                    }
                    if ($value['sqltype'] == "<" && db_is_valid_amount($value['value'])) {
                        $criteria[] = "" . $key . "<" . $value['value'];
                        continue;
                    }
                    if ($value['sqltype'] == "<=" && db_is_valid_amount($value['value'])) {
                        $criteria[] = "" . $origkey . "<=" . $value['value'];
                        continue;
                    }
                    if ($value['sqltype'] == ">=" && db_is_valid_amount($value['value'])) {
                        $criteria[] = "" . $origkey . ">=" . $value['value'];
                        continue;
                    }
                    if ($value['sqltype'] == "TABLEJOIN") {
                        $criteria[] = "" . $key . "=" . db_escape_string($value['value']) . "";
                        continue;
                    }
                    if ($value['sqltype'] == "IN") {
                        $criteria[] = "" . $key . " IN (" . db_build_in_array($value['values']) . ")";
                        continue;
                    }
                    exit("Invalid input condition");
                    continue;
                }
                if (substr($key, 0, 3) == "MD5") {
                    $key = explode("(", $origkey, 2);
                    $key = explode(")", $key[1], 2);
                    $key = db_make_safe_field($key[0]);
                    $key = "MD5(" . $key . ")";
                } else {
                    $key = db_build_quoted_field($key);
                }
                $criteria[] = "" . $key . "='" . db_escape_string($value) . "'";
            }
            $query .= " WHERE " . implode(" AND ", $criteria);
        } else {
            $query .= " WHERE " . $where;
        }
    }
    if ($orderby) {
        $orderbysql = tokenizeOrderby($orderby, $orderbyorder);
        $query .= " ORDER BY " . implode(",", $orderbysql);
    }
    if ($limit) {
        if (strpos($limit, ",")) {
            $limit = explode(",", $limit);
            $limit = (int) $limit[0] . "," . (int) $limit[1];
        } else {
            $limit = (int) $limit;
        }
        $query .= " LIMIT " . $limit;
    }
    $result = mysql_query($query, $whmcsmysql);
    if (!$result && ($CONFIG['SQLErrorReporting'] || $mysql_errors)) {
        logActivity("SQL Error: " . mysql_error($whmcsmysql) . " - Full Query: " . $query);
    }
    ++$query_count;
    return $result;
}
Beispiel #16
0
function CalcPromoDiscount($pid, $cycle, $fpamount, $recamount, $setupfee = 0)
{
    global $promo_data;
    global $currency;
    $id = $promo_data['id'];
    $promotioncode = $promo_data['code'];
    if (!$id) {
        return false;
    }
    if ($_SESSION['adminid'] && !defined("CLIENTAREA")) {
    } else {
        $newsignups = $promo_data['newsignups'];
        if ($newsignups && $_SESSION['uid']) {
            $result = select_query("tblorders", "COUNT(*)", array("userid" => $_SESSION['uid']));
            $data = mysql_fetch_array($result);
            $previousorders = $data[0];
            if (2 <= $previousorders) {
                return false;
            }
        }
        $existingclient = $promo_data['existingclient'];
        $onceperclient = $promo_data['onceperclient'];
        if ($existingclient) {
            $result = select_query("tblorders", "count(*)", array("status" => "Active", "userid" => $_SESSION['uid']));
            $orderCount = mysql_fetch_array($result);
            if ($orderCount[0] < 1) {
                return false;
            }
        }
        if ($onceperclient) {
            $result = select_query("tblorders", "count(*)", "promocode='" . db_escape_string($promotioncode) . "' AND userid=" . (int) $_SESSION['uid'] . " AND status IN ('Pending','Active')");
            $orderCount = mysql_fetch_array($result);
            if (0 < $orderCount[0]) {
                return false;
            }
        }
        $applyonce = $promo_data['applyonce'];
        $promoapplied = $promo_data['promoapplied'];
        if ($applyonce && $promoapplied) {
            return false;
        }
        $appliesto = explode(",", $promo_data['appliesto']);
        if (!in_array($pid, $appliesto)) {
            return false;
        }
        $expiredate = $promo_data['expirationdate'];
        if ($expiredate != "0000-00-00") {
            $year = substr($expiredate, 0, 4);
            $month = substr($expiredate, 5, 2);
            $day = substr($expiredate, 8, 2);
            $validuntil = $year . $month . $day;
            $dayofmonth = date("d");
            $monthnum = date("m");
            $yearnum = date("Y");
            $todaysdate = $yearnum . $monthnum . $dayofmonth;
            if ($validuntil < $todaysdate) {
                return false;
            }
        }
        $cycles = $promo_data['cycles'];
        if ($cycles) {
            $cycles = explode(",", $cycles);
            if (!in_array($cycle, $cycles)) {
                return false;
            }
        }
        $maxuses = $promo_data['maxuses'];
        if ($maxuses) {
            $uses = $promo_data['uses'];
            if ($maxuses <= $uses) {
                return false;
            }
        }
        $requires = $promo_data['requires'];
        $requiresexisting = $promo_data['requiresexisting'];
        if ($requires) {
            $requires = explode(",", $requires);
            $hasrequired = false;
            if (is_array($_SESSION['cart']['products'])) {
                foreach ($_SESSION['cart']['products'] as $values) {
                    if (in_array($values['pid'], $requires)) {
                        $hasrequired = true;
                    }
                    if (is_array($values['addons'])) {
                        foreach ($values['addons'] as $addonid) {
                            if (in_array("A" . $addonid, $requires)) {
                                $hasrequired = true;
                                continue;
                            }
                        }
                        continue;
                    }
                }
            }
            if (is_array($_SESSION['cart']['addons'])) {
                foreach ($_SESSION['cart']['addons'] as $values) {
                    if (in_array("A" . $values['id'], $requires)) {
                        $hasrequired = true;
                        continue;
                    }
                }
            }
            if (is_array($_SESSION['cart']['domains'])) {
                foreach ($_SESSION['cart']['domains'] as $values) {
                    $domainparts = explode(".", $values['domain'], 2);
                    $tld = $domainparts[1];
                    if (in_array("D." . $tld, $requires)) {
                        $hasrequired = true;
                        continue;
                    }
                }
            }
            if (!$hasrequired && $requiresexisting) {
                $requiredproducts = $requiredaddons = array();
                $requireddomains = "";
                foreach ($requires as $v) {
                    if (substr($v, 0, 1) == "A") {
                        $requiredaddons[] = substr($v, 1);
                        continue;
                    }
                    if (substr($v, 0, 1) == "D") {
                        $requireddomains .= "domain LIKE '%" . substr($v, 1) . "' OR ";
                        continue;
                    }
                    $requiredproducts[] = $v;
                }
                if (count($requiredproducts)) {
                    $result = select_query("tblhosting", "COUNT(*)", "userid='" . (int) $_SESSION['uid'] . "' AND packageid IN (" . db_build_in_array($requiredproducts) . ") AND domainstatus='Active'");
                    $data = mysql_fetch_array($result);
                    if ($data[0]) {
                        $hasrequired = true;
                    }
                }
                if (count($requiredaddons)) {
                    $result = select_query("tblhostingaddons", "COUNT(*)", "tblhosting.userid='" . (int) $_SESSION['uid'] . "' AND addonid IN (" . db_build_in_array($requiredaddons) . ") AND status='Active'", "", "", "", "tblhosting ON tblhosting.id=tblhostingaddons.hostingid");
                    $data = mysql_fetch_array($result);
                    if ($data[0]) {
                        $hasrequired = true;
                    }
                }
                if ($requireddomains) {
                    $result = select_query("tbldomains", "COUNT(*)", "userid='" . (int) $_SESSION['uid'] . "' AND status='Active' AND (" . substr($requireddomains, 0, 0 - 4) . ")");
                    $data = mysql_fetch_array($result);
                    if ($data[0]) {
                        $hasrequired = true;
                    }
                }
            }
            if (!$hasrequired) {
                return false;
            }
        }
    }
    $type = $promo_data['type'];
    $value = $promo_data['value'];
    $onetimediscount = 0;
    if ($type == "Percentage") {
        $onetimediscount = $fpamount * ($value / 100);
    } else {
        if ($type == "Fixed Amount") {
            if ($currency['id'] != 1) {
                $promo_data['value'] = $value = convertCurrency($value, 1, $currency['id']);
            }
            if ($fpamount < $value) {
                $onetimediscount = $fpamount;
            } else {
                $onetimediscount = $value;
            }
        } else {
            if ($type == "Price Override") {
                if ($currency['id'] != 1) {
                    $promo_data['value'] = convertCurrency($promo_data['value'], 1, $currency['id']);
                }
                if (!isset($promo_data['priceoverride'])) {
                    $promo_data['priceoverride'] = $promo_data['value'];
                }
                $onetimediscount = $fpamount - $promo_data['priceoverride'];
            } else {
                if ($type == "Free Setup") {
                    $onetimediscount = $setupfee;
                    $promo_data['value'] += $setupfee;
                }
            }
        }
    }
    $recurringdiscount = 0;
    $recurring = $promo_data['recurring'];
    if ($recurring) {
        if ($type == "Percentage") {
            $recurringdiscount = $recamount * ($value / 100);
        } else {
            if ($type == "Fixed Amount") {
                if ($recamount < $value) {
                    $recurringdiscount = $recamount;
                } else {
                    $recurringdiscount = $value;
                }
            } else {
                if ($type == "Price Override") {
                    $recurringdiscount = $recamount - $promo_data['priceoverride'];
                }
            }
        }
    }
    $onetimediscount = round($onetimediscount, 2);
    $recurringdiscount = round($recurringdiscount, 2);
    $promo_data['promoapplied'] = true;
    return array("onetimediscount" => $onetimediscount, "recurringdiscount" => $recurringdiscount);
}
Beispiel #17
0
$where = array();
if ($serviceid) {
    if (is_numeric($serviceid)) {
        $where[] = "hostingid=" . (int) $serviceid;
    } else {
        $serviceids = explode(",", $serviceid);
        $serviceids = db_build_in_array(db_escape_numarray($serviceids));
        if ($serviceids) {
            $where[] = "hostingid IN (" . $serviceids . ")";
        }
    }
}
if ($clientid) {
    $result = select_query("tblhosting", "", array("userid" => $clientid));
    $hostingids = array();
    while ($data = mysql_fetch_array($result)) {
        $hostingids[] = (int) $data['id'];
    }
    $where[] = "hostingid IN (" . db_build_in_array($hostingids) . ")";
}
if ($addonid) {
    $where[] = "addonid=" . (int) $addonid;
}
$result = select_query("tblhostingaddons", "", implode(" AND ", $where));
$apiresults = array("result" => "success", "serviceid" => $serviceid, "clientid" => $clientid, "totalresults" => mysql_num_rows($result));
while ($data = mysql_fetch_array($result)) {
    $aid = $data['id'];
    $addonarray = array("id" => $data['id'], "userid" => get_query_val("tblhosting", "userid", array("id" => $data['hostingid'])), "orderid" => $data['orderid'], "serviceid" => $data['hostingid'], "addonid" => $data['addonid'], "name" => $data['name'], "setupfee" => $data['setupfee'], "recurring" => $data['recurring'], "billingcycle" => $data['billingcycle'], "tax" => $data['tax'], "status" => $data['status'], "regdate" => $data['regdate'], "nextduedate" => $data['nextduedate'], "nextinvoicedate" => $data['nextinvoicedate'], "paymentmethod" => $data['paymentmethod'], "notes" => $data['notes']);
    $apiresults['addons']['addon'][] = $addonarray;
}
$responsetype = "xml";
Beispiel #18
0
    if ($deptfilter) {
        $filters[] = "did IN (" . db_build_in_array(getAdminDepartmentAssignments()) . ")";
    }
    $query .= implode(" AND ", $filters) . (" ORDER BY tbltickets." . $orderby . " " . $order);
    $numresultsquery = "SELECT COUNT(tbltickets.id)" . $query;
    $result = full_query($numresultsquery);
    $data = mysql_fetch_array($result);
    $numrows = $data[0];
    $query = "SELECT tbltickets.*,tblclients.firstname,tblclients.lastname,tblclients.companyname,tblclients.groupid" . $query . " LIMIT " . (int) $page * $limit . "," . (int) $limit;
    $result = full_query($query);
    buildAdminTicketListArray($result);
    echo $aInt->sortableTable(array("checkall", "", $aInt->lang("support", "department"), array("title", $aInt->lang("fields", "subject")), $aInt->lang("support", "submitter"), array("status", $aInt->lang("fields", "status")), array("lastreply", $aInt->lang("support", "lastreply"))), $tabledata, $tableformurl, $tableformbuttons, true);
    $smartyvalues['tagcloud'] = $tickets->buildTagCloud();
}
if ($action == "search") {
    $where = "tid='" . db_escape_string($ticketid) . "' AND did IN (" . db_build_in_array(db_escape_numarray(getAdminDepartmentAssignments())) . ")";
    $result = select_query("tbltickets", "", $where);
    $data = mysql_fetch_array($result);
    $id = $data['id'];
    if (!$id) {
        echo "<p>" . $aInt->lang("support", "ticketnotfound") . "  <a href=\"javascript:history.go(-1)\">" . $aInt->lang("support", "pleasetryagain") . "</a>.</p>";
    } else {
        $action = "viewticket";
    }
}
if ($action == "viewticket") {
    releaseSession();
    $aInt->template = "viewticket";
    $smartyvalues['inticket'] = true;
    $ticket = new WHMCS_Tickets();
    $ticket->setID($id);
Beispiel #19
0
function createUpgradeOrder($id, $ordernotes, $promocode, $paymentmethod)
{
    global $CONFIG;
    global $remote_ip;
    global $orderdescription;
    global $orderamount;
    if ($promocode && !$GLOBALS['qualifies']) {
        $promocode = "";
    }
    if ($promocode) {
        $result = select_query("tblpromotions", "upgradeconfig", array("code" => $promocode));
        $data = mysql_fetch_array($result);
        $upgradeconfig = $data['upgradeconfig'];
        $upgradeconfig = unserialize($upgradeconfig);
        $promo_type = $upgradeconfig['discounttype'];
        $promo_value = $upgradeconfig['value'];
        update_query("tblpromotions", array("uses" => "+1"), array("code" => $promocode));
    }
    $order_number = generateUniqueID();
    $orderid = insert_query("tblorders", array("ordernum" => $order_number, "userid" => $_SESSION['uid'], "date" => "now()", status => "Pending", "promocode" => $promocode, "promotype" => $promo_type, "promovalue" => $promo_value, "paymentmethod" => $paymentmethod, "ipaddress" => $remote_ip, "amount" => $orderamount, "notes" => $ordernotes));
    foreach ($_SESSION['upgradeids'] as $upgradeid) {
        update_query("tblupgrades", array("orderid" => $orderid), array("id" => $upgradeid));
    }
    sendMessage("Order Confirmation", $_SESSION['uid'], array("order_id" => $orderid, "order_number" => $order_number, "order_details" => $orderdescription));
    logActivity("Upgrade Order Placed - Order ID: " . $orderid);
    if (!function_exists("createInvoices")) {
        include ROOTDIR . "/includes/processinvoices.php";
    }
    $invoiceid = 0;
    $invoiceid = createInvoices($_SESSION['uid'], true);
    if ($invoiceid) {
        $result = select_query("tblinvoiceitems", "invoiceid", "type='Upgrade' AND relid IN (" . db_build_in_array(db_escape_numarray($_SESSION['upgradeids'])) . ")", "invoiceid", "DESC");
        $data = mysql_fetch_array($result);
        $invoiceid = $data['invoiceid'];
    }
    if ($CONFIG['OrderDaysGrace']) {
        $new_time = mktime(0, 0, 0, date("m"), date("d") + $CONFIG['OrderDaysGrace'], date("Y"));
        $duedate = date("Y-m-d", $new_time);
        update_query("tblinvoices", array("duedate" => $duedate), array("id" => $invoiceid));
    }
    if (!$CONFIG['NoInvoiceEmailOnOrder']) {
        sendMessage("Invoice Created", $invoiceid);
    }
    update_query("tblorders", array("invoiceid" => $invoiceid), array("id" => $orderid));
    $result = select_query("tblclients", "firstname, lastname, companyname, email, address1, address2, city, state, postcode, country, phonenumber, ip, host", array("id" => $_SESSION['uid']));
    $data = mysql_fetch_array($result);
    list($firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, $postcode, $country, $phonenumber, $ip, $host) = $data;
    $nicegatewayname = get_query_val("tblpaymentgateways", "value", array("gateway" => $paymentmethod, "setting" => "Name"));
    $ordertotal = get_query_val("tblinvoices", "total", array("id" => $invoiceid));
    $adminemailitems = "";
    if ($invoiceid) {
        $result = select_query("tblinvoiceitems", "description", "type='Upgrade' AND relid IN (" . db_build_in_array(db_escape_numarray($_SESSION['upgradeids'])) . ")", "invoiceid", "DESC");
        while ($invoicedata = mysql_fetch_assoc($result)) {
            $adminemailitems .= $invoicedata['description'] . "<br />";
        }
    } else {
        $adminemailitems .= "Upgrade/Downgrade";
    }
    sendAdminMessage("New Order Notification", array("order_id" => $orderid, "order_number" => $order_number, "order_date" => date("d/m/Y H:i:s"), "invoice_id" => $invoiceid, "order_payment_method" => $nicegatewayname, "order_total" => formatCurrency($ordertotal), "client_id" => $_SESSION['uid'], "client_first_name" => $firstname, "client_last_name" => $lastname, "client_email" => $email, "client_company_name" => $companyname, "client_address1" => $address1, "client_address2" => $address2, "client_city" => $city, "client_state" => $state, "client_postcode" => $postcode, "client_country" => $country, "client_phonenumber" => $phonenumber, "order_items" => $adminemailitems, "order_notes" => "", "client_ip" => $ip, "client_hostname" => $host), "account");
    return array("id" => $id, "orderid" => $orderid, "order_number" => $order_number, "invoiceid" => $invoiceid);
}
Beispiel #20
0
                     if ($prodfiltertype == "beforedue") {
                         $criteria[] = "nextduedate='" . date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + $prodnumdays, date("Y"))) . "'";
                     }
                 }
             }
             if (count($prodstatus)) {
                 $criteria[] = "status IN (" . db_build_in_array($prodstatus) . ")";
             }
             if (count($prodexcludepid)) {
                 if (implode($prodexcludepid)) {
                     $criteria[] = "(SELECT COUNT(*) FROM tblhosting h2 WHERE h2.userid=(SELECT userid FROM tblhosting WHERE tblhosting.id=tblhostingaddons.hostingid) AND h2.packageid IN (" . db_build_in_array($prodexcludepid) . ") AND h2.domainstatus='Active')=0";
                 }
             }
             if (count($prodexcludeaid)) {
                 if (implode($prodexcludeaid)) {
                     $criteria[] = "(SELECT COUNT(*) FROM tblhostingaddons h2 WHERE h2.hostingid=tblhostingaddons.hostingid AND tblhostingaddons.addonid IN (" . db_build_in_array($prodexcludeaid) . ") AND tblhostingaddons.status='Active')=0";
                 }
             }
             if ($marketing) {
                 $criteria[] = "(SELECT COUNT(*) FROM tblclients h3 WHERE h3.id=(SELECT userid FROM tblhosting WHERE tblhosting.id=tblhostingaddons.hostingid) AND h3.emailoptout = '0')=1";
             }
             $query1 .= implode(" AND ", $criteria);
         }
     }
 }
 $result2 = select_query("tblemailtemplates", "name", array("id" => $emailtplid));
 $data = mysql_fetch_array($result2);
 $emailtplname = $data[0];
 $count = 0;
 if ($query) {
     $result2 = full_query($query);
Beispiel #21
0
        exit;
    }
    $selectedinvoices = db_escape_numarray($selectedinvoices);
    sort($selectedinvoices);
    $endinvoiceid = end($selectedinvoices);
    update_query("tblinvoiceitems", array("invoiceid" => $endinvoiceid), "invoiceid IN (" . db_build_in_array($selectedinvoices) . ")");
    update_query("tblaccounts", array("invoiceid" => $endinvoiceid), "invoiceid IN (" . db_build_in_array($selectedinvoices) . ")");
    update_query("tblorders", array("invoiceid" => $endinvoiceid), "invoiceid IN (" . db_build_in_array($selectedinvoices) . ")");
    $result = select_query("tblinvoices", "SUM(credit)", "id IN (" . db_build_in_array($selectedinvoices) . ")");
    $data = mysql_fetch_array($result);
    $totalcredit = $data[0];
    update_query("tblinvoices", array("credit" => $totalcredit), array("id" => $endinvoiceid));
    unset($selectedinvoices[count($selectedinvoices) - 1]);
    delete_query("tblinvoices", "id IN (" . db_build_in_array($selectedinvoices) . ")");
    updateInvoiceTotal($endinvoiceid);
    logActivity("Merged Invoice IDs " . db_build_in_array($selectedinvoices) . (" to Invoice ID: " . $endinvoiceid), $userid);
    if ($page) {
        $userid .= "&page=" . $page;
    }
    redir("userid=" . $userid . "&filter=1");
}
if ($masspay) {
    check_token("WHMCS.admin.default");
    if (count($selectedinvoices) < 2) {
        if ($page) {
            $userid .= "&page=" . $page;
        }
        redir("userid=" . $userid . "&masspayerr=1");
        exit;
    }
    $invoiceid = createInvoices($userid);
Beispiel #22
0
/**
 *
 * @ WHMCS FULL DECODED & NULLED
 *
 * @ Version  : 5.2.15
 * @ Author   : MTIMER
 * @ Release on : 2013-12-24
 * @ Website  : http://www.mtimer.cn
 *
 **/
function createInvoices($func_userid = "", $noemails = "", $nocredit = "", $specificitems = "")
{
    global $whmcs;
    global $cron;
    global $CONFIG;
    global $_LANG;
    global $invoicecount;
    global $invoiceid;
    global $continuous_invoicing_active_only;
    $continvoicegen = $whmcs->get_config("ContinuousInvoiceGeneration");
    $invoicedate = date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBefore'], date("Y")));
    $invoicedatemonthly = $CONFIG['CreateInvoiceDaysBeforeMonthly'] ? date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBeforeMonthly'], date("Y"))) : $invoicedate;
    $invoicedatequarterly = $CONFIG['CreateInvoiceDaysBeforeQuarterly'] ? date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBeforeQuarterly'], date("Y"))) : $invoicedate;
    $invoicedatesemiannually = $CONFIG['CreateInvoiceDaysBeforeSemiAnnually'] ? date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBeforeSemiAnnually'], date("Y"))) : $invoicedate;
    $invoicedateannually = $CONFIG['CreateInvoiceDaysBeforeAnnually'] ? date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBeforeAnnually'], date("Y"))) : $invoicedate;
    $invoicedatebiennially = $CONFIG['CreateInvoiceDaysBeforeBiennially'] ? date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBeforeBiennially'], date("Y"))) : $invoicedate;
    $invoicedatetriennially = $CONFIG['CreateInvoiceDaysBeforeTriennially'] ? date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBeforeTriennially'], date("Y"))) : $invoicedate;
    $domaininvoicedate = 0 < $whmcs->get_config("CreateDomainInvoiceDaysBefore") ? date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateDomainInvoiceDaysBefore'], date("Y"))) : $invoicedate;
    $matchfield = $continvoicegen ? "nextinvoicedate" : "nextduedate";
    $statusfilter = "'Pending','Active'";
    if (!$continuous_invoicing_active_only) {
        $statusfilter .= ",'Suspended'";
    }
    $hostingquery = "paymentmethod!='' AND domainstatus IN (" . $statusfilter . ") AND billingcycle!='Free' AND billingcycle!='Free Account' AND nextduedate!='00000000' AND nextinvoicedate!='00000000' AND ((billingcycle='Monthly' AND " . $matchfield . "<='" . $invoicedatemonthly . ("') OR (billingcycle='Quarterly' AND " . $matchfield . "<='") . $invoicedatequarterly . ("') OR (billingcycle='Semi-Annually' AND " . $matchfield . "<='") . $invoicedatesemiannually . ("') OR (billingcycle='Annually' AND " . $matchfield . "<='") . $invoicedateannually . ("') OR (billingcycle='Biennially' AND " . $matchfield . "<='") . $invoicedatebiennially . ("') OR (billingcycle='Triennially' AND " . $matchfield . "<='") . $invoicedatetriennially . "') OR (billingcycle='One Time'))";
    $domainquery = "paymentmethod!='' AND (donotrenew='' OR `status`='Pending') AND `status` IN (" . $statusfilter . ") AND " . $matchfield . "<='" . $domaininvoicedate . "'";
    $hostingaddonsquery = "tblhostingaddons.paymentmethod!='' AND tblhostingaddons.billingcycle!='Free' AND tblhostingaddons.billingcycle!='Free Account' AND tblhostingaddons.status IN (" . $statusfilter . ") AND tblhostingaddons.nextduedate!='00000000' AND tblhostingaddons.nextinvoicedate!='00000000' AND ((tblhostingaddons.billingcycle='Monthly' AND tblhostingaddons." . $matchfield . "<='" . $invoicedatemonthly . ("') OR (tblhostingaddons.billingcycle='Quarterly' AND tblhostingaddons." . $matchfield . "<='") . $invoicedatequarterly . ("') OR (tblhostingaddons.billingcycle='Semi-Annually' AND tblhostingaddons." . $matchfield . "<='") . $invoicedatesemiannually . ("') OR (tblhostingaddons.billingcycle='Annually' AND tblhostingaddons." . $matchfield . "<='") . $invoicedateannually . ("') OR (tblhostingaddons.billingcycle='Biennially' AND tblhostingaddons." . $matchfield . "<='") . $invoicedatebiennially . ("') OR (tblhostingaddons.billingcycle='Triennially' AND tblhostingaddons." . $matchfield . "<='") . $invoicedatetriennially . "') OR (tblhostingaddons.billingcycle='One Time'))";
    $i = 0;
    $billableitemqry = "";
    if ($func_userid != "") {
        $hostingquery .= " AND userid=" . (int) $func_userid;
        $domainquery .= " AND userid=" . (int) $func_userid;
        $hostingaddonsquery .= " AND tblhosting.userid=" . (int) $func_userid;
        $billableitemqry = " AND userid=" . (int) $func_userid;
    }
    if (is_array($specificitems)) {
        $hostingquery = $domainquery = $hostingaddonsquery = "";
        if ($specificitems['products']) {
            $hostingquery .= "(id IN (" . db_build_in_array(db_escape_numarray($specificitems['products'])) . ") AND billingcycle!='Free' AND billingcycle!='Free Account')";
        }
        if ($specificitems['addons']) {
            $hostingaddonsquery .= "tblhostingaddons.id IN (" . db_build_in_array(db_escape_numarray($specificitems['addons'])) . ") AND tblhostingaddons.billingcycle!='Free' AND tblhostingaddons.billingcycle!='Free Account'";
        }
        if ($specificitems['domains']) {
            $domainquery .= "id IN (" . db_build_in_array(db_escape_numarray($specificitems['domains'])) . ")";
        }
    }
    $AddonsArray = $AddonSpecificIDs = array();
    if ($hostingquery) {
        $servicecount = 0;
        $cancellationreqids = array();
        $result = select_query("tblcancelrequests", "DISTINCT relid", "");
        while ($data = mysql_fetch_array($result)) {
            $cancellationreqids[] = $data[0];
        }
        $result = select_query("tblhosting", "tblhosting.id,tblhosting.userid,tblhosting.nextduedate,tblhosting.nextinvoicedate,tblhosting.billingcycle,tblhosting.regdate,tblhosting.firstpaymentamount,tblhosting.amount,tblhosting.domain,tblhosting.paymentmethod,tblhosting.packageid,tblhosting.promoid,tblhosting.domainstatus", $hostingquery, "domain", "ASC");
        $totalservicerows = mysql_num_rows($result);
        while ($data = mysql_fetch_array($result)) {
            $id = $serviceid = $data['id'];
            if (!in_array($serviceid, $cancellationreqids)) {
                $userid = $data['userid'];
                $nextduedate = $data[$matchfield];
                $billingcycle = $data['billingcycle'];
                $status = $data['domainstatus'];
                $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Hosting", "relid" => $serviceid, "duedate" => $nextduedate));
                $contblock = false;
                if (!$num_rows && $continvoicegen && $status == "Pending") {
                    $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Hosting", "relid" => $serviceid));
                    $contblock = true;
                }
                if ($num_rows == 0) {
                    $regdate = $data['regdate'];
                    $amount = $regdate == $nextduedate ? $data['firstpaymentamount'] : $data['amount'];
                    $domain = $data['domain'];
                    $paymentmethod = $data['paymentmethod'];
                    $pid = $data['packageid'];
                    $promoid = $data['promoid'];
                    $productdetails = getInvoiceProductDetails($id, $pid, $regdate, $nextduedate, $billingcycle, $domain);
                    $description = $productdetails['description'];
                    $tax = $productdetails['tax'];
                    $recurringcycles = $productdetails['recurringcycles'];
                    $recurringfinished = false;
                    if ($recurringcycles) {
                        $num_rows3 = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Hosting", "relid" => $id));
                        if ($recurringcycles <= $num_rows3) {
                            update_query("tblhosting", array("domainstatus" => "Completed"), array("id" => $id));
                            run_hook("ServiceRecurringCompleted", array("serviceid" => $id, "recurringinvoices" => $num_rows3));
                            $recurringfinished = true;
                        }
                    }
                    if (!$recurringfinished) {
                        $promovals = getInvoiceProductPromo($amount, $promoid, $userid, $id);
                        if (isset($promovals['description'])) {
                            $amount -= $promovals['amount'];
                        }
                        insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "Hosting", "relid" => $id, "description" => $description, "amount" => $amount, "taxed" => $tax, "duedate" => $nextduedate, "paymentmethod" => $paymentmethod));
                        if (isset($promovals['description'])) {
                            insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "PromoHosting", "relid" => $id, "description" => $promovals['description'], "amount" => $promovals['amount'], "taxed" => $tax, "duedate" => $nextduedate, "paymentmethod" => $paymentmethod));
                        }
                    }
                } else {
                    if (!$contblock && $continvoicegen && $billingcycle != "One Time") {
                        update_query("tblhosting", array("nextinvoicedate" => getInvoicePayUntilDate($nextduedate, $billingcycle, true)), array("id" => $id));
                    }
                }
            }
            if ($hostingaddonsquery) {
                $result3 = select_query("tblhostingaddons", "tblhostingaddons.*,tblhostingaddons.regdate AS addonregdate,tblhosting.userid,tblhosting.domain", $hostingaddonsquery . (" AND tblhostingaddons.hostingid='" . $id . "'"), "tblhostingaddons`.`name", "ASC", "", "tblhosting ON tblhosting.id=tblhostingaddons.hostingid");
                while ($data = mysql_fetch_array($result3)) {
                    $id = $data['id'];
                    $userid = $data['userid'];
                    $nextduedate = $data[$matchfield];
                    $status = $data['status'];
                    $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Addon", "relid" => $id, "duedate" => $nextduedate));
                    $contblock = false;
                    if (!$num_rows && $continvoicegen && $status == "Pending") {
                        $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Addon", "relid" => $id));
                        $contblock = true;
                    }
                    if ($num_rows == 0) {
                        $hostingid = $serviceid = $data['hostingid'];
                        $addonid = $data['addonid'];
                        $domain = $data['domain'];
                        $regdate = $data['addonregdate'];
                        $name = $data['name'];
                        $setupfee = $data['setupfee'];
                        $amount = $data['recurring'];
                        $paymentmethod = $data['paymentmethod'];
                        $billingcycle = $data['billingcycle'];
                        $tax = $data['tax'];
                        if (!$name) {
                            if (isset($AddonsArray[$addonid])) {
                                $name = $AddonsArray[$addonid];
                            } else {
                                $AddonsArray[$addonid] = $name = get_query_val("tbladdons", "name", array("id" => $addonid));
                            }
                        }
                        $tax = $CONFIG['TaxEnabled'] && $tax ? "1" : "0";
                        $invoicepayuntildate = getInvoicePayUntilDate($nextduedate, $billingcycle);
                        $paydates = "";
                        if ($billingcycle != "One Time") {
                            $paydates = "(" . fromMySQLDate($nextduedate) . " - " . fromMySQLDate($invoicepayuntildate) . ")";
                        }
                        $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Addon", "relid" => $id, "duedate" => $nextduedate));
                        if ($num_rows == 0) {
                            if (!in_array($serviceid, $cancellationreqids)) {
                                if ($regdate == $nextduedate) {
                                    $amount = $amount + $setupfee;
                                }
                                if ($domain) {
                                    $domain = "(" . $domain . ") ";
                                }
                                $description = $_LANG['orderaddon'] . (" " . $domain . "- " . $name . " " . $paydates);
                                insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "Addon", "relid" => $id, "description" => $description, "amount" => $amount, "taxed" => $tax, "duedate" => $nextduedate, "paymentmethod" => $paymentmethod));
                                $AddonSpecificIDs[] = $id;
                            }
                        }
                        if (!$contblock && $continvoicegen) {
                            update_query("tblhostingaddons", array("nextinvoicedate" => getInvoicePayUntilDate($nextduedate, $billingcycle, true)), array("id" => $id));
                        }
                    }
                }
            }
            ++$servicecount;
            if (is_object($cron)) {
                $cron->logActivityDebug("Invoicing Loop Service ID " . $serviceid . " - " . $servicecount . " of " . $totalservicerows);
            }
        }
    }
    if ($hostingaddonsquery) {
        $addoncount = 0;
        if (count($AddonSpecificIDs)) {
            $hostingaddonsquery .= " AND tblhostingaddons.id NOT IN (" . db_build_in_array(db_escape_numarray($AddonSpecificIDs)) . ")";
        }
        $result = select_query("tblhostingaddons", "tblhostingaddons.*,tblhostingaddons.regdate AS addonregdate,tblhosting.userid,tblhosting.domain", $hostingaddonsquery, "tblhostingaddons`.`name", "ASC", "", "tblhosting ON tblhosting.id=tblhostingaddons.hostingid");
        $totaladdonrows = mysql_num_rows($result);
        while ($data = mysql_fetch_array($result)) {
            $id = $data['id'];
            $userid = $data['userid'];
            $nextduedate = $data[$matchfield];
            $status = $data['status'];
            $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Addon", "relid" => $id, "duedate" => $nextduedate));
            $contblock = false;
            if (!$num_rows && $continvoicegen && $status == "Pending") {
                $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("userid" => $userid, "type" => "Addon", "relid" => $id));
                $contblock = true;
            }
            if ($num_rows == 0) {
                $hostingid = $serviceid = $data['hostingid'];
                $addonid = $data['addonid'];
                $domain = $data['domain'];
                $regdate = $data['addonregdate'];
                $name = $data['name'];
                $setupfee = $data['setupfee'];
                $amount = $data['recurring'];
                $paymentmethod = $data['paymentmethod'];
                $billingcycle = $data['billingcycle'];
                $tax = $data['tax'];
                if (!$name) {
                    if ($AddonsArray[$addonid]) {
                        $name = $AddonsArray[$addonid];
                    } else {
                        $AddonsArray[$addonid] = $name = get_query_val("tbladdons", "name", array("id" => $addonid));
                    }
                }
                $tax = $CONFIG['TaxEnabled'] && $tax ? "1" : "0";
                $invoicepayuntildate = getInvoicePayUntilDate($nextduedate, $billingcycle);
                $paydates = "";
                if ($billingcycle != "One Time") {
                    $paydates = "(" . fromMySQLDate($nextduedate) . " - " . fromMySQLDate($invoicepayuntildate) . ")";
                }
                if (!in_array($serviceid, $cancellationreqids)) {
                    if ($regdate == $nextduedate) {
                        $amount = $amount + $setupfee;
                    }
                    if ($domain) {
                        $domain = "(" . $domain . ") ";
                    }
                    $description = $_LANG['orderaddon'] . (" " . $domain . "- " . $name . " " . $paydates);
                    insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "Addon", "relid" => $id, "description" => $description, "amount" => $amount, "taxed" => $tax, "duedate" => $nextduedate, "paymentmethod" => $paymentmethod));
                }
            } else {
                if (!$contblock && $continvoicegen) {
                    update_query("tblhostingaddons", array("nextinvoicedate" => getInvoicePayUntilDate($nextduedate, $billingcycle, true)), array("id" => $id));
                }
            }
            ++$addoncount;
            if (is_object($cron)) {
                $cron->logActivityDebug("Invoicing Loop Addon ID " . $id . " - " . $addoncount . " of " . $totaladdonrows);
            }
        }
    }
    if ($domainquery) {
        $domaincount = 0;
        $result = select_query("tbldomains", "", $domainquery, "domain", "ASC");
        $totaldomainrows = mysql_num_rows($result);
        while ($data = mysql_fetch_array($result)) {
            $id = $data['id'];
            $userid = $data['userid'];
            $nextduedate = $data[$matchfield];
            $status = $data['status'];
            $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", "userid='" . $userid . "' AND type IN ('Domain','DomainRegister','DomainTransfer') AND relid='" . $id . "' AND duedate='" . $nextduedate . "'");
            $contblock = false;
            if (!$num_rows && $continvoicegen && $status == "Pending") {
                $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", "userid='" . $userid . "' AND type IN ('Domain','DomainRegister','DomainTransfer') AND relid='" . $id . "'");
                $contblock = true;
            }
            if ($num_rows == 0) {
                $type = $data['type'];
                $domain = $data['domain'];
                $registrationperiod = $data['registrationperiod'];
                $regdate = $data['registrationdate'];
                $expirydate = $data['expirydate'];
                $paymentmethod = $data['paymentmethod'];
                $dnsmanagement = $data['dnsmanagement'];
                $emailforwarding = $data['emailforwarding'];
                $idprotection = $data['idprotection'];
                $promoid = $data['promoid'];
                getUsersLang($userid);
                if ($expirydate == "0000-00-00") {
                    $expirydate = $nextduedate;
                }
                if ($regdate == $nextduedate) {
                    $amount = $data['firstpaymentamount'];
                    if ($type == "Transfer") {
                        $domaindesc = $_LANG['domaintransfer'];
                    } else {
                        $domaindesc = $_LANG['domainregistration'];
                        $type = "Register";
                    }
                } else {
                    $amount = $data['recurringamount'];
                    $domaindesc = $_LANG['domainrenewal'];
                    $type = "";
                }
                $tax = $CONFIG['TaxEnabled'] && $CONFIG['TaxDomains'] ? "1" : "0";
                $domaindesc .= " - " . $domain . " - " . $registrationperiod . " " . $_LANG['orderyears'];
                if ($type != "Transfer") {
                    $domaindesc .= " (" . fromMySQLDate($expirydate) . " - " . fromMySQLDate(getInvoicePayUntilDate($expirydate, $registrationperiod)) . ")";
                }
                if ($dnsmanagement) {
                    $domaindesc .= "\r\n + " . $_LANG['domaindnsmanagement'];
                }
                if ($emailforwarding) {
                    $domaindesc .= "\r\n + " . $_LANG['domainemailforwarding'];
                }
                if ($idprotection) {
                    $domaindesc .= "\r\n + " . $_LANG['domainidprotection'];
                }
                $promo_description = $promo_amount = 0;
                if ($promoid) {
                    $data = get_query_vals("tblpromotions", "", array("id" => $promoid));
                    $promo_id = $data['id'];
                    if ($promo_id) {
                        $promo_code = $data['code'];
                        $promo_type = $data['type'];
                        $promo_recurring = $data['recurring'];
                        $promo_value = $data['value'];
                        if ($promo_recurring || !$promo_recurring && $regdate == $nextduedate) {
                            if ($promo_type == "Percentage") {
                                $promo_amount = round($amount / (1 - $promo_value / 100), 2) - $amount;
                                $promo_value .= "%";
                            } else {
                                if ($promo_type == "Fixed Amount") {
                                    $promo_amount = $promo_value;
                                    $currency = getCurrency($userid);
                                    $promo_value = formatCurrency($promo_value);
                                }
                            }
                            $amount += $promo_amount;
                            $promo_recurring = $promo_recurring ? $_LANG['recurring'] : $_LANG['orderpaymenttermonetime'];
                            $promo_description = $_LANG['orderpromotioncode'] . (": " . $promo_code . " - " . $promo_value . " " . $promo_recurring . " ") . $_LANG['orderdiscount'];
                            $promo_amount *= 0 - 1;
                        }
                    }
                }
                insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "Domain" . $type, "relid" => $id, "description" => $domaindesc, "amount" => $amount, "taxed" => $tax, "duedate" => $nextduedate, "paymentmethod" => $paymentmethod));
                if ($promo_description) {
                    insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "PromoDomain", "relid" => $id, "description" => $promo_description, "amount" => $promo_amount, "taxed" => $tax, "duedate" => $nextduedate, "paymentmethod" => $paymentmethod));
                }
            } else {
                if (!$contblock && $continvoicegen) {
                    $year = substr($nextduedate, 0, 4);
                    $month = substr($nextduedate, 5, 2);
                    $day = substr($nextduedate, 8, 2);
                    $new_time = mktime(0, 0, 0, $month, $day, $year + $registrationperiod);
                    $nextinvoicedate = date("Ymd", $new_time);
                    update_query("tbldomains", array("nextinvoicedate" => $nextinvoicedate), array("id" => $id));
                }
            }
            getUsersLang(0);
            ++$domaincount;
            if (is_object($cron)) {
                $cron->logActivityDebug("Invoicing Loop Domain ID " . $id . " - " . $domaincount . " of " . $totaldomainrows);
            }
        }
    }
    if (!is_array($specificitems)) {
        $billableitemstax = $CONFIG['TaxEnabled'] && $CONFIG['TaxBillableItems'] ? "1" : "0";
        $result = select_query("tblbillableitems", "", "((invoiceaction='1' AND invoicecount='0') OR (invoiceaction='3' AND invoicecount='0' AND duedate<='" . $invoicedate . "') OR (invoiceaction='4' AND duedate<='" . $invoicedate . "' AND (recurfor='0' OR invoicecount<recurfor)))" . $billableitemqry);
        while ($data = mysql_fetch_array($result)) {
            $paymentmethod = getClientsPaymentMethod($data['userid']);
            if ($data['invoiceaction'] != "4") {
                insert_query("tblinvoiceitems", array("userid" => $data['userid'], "type" => "Item", "relid" => $data['id'], "description" => $data['description'], "amount" => $data['amount'], "taxed" => $billableitemstax, "duedate" => $data['duedate'], "paymentmethod" => $paymentmethod));
            }
            $updatearray = array("invoicecount" => "+1");
            if ($data['invoiceaction'] == "4") {
                $num_rows = get_query_val("tblinvoiceitems", "COUNT(id)", array("type" => "Item", "relid" => $data['id'], "duedate" => $data['duedate']));
                if ($num_rows == 0) {
                    insert_query("tblinvoiceitems", array("userid" => $data['userid'], "type" => "Item", "relid" => $data['id'], "description" => $data['description'], "amount" => $data['amount'], "taxed" => $billableitemstax, "duedate" => $data['duedate'], "paymentmethod" => $paymentmethod));
                }
                $adddays = $addmonths = $addyears = 0;
                if ($data['recurcycle'] == "Days") {
                    $adddays = $data['recur'];
                } else {
                    if ($data['recurcycle'] == "Weeks") {
                        $adddays = $data['recur'] * 7;
                    } else {
                        if ($data['recurcycle'] == "Months") {
                            $addmonths = $data['recur'];
                        } else {
                            if ($data['recurcycle'] == "Years") {
                                $addyears = $data['recur'];
                            }
                        }
                    }
                }
                $year = substr($data['duedate'], 0, 4);
                $month = substr($data['duedate'], 5, 2);
                $day = substr($data['duedate'], 8, 2);
                $updatearray['duedate'] = date("Ymd", mktime(0, 0, 0, $month + $addmonths, $day + $adddays, $year + $addyears));
            }
            update_query("tblbillableitems", $updatearray, array("id" => $data['id']));
        }
    }
    $invoicecount = $invoiceid = 0;
    $where = array();
    $where[] = "invoiceid=0";
    if ($func_userid) {
        $where[] = "userid=" . (int) $func_userid;
    }
    if (!is_array($specificitems)) {
        $where[] = "tblclients.separateinvoices=''";
        $where[] = "(tblclientgroups.separateinvoices='' OR tblclientgroups.separateinvoices is null)";
    }
    $result = select_query("tblinvoiceitems", "DISTINCT tblinvoiceitems.userid,tblinvoiceitems.duedate,tblinvoiceitems.paymentmethod", implode(" AND ", $where), "duedate", "ASC", "", "tblclients ON tblclients.id=tblinvoiceitems.userid LEFT JOIN tblclientgroups ON tblclientgroups.id=tblclients.groupid");
    while ($data = mysql_fetch_array($result)) {
        createInvoicesProcess($data, $noemails, $nocredit);
    }
    if (!is_array($specificitems)) {
        $where = array();
        $where[] = "invoiceid=0";
        if ($func_userid) {
            $where[] = "userid=" . (int) $func_userid;
        }
        $where[] = "(tblclients.separateinvoices='on' OR tblclientgroups.separateinvoices='on')";
        $result = select_query("tblinvoiceitems", "tblinvoiceitems.id,tblinvoiceitems.userid,tblinvoiceitems.type,tblinvoiceitems.relid,tblinvoiceitems.duedate,tblinvoiceitems.paymentmethod", implode(" AND ", $where), "duedate", "ASC", "", "tblclients ON tblclients.id=tblinvoiceitems.userid LEFT JOIN tblclientgroups ON tblclientgroups.id=tblclients.groupid");
        while ($data = mysql_fetch_array($result)) {
            createInvoicesProcess($data, $noemails, $nocredit);
        }
    }
    if (is_object($cron)) {
        $cron->logActivity("" . $invoicecount . " Invoices Created", true);
        $cron->emailLog($invoicecount . " Invoices Created");
    }
    if ($func_userid) {
        return $invoiceid;
    }
}
Beispiel #23
0
     }
 }
 $tplvars['tickets'] = $tickets;
 $invoiceids = explode(",", $invoiceids);
 foreach ($invoiceids as $k => $invoiceid) {
     if (!$invoiceid) {
         unset($invoiceids[$k]);
         continue;
     }
 }
 if (!function_exists("getGatewaysArray")) {
     require ROOTDIR . "/includes/gatewayfunctions.php";
 }
 $gateways = getGatewaysArray();
 $ticketinvoicesquery = !empty($ticketinvoicelinks) ? "(" . implode(" OR ", $ticketinvoicelinks) . ") OR " : "";
 $result = select_query("tblinvoices", "", "id IN (SELECT invoiceid FROM tblinvoiceitems WHERE description LIKE '%Project #" . $projectid . "%' OR " . $ticketinvoicesquery . " (type='Project' AND relid='" . $projectid . "')) OR id IN (" . db_build_in_array(db_escape_numarray($invoiceids)) . ")", "id", "ASC");
 while ($data = mysql_fetch_array($result)) {
     $invoices[] = array("id" => $data['id'], "date" => fromMySQLDate($data['date'], 0, 1), "duedate" => fromMySQLDate($data['duedate'], 0, 1), "datepaid" => fromMySQLDate($data['datepaid'], 0, 1), "total" => formatCurrency($data['total']), "paymentmethod" => $gateways[$data['paymentmethod']], "status" => $data['status'], "rawstatus" => strtolower($data['status']));
 }
 $tplvars['invoices'] = $invoices;
 $attachments = explode(",", $attachments);
 foreach ($attachments as $i => $attachment) {
     $attachment = substr($attachment, 7);
     if ($attachment) {
         $attachmentsarray[$i] = array("filename" => $attachment);
         continue;
     }
 }
 $tplvars['attachments'] = $attachmentsarray;
 $totaltimecount = 0;
 $i = 1;
Beispiel #24
0
 public function display()
 {
     global $templates_compiledir;
     global $CONFIG;
     global $disable_admin_ticket_page_counts;
     global $_ADMINLANG;
     $this->smarty = new Smarty();
     $this->smarty->template_dir = $this->getTemplatePath();
     $this->smarty->compile_dir = $templates_compiledir;
     if ($this->inClientsProfile) {
         $this->title = "Clients Profile";
         $this->sidebar = "clients";
         $this->icon = "clientsprofile";
     }
     if (count($this->chartFunctions)) {
         $chartredrawjs = "function redrawCharts() { ";
         foreach ($this->chartFunctions as $chartfunc) {
             $chartredrawjs .= $chartfunc . "(); ";
         }
         $chartredrawjs .= "}";
         $this->extrajscode[] = $chartredrawjs;
         $this->extrajscode[] = "\$(window).bind(\"resize\", function(event) { redrawCharts(); });";
     }
     $jquerycode = count($this->internaljquerycode) ? implode("\r\n", $this->internaljquerycode) : "";
     if ($this->jquerycode) {
         $jquerycode .= "\r\n" . $this->jquerycode;
     }
     $this->assign("charset", $CONFIG['Charset']);
     $this->assign("template", $this->adminTemplate);
     $this->assign("pagetemplate", $this->template);
     if (isset($_SESSION['adminid'])) {
         $this->assign("adminid", $_SESSION['adminid']);
     }
     $this->assign("filename", $this->filename);
     $this->assign("pagetitle", $this->title);
     $this->assign("helplink", str_replace(" ", "_", $this->helplink));
     $this->assign("sidebar", $this->sidebar);
     $this->assign("minsidebar", isset($_COOKIE['WHMCSMinSidebar']) ? true : false);
     $this->assign("pageicon", $this->icon);
     $this->assign("jquerycode", $jquerycode);
     $this->assign("jscode", $this->jscode . implode("\r\n", $this->extrajscode));
     $this->assign("_ADMINLANG", $_ADMINLANG);
     $this->assign("csrfToken", generate_token("plain"));
     $addonmodulesperms = unserialize($CONFIG['AddonModulesPerms']);
     $this->assign("datepickerformat", str_replace(array("DD", "MM", "YYYY"), array("dd", "mm", "yy"), $CONFIG['DateFormat']));
     if (isset($_SESSION['adminid'])) {
         $result = select_query("tbladmins", "firstname,lastname,notes,supportdepts,roleid", array("id" => $_SESSION['adminid']));
         $data = mysql_fetch_array($result);
         $admin_username = $data['firstname'] . " " . $data['lastname'];
         $admin_notes = $data['notes'];
         $admin_supportdepts = $data['supportdepts'];
         $admin_roleid = $data['roleid'];
         $this->assign("admin_username", ucfirst($admin_username));
         $this->assign("admin_notes", $admin_notes);
         $admin_perms = array();
         $adminpermsarray = getAdminPermsArray();
         $result = select_query("tbladminperms", "permid", array("roleid" => $admin_roleid));
         while ($data = mysql_fetch_array($result)) {
             $admin_perms[] = $adminpermsarray[$data[0]];
         }
         $this->assign("admin_perms", $admin_perms);
         $this->assign("addon_modules", $addonmodulesperms[$admin_roleid]);
     }
     $admins = "";
     $query = "SELECT DISTINCT adminusername FROM tbladminlog WHERE lastvisit>='" . date("Y-m-d H:i:s", mktime(date("H"), date("i") - 15, date("s"), date("m"), date("d"), date("Y"))) . "' AND logouttime='0000-00-00' ORDER BY lastvisit ASC";
     $result = full_query($query);
     while ($data = mysql_fetch_array($result)) {
         $admins .= $data['adminusername'] . ", ";
     }
     $this->assign("adminsonline", substr($admins, 0, 0 - 2));
     $flaggedticketschecked = false;
     $flaggedtickets = 0;
     if ($this->sidebar == "support") {
         $allactive = $awaitingreply = 0;
         $ticketcounts = array();
         $admin_supportdepts_qry = array();
         $admin_supportdepts = explode(",", $admin_supportdepts);
         foreach ($admin_supportdepts as $deptid) {
             if (trim($deptid)) {
                 $admin_supportdepts_qry[] = (int) $deptid;
                 continue;
             }
         }
         if (count($admin_supportdepts_qry) < 1) {
             $admin_supportdepts_qry[] = 0;
         }
         if ($disable_admin_ticket_page_counts) {
             $query = "SELECT tblticketstatuses.title,'x',showactive,showawaiting FROM tblticketstatuses ORDER BY sortorder ASC";
         } else {
             $query = "SELECT tblticketstatuses.title,(SELECT COUNT(tbltickets.id) FROM tbltickets WHERE did IN (" . db_build_in_array($admin_supportdepts_qry) . ") AND tbltickets.status=tblticketstatuses.title),showactive,showawaiting FROM tblticketstatuses ORDER BY sortorder ASC";
         }
         $result = full_query($query);
         while ($data = mysql_fetch_array($result)) {
             $ticketcounts[] = array("title" => $data[0], "count" => $data[1]);
             if ($data['showactive']) {
                 $allactive += $data[1];
             }
             if ($data['showawaiting']) {
                 $awaitingreply += $data[1];
             }
         }
         if (!$disable_admin_ticket_page_counts) {
             $result = select_query("tbltickets", "COUNT(*)", "status!='Closed' AND flag='" . (int) $_SESSION['adminid'] . "'");
             $data = mysql_fetch_array($result);
             $flaggedtickets = $data[0];
             $flaggedticketschecked = true;
         }
         $this->assign("ticketsallactive", $allactive);
         $this->assign("ticketsawaitingreply", $awaitingreply);
         $this->assign("ticketsflagged", $flaggedtickets);
         $this->assign("ticketcounts", $ticketcounts);
         $this->assign("ticketstatuses", $ticketcounts);
         $departments = array();
         $result = select_query("tblticketdepartments", "id,name", "id IN (" . db_build_in_array($admin_supportdepts_qry) . ")", "order", "ASC");
         while ($data = mysql_fetch_array($result)) {
             $departments[] = array("id" => $data['id'], "name" => $data['name']);
         }
         $this->assign("ticketdepts", $departments);
     }
     if (checkPermission("Sidebar Statistics", true)) {
         $templatevars = array();
         $pendingorderstatuses = array();
         $result = select_query("tblorderstatuses", "title", "showpending=1");
         while ($data = mysql_fetch_array($result)) {
             $pendingorderstatuses[] = $data['title'];
         }
         $query = "SELECT COUNT(*) FROM tblorders INNER JOIN tblclients ON tblclients.id=tblorders.userid WHERE tblorders.status IN (" . db_build_in_array($pendingorderstatuses) . ")";
         $result = full_query($query);
         $data = mysql_fetch_array($result);
         $templatevars['orders']['pending'] = $data[0];
         $templatevars['clients']['active'] = $templatevars['clients']['inactive'] = $templatevars['clients']['closed'] = 0;
         $query = "SELECT status,COUNT(*) FROM tblclients GROUP BY status";
         $result = full_query($query);
         while ($data = mysql_fetch_array($result)) {
             $templatevars['clients'][strtolower($data[0])] = $data[1];
         }
         $templatevars['services']['pending'] = $templatevars['services']['active'] = $templatevars['services']['suspended'] = $templatevars['services']['terminated'] = $templatevars['services']['cancelled'] = $templatevars['services']['fraud'] = 0;
         $query = "SELECT domainstatus,COUNT(*) FROM tblhosting GROUP BY domainstatus";
         $result = full_query($query);
         while ($data = mysql_fetch_array($result)) {
             $templatevars['services'][strtolower($data[0])] = $data[1];
         }
         $templatevars['domains']['pending'] = $templatevars['domains']['active'] = $templatevars['domains']['pendingtransfer'] = $templatevars['domains']['expired'] = $templatevars['domains']['cancelled'] = $templatevars['domains']['fraud'] = 0;
         $query = "SELECT status,COUNT(*) FROM tbldomains GROUP BY status";
         $result = full_query($query);
         while ($data = mysql_fetch_array($result)) {
             $templatevars['domains'][str_replace(" ", "", strtolower($data[0]))] = $data[1];
         }
         $query = "SELECT COUNT(id) FROM tblinvoices WHERE status='Unpaid'";
         $result = full_query($query);
         $data = mysql_fetch_array($result);
         $templatevars['invoices']['unpaid'] = $data[0];
         $query = "SELECT COUNT(id) FROM tblinvoices WHERE status='Unpaid' AND duedate<'" . date("Ymd") . "'";
         $result = full_query($query);
         $data = mysql_fetch_array($result);
         $templatevars['invoices']['overdue'] = $data[0];
         if (!$disable_admin_ticket_page_counts) {
             $query = "SELECT COUNT(*) FROM tbltickets WHERE status!='Closed'";
             $result = full_query($query);
             $data = mysql_fetch_array($result);
             $templatevars['tickets']['active'] = $data[0];
             $query = "SELECT COUNT(*) FROM tbltickets WHERE status IN (SELECT title FROM `tblticketstatuses` WHERE showawaiting = '1')";
             $result = full_query($query);
             $data = mysql_fetch_array($result);
             $templatevars['tickets']['awaitingreply'] = $data[0];
             if ($flaggedticketschecked) {
                 $templatevars['tickets']['flagged'] = $flaggedtickets;
             } else {
                 $query = "SELECT COUNT(*) FROM tbltickets WHERE status!='Closed' AND flag='" . (int) $_SESSION['adminid'] . "'";
                 $result = full_query($query);
                 $data = mysql_fetch_array($result);
                 $templatevars['tickets']['flagged'] = $data[0];
             }
             $ticketstats = array();
             $query = "SELECT status,COUNT(*) FROM tbltickets GROUP BY status";
             $result = full_query($query);
             while ($data = mysql_fetch_array($result)) {
                 $ticketstats[$data[0]] = $data[1];
             }
             $templatevars['tickets']['onhold'] = array_key_exists("On Hold", $ticketstats) ? $ticketstats["On Hold"] : "0";
             $templatevars['tickets']['inprogress'] = array_key_exists("In Progress", $ticketstats) ? $ticketstats["In Progress"] : "0";
         }
         $this->assign("sidebarstats", $templatevars);
     }
     $this->assignToSmarty();
     $this->output();
 }
Beispiel #25
0
 $smarty->assign("breadcrumbnav", $breadcrumbnav);
 $kbarticles = array();
 $smartyvalues['searchterm'] = $search;
 $searchterms = array();
 $searchparts = explode(" ", html_entity_decode($search));
 foreach ($searchparts as $searchpart) {
     if ($searchpart) {
         $searchterms[] = "(title LIKE '%" . db_escape_string($searchpart) . "%' OR article LIKE '%" . db_escape_string($searchpart) . "%')";
         continue;
     }
 }
 $searchqry = implode(" AND ", $searchterms);
 if (!$searchqry) {
     $searchqry = "id='x'";
 }
 $query = "SELECT DISTINCT id FROM tblknowledgebase WHERE " . $searchqry . " AND (SELECT categoryid FROM tblknowledgebaselinks WHERE ((articleid=tblknowledgebase.id) OR (articleid=tblknowledgebase.parentid)) LIMIT 1) IN (" . db_build_in_array($idnumbers) . ") ORDER BY `order` ASC,`title` ASC";
 $result = full_query($query);
 $articleids = array();
 while ($data = mysql_fetch_array($result)) {
     $id = $data['id'];
     $result2 = select_query("tblknowledgebase", "", array("id" => $id));
     $data = mysql_fetch_array($result2);
     $title = $data['title'];
     $article = $data['article'];
     $views = $data['views'];
     $parentid = $data['parentid'];
     if ($parentid) {
         $result2 = select_query("tblknowledgebase", "", array("id" => $parentid));
         $data = mysql_fetch_array($result2);
         $id = $data['id'];
         $title = $data['title'];
Beispiel #26
0
// Generate report if period is selected.
if ($queryStartDate && $queryEndDate) {
    $reportdata['currencyselections'] = true;
    // Define table headings.
    $reportdata['tableheadings'] = array('Country Name', 'Country Code', 'VAT Rate', 'Number of Invoices', 'Total Value Invoiced (Excl. VAT)', 'Total VAT Collected', 'Currency');
    // Output reporting period.
    $reportdata['headertext'] .= '<h2 style="margin:0;">For Period ' . date("jS F Y", $queryStartDate) . ' to ' . date("jS F Y", $queryEndDate) . '</h2>';
    // Fetch country names.
    $countries = array();
    require ROOTDIR . '/includes/countries.php';
    // Fetch all configured country based tax rates.
    $taxRates = array();
    $result = select_query('tbltax', 'country,taxrate', "state='' AND country!=''");
    while ($data = mysql_fetch_array($result)) {
        $taxRates[$data['country']] = $data['taxrate'];
    }
    // Build query to calculate data for report.
    $query = "SELECT tblclients.country, COUNT(tblinvoices.id) as invoicecount, " . "SUM(tblinvoices.subtotal) as totalinvoiced, " . "SUM(tblinvoices.tax + tblinvoices.tax2) as totalvat " . "FROM tblinvoices " . "INNER JOIN tblclients ON tblclients.id = tblinvoices.userid " . "WHERE (tblinvoices.tax > 0 OR tblinvoices.tax2 > 0) " . "AND tblclients.country IN (" . db_build_in_array($euCountries) . ") " . "AND datepaid >= '" . date("Y-m-d", $queryStartDate) . "' " . "AND datepaid <= '" . date("Y-m-d", $queryEndDate) . " 23:59:59' " . "AND tblinvoices.status = 'Paid' " . "AND currency = " . (int) $currencyid . " " . "AND (SELECT count(tblinvoiceitems.id) " . "FROM tblinvoiceitems " . "WHERE invoiceid = tblinvoices.id " . "AND (type = 'AddFunds' OR type = 'Invoice') " . ") = 0 " . "GROUP BY tblclients.country " . "ORDER BY tblclients.country ASC";
    $result = full_query($query);
    while ($data = mysql_fetch_array($result)) {
        $countryCode = $data['country'];
        $invoiceCount = $data['invoicecount'];
        $totalInvoiced = $data['totalinvoiced'];
        $totalVat = $data['totalvat'];
        $countryName = isset($countries[$countryCode]) ? $countries[$countryCode] : 'Unrecognised Country';
        $taxRate = isset($taxRates[$countryCode]) ? $taxRates[$countryCode] . '%' : 'Tax Rate Not Found';
        $reportdata['tablevalues'][] = array($countryName, $countryCode, $taxRate, $invoiceCount, $totalInvoiced, $totalVat, $currencyCode);
    }
    $reportdata['footertext'] = "* If a country does not appear in the report, then no VAT was collected " . "from customers in that country during the period selected.";
    $reportdata['footertext'] .= "<br />Isle of Man (GB) and Monaco (FR) are listed in this report as " . "EU Overseas Territories of their respective countries and should be included in any figures " . "provided to tax authorities. " . "<a href='http://europa.eu/youreurope/business/vat-customs/cross-border/index_en.htm' target='_blank'>" . "More Information</a>";
}
Beispiel #27
0
    $filters->redir();
}
if ($whmcs->get_req_var("massdelete")) {
    check_token("WHMCS.admin.default");
    checkPermission("Delete Order");
    if (is_array($selectedorders)) {
        foreach ($selectedorders as $orderid) {
            deleteOrder($orderid);
        }
    }
    $filters->redir();
}
if ($whmcs->get_req_var("sendmessage")) {
    check_token("WHMCS.admin.default");
    $clientslist = "";
    $result = select_query("tblorders", "DISTINCT userid", "id IN (" . db_build_in_array($selectedorders) . ")");
    while ($data = mysql_fetch_array($result)) {
        $clientslist .= "selectedclients[]=" . $data['userid'] . "&";
    }
    redir("type=general&multiple=true&" . substr($clientslist, 0, 0 - 1), "sendmessage.php");
}
ob_start();
if (!$action) {
    releaseSession();
    echo $aInt->Tabs(array($aInt->lang("global", "searchfilter")), true);
    $client = $filters->get("client");
    $clientid = $filters->get("clientid");
    if (!$clientid && $client) {
        $clientid = $client;
    }
    $clientname = $filters->get("clientname");
Beispiel #28
0
    $filters[] = "title LIKE '%" . mysql_real_escape_string($subject) . "%'";
}
if (!$ignore_dept_assignments) {
    $result = select_query("tbladmins", "supportdepts", array("id" => $_SESSION['adminid']));
    $data = mysql_fetch_array($result);
    $supportdepts = $data[0];
    $supportdepts = explode(",", $supportdepts);
    $deptids = array();
    foreach ($supportdepts as $id) {
        if (trim($id)) {
            $deptids[] = trim($id);
            continue;
        }
    }
    if (count($deptids)) {
        $filters[] = "did IN (" . db_build_in_array(db_escape_numarray($deptids)) . ")";
    }
}
$where = implode(" AND ", $filters);
$result = select_query("tbltickets", "COUNT(id)", $where);
$data = mysql_fetch_array($result);
$totalresults = $data[0];
$apiresults = array("result" => "success", "totalresults" => $totalresults, "startnumber" => $limitstart);
$result = select_query("tbltickets", "", $where, "lastreply", "DESC", "" . $limitstart . "," . $limitnum);
$apiresults['numreturned'] = mysql_num_rows($result);
while ($data = mysql_fetch_array($result)) {
    $id = $data['id'];
    $tid = $data['tid'];
    $deptid = $data['did'];
    $userid = $data['userid'];
    $name = $data['name'];
Beispiel #29
0
function widget_system_overview($vars)
{
    global $whmcs, $_ADMINLANG;
    $title = $_ADMINLANG['home']['sysoverview'];
    if ($whmcs->get_req_var('getsystemoverview')) {
        $activeclients = get_query_val("tblclients", "COUNT(id)", "status='Active'");
        $totalclients = get_query_val("tblclients", "COUNT(id)", "");
        $clientsactive = $activeclients == 0 || $totalclients == 0 ? '0' : round($activeclients / $totalclients * 100, 0);
        $activeservices = get_query_val("tblhosting", "COUNT(id)", "domainstatus='Active'");
        $totalservices = get_query_val("tblhosting", "COUNT(id)", "");
        $servicesactive = $activeservices == 0 || $totalservices == 0 ? '0' : round($activeservices / $totalservices * 100, 0);
        $unpaidinvoices = get_query_val("tblinvoices", "COUNT(id)", "status='Unpaid'");
        $overdueinvoices = get_query_val("tblinvoices", "COUNT(id)", "status='Unpaid' AND duedate<'" . date("Ymd") . "'");
        $overduestatus = $overdueinvoices == 0 || $unpaidinvoices == 0 ? '0' : round($overdueinvoices / $unpaidinvoices * 100, 0);
        echo '
<table width="100%">
<tr>
    <td width="150">Clients</td>
    <td>
    <div class="percentbar">
    <div class="active" style="width:' . $clientsactive . '%">' . $clientsactive . '% Active</div>
    </div>
    </td>
    <td class="totals">' . $totalclients . '</td>
</tr>
<tr>
    <td>Services</td>
    <td>
    <div class="percentbar">
    <div class="active" style="width:' . $servicesactive . '%">' . $servicesactive . '% Active</div>
    </div>
    </td>
    <td class="totals">' . $totalservices . '</td>
</tr>
<tr>
    <td>Unpaid Invoices</td>
    <td>
    <div class="percentbar">
    <div class="overdue" style="width:' . $overduestatus . '%">' . $overduestatus . '% Overdue</div>
    </div>
    </td>
    <td class="totals">' . $unpaidinvoices . '</td>
</tr>
</table>
';
        exit;
    }
    $adminusername = get_query_val("tbladmins", "username", array("id" => $vars['adminid']));
    $lastlogin = get_query_vals("tbladminlog", "lastvisit,ipaddress", array("adminusername" => $adminusername), "lastvisit", "DESC", "1,1");
    $lastlogindate = $lastlogin[0] ? fromMySQLDate($lastlogin[0], true) : '(None Recorded)';
    $lastloginip = $lastlogin[1] ? $lastlogin[1] : '-';
    $content = '
<style>
#systemoverviewstats {
    display: none;
}
#systemoverviewstats div.percentbar {
    width: 100%;
    height: 24px;
    border: 1px solid #ccc;
    background-color: #efefef;
}
#systemoverviewstats div.percentbar div.active {
    height: 24px;
    line-height: 24px;
    background-color: #84B429;
    color: #fff;
    font-weight: bold;
    text-align: center;
    overflow: hidden;
}
#systemoverviewstats div.percentbar div.overdue {
    height: 24px;
    line-height: 24px;
    background-color: #cc0000;
    color: #fff;
    font-weight: bold;
    text-align: center;
}
#systemoverviewstats td {
    text-align: center;
    font-weight: bold;
    height: 35px;
}
.lastlogin {
    margin-bottom:5px;
    padding:3px;
    text-align: center;
}
</style>

<div id="systemoverviewstats">' . $vars['loading'] . '</div>

<div class="lastlogin">' . $_ADMINLANG['home']['lastlogin'] . ': <strong>' . $lastlogindate . '</strong> ' . $_ADMINLANG['home']['lastloginip'] . ' <strong>' . $lastloginip . '</strong></div>

';
    $statusfilter = array();
    $result = select_query("tblticketstatuses", "title", array("showawaiting" => "1"));
    while ($data = mysql_fetch_array($result)) {
        $statusfilter[] = $data[0];
    }
    $result = full_query("SELECT COUNT(*) FROM tbltickets WHERE status IN (" . db_build_in_array($statusfilter) . ")");
    $data = mysql_fetch_array($result);
    $ticketsawaitingreply = $data[0];
    $result = full_query("SELECT COUNT(*) FROM tblcancelrequests INNER JOIN tblhosting ON tblhosting.id=tblcancelrequests.relid WHERE (tblhosting.domainstatus!='Cancelled' AND tblhosting.domainstatus!='Terminated')");
    $data = mysql_fetch_array($result);
    $cancellationrequests = $data[0];
    $result = full_query("SELECT COUNT(*) FROM tbltodolist WHERE status!='Completed' AND status!='Postponed' AND duedate<='" . date("Y-m-d") . "'");
    $data = mysql_fetch_array($result);
    $todoitemsdue = $data[0];
    $result = full_query("SELECT COUNT(*) FROM tblnetworkissues WHERE status!='Scheduled' AND status!='Resolved'");
    $data = mysql_fetch_array($result);
    $opennetworkissues = $data[0];
    $jquerycode = 'jQuery.post("index.php", { getsystemoverview: 1 },
    function(data){
        jQuery("#systemoverviewstats").html(data);
        jQuery("#systemoverviewstats").slideDown();
        jQuery("#sysoverviewbanner").html("<div style=\\"margin:0 0 -5px 0;padding: 10px;background-color: #FBEEEB;border: 1px dashed #cc0000;font-weight: bold;color: #cc0000;font-size:14px;text-align: center;-moz-border-radius: 10px;-webkit-border-radius: 10px;-o-border-radius: 10px;border-radius: 10px;\\">' . $_ADMINLANG['global']['attentionitems'] . ': &nbsp; <a href=\\"supporttickets.php\\">' . $ticketsawaitingreply . ' ' . $_ADMINLANG['stats']['ticketsawaitingreply'] . '</a> &nbsp;-&nbsp; <a href=\\"cancelrequests.php\\">' . $cancellationrequests . ' ' . $_ADMINLANG['stats']['pendingcancellations'] . '</a> &nbsp;-&nbsp; <a href=\\"todolist.php\\">' . $todoitemsdue . ' ' . $_ADMINLANG['stats']['todoitemsdue'] . '</a> &nbsp;-&nbsp; <a href=\\"networkissues.php\\">' . $opennetworkissues . ' ' . $_ADMINLANG['stats']['opennetworkissues'] . '</a></div>");
});';
    return array('title' => $title, 'content' => $content, 'jquerycode' => $jquerycode);
}
Beispiel #30
0
function doFraudCheck($params, $checkonly = false)
{
    global $_LANG;
    global $cc_encryption_hash;
    $availablelanguages = array("English", "Arabic", "Cantonese", "Croatian", "Czech", "Danish", "Dutch", "Estonian", "Finnish", "French", "German", "Greek", "Hebrew", "Hindi", "Hungarian", "Italian", "Japanese", "Korean", "Mandarin", "Norwegian", "Polish", "Portuguese", "Portugueseeu", "Romanian", "Russian", "Slovakian", "Spanish", "Swedish", "Thai", "Turkish", "Ukrainian", "Vietnamese");
    if (in_array($_SESSION['Language'], $availablelanguages)) {
        $params['Language'] = $_SESSION['Language'];
    }
    if ($params['Language'] == "Portuguese-br") {
        $params['Language'] = "PT_BR";
    }
    if ($params['Language'] == "Portuguese-pt") {
        $params['Language'] = "PT_PT";
    }
    $phonecc = $params['clientsdetails']['countrycode'];
    $phonenumber = $params['clientsdetails']['phonenumber'];
    if ($phonecc == "44" && substr($phonenumber, 0, 1) == "0") {
        $phonenumber = substr($phonenumber, 1);
    }
    $phonecclen = strlen($phonecc);
    if (substr($phonenumber, 0, $phonecclen) == $phonecc) {
        $phonenumber = "+" . $phonenumber;
    } else {
        $phonenumber = "+" . $phonecc . $phonenumber;
    }
    $emaildomain = explode("@", $params['clientsdetails']['email'], 2);
    $emaildomain = $emaildomain[1];
    $cchash = md5($cc_encryption_hash . $params['clientsdetails']['userid']);
    $cardnum = get_query_val("tblclients", "AES_DECRYPT(cardnum,'" . $cchash . "') as cardnum", array("id" => $params['clientsdetails']['userid']));
    $url = "http://minfraud3.maxmind.com/app/ccv2r";
    $postfields = array();
    $postfields['license_key'] = $params["MaxMind License Key"];
    $postfields['requested_type'] = isset($params["Service Type"]) && $params["Service Type"] == "Premium" ? "premium" : "standard";
    $postfields['i'] = $params['ip'];
    $postfields['EmailMD5'] = md5($params['clientsdetails']['email']);
    $postfields['PasswordMD5'] = md5($params['clientsdetails']['password']);
    $postfields['city'] = $params['clientsdetails']['city'];
    $postfields['region'] = $params['clientsdetails']['state'];
    $postfields['postal'] = $params['clientsdetails']['postcode'];
    $postfields['country'] = $params['clientsdetails']['country'];
    $postfields['domain'] = $emaildomain;
    $postfields['custPhone'] = $phonenumber;
    if ($cardnum) {
        $postfields['bin'] = substr($cardnum, 0, 6);
    }
    $postfields['shipAddr'] = $params['clientsdetails']['address1'];
    $postfields['shipCity'] = $params['clientsdetails']['city'];
    $postfields['shipRegion'] = $params['clientsdetails']['state'];
    $postfields['shipPostal'] = $params['clientsdetails']['postcode'];
    $postfields['shipCountry'] = $params['clientsdetails']['country'];
    $postfields['txnID'] = $_SESSION['orderdetails']['OrderID'];
    $postfields['sessionID'] = session_id();
    $postfields['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    $postfields['accept_language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
        $postfields['forwardedIP'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    $content = curlCall($url, $postfields);
    if (substr($content, 0, 10) == "CURL Error") {
        $results['err'] = $content;
    } else {
        if (!$content) {
            $results['err'] = "No Response Received";
        } else {
            $results = array();
            $keyvaluepairs = explode(";", $content);
            foreach ($keyvaluepairs as $v) {
                $v = explode("=", $v);
                $results[$v[0]] = $v[1];
            }
        }
    }
    if ($checkonly) {
        return $results;
    }
    if ($params["Reject Free Email Service"] == "on" && $results['freeMail'] == "Yes") {
        $results['error']['title'] = $_LANG['maxmind_title'] . " " . $_LANG['maxmind_error'];
        $results['error']['description'] = $_LANG['maxmind_rejectemail'];
    }
    if ($params["Reject Country Mismatch"] == "on" && $results['countryMatch'] == "No") {
        $results['error']['title'] = $_LANG['maxmind_title'] . " " . $_LANG['maxmind_error'];
        $results['error']['description'] = $_LANG['maxmind_countrymismatch'];
    }
    if ($params["Reject Anonymous Proxy"] == "on" && $results['anonymousProxy'] == "Yes") {
        $results['error']['title'] = $_LANG['maxmind_title'] . " " . $_LANG['maxmind_error'];
        $results['error']['description'] = $_LANG['maxmind_anonproxy'];
    }
    if ($params["Reject High Risk Country"] == "on" && $results['highRiskCountry'] == "Yes") {
        $results['error']['title'] = $_LANG['maxmind_title'] . " " . $_LANG['maxmind_error'];
        $results['error']['description'] = $_LANG['maxmind_highriskcountry'];
    }
    $score = $params["Use New Risk Score"] ? $results['riskScore'] : $results['score'];
    if ($params["MaxMind Fraud Risk Score"] != "" && $params["MaxMind Fraud Risk Score"] < $score) {
        $results['error']['title'] = $_LANG['maxmind_title'] . " " . $_LANG['maxmind_error'];
        $results['error']['description'] = $_LANG['maxmind_highfraudriskscore'];
    }
    $forcephoneverify = false;
    $forcepids = $params["Force Phone Verify Products"];
    if ($forcepids) {
        $forcepids = explode(",", $forcepids);
        foreach ($forcepids as $k => $v) {
            $forcepids[$k] = trim($v);
        }
        $result = select_query("tblhosting", "COUNT(id)", "orderid=" . (int) $_SESSION['orderdetails']['OrderID'] . " AND packageid IN (" . db_build_in_array(db_escape_numarray($forcepids)) . ")");
        $data = mysql_fetch_array($result);
        if ($data[0]) {
            $forcephoneverify = true;
        }
    }
    if (!$params['error']['title'] && $params["Perform Telephone Verification"] && ($params["Telephone Fraud Score"] <= $score || $forcephoneverify)) {
        if ($_POST['pin']) {
            if ($_POST['pin'] != $_SESSION['maxmindpin']) {
                $results['error']['title'] = $_LANG['maxmind_title'] . " " . $_LANG['maxmind_incorrectcode'];
                $results['error']['description'] = "<p>" . $_LANG['maxmind_faileddescription'] . "</p>";
                $results['code'] = $_SESSION['maxmindpin'];
                $results['message'] = "Pin Code Verification Failed";
            }
        } else {
            $pin = "";
            $i = 0;
            while ($i < 4) {
                $pin .= mt_rand(1, 9);
                ++$i;
            }
            $_SESSION['maxmindpin'] = $pin;
            $url = "https://www.maxmind.com/app/telephone_http";
            $postfields = array();
            $postfields['l'] = $params["MaxMind License Key"];
            $postfields['phone'] = $phonenumber;
            $postfields['verify_code'] = $pin;
            if ($params['Language'] != "English") {
                $postfields['language'] = $params['Language'];
            }
            $content = curlCall($url, $postfields);
            if (substr($content, 0, 10) == "CURL Error") {
                $results['err'] = $content;
            } else {
                if (!$content) {
                    $results['err'] = "No Response Received";
                } else {
                    $keyvaluepairs = explode(";", $content);
                    foreach ($keyvaluepairs as $v) {
                        $v = explode("=", $v);
                        $results[$v[0]] = $v[1];
                    }
                }
            }
            $results['userinput'] = "true";
            $results['title'] = $_LANG['maxmind_title'];
            $results['description'] = "<p>" . $_LANG['maxmind_callingnow'] . "</p>\n<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?step=fraudcheck\">\n<center><div id=\"pinnumber\" align=\"center\">" . $_LANG['maxmind_pincode'] . ": <input type=\"text\" name=\"pin\" size=\"10\"></div></center>\n<p align=\"center\"><input type=\"submit\" value=\"" . $_LANG['ordercontinuebutton'] . "\"></p>\n</form>";
        }
    }
    return $results;
}