102 lines
2.4 KiB
PHP
102 lines
2.4 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class supports Service Plugins.
|
|
*
|
|
* @package Service
|
|
* @category Models
|
|
* @author Deon George
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
* @license http://dev.osbill.net/license.html
|
|
*/
|
|
abstract class Model_Service_Plugin extends ORM {
|
|
// Reset any sorting that may be defined in our parent
|
|
protected $_sorting = array();
|
|
|
|
protected $_belongs_to = array(
|
|
'service'=>array(),
|
|
);
|
|
|
|
/** REQUIRED ABSTRACT METHODS **/
|
|
|
|
/**
|
|
* Service attributes
|
|
*/
|
|
abstract public function attributes($variable=NULL);
|
|
|
|
/**
|
|
* When does our service expire
|
|
*/
|
|
abstract public function expire();
|
|
|
|
/**
|
|
* The table attributes that provide username/password values
|
|
*/
|
|
abstract public function password();
|
|
abstract public function username();
|
|
|
|
/** LOCAL METHODS **/
|
|
|
|
/**
|
|
* Provide the button that launches the management of this service, generally from a 3rd party
|
|
*/
|
|
protected function manage() {
|
|
// Dont show the manage button for expired or inactive services
|
|
if (! $this->service->active OR $this->service->expiring())
|
|
return FALSE;
|
|
|
|
static $x = '';
|
|
|
|
// If $x is already set, we've rendered this JS
|
|
if (! $x) {
|
|
$x = Random::char();
|
|
|
|
Session::instance()->set('manage_button',$x);
|
|
|
|
Script::factory()
|
|
->type('stdin')
|
|
->data('
|
|
$(document).ready(function() {
|
|
var x=0;
|
|
|
|
$("button[name=submit]").click(function() {
|
|
var t=$(this).val().split(":");
|
|
if (x++) { alert("Session expired, please refresh the page!"); return false; }
|
|
|
|
$.getJSON("'.URL::link('user','service/ajaxmanage/'.$this->service_id,TRUE).'", { k: "'.$x.'",t: t[1] },
|
|
function(data) {$.each(data, function(key, val) { $("#"+key+"_"+t[0]+"_"+t[1]).val(val); }); })
|
|
.error(function() { alert("There was a problem with the request"); return false; })
|
|
.success(function() { $("form[id=id_"+t[0]+"_"+t[1]+"]").submit(); });
|
|
});
|
|
});'
|
|
);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* Return the name of the plugin
|
|
*/
|
|
protected function plugin() {
|
|
return strtolower(preg_replace('/(.*)_([a-zA-Z]+)$/',"$2",get_class($this)));
|
|
}
|
|
|
|
/**
|
|
* Form info for admins to update plugin data
|
|
*/
|
|
public function render_edit() {
|
|
return View::factory(sprintf('service/admin/plugin/%s/edit',$this->plugin()))
|
|
->set('o',$this);
|
|
}
|
|
|
|
/**
|
|
* View details of the service
|
|
*/
|
|
public function render_view() {
|
|
return View::factory(sprintf('service/user/plugin/%s/view',$this->plugin()))
|
|
->set('o',$this);
|
|
}
|
|
}
|
|
?>
|