示例#1
0
 public function __construct()
 {
     parent::__construct();
     $this->auth = \Strong\Strong::getInstance();
     if ($this->auth->loggedIn()) {
         $this->user = $this->auth->getUser();
     }
 }
示例#2
0
 public function __construct()
 {
     $this->app = \App::getInstance();
     // for control auth author user
     $this->auth = \Strong\Strong::getInstance();
     if ($this->auth->loggedIn()) {
         $this->user = $this->auth->getUser();
     }
     $this->template_header = "<div>\n\t\t<div>DEPO FARMASI RUMAH SAKIT MATA MASYARAKAT</div>\n\t\t<div>JAWA TIMUR</div>\n\t\t<div>JL. GAYUNG KEBONSARI TIMUR 49</div>\n\t\t<div>SURABAYA</div>\n\t\t</div>";
 }
示例#3
0
 /**
  * Logout user and redirects to Main Page
  */
 public static function getLogoutPage()
 {
     $strong = \Strong\Strong::getInstance();
     $strong->logout(true);
     $app = \Slim\Slim::getInstance();
     if (MAINURL != '') {
         $app->redirect(MAINURL);
     } else {
         $app->redirect('/');
     }
 }
示例#4
0
 /**
  * HTTPAuth based authentication
  *
  * This method will check the HTTP request headers for previous authentication. If
  * the request has already authenticated, the next middleware is called. Otherwise,
  * a 401 Authentication Required response is returned to the client.
  *
  * @param \Strong\Strong $auth
  * @param object $req
  */
 private function httpAuth($auth, $req)
 {
     $res = $this->app->response();
     $authUser = $req->headers('PHP_AUTH_USER');
     $authPass = $req->headers('PHP_AUTH_PW');
     if ($authUser && $authPass && $auth->login($authUser, $authPass)) {
         $this->next->call();
     } else {
         $res->status(401);
         $res->header('WWW-Authenticate', sprintf('Basic realm="%s"', $this->config['realm']));
     }
 }
示例#5
0
 public function call()
 {
     $app = $this->app;
     if ($app->view instanceof \Slim\Views\Twig) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
         $userDAO = new \GitGis\Whatsapp\Model\UserDAO();
         $user = $userDAO->fetch($user['id']);
         $app->view->set('user', $user);
         $twig = $app->view->getInstance();
         $twig->addFunction(new \Twig_SimpleFunction('hasRole', function ($role) use($user) {
             return in_array($role, explode(',', $user->getRoles()));
         }));
     }
     $this->next->call();
 }
示例#6
0
 /**
  * Get user edit form
  * 
  * @param number $id
  */
 public static function getEditPage($id)
 {
     $app = \Slim\Slim::getInstance();
     $dao = new UserDAO();
     if (!$dao->hasRole('ADMIN')) {
         return $app->status(403);
     }
     $app->expires(time());
     $item = $dao->fetch($id);
     if (empty($item)) {
         return $app->notFound();
     }
     $app->view->set('menu', 'users');
     $app->view->set('id', $id);
     $app->view->set('item', $item);
     $strong = \Strong\Strong::getInstance();
     $user = $strong->getUser();
     $app->view->set('user', $user);
     $app->render('users/edit.twig.html');
 }
示例#7
0
 /**
  * Get list of messages
  */
 public static function getPage($page = 0)
 {
     $app = \Slim\Slim::getInstance();
     $app->expires(time());
     $userDAO = new UserDAO();
     $groupDAO = new GroupDAO();
     $groupsQuery = array();
     if (!$userDAO->hasRole('ADMIN')) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
         $groupsQuery['user_id'] = $user['id'];
     }
     $groups = $groupDAO->getList($groupsQuery);
     if (0 == $groups['total']) {
         return $app->redirect(MAINURL . '/groups');
     }
     $chatDAO = new ChatDAO();
     $query = $_GET;
     $query['from'] = preg_replace('![^0-9]*!', '', $query['search']);
     if (!$userDAO->hasRole('ADMIN')) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
         $query['user_id'] = $user['id'];
     }
     $pager = new Pager(MAINURL . '/inbox/', 25);
     $pager->setPage($page);
     $query = $pager->getQueryArray($query);
     $list = $chatDAO->getList($query);
     $pager->setCount(count($list['list']));
     if (isset($list['total'])) {
         $pager->setTotal($list['total']);
     }
     $app->view->set('menu', 'inbox');
     $app->view->set('query', $query);
     $app->view->set('result', $list);
     $app->view->set('pager', $pager);
     $app->render('inbox/list.twig.html');
 }
