foreach ($r as $k => $v) {
         $myid = $v['id'];
         $mylic = $v['license'];
         $data = select_query("whmcsresellerlicenses", "id", array("license_id" => $myid));
         if (!mysql_num_rows($data)) {
             insert_query("whmcsresellerlicenses", array("license_id" => $myid, "license" => $mylic));
             $imp_count++;
         }
     }
     $ch = curl_init();
     $content = wr_dologin($ch, $myemail, $mypass);
     if (!$content) {
         $data = mysql_query("SELECT * FROM whmcsresellerlicenses");
         while ($r = mysql_fetch_array($data)) {
             $lic_id = $r['license_id'];
             $lic_info = wr_get_lic_info($ch, $lic_id);
             $lic_status = $lic_info['status'];
             $lic_domains = $lic_info['domains'];
             $lic_ips = $lic_info['ips'];
             $lic_path = $lic_info['directory'];
             $lic_type = $lic_info['type'];
             mysql_query("UPDATE whmcsresellerlicenses SET status='{$lic_status}', domains='{$lic_domains}', ips='{$lic_ips}', path='{$lic_path}', type='{$lic_type}' WHERE license_id='{$lic_id}'");
         }
     }
     curl_close($ch);
     $msg = "Imported {$imp_count} licenses.";
     break;
 case "reissue":
     $lic_id = $_REQUEST['lic_id'];
     $ch = curl_init();
     $data = wr_dologin($ch, $myemail, $mypass);
function whmcsreseller_ClientArea($params)
{
    include 'functions.php';
    $userid = $params['clientsdetails']['userid'];
    $serviceid = $params['serviceid'];
    $lic_id = wr_get_lic_id_byuser($userid, $serviceid);
    $data = select_query("whmcsresellerconf", "name, value", array());
    while ($r = mysql_fetch_array($data)) {
        switch ($r['name']) {
            case "email":
                $myemail = $r['value'];
                break;
            case "password":
                $mypass = base64_decode($r['value']);
                break;
        }
    }
    if (isset($_REQUEST['_a'])) {
        if (!isset($_POST['lic_id']) && !isset($_POST['id']) && !isset($_POST['user_id'])) {
            print '<div class="errorbox" align="center" width="60%">Unauthorized Access Attempt.</div>';
        } else {
            $mylic_id = $_POST['lic_id'];
            $myservice_id = $_POST['id'];
            $myuser_id = $_POST['user_id'];
            $d = select_query("whmcsresellerlicenses", "*", array("license_id" => $mylic_id, "user_id" => $myuser_id, "prod_id" => $myservice_id));
            if (!mysql_num_rows($data)) {
                print '<div class="errorbox" align="center" width="60%">Unauthorized Access Attempt.</div>';
            } else {
                $data = select_query("whmcsresellerconf", "*");
                while ($r = mysql_fetch_array($data)) {
                    switch ($r['name']) {
                        case "email":
                            $whmcs_email = $r['value'];
                            break;
                        case "password":
                            $whmcs_pass = base64_decode($r['value']);
                            break;
                    }
                }
                $ch = curl_init();
                $data = wr_dologin($ch, $whmcs_email, $whmcs_pass);
                if (!$data) {
                    $lic_info = wr_get_lic_info($ch, $lic_id);
                    $lic_status = $lic_info['status'];
                    if ($lic_status != "Reissued") {
                        wr_reissue_lic($ch, $lic_id);
                    }
                }
                curl_close($ch);
            }
        }
    }
    $prod_data = select_query("tblhosting", "domainstatus", array("id" => $serviceid, "domainstatus" => "Active"));
    $isactive = mysql_num_rows($prod_data);
    $ch = curl_init();
    $data = wr_dologin($ch, $myemail, $mypass);
    if (!$data) {
        $lic_info = wr_get_lic_info($ch, $lic_id);
    }
    curl_close($ch);
    $lic_status = $lic_info['status'];
    if ($lic_status == "Reissued") {
        $lic_domains = "";
        $lic_ips = "";
        $lic_path = "";
        $lic_key = $lic_info['license'];
        $code = '<br /><div class="errorbox">The Valid Domains, IPs and Directory will be detected & saved the next time the license is verified.</div><br />';
    } else {
        $lic_domains = $lic_info['domains'];
        $lic_ips = $lic_info['ips'];
        $lic_path = $lic_info['directory'];
        $lic_key = $lic_info['license'];
        switch ($lic_info['type']) {
            case "nobranding":
                $type = "No Branding";
                break;
            case "branding":
                $type = "Branding";
                break;
        }
        $code = '<br />';
    }
    $code = $code . '<table cellspacing="1" cellpadding="0" class="frame"><tr><td>
			<table width="100%" cellpadding="2">
			<tr><td class="fieldarea">License Key:</td><td><input id="tbstyle" type="text" size="40" value="' . $lic_key . '" readonly=true></td></tr>
			<tr><td class="fieldarea">Valid Domains:</td><td><textarea id="tastyle" cols="40" readonly=true>' . $lic_domains . '</textarea></td></tr>
			<tr><td class="fieldarea">Valid IPs:</td><td><textarea id="tastyle" cols="40" readonly=true>' . $lic_ips . '</textarea></td></tr>
			<tr><td class="fieldarea">Valid Directory:</td><td><textarea id="tastyle" cols="40" readonly=true>' . $lic_path . '</textarea></td></tr>
			<tr><td class="fieldarea">License Type:</td><td>' . $type . '</td></tr>
			<tr><td class="fieldarea">Status:</td><td>' . $lic_status . '</td></tr></table></td></tr>';
    if ($lic_status == "Reissued") {
        $code = $code . '<tr><td align="center">&nbsp;</td></tr>';
    } else {
        $code = $code . '<tr><td align="center">
						<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?action=productdetails&_a=reissue">
						<input type="hidden" name="id" value="' . $params['serviceid'] . '" />
						<input type="hidden" name="lic_id" value="' . $lic_id . '" />
						<input type="hidden" name="user_id" value="' . $userid . '" />
						<input type="submit" value="Reissue License" class="button" />
						</td></tr>';
    }
    $code = $code . '</table>';
    if (!$lic_key || !$isactive) {
        return '<br /><div class="errorbox">No license is currently assigned.</div>';
    } else {
        return $code;
    }
}