Exemplo n.º 1
0
 /**
  * @return DBBalance
  */
 public static function GetInstance()
 {
     if (self::$Instance === null) {
         self::$Instance = new DBBalance();
     }
     return self::$Instance;
 }
Exemplo n.º 2
0
 /**
  * Renew domain
  * @param $params = array(
  *  	name		string
  *   	period		int
  *    	userId		int						User ID (In admin mode)
  *    	noBilling	bool					Disable billing for domain opeartion (In admin mode)
  * )
  * @return object
  */
 function RenewDomain($params = null)
 {
     // Check params
     if ($this->access_mode == self::ACCESS_MODE_ADMIN) {
         if (!$params["userId"]) {
             throw new Exception(sprintf("'%s' parameter is required", "userId"));
         }
     } else {
         // Reset user disabled params
         $params["noBilling"] = false;
     }
     $user_id = $this->user_id ? $this->user_id : $params["userId"];
     if (!$params["name"]) {
         throw new Exception(sprintf("'%s' parameter is required", "name"));
     }
     $period = (int) $params["period"] ? (int) $params["period"] : 1;
     list($name, $tld) = explode(".", $params["name"], 2);
     $registry = $this->registry_factory->GetRegistryByExtension($tld);
     $domain = DBDomain::GetInstance()->LoadByName($name, $tld);
     $domain->Period = $period;
     if (!$params["noBilling"]) {
         // Check that enougth money
         $client = Client::Load($user_id);
         $balance = DBBalance::GetInstance()->LoadClientBalance($user_id);
         $invoice = new Invoice(INVOICE_PURPOSE::DOMAIN_RENEW, $domain, $domain->UserID);
         $invoice->Description = sprintf(_("%s domain name renewal for %s year(s)"), $domain->GetHostName(), $period);
         $this->CheckEnoughtMoney($client, $balance, $invoice);
         $invoice->ItemID = $domain->ID;
         $this->MakePayment($client, $balance, $invoice);
     }
     $registry->RenewDomain($domain, array('period' => $domain->Period));
     return new stdClass();
 }
        public function OnStartForking()
        {            
            $DbBalance = DBBalance::GetInstance();
            $db = Core::GetDBInstance();
            			
			// Get packages. Order by their commercial value.
            $sql = "SELECT SUM(discount)/COUNT(packageid) AS cv, packageid AS id, min_domains, min_balance  
				FROM discounts d 
				INNER JOIN packages p ON p.id = d.packageid
				WHERE p.min_domains IS NOT NULL OR p.min_balance IS NOT NULL
				GROUP BY packageid ORDER BY cv";
            $packages = (array)$db->GetAll($sql);
            foreach ($packages as &$pkg)
            {
            	$pkg["min_balance"] = (float)$pkg["min_balance"];
            	$pkg["min_domains"] = (int)$pkg["min_domains"];
            } 
            
            if ($packages)
            {
				foreach((array)$db->GetAll("SELECT id FROM users WHERE package_fixed != 1") as $user)
				{ 
					$Balance = $DbBalance->LoadClientBalance($user["id"]);
					$num_domains = (int)$db->GetOne("
						SELECT COUNT(*) 
						FROM domains 
						WHERE userid = ? AND status NOT IN (
							'".DOMAIN_STATUS::EXPIRED."', 
							'".DOMAIN_STATUS::TRANSFER_FAILED."', 
							'".DOMAIN_STATUS::REJECTED."', 
							'".DOMAIN_STATUS::REGISTRATION_FAILED."',
							'".DOMAIN_STATUS::APPLICATION_RECALLED."')
					", array($user["id"]));
					
					$newpackageid = 0;
					foreach ($packages as $package)
					{
						if (($package["min_domains"] && $num_domains > $package["min_domains"])
							|| ($package["min_balance"] && $Balance->Total > $package["min_balance"]))
						{
							$newpackageid = $package["id"];
						}
					}
					
					$db->Execute("UPDATE users SET packageid=? WHERE id=?", array($newpackageid, $user["id"]));
				}
            }
        }
 public function OnPaid(Invoice $Invoice, AbstractPaymentModule $payment_module = null)
 {
     if ($Invoice->Purpose != INVOICE_PURPOSE::BALANCE_DEPOSIT) {
         return;
     }
     Log::Log("BalanceInvoiceObserver::OnPaid(InvoiceID={$Invoice->ID})", E_USER_NOTICE);
     try {
         $Balance = DBBalance::GetInstance()->LoadClientBalance($Invoice->UserID);
         $Operation = $Balance->CreateOperation(BalanceOperationType::Deposit, $Invoice->GetTotal());
         $Operation->InvoiceID = $Invoice->ID;
         $Balance->ApplyOperation($Operation);
     } catch (Exception $e) {
         Log::Log("BalanceInvoiceObserver::OnPaid() thrown exception: {$e->getMessage()}", E_USER_ERROR);
     }
     // OnPaymentComplete routine succeffully completed.
     Log::Log("BalanceInvoiceObserver::OnPaid Successfully completed.", E_USER_NOTICE);
 }
Exemplo n.º 5
0
    }
    $sql .= !stristr($sql, "WHERE") ? " WHERE " : " AND ";
    $sql .= join(" OR ", $likes);
}
$sort_names = array("date_reg" => "dtregistered");
$sort = $req_sort ? key_exists($req_sort, $sort_names) ? $sort_names[$req_sort] : mysql_escape_string($req_sort) : $sort_names["login"];
$dir = $req_dir ? mysql_escape_string($req_dir) : "ASC";
$sql .= " ORDER BY {$sort} {$dir}";
// Total rows
$response["total"] = $db->GetOne(preg_replace('/SELECT [^F]+FROM/is', 'SELECT COUNT(*) FROM', $sql, 1));
$start = $req_start ? (int) $req_start : 0;
$limit = $req_limit ? (int) $req_limit : 20;
$sql .= " LIMIT {$start}, {$limit}";
// Rows
$response["data"] = array();
$DbBalance = DBBalance::GetInstance();
foreach ($db->GetAll($sql) as $row) {
    $row["num_domains"] = $db->GetOne("SELECT COUNT(*) FROM domains WHERE userid='{$row['id']}'");
    $row["num_contacts"] = $db->GetOne("SELECT COUNT(*) FROM contacts WHERE userid='{$row['id']}'");
    $row["num_invoices"] = $db->GetOne("SELECT COUNT(*) FROM invoices WHERE userid='{$row['id']}' AND hidden=0");
    $row["isactive"] = $row["status"] == 1;
    unset($row["status"]);
    try {
        $Balance = $DbBalance->LoadClientBalance($row["id"]);
        $row["balance"] = $Balance->Total;
    } catch (Exception $ignore) {
        $row["balance"] = 0;
    }
    $row["package"] = $row["packageid"] > 0 ? $db->GetOne("SELECT name FROM packages WHERE id='{$row['packageid']}'") : 'Default';
    $row["date_reg"] = $row["dtregistered"] ? date("M j, Y H:i:s", $row["dtregistered"]) : null;
    //		$row["date_reg"] = null;
Exemplo n.º 6
0
		if ($get_search && $post_filter_q != $get_search && !$post_filter_q)
		{
			$_POST["filter_q"] = $post_filter_q = rawurldecode($get_search);
			$_POST["Submit"] = $post_Submit = "Filter";
			$_POST["act"] = $post_act = "filter1";
			unset($_SESSION['filter']);
		}
			
		// tempalte folder
		$tplpath = $display['tplpath'] = 'client';
		
		// Get User settings
		$user_cfg = $db->GetAll("SELECT * FROM user_settings WHERE userid='{$_SESSION['userid']}'");
		foreach ($user_cfg as $ucfg)
			define("CF_USERS_".strtoupper($ucfg["key"]), $ucfg["value"]);
			
		// Load client balance
		try
		{
			$Balance = DBBalance::GetInstance()->LoadClientBalance($_SESSION['userid']);
			$display["balance"] = $Balance->Total;
			$display["currency"] = CONFIG::$CURRENCY;
		}
		catch (Exception $e)
		{
			Log::Log("Cannot load client balance. ".$e->getMessage(), E_USER_ERROR);
		}
	}
	