示例#8
0
 public static function forceSync()
 {
     $senderDAO = new SenderDAO();
     $strong = \Strong\Strong::getInstance();
     $user = $strong->getUser();
     $sendersQuery = array();
     $sendersQuery['user_id'] = $user['id'];
     $senders = $senderDAO->getList($sendersQuery);
     foreach ($senders['list'] as $sender) {
         $sender = $senderDAO->fetch($sender->getId());
         if (empty($sender)) {
             continue;
         }
         $flags = $sender->getFlags();
         $flags |= Sender::FLAG_UNSYNC;
         $sender->setFlags($flags);
         $senderDAO->save($sender);
     }
 }
示例#9
0
 public static function getInboxPage($page = 0)
 {
     $app = \Slim\Slim::getInstance();
     $limit = 25;
     if ($_GET['format'] == 'csv') {
         $page = 0;
         $limit = 10000;
     }
     $userDAO = new UserDAO();
     $chatDAO = new ChatDAO();
     $formUtils = new FormUtils();
     $startTime = $formUtils->toTimestamp($_GET['start_date'] . ' 00:00');
     $endTime = $formUtils->toTimestamp($_GET['end_date'] . ' 23:59');
     if ($endTime <= 0) {
         $endTime = time();
     }
     if ($startTime <= 0) {
         $startTime = $endTime - 7 * 24 * 3600;
     }
     $app->view->set('start_date', $startTime);
     $app->view->set('end_date', $endTime);
     $query = $_GET;
     $query['start_date'] = $startTime;
     $query['end_date'] = $endTime;
     if (!$userDAO->hasRole('ADMIN')) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
         $query['user_id'] = $user['id'];
     }
     $pager = new Pager(MAINURL . '/reports/inbox/?' . http_build_query($_GET), $limit);
     $pager->setPage($page);
     $query = $pager->getQueryArray($query);
     $list = $chatDAO->getList($query);
     $pager->setCount(count($list['list']));
     if (isset($list['total'])) {
         $pager->setTotal($list['total']);
     }
     $reportTable = array();
     foreach ($list['list'] as $message) {
         $reportTable[] = $message;
     }
     $app->view->set('menu', 'reports');
     $app->view->set('reportTable', array_values($reportTable));
     $app->view->set('query', $query);
     $app->view->set('pager', $pager);
     if ($_GET['format'] == 'csv') {
         header("Content-type: text/csv");
         header("Content-disposition: attachment; filename=inbox.csv");
         $app->render('reports/inbox.twig.csv');
     } else {
         $app->render('reports/inbox.twig.html');
     }
 }
示例#10
0
 public function testGetProvider()
 {
     $strong = Strong::factory(array('provider' => 'mock'));
     $this->assertInstanceOf('\\Strong\\Provider\\Mock', $strong->getProvider());
 }
示例#11
0
 /**
  * Creates video message and redirects to edit
  */
 public static function getSendVideo()
 {
     $app = \Slim\Slim::getInstance();
     $dao = new MessageDAO();
     $item = new Message();
     $item->setKind(Message::KIND_VIDEO_MSG);
     $item->setCtime(time());
     $strong = \Strong\Strong::getInstance();
     $user = $strong->getUser();
     $item->setUserId($user['id']);
     $item = $dao->save($item);
     $app->redirect(MAINURL . '/messages/edit/' . $item->getId());
 }
示例#12
0
 public function __construct(array $config = array(), \Strong\Strong $strong = null)
 {
     $this->config = array_merge($this->settings, $config);
     $this->auth = !empty($strong) ? $strong : \Strong\Strong::factory($this->config);
 }
示例#13
0
 public function html_render($template)
 {
     if ($len = strpos(strrev($template), '.')) {
         $template = substr($template, 0, -($len + 1));
     }
     $auth = null;
     $this->auth = \Strong\Strong::getInstance();
     if ($this->auth->loggedIn()) {
         $auth = $this->auth->getUser();
     }
     $condition = array('conditions' => "aktif = TRUE", 'limit' => 1, 'offset' => 0, 'order' => 'id DESC');
     $version = \Version::first($condition);
     if (!is_null($version) && !empty($version)) {
         $version = sprintf("version - %d.%d.%s", $version->major, $version->minor, $version->patch);
     }
     $uri = explode("/", substr($this->request()->getResourceUri(), 1));
     $var_append = array('baseurl' => BASEURL, 'asset' => ASSET, 'bread' => $uri, 'auth' => $auth, 'version' => $version);
     $this->view->appendData($var_append);
 }
示例#14
0
 public function hasRole($role, User $user = null)
 {
     if (empty($user)) {
         $strong = \Strong\Strong::getInstance();
         $user = $strong->getUser();
     }
     if (is_array($user)) {
         $user = $this->fetch($user['id']);
     }
     return in_array($role, explode(',', $user->getRoles()));
 }
示例#15
0
 /**
  * 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');
     }
 }