2013-10-10 02:44:53 +00:00
|
|
|
<?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_OSB {
|
|
|
|
// Reset any sorting that may be defined in our parent
|
|
|
|
protected $_sorting = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When does our service expire
|
|
|
|
*/
|
|
|
|
abstract public function expire();
|
|
|
|
|
|
|
|
/**
|
2013-11-14 11:50:35 +00:00
|
|
|
* Our service name as defined in the DB
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-11-14 11:50:35 +00:00
|
|
|
abstract public function name();
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-14 11:50:35 +00:00
|
|
|
* The table attributes that provide username/password values
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-11-14 11:50:35 +00:00
|
|
|
abstract public function password_value();
|
|
|
|
abstract public function username_value();
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-14 11:50:35 +00:00
|
|
|
* Get specific service details for use in other modules
|
|
|
|
* For Example: Invoice
|
|
|
|
*
|
|
|
|
* @todo Make the rendered items configurable
|
|
|
|
* @todo Change this method name, now that it is public
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-11-14 11:50:35 +00:00
|
|
|
public function _details($type) {
|
|
|
|
switch ($type) {
|
|
|
|
// Nothing to add for invoices
|
|
|
|
case 'invoice_detail_items':
|
|
|
|
return array();
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
|
|
|
|
}
|
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-14 11:50:35 +00:00
|
|
|
/**
|
|
|
|
* Provide the button that launches the management of this service, generally from a 3rd party
|
|
|
|
*/
|
2013-10-10 02:44:53 +00:00
|
|
|
public function manage_button() {
|
2013-09-06 05:39:56 +00:00
|
|
|
if (! $this->service->status OR $this->service->expiring())
|
2013-10-10 02:44:53 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
static $k = '';
|
|
|
|
|
|
|
|
// If $k is already set, we've rendered this JS
|
|
|
|
if ($k)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
$k = Random::char();
|
|
|
|
Session::instance()->set('manage_button',$k);
|
|
|
|
|
|
|
|
Script::add(array('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: "'.$k.'",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;
|
|
|
|
}
|
|
|
|
|
2013-11-14 11:50:35 +00:00
|
|
|
/**
|
|
|
|
* Return the name of the plugin
|
|
|
|
*/
|
2013-11-09 04:51:08 +00:00
|
|
|
protected function plugin() {
|
|
|
|
return strtolower(preg_replace('/(.*)_([a-zA-Z]+)$/',"$2",get_class($this)));
|
|
|
|
}
|
|
|
|
|
2013-10-10 02:44:53 +00:00
|
|
|
/**
|
2013-11-27 00:22:20 +00:00
|
|
|
* Form info for admins to update plugin data
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-11-27 00:22:20 +00:00
|
|
|
public function render_edit() {
|
|
|
|
return View::factory(sprintf('service/admin/plugin/%s/edit',$this->plugin()))
|
|
|
|
->set('o',$this);
|
2013-11-14 11:50:35 +00:00
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-14 11:50:35 +00:00
|
|
|
/**
|
|
|
|
* View details of the service
|
|
|
|
*/
|
2013-11-27 00:22:20 +00:00
|
|
|
public function render_view() {
|
2013-11-14 11:50:35 +00:00
|
|
|
return View::factory(sprintf('service/user/plugin/%s/view',$this->plugin()))
|
|
|
|
->set('o',$this);
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
2013-11-27 00:22:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show our service name as defined in the DB with product suffix.
|
|
|
|
*/
|
|
|
|
public function service_name() {
|
|
|
|
return sprintf('%s - %s',$this->service->product->title(),$this->name());
|
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
?>
|