?>
Exemplo n.º 7
0
 public function ApplyOperation(BalanceOperation $Operation)
 {
     $Operation->Date = time();
     $this->DBBalance->SaveOperation($Operation, $this);
 }
Exemplo n.º 8
0
 /**
  * 
  * @param $params = array(
  * 		userId		int		User ID (Only in admin mode)
  * )
  * @return object
  */
 function GetBalanceInfo($params = null)
 {
     $user_id = $this->access_mode == self::ACCESS_MODE_ADMIN ? $params["userId"] : $this->user_id;
     if (!$user_id) {
         throw new Exception(sprintf("'%s' parameter is required", "userId"));
     }
     $db_balance = DBBalance::GetInstance();
     $balance = $db_balance->LoadClientBalance($user_id);
     $ret = new stdClass();
     $ret->balance = new stdClass();
     $ret->balance->total = $balance->Total;
     $ret->balance->currency = CONFIG::$CURRENCYISO;
     return $ret;
 }
Exemplo n.º 9
0
require_once 'src/prepend.inc.php';
if ($_POST) {
    if (!$post_userid) {
        $err[] = sprintf(_("%s is required"), "Client");
    }
    if (!$post_description) {
        $err[] = sprintf(_("%s is required"), "Description");
    }
    $post_amount = floatval(str_replace(",", ".", $post_amount));
    if (!$post_amount) {
        $err[] = sprintf(_("%s is required"), "Amount");
    }
    if (!$err) {
        try {
            $Client = Client::Load($post_userid);
            $Balance = DBBalance::GetInstance()->LoadClientBalance($Client->ID);
            $Operation = $Balance->CreateOperation($post_type, $post_amount);
            $Operation->Description = $post_description;
            $Balance->ApplyOperation($Operation);
        } catch (Exception $e) {
            $err[] = $e->getMessage();
        }
    }
    if (!$err) {
        $okmsg = "Balance operation apply successfully";
        CoreUtils::Redirect("balance_operation.php");
    }
}
$display["attr"] = array_merge($_GET, $_POST);
$display["users"] = $db->GetAll("SELECT * FROM users ORDER BY login");
$display["currency"] = CONFIG::$CURRENCY;