whmcs client form

This commit is contained in:
drigato 2014-06-12 17:54:20 -04:00
parent e5a74e7285
commit 81ceafbfbd
6 changed files with 250 additions and 3 deletions

View File

@ -29,7 +29,8 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
->add(new Zend_Acl_Resource('audiopreview'))
->add(new Zend_Acl_Resource('webstream'))
->add(new Zend_Acl_Resource('locale'))
->add(new Zend_Acl_Resource('upgrade'));
->add(new Zend_Acl_Resource('upgrade'))
->add(new Zend_Acl_Resource('billing'));
/** Creating permissions */
$ccAcl->allow('G', 'index')
@ -54,7 +55,8 @@ $ccAcl->allow('G', 'index')
->allow('A', 'listenerstat')
->allow('A', 'user')
->allow('A', 'systemstatus')
->allow('A', 'preference');
->allow('A', 'preference')
->allow('A', 'billing');
$aclPlugin = new Zend_Controller_Plugin_Acl($ccAcl);

View File

@ -0,0 +1,58 @@
<?php
class BillingController extends Zend_Controller_Action {
public function indexAction()
{
}
public function purchaseAction()
{
$form = new Application_Form_BillingPurchase();
$this->view->form = $form;
//$this->view->html = $this->view->render('billing/purchase.phtml');
}
public static function getClientDetails()
{
try {
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "getclientsdetails";
$postfields["stats"] = true;
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
$postfields["clientid"] = 1822;
$postfields["responsetype"] = "json";
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //Aggressive 5 second timeout
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$jsondata = curl_exec($ch);
if (curl_error($ch)) {
//die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
throw new Exception("WHMCS server down or invalid request.");
}
curl_close($ch);
$arr = json_decode($jsondata, true);
return $arr["client"];
} catch (Exception $e) {
Logging::info($e->getMessage());
}
}
}

View File

@ -0,0 +1,180 @@
<?php
require_once 'Zend/Locale.php';
class Application_Form_BillingPurchase extends Zend_Form
{
public function init()
{
/*$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/billing-purchase.phtml'))));*/
$client = BillingController::getClientDetails();
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
$emailValidator = Application_Form_Helper_ValidationTypes::overrideEmailAddressValidator();
$firstname = new Zend_Form_Element_Text('firstname');
$firstname->setLabel(_('First Name:'))
->setValue($client["firstname"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($firstname);
$lastname = new Zend_Form_Element_Text('lastname');
$lastname->setLabel(_('Last Name:'))
->setValue($client["lastname"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($lastname);
$companyname = new Zend_Form_Element_Text('companyname');
$companyname->setLabel(_('Company Name:'))
->setValue($client["companyname"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($companyname);
$email = new Zend_Form_Element_Text('email');
$email->setLabel(_('Email Address:'))
->setValue($client["email"])
->setAttrib('class', 'input_text')
->setRequired(true)
->setAttrib('readonly', 'readonly')
->addValidator($emailValidator)
->addFilter('StringTrim');
$this->addElement($email);
$address1 = new Zend_Form_Element_Text('address1');
$address1->setLabel(_('Address 1:'))
->setValue($client["address1"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($address1);
$address2 = new Zend_Form_Element_Text('address2');
$address2->setLabel(_('Address 2:'))
->setValue($client["address2"])
->setAttrib('class', 'input_text')
->addFilter('StringTrim');
$this->addElement($address2);
$city = new Zend_Form_Element_Text('city');
$city->setLabel(_('City:'))
->setValue($client["city"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($city);
//TODO: get list from whmcs?
$state = new Zend_Form_Element_Text('state');
$state->setLabel(_('State/Region:'))
->setValue($client["state"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($state);
$postcode = new Zend_Form_Element_Text('postcode');
$postcode->setLabel(_('Zip Code:'))
->setValue($client["postcode"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($postcode);
$locale = new Zend_Locale('en_US');
$countries = $locale->getTranslationList('Territory', 'en', 2);
asort($countries, SORT_LOCALE_STRING);
$country = new Zend_Form_Element_Select('country');
$country->setLabel(_('Country:'))
->setValue($client["country"])
->setAttrib('class', 'input_text')
->setMultiOptions($countries)
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($country);
$phonenumber = new Zend_Form_Element_Text('phonenumber');
$phonenumber->setLabel(_('Phone Number:'))
->setValue($client["phonenumber"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($phonenumber);
//TODO: get list from whmcs
$securityqid = new Zend_Form_Element_Text('securityqid');
$securityqid->setLabel(_('Please choose a security question:'))
->setValue($client["securityqid"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($securityqid);
$securityqans = new Zend_Form_Element_Text('securityqans');
$securityqans->setLabel(_('Please enter an answer:'))
->setValue($client["securityqans"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($securityqans);
foreach ($client["customfields"] as $field) {
if ($field["id"] == 7) {
$vatvalue = $field["value"];
} elseif ($field["id"] == 71) {
$subscribevalue = $field["value"];
}
}
$vat = new Zend_Form_Element_Text('vat');
$vat->setLabel(_('VAT/Tax ID (EU only)'))
->setValue($vatvalue)
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($vat);
$subscribe = new Zend_Form_Element_Checkbox('subscribe');
$subscribe->setLabel(_('Subscribe to Sourcefabric newsletter'))
->setValue($subscribevalue)
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($subscribe);
$password = new Zend_Form_Element_Password('whmcspassword');
$password->setLabel(_('Password:'));
$password->setAttrib('class', 'input_text');
$password->setRequired(true);
$password->addFilter('StringTrim');
$password->addValidator($notEmptyValidator);
$this->addElement($password);
$passwordVerify = new Zend_Form_Element_Password('whmcspasswordVerify');
$passwordVerify->setLabel(_('Verify Password:'));
$passwordVerify->setAttrib('class', 'input_text');
$passwordVerify->setRequired(true);
$passwordVerify->addFilter('StringTrim');
$passwordVerify->addValidator($notEmptyValidator);
$this->addElement($passwordVerify);
}
}

View File

@ -24,7 +24,9 @@
<div class="personal-block solo">
<ul>
<li>
<a id="current-user" href=<?php echo $baseUrl . "User/edit-user"?>><span class="name"><?php echo $this->escape($this->loggedInAs()); ?></span></a> | <a href=<?php echo $baseUrl . "Login/logout"?>><?php echo _("Logout")?></a>
<span class="trial-box-button"><a title="Billing" href=<?php echo $baseUrl . 'billing/purchase'?>>Buy Now</a></span>&nbsp;
<a id="current-user" href=<?php echo $baseUrl . "User/edit-user"?>><span class="name"><?php echo $this->escape($this->loggedInAs()); ?></span></a>
| <a href=<?php echo $baseUrl . "Login/logout"?>><?php echo _("Logout")?></a>
</li>
</ul>
</div>

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1,4 @@
<div class="ui-widget ui-widget-content block-shadow clearfix padded-strong">
<?php //echo $this->successMessage ?>
<?php echo $this->form ?>
</div>