62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class provides User with a TSM node functions
|
|
*
|
|
* @package TSM Access Management
|
|
* @category Controllers/User
|
|
* @author Deon George
|
|
* @copyright (c) 2009-2013 Deon George
|
|
* @license http://dev.leenooks.net/license.html
|
|
*/
|
|
class Controller_User_Node extends Controller_Node {
|
|
protected $secure_actions = array(
|
|
'add'=>0,
|
|
'view'=>0,
|
|
);
|
|
|
|
private function node_name($i) {
|
|
return sprintf('%s%02d',$this->ao->id(),$i);
|
|
}
|
|
|
|
public function action_add() {
|
|
$n = ORM::factory('NODE')->where('EMAIL_ADDRESS','=',$this->ao->email)->find_all();
|
|
|
|
if ($n->count() >= $this->ao->max_nodes) {
|
|
SystemMessage::add(array(
|
|
'title'=>_('Maximum nodes created'),
|
|
'type'=>'info',
|
|
'body'=>_('Additional nodes cannot be created for your account, you have already reached your maximum. If you really need more, please contact us.'),
|
|
));
|
|
|
|
HTTP::redirect(URL::link('user','welcome'));
|
|
}
|
|
|
|
if ($this->request->post()) {
|
|
// Find a free name.
|
|
for ($i=1;$i<=$n->count();$i++)
|
|
if (! Object::in_array('NODE_NAME',$this->node_name($i),$n->as_array()))
|
|
break;
|
|
|
|
$no = ORM::factory('NODE');
|
|
$no->NODE_NAME=$this->node_name($i);
|
|
$no->CONTACT=$this->ao->name();
|
|
$no->EMAILADDRESS=$this->ao->email;
|
|
$no->values($x=Arr::merge(Kohana::$config->load('tsm')->node_create,$this->request->post()));
|
|
|
|
$this->save($no);
|
|
|
|
if ($no->saved())
|
|
#HTTP::redirect(URL::link('user','node/view/'.$no->NODE_NAME));
|
|
HTTP::redirect(URL::link('user','welcome'));
|
|
}
|
|
|
|
Block::factory()
|
|
->type('form-horizontal')
|
|
->title('Register NODE')
|
|
->title_icon('fa-desktop')
|
|
->body(View::factory('node/user/add')->set('o',$this->ao));
|
|
}
|
|
}
|
|
?>
|