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')
|
2012-12-10 22:55:44 +01:00
|
|
|
->addActionContext('edit-user', 'json')
|
2011-02-11 17:43:03 +01:00
|
|
|
->initContext();
|
2010-12-17 23:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2012-10-19 17:09:34 +02:00
|
|
|
$baseUrl = Application_Common_OsPath::getBaseDir();
|
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-10-27 00:09:30 +02:00
|
|
|
$params = $request->getPost();
|
|
|
|
$postData = explode('&', $params['data']);
|
|
|
|
foreach($postData as $k=>$v) {
|
|
|
|
$v = explode('=', $v);
|
|
|
|
$formData[$v[0]] = urldecode($v[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($form->isValid($formData)) {
|
2012-07-11 00:53:06 +02:00
|
|
|
|
2012-09-18 23:22:14 +02:00
|
|
|
if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1
|
2012-10-27 00:09:30 +02:00
|
|
|
&& $formData['login'] == 'admin'
|
|
|
|
&& $formData['user_id'] != 0) {
|
|
|
|
$this->view->form = $form;
|
2012-11-15 20:05:36 +01:00
|
|
|
$this->view->successMessage = "<div class='errors'>"._("Specific action is not allowed in demo version!")."</div>";
|
2012-10-27 00:09:30 +02:00
|
|
|
die(json_encode(array("valid"=>"false", "html"=>$this->view->render('user/add-user.phtml'))));
|
|
|
|
} elseif ($form->validateLogin($formData)) {
|
|
|
|
$user = new Application_Model_User($formData['user_id']);
|
2013-01-09 19:25:18 +01:00
|
|
|
if (empty($formData['user_id'])) {
|
|
|
|
$user->setLogin($formData['login']);
|
|
|
|
}
|
2012-10-27 00:09:30 +02:00
|
|
|
$user->setFirstName($formData['first_name']);
|
|
|
|
$user->setLastName($formData['last_name']);
|
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-10-27 00:09:30 +02:00
|
|
|
if ($formData['password'] != "xxxxxx") {
|
|
|
|
$user->setPassword($formData['password']);
|
2012-09-18 23:22:14 +02:00
|
|
|
}
|
2012-10-27 00:09:30 +02:00
|
|
|
$user->setType($formData['type']);
|
|
|
|
$user->setEmail($formData['email']);
|
|
|
|
$user->setCellPhone($formData['cell_phone']);
|
|
|
|
$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
|
|
|
|
2013-01-09 19:38:38 +01:00
|
|
|
// Language and timezone settings are saved on a per-user basis
|
|
|
|
// By default, the default language, and timezone setting on
|
|
|
|
// preferences page is what gets assigned.
|
2013-01-03 22:19:02 +01:00
|
|
|
Application_Model_Preference::SetUserLocale($user->getId());
|
2013-01-09 19:38:38 +01:00
|
|
|
Application_Model_Preference::SetUserTimezone($user->getId());
|
2013-01-03 22:19:02 +01:00
|
|
|
|
2011-02-11 17:43:03 +01:00
|
|
|
$form->reset();
|
2012-10-27 00:09:30 +02:00
|
|
|
$this->view->form = $form;
|
2011-03-25 03:29:14 +01:00
|
|
|
|
2012-10-27 00:09:30 +02:00
|
|
|
if (strlen($formData['user_id']) == 0) {
|
2012-11-15 20:05:36 +01:00
|
|
|
$this->view->successMessage = "<div class='success'>"._("User added successfully!")."</div>";
|
2011-03-25 03:29:14 +01:00
|
|
|
} else {
|
2012-11-15 20:05:36 +01:00
|
|
|
$this->view->successMessage = "<div class='success'>"._("User updated successfully!")."</div>";
|
2011-03-25 03:29:14 +01:00
|
|
|
}
|
2012-10-27 00:09:30 +02:00
|
|
|
|
|
|
|
die(json_encode(array("valid"=>"true", "html"=>$this->view->render('user/add-user.phtml'))));
|
2012-11-12 18:29:07 +01:00
|
|
|
} else {
|
|
|
|
$this->view->form = $form;
|
|
|
|
die(json_encode(array("valid"=>"false", "html"=>$this->view->render('user/add-user.phtml'))));
|
2011-02-11 17:43:03 +01:00
|
|
|
}
|
2012-10-27 00:09:30 +02:00
|
|
|
} else {
|
|
|
|
$this->view->form = $form;
|
|
|
|
die(json_encode(array("valid"=>"false", "html"=>$this->view->render('user/add-user.phtml'))));
|
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
|
|
|
}
|
2012-12-10 22:55:44 +01:00
|
|
|
|
|
|
|
public function editUserAction()
|
|
|
|
{
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$form = new Application_Form_EditUser();
|
|
|
|
if ($request->isPost()) {
|
2013-01-10 19:55:52 +01:00
|
|
|
$formData = $request->getPost();
|
2012-12-10 22:55:44 +01:00
|
|
|
|
|
|
|
if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1
|
|
|
|
&& $formData['cu_login'] == 'admin') {
|
|
|
|
$this->view->form = $form;
|
|
|
|
$this->view->successMessage = "<div class='errors'>"._("Specific action is not allowed in demo version!")."</div>";
|
|
|
|
die(json_encode(array("html"=>$this->view->render('user/edit-user.phtml'))));
|
|
|
|
} else if ($form->isValid($formData) &&
|
|
|
|
$form->validateLogin($formData['cu_login'], $formData['cu_user_id'])) {
|
|
|
|
$user = new Application_Model_User($formData['cu_user_id']);
|
|
|
|
$user->setFirstName($formData['cu_first_name']);
|
|
|
|
$user->setLastName($formData['cu_last_name']);
|
|
|
|
// We don't allow 6 x's as a password.
|
|
|
|
// The reason is because we use that as a password placeholder
|
|
|
|
// on the client side.
|
|
|
|
if ($formData['cu_password'] != "xxxxxx") {
|
|
|
|
$user->setPassword($formData['cu_password']);
|
|
|
|
}
|
|
|
|
$user->setEmail($formData['cu_email']);
|
|
|
|
$user->setCellPhone($formData['cu_cell_phone']);
|
|
|
|
$user->setSkype($formData['cu_skype']);
|
|
|
|
$user->setJabber($formData['cu_jabber']);
|
|
|
|
$user->save();
|
2013-01-10 19:55:52 +01:00
|
|
|
|
2013-01-10 20:01:03 +01:00
|
|
|
Application_Model_Preference::SetUserLocale($user->getId(), $formData['cu_locale']);
|
|
|
|
Application_Model_Preference::SetUserTimezone($user->getId(), $formData['cu_timezone']);
|
|
|
|
|
2013-01-10 19:55:52 +01:00
|
|
|
//configure localization with new locale setting
|
|
|
|
Application_Model_Locale::configureLocalization($formData['cu_locale']);
|
|
|
|
//reinitialize form so language gets translated
|
|
|
|
$form = new Application_Form_EditUser();
|
|
|
|
|
|
|
|
$this->view->successMessage = "<div class='success'>"._("Settings updated successfully!")."</div>";
|
2012-12-10 22:55:44 +01:00
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
2013-01-10 19:55:52 +01:00
|
|
|
$this->view->html = $this->view->render('user/edit-user.phtml');
|
2012-12-10 22:55:44 +01:00
|
|
|
}
|
|
|
|
$this->view->form = $form;
|
|
|
|
$this->view->html = $this->view->render('user/edit-user.phtml');
|
|
|
|
}
|
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-09-19 00:20:33 +02:00
|
|
|
Logging::info("Reassign to user {$new_owner->getDbId()}");
|
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
|
|
|
}
|