2014-10-28 05:33:15 +00:00
|
|
|
<?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() {
|
2014-10-28 05:56:56 +00:00
|
|
|
$n = ORM::factory('NODE')->where('EMAIL_ADDRESS','=',$this->ao->email)->find_all();
|
2014-10-28 05:33:15 +00:00
|
|
|
|
2014-10-28 05:56:56 +00:00
|
|
|
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.'),
|
|
|
|
));
|
2014-10-28 05:33:15 +00:00
|
|
|
|
2014-10-28 05:56:56 +00:00
|
|
|
HTTP::redirect(URL::link('user','welcome'));
|
|
|
|
}
|
2014-10-28 05:33:15 +00:00
|
|
|
|
2014-10-28 05:56:56 +00:00
|
|
|
if ($this->request->post()) {
|
2014-10-28 05:33:15 +00:00
|
|
|
// Find a free name.
|
2015-09-29 13:27:44 +00:00
|
|
|
for ($i=1;$i<=$n->count();$i++)
|
2014-10-28 05:33:15 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|