/** * Get list of messages */ public static function getPage($page = 0) { $app = \Slim\Slim::getInstance(); $dao = new MessageDAO(); $userDAO = new UserDAO(); $users = $userDAO->getList(); $groupDAO = new GroupDAO(); $groupsQuery = array(); $senderDAO = new SenderDAO(); $sendersQuery = array(); if (!$userDAO->hasRole('ADMIN')) { $strong = \Strong\Strong::getInstance(); $user = $strong->getUser(); $groupsQuery['user_id'] = $user['id']; $sendersQuery['user_id'] = $user['id']; } $groups = $groupDAO->getList($groupsQuery); if (0 == $groups['total']) { return $app->redirect(MAINURL . '/groups'); } $senders = $senderDAO->getList($sendersQuery); if (0 == $senders['total']) { return $app->redirect(MAINURL . '/senders'); } $app->expires(time()); $query = $_GET; if (!$userDAO->hasRole('ADMIN')) { $strong = \Strong\Strong::getInstance(); $user = $strong->getUser(); $query['user_id'] = $user['id']; } $pager = new Pager(MAINURL . '/messages/', 25); $pager->setPage($page); $query = $pager->getQueryArray($query); $list = $dao->getList($query); $pager->setCount(count($list['list'])); if (isset($list['total'])) { $pager->setTotal($list['total']); } foreach ($list['list'] as $k => $v) { $list['list'][$k]->dataHuman = self::getHumanUrl($v); } $app->view->set('menu', 'messages'); $app->view->set('result', $list); $app->view->set('pager', $pager); $app->view->set('groups', $groups); $app->view->set('senders', $senders); $app->view->set('users', $users); $app->render('messages/list.twig.html'); }
/** * Process edit group form, validate, save to DB * * @param unknown $id * @return boolean */ public static function postEditPage($id) { $app = \Slim\Slim::getInstance(); $dao = new GroupDAO(); $userDAO = new UserDAO(); $item = $dao->fetch($id); if (empty($item)) { return $app->notFound(); } $item->setNickname($_POST['nickname']); if ($userDAO->hasRole('ADMIN')) { $item->setUserId($_POST['user_id']); } else { if (empty($id)) { $strong = \Strong\Strong::getInstance(); $user = $strong->getUser(); $item->setUserId($user['id']); } } $validator = new \Valitron\Validator($_POST); $validator->rule('required', 'nickname'); if ($validator->validate()) { $item = $dao->save($item); if (empty($id)) { $app->flash('info', 'Group ' . $item->getNickname() . ' has been created successfully'); } if (!empty($_POST['force_sync'])) { self::forceSync(); } $app->redirect(MAINURL . '/groups/edit/' . $item->getId()); } else { $app->view->set('menu', 'groups'); $app->view->set('id', $id); $app->view->set('users', $userDAO->getList()); $app->view->set('item', $item); $app->view->set('numbers', $dao->getNumbers($item->getId())); $app->view->set('errors', $validator->errors()); $app->render('groups/edit.twig.html'); } }
/** * Process user edit form * * @param number $id * @return boolean */ public static function postEditPage($id) { $app = \Slim\Slim::getInstance(); $dao = new UserDAO(); if (!$dao->hasRole('ADMIN')) { return $app->status(403); } $item = $dao->fetch($id); if (empty($item)) { return $app->notFound(); } $item->setUsername($_POST['username']); if ($_POST['credits'] > 0) { $item->setCredits($_POST['credits']); } if (is_array($_POST['roles'])) { $item->setRoles(implode(',', $_POST['roles'])); } else { $item->setRoles(''); } $item->setUsername($_POST['username']); if (!empty($_POST['password'])) { $item->setPassword(md5($_POST['password'])); } $validator = new \Valitron\Validator($_POST); $validator->addRule('repeat', function ($name, $value) { if ($value != $_POST['password']) { return false; } return true; }); $validator->addRule('unique_username', function ($name, $value) use($id, $dao) { $list = $dao->getList(array('username' => $value)); if (!empty($list['list'])) { foreach ($list['list'] as $item) { if ($item->getId() != $id) { return false; } } } return true; }, 'is not unique'); $validator->rule('unique_username', 'username'); $validator->rule('repeat', 'repeat'); $validator->label('Password repeat'); if (empty($id)) { $validator->rule('required', 'password'); } $validator->rule('required', 'username'); $validator->label('Login'); if ($validator->validate()) { $item = $dao->save($item); if (empty($id)) { $app->flash('info', 'Account ' . $item->getUsername() . ' has been created successfully'); } $app->redirect(MAINURL . '/users/edit/' . $item->getId()); } else { $app->view->set('menu', 'users'); $app->view->set('id', $id); $app->view->set('item', $item); $app->view->set('errors', $validator->errors()); $app->render('users/edit.twig.html'); } }
/** * Process edit sender form, validate, save to DB * * @param unknown $id * @return boolean */ public static function postEditPage($id) { $app = \Slim\Slim::getInstance(); $dao = new SenderDAO(); $userDAO = new UserDAO(); $item = $dao->fetch($id); if (empty($item)) { return $app->notFound(); } $_POST['username'] = preg_replace('![^0-9]*!', '', $_POST['username']); $item->setNickname($_POST['nickname']); if (empty($id)) { $item->setUsername($_POST['username']); } if ($userDAO->hasRole('ADMIN')) { $item->setUserId($_POST['user_id']); } else { if (empty($id)) { $strong = \Strong\Strong::getInstance(); $user = $strong->getUser(); $item->setUserId($user['id']); } } $validator = new \Valitron\Validator($_POST); $validator->addRule('unique_username', function ($name, $value) use($id, $dao) { $list = $dao->getList(array('username' => $value)); if (!empty($list['list'])) { foreach ($list['list'] as $item) { if ($item->getId() != $id) { return false; } } } return true; }, 'is not unique'); $validator->rule('unique_username', 'username'); $validator->rule('required', 'nickname'); $validator->rule('required', 'username'); $validator->label('MSISDN'); if ($validator->validate()) { $item = $dao->save($item); $app->flash('info', 'Sender ' . $item->getNickname() . ' has been created successfully'); $app->redirect(MAINURL . '/senders/edit/' . $item->getId()); } else { $app->view->set('menu', 'senders'); $app->view->set('id', $id); $app->view->set('users', $userDAO->getList()); $app->view->set('item', $item); $app->view->set('errors', $validator->errors()); $app->render('senders/edit.twig.html'); } }