2010-12-17 23:56:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class UserController extends Zend_Controller_Action
|
|
|
|
{
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2011-02-08 01:03:14 +01:00
|
|
|
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
2011-02-11 17:43:03 +01:00
|
|
|
$ajaxContext->addActionContext('get-hosts', 'json')
|
|
|
|
->addActionContext('get-user-data-table-info', 'json')
|
|
|
|
->addActionContext('get-user-data', 'json')
|
|
|
|
->addActionContext('remove-user', 'json')
|
|
|
|
->initContext();
|
2010-12-17 23:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addUserAction()
|
2011-02-08 01:03:14 +01:00
|
|
|
{
|
2012-01-25 20:12:19 +01:00
|
|
|
global $CC_CONFIG;
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2011-02-11 17:43:03 +01:00
|
|
|
$request = $this->getRequest();
|
2011-04-18 17:02:09 +02:00
|
|
|
$baseUrl = $request->getBaseUrl();
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2012-08-30 22:00:14 +02:00
|
|
|
$js_files = array(
|
|
|
|
'/js/datatables/js/jquery.dataTables.js?',
|
|
|
|
'/js/datatables/plugin/dataTables.pluginAPI.js?',
|
|
|
|
'/js/airtime/user/user.js?'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($js_files as $js) {
|
|
|
|
$this->view->headScript()->appendFile(
|
|
|
|
$baseUrl.$js.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
}
|
2012-05-18 16:00:36 +02:00
|
|
|
|
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/users.css?'.$CC_CONFIG['airtime_version']);
|
2011-04-18 17:02:09 +02:00
|
|
|
|
2011-02-11 17:43:03 +01:00
|
|
|
$form = new Application_Form_AddUser();
|
2011-03-25 03:29:14 +01:00
|
|
|
|
|
|
|
$this->view->successMessage = "";
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2011-02-11 17:43:03 +01:00
|
|
|
if ($request->isPost()) {
|
2012-07-11 00:53:06 +02:00
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
|
|
|
|
$formdata = $form->getValues();
|
2012-09-18 23:22:14 +02:00
|
|
|
if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1
|
|
|
|
&& $formdata['login'] == 'admin'
|
|
|
|
&& $formdata['user_id'] != 0) {
|
2012-01-25 20:12:19 +01:00
|
|
|
$this->view->successMessage = "<div class='errors'>Specific action is not allowed in demo version!</div>";
|
2012-07-16 03:17:13 +02:00
|
|
|
} elseif ($form->validateLogin($formdata)) {
|
2011-09-23 23:00:55 +02:00
|
|
|
$user = new Application_Model_User($formdata['user_id']);
|
2011-02-11 17:43:03 +01:00
|
|
|
$user->setFirstName($formdata['first_name']);
|
|
|
|
$user->setLastName($formdata['last_name']);
|
|
|
|
$user->setLogin($formdata['login']);
|
2012-09-18 23:22:14 +02:00
|
|
|
// We don't allow 6 x's as a password.
|
2012-08-30 18:26:36 +02:00
|
|
|
// The reason is because we that as a password placeholder
|
|
|
|
// on the client side.
|
2012-09-18 23:22:14 +02:00
|
|
|
if ($formdata['password'] != "xxxxxx") {
|
2011-02-11 17:43:03 +01:00
|
|
|
$user->setPassword($formdata['password']);
|
2012-09-18 23:22:14 +02:00
|
|
|
}
|
2011-02-11 17:43:03 +01:00
|
|
|
$user->setType($formdata['type']);
|
2011-02-12 00:13:26 +01:00
|
|
|
$user->setEmail($formdata['email']);
|
2012-06-13 19:39:54 +02:00
|
|
|
$user->setCellPhone($formdata['cell_phone']);
|
2011-02-12 00:13:26 +01:00
|
|
|
$user->setSkype($formdata['skype']);
|
|
|
|
$user->setJabber($formdata['jabber']);
|
2011-02-11 17:43:03 +01:00
|
|
|
$user->save();
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2011-02-11 17:43:03 +01:00
|
|
|
$form->reset();
|
2011-03-25 03:29:14 +01:00
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
if (strlen($formdata['user_id']) == 0) {
|
2011-03-25 03:29:14 +01:00
|
|
|
$this->view->successMessage = "<div class='success'>User added successfully!</div>";
|
|
|
|
} else {
|
|
|
|
$this->view->successMessage = "<div class='success'>User updated successfully!</div>";
|
|
|
|
}
|
2011-02-11 17:43:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2011-02-11 17:43:03 +01:00
|
|
|
$this->view->form = $form;
|
2010-12-17 23:56:01 +01:00
|
|
|
}
|
|
|
|
|
2011-01-25 00:44:28 +01:00
|
|
|
public function getHostsAction()
|
|
|
|
{
|
2012-08-23 20:44:14 +02:00
|
|
|
$search = $this->_getParam('term');
|
|
|
|
$res = Application_Model_User::getHosts($search);
|
2011-09-23 23:00:55 +02:00
|
|
|
$this->view->hosts = Application_Model_User::getHosts($search);
|
2011-01-26 05:14:35 +01:00
|
|
|
}
|
2011-01-25 00:44:28 +01:00
|
|
|
|
2011-02-08 01:03:14 +01:00
|
|
|
public function getUserDataTableInfoAction()
|
|
|
|
{
|
|
|
|
$post = $this->getRequest()->getPost();
|
2011-09-23 23:00:55 +02:00
|
|
|
$users = Application_Model_User::getUsersDataTablesInfo($post);
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2011-02-11 17:43:03 +01:00
|
|
|
die(json_encode($users));
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getUserDataAction()
|
|
|
|
{
|
|
|
|
$id = $this->_getParam('id');
|
2011-09-23 23:00:55 +02:00
|
|
|
$this->view->entries = Application_Model_User::GetUserData($id);
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function removeUserAction()
|
|
|
|
{
|
|
|
|
// action body
|
2011-05-17 04:37:54 +02:00
|
|
|
$delId = $this->_getParam('id');
|
2012-08-30 21:23:12 +02:00
|
|
|
$valid_actions = array("delete_cascade", "reassign_to");
|
|
|
|
$files_action = $this->_getParam('deleted_files');
|
|
|
|
|
|
|
|
# TODO : remove this. we only use default for now not to break the UI.
|
|
|
|
if (!$files_action) { # set default action
|
2012-09-14 20:51:50 +02:00
|
|
|
$files_action = "reassign_to";
|
2012-09-18 21:26:43 +02:00
|
|
|
$new_owner = Application_Model_User::getFirstAdmin();
|
2012-08-30 21:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# only delete when valid action is selected for the owned files
|
|
|
|
if (! in_array($files_action, $valid_actions) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-17 04:37:54 +02:00
|
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
|
|
|
$userId = $userInfo->id;
|
|
|
|
|
2012-08-30 21:23:12 +02:00
|
|
|
# Don't let users delete themselves
|
|
|
|
if ($delId == $userId) {
|
|
|
|
return;
|
2011-05-17 04:37:54 +02:00
|
|
|
}
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2012-08-30 21:23:12 +02:00
|
|
|
$user = new Application_Model_User($delId);
|
2011-02-09 19:03:46 +01:00
|
|
|
|
2012-08-30 21:23:12 +02:00
|
|
|
# Take care of the user's files by either assigning them to somebody
|
|
|
|
# or deleting them all
|
|
|
|
if ($files_action == "delete_cascade") {
|
|
|
|
$user->deleteAllFiles();
|
|
|
|
} elseif ($files_action == "reassign_to") {
|
2012-09-18 21:26:43 +02:00
|
|
|
// TODO : fix code to actually use the line below and pick a
|
|
|
|
// real owner instead of defaulting to the first found admin
|
|
|
|
//$new_owner_id = $this->_getParam("new_owner");
|
|
|
|
//$new_owner = new Application_Model_User($new_owner_id);
|
|
|
|
$user->donateFilesTo( $new_owner );
|
2012-08-30 21:23:12 +02:00
|
|
|
}
|
|
|
|
# Finally delete the user
|
|
|
|
$this->view->entries = $user->delete();
|
|
|
|
}
|
2010-12-17 23:56:01 +01:00
|
|
|
}
|