示例#1
0
 public function test(Request $request, Response $response, array $args)
 {
     $uid = $args['uid'];
     $myaccount = R::load('accounts', $uid);
     $accountId = $myaccount->accountid;
     $account = R::findOne('accounts', ' accountid = ?', [$accountId]);
     if (!empty($account)) {
         $apiKey = $account['apikey'];
         $type = $account['servertype'];
         $oandaInfo = new Broker_Oanda($type, $apiKey, $accountId);
     } else {
         $this->flash->addMessage('flash', "Oanda AccountId not found");
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('homepage'));
     }
     $side = 'buy';
     $pair = 'EUR_USD';
     $price = '1.1400';
     $expiry = time() + 60;
     $stopLoss = '1.1300';
     $takeProfit = NULL;
     $risk = 1;
     //        $side='buy';
     //        $pair='GBP_CHF';
     //        $price='2.1443';
     //        $expiry = $oandaInfo->getExpiry(time()+60);
     //        $stopLoss='2.1452';
     //        $takeProfit=NULL;
     //        $risk=1;
     //$oandaInfo->placeLimitOrder($side,$pair,$price,$expiry,$stopLoss,$takeProfit,$risk);
     $oandaInfo->processTransactions();
 }
示例#2
0
 public function notifyAction()
 {
     $id = 1;
     $settings = R::load('settings', $id);
     $time_before = c::now()->modify('+' . $settings->time_before)->toDateString();
     $transport = \Swift_SmtpTransport::newInstance($settings->mail_host, $settings->mail_port)->setUsername($settings->mail_username)->setPassword($settings->mail_password);
     $mailer = \Swift_Mailer::newInstance($transport);
     $client = new \Services_Twilio($settings->twilio_sid, $settings->twilio_token);
     $recepients = R::findAll('recepients');
     $events = R::find("events", "is_enabled = 1 AND date = '{$time_before}'");
     foreach ($events as $event) {
         foreach ($recepients as $recepient) {
             $subject = preg_replace(array('/{title}/', '/{date}/'), array($event->title, $event->date), $settings->subject);
             $end_date = c::parse($event->date)->modify('+' . $event->days . ' days')->toDateString();
             $body_patterns = array('/{name}/', '/{title}/', '/{start_date}/', '/<!(\\w+) ({\\w+})>/');
             $body_replacements = array($settings->name, $event->title, $event->date, "\$1 {$end_date}");
             if ($event->days == 1) {
                 $body_replacements[3] = '';
             }
             $body = preg_replace($body_patterns, $body_replacements, $settings->msg_template);
             if ($recepient->email && $settings->mail_username && $settings->mail_password) {
                 $message = \Swift_Message::newInstance()->setSubject($subject)->setBody($body)->setFrom(array($settings->email => $settings->name))->setTo(array($recepient->email => $recepient->name));
                 try {
                     $response = $mailer->send($message);
                 } catch (\Exception $e) {
                     //todo: log error
                 }
             } else {
                 if ($recepient->phone_number && $settings->twilio_sid && $settings->twilio_token && $settings->twilio_phonenumber) {
                     $message = $client->account->messages->sendMessage($settings->twilio_phonenumber, $recepient->phone_number, $body);
                 }
             }
         }
     }
 }
示例#3
0
 public function getItemCategoryById($id)
 {
     $category = R::load('itemcategory', $id);
     if (!$category->id) {
         throw new InvalidArgumentException('Invalid itemcategory id');
     }
     return $this->exportItemCategory($category);
 }
示例#4
0
 public function add_view()
 {
     $id = $this->slim->request->post()['id'];
     $item = R::load('ecatalog', $id);
     $item->view_count += 1;
     R::store($item);
     echo '555';
     exit;
 }
示例#5
0
 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     $identity = $this->authService->getIdentity();
     $user = R::load('user', $identity->id);
     if (!($school = $user->school)) {
         return false;
     }
     $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
     return null === $appForm;
 }
 public function __invoke($req, $res, $next)
 {
     $identity = $this->authService->getIdentity();
     if (!$identity) {
         return $res->withStatus(403, 'No identity');
     }
     $user = R::load('user', $identity->id);
     if (!($school = $user->school)) {
         return $res->withStatus(403, 'No school');
     }
     return $next($req->withAttribute('school', (object) array_merge($school->export(), ['eduadmin' => $school->eduadmin->name, 'regioneduadmin' => $school->eduadmin->regioneduadmin->name])), $res);
 }
示例#7
0
 public function __invoke(Request $req, Response $res, callable $next)
 {
     $res = $next($req, $res);
     $identity = $this->authService->getIdentity();
     if ($identity && $identity instanceof RoleAwareInterface) {
         $user = R::load('user', $identity->id);
         $role = $user && isset($user->role) ? $user->role : 'user';
         $validRoles = $this->acl->getRoles();
         $role = in_array($role, $validRoles) ? $role : 'user';
         $identity->setRole($role);
         $this->authService->getStorage()->write($identity);
     }
     return $res;
 }
示例#8
0
 public function edit(Request $request, Response $response, array $args)
 {
     $uid = $args['uid'];
     if (empty($uid)) {
         $this->flash->addMessage('flash', 'No record specified');
         return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts'));
     }
     $id = $this->authenticator->getIdentity();
     $user = R::load('users', $id['id']);
     if ($uid != 'new') {
         $account = R::load('accounts', $uid);
         if ($account->id == 0) {
             $this->flash->addMessage('flash', 'No record found');
             return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts'));
         }
         // restrict access to own profile or Admin role
         if ($account->users->id != $id['id']) {
             if (strtolower($id['role']) != 'admin') {
                 $this->flash->addMessage('flash', 'Access Denied');
                 return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('accounts'));
             }
         }
     } else {
         $account = R::dispense('accounts');
     }
     if ($request->isPost()) {
         $data = $request->getParams();
         $account->import($data, 'apikey,accountid,servertype');
         $account->users = $user;
         $account->lasttid = 0;
         $oandaInfo = FALSE;
         // verify and get account balance
         try {
             $oandaInfo = new Broker_Oanda($account['servertype'], $account['apikey'], $account['accountid'], 0);
         } catch (\Exception $e) {
             $viewData['flash'] = 'Account Details Invalid';
         }
         if ($oandaInfo != FALSE) {
             $aid = R::store($account);
             $oandaInfo->updateAccount();
             $this->flash->addMessage('flash', "account updated");
             return $response->withRedirect($request->getUri()->getBaseUrl() . $this->router->pathFor('editaccount', ['uid' => $aid]));
         }
     }
     $viewData['account'] = $account;
     $this->view->render($response, 'account.twig', $viewData);
     return $response;
 }
示例#9
0
文件: Page.php 项目: Koohiisan/Enpowi
 private function convertFromBean()
 {
     $bean = $this->_bean;
     if (!$this->exists()) {
         return;
     }
     $this->id = $bean->getID();
     $this->name = $bean->name;
     $this->content = $bean->content;
     $this->created = $bean->created;
     $this->user = new User(null, R::load('user', $bean->userId));
     $this->contributors = [];
     foreach ($bean->sharedUser as $contributor) {
         $this->contributors[] = new User(null, $contributor);
     }
 }
 public function testDB()
 {
     $app = new Application();
     $app->register(new RedBeanServiceProvider(), array('db.options' => array('dsn' => 'sqlite:' . __DIR__ . '/test.sqlite')));
     $app['db'];
     //db init
     $post = R::dispense('post');
     $post->text = 'Hello World';
     $id = R::store($post);
     //Create or Update
     $fetchedPost = R::load('post', $id);
     //Retrieve
     $this->assertSame($post->text, $fetchedPost->text);
     $this->assertTrue(file_exists(__DIR__ . '/test.sqlite'));
     unlink(__DIR__ . '/test.sqlite');
 }
示例#11
0
文件: Details.php 项目: kiswa/SMPLog
 public function getDetails($request, $response, $args)
 {
     $details = R::load('detail', 1);
     if (!$details->id) {
         $details->name = 'SMPLog';
         $details->description = 'A blog published by SMPLog.';
         $details->image = '';
         R::store($details);
     }
     if (empty($details->name)) {
         $details->name = 'SMPLog';
         R::store($details);
     }
     $this->apiJson->setSuccess();
     $this->apiJson->addData($details->export());
     return $this->jsonResponse($response);
 }
示例#12
0
 public function __invoke(Request $req, Response $res)
 {
     $identity = $this->authService->getIdentity();
     if (null === $identity) {
         return $res;
     }
     $user = R::load('user', $identity->id);
     if (!$user->school_id) {
         return $res;
     }
     $school_id = $user->school_id;
     $sync = $this->syncFromInventory;
     $result = $sync($school_id);
     if (false === $result) {
         return $res->withStatus(500);
     }
     return $res->withJson($result);
 }
示例#13
0
 public function updateRss()
 {
     $blog = R::load('blog', 1);
     $posts = R::find('post', ' is_published = 1 ORDER BY publish_date DESC ');
     $xml = $this->getChannelXml($blog);
     $count = 1;
     foreach ($posts as $post) {
         if ($count == 10) {
             break;
         }
         $xml .= $this->getItemXml($post);
         $count++;
     }
     $xml .= "\n\t</channel>" . "\n</rss>";
     try {
         file_put_contents('../rss/rss.xml', $xml);
     } catch (Exception $ex) {
     }
 }
示例#14
0
 public function __invoke(Request $req, Response $res, callable $next)
 {
     $res = $next($req, $res);
     $identity = $this->authService->getIdentity();
     if (null === $identity) {
         return $res;
     }
     $user = R::load('user', $identity->id);
     if (!$user->school_id) {
         return $res;
     }
     $school_id = $user->school_id;
     if (0 < count($this->labService->getLabsBySchoolId($school_id))) {
         return $res;
     }
     $sync = $this->syncFromInventory;
     $sync($school_id);
     return $res;
 }
示例#15
0
 public function load($id)
 {
     $this->loadBean(R::load($this->type, $id));
     return $this;
 }
示例#16
0
 /**
  * @param \RedBeanPHP\OODBBean $pair
  *
  * @return array
  */
 protected static function getPairCurrencies($pair)
 {
     $currencyFrom = RedBean::load('currency', $pair->currencyFrom_id);
     $currencyTo = RedBean::load('currency', $pair->currencyTo_id);
     return array($currencyFrom, $currencyTo);
 }
示例#17
0
        $file = R::load('attachment', $data->fileId);
        if ($file->id) {
            $filename = $file->name;
            $before = $item->export();
            unlink('uploads/' . $file->filename);
            R::trash($file);
            R::store($item);
            logAction($actor->username . ' removed attachment ' . $filename . ' from item ' . $item->title, $before, $item, $itemId);
            $jsonResponse->addAlert('success', $filename . ' was deleted.');
            $jsonResponse->addBeans($item);
        }
    }
    $app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\\d+']);
// Remove an item.
$app->post('/items/remove', function () use($app, $jsonResponse) {
    $data = json_decode($app->environment['slim.input']);
    if (validateToken(true)) {
        $item = R::load('item', $data->itemId);
        if ($item->id) {
            $before = $item->export();
            R::trash($item);
            renumberItems($item->lane_id, $item->position);
            $actor = getUser();
            logAction($actor->username . ' removed item ' . $item->title, $before, null, $data->itemId);
            $jsonResponse->addAlert('success', $item->title . ' was deleted.');
            $jsonResponse->addBeans(getBoards());
        }
    }
    $app->response->setBody($jsonResponse->asJson());
});
示例#18
0
 /**
  *
  * @param int $quizid            
  * @return Quiz
  */
 function getQuiz($quizid)
 {
     return R::load(QUIZ, $quizid);
 }
 /**
  *
  * @param Request $request            
  * @param Response $response            
  * @param unknown $args            
  */
 public function resultsdelete(Request $request, Response $response, $args)
 {
     $id = $args['id'];
     $record = R::load(USER, $id);
     if ($record) {
         R::trash($record);
     }
     return $response->withRedirect($this->router->pathFor('results'));
 }
示例#20
0
 private function setAdminToken($jwt)
 {
     $user = R::load('user', 1);
     $user->active_token = $jwt;
     R::store($user);
 }
示例#21
0
 /**
  * @RequestMapping(url="account/chapter/{chapter_id}/page/{page_id}",type=template,auth=true)
  * @RequestParams(true)
  * @Role(USER)
  * @Role(ADMIN)
  */
 function editPage($model, $chapter_id = null, $page_id = null, $title = null)
 {
     Service::DBSetup();
     $page = R::load("page", $page_id);
     $chapter = R::load("chapter", $page->chapter_id);
     $comic = R::load("comic", $chapter->comic_id);
     $model->assign("comic", $comic);
     $model->assign("chapter", $chapter);
     $model->assign("page", $page);
     return "member/page";
 }
示例#22
0
function runAutoActions(&$item)
{
    $lane = R::load('lane', $item->laneId);
    $board = R::load('board', $lane->boardId);
    foreach ($board->ownAutoaction as $action) {
        switch ($action->triggerId) {
            case 0:
                // Item moves to lane
                if ($item->laneId == $action->secondaryId) {
                    updateItemFromAction($item, $action);
                }
                break;
            case 1:
                // Item assigned to user
                if ($item->assignee == $action->secondaryId || $action->secondaryId == 0 && $item->assignee == null) {
                    updateItemFromAction($item, $action);
                }
                break;
            case 2:
                // Item assigned to category
                if ($item->category == $action->secondaryId || $action->secondaryId == 0 && $item->category == null) {
                    updateItemFromAction($item, $action);
                }
                break;
        }
    }
}
示例#23
0
文件: Auth.php 项目: kiswa/SMPLog
 private static function getJwtKey()
 {
     self::CreateJwtKey();
     $key = R::load('jwt', 1);
     return $key->secret;
 }
示例#24
0
 /**
  * @param int|string $id
  * @param null $contents
  * @return bool|RedBeanModel
  */
 public function update($id, $contents = null)
 {
     $this->instance = R::load($this->table, $id);
     return is_null($contents) ? $this : $this->with($contents);
 }
示例#25
0
 public function removeLabAttachment($lab_id)
 {
     $lab = R::load('lab', $lab_id);
     if (!$lab->id) {
         throw new InvalidArgumentException('No lab');
     }
     if (!$lab->attachment) {
         return;
     }
     if (is_writable($this->filesPath . '/' . $lab->attachment)) {
         unlink($this->filesPath . '/' . $lab->attachment);
     }
     $lab->attachment = null;
     $lab->attachment_mime = null;
     R::store($lab);
 }
示例#26
0
 public function __invoke(Request $req, Response $res, callable $next)
 {
     $res = $next($req, $res);
     $identity = $this->authService->getIdentity();
     if (!$identity) {
         return $res;
     }
     $registryNo = $this->findUnitRegitryNo($identity);
     if (null === $registryNo) {
         $this->logger->error(sprintf('Unit for user %s not found in LDAP', $identity->mail), $identity->toArray());
         return $this->logoutAndRediret($res, sprintf('Το σχολείο με email %s δεν βρέθηκε στο Κατάλογο του ΠΣΔ. <a href="%s" title="SSO logout">SSO Logout</a>', $identity->mail, $this->ssoLogoutUrl));
     }
     $school = R::findOne('school', 'registry_no = ?', [$registryNo]);
     try {
         if (!$school) {
             $unit = call_user_func($this->fetchUnit, $registryNo);
             if (null === $unit) {
                 $mmId = $this->findUnitMmId($identity);
                 $unit = call_user_func($this->fetchUnitFromMMById, $mmId);
             }
             if (null === $unit) {
                 $this->logger->error(sprintf('Unit with %s for user %s not found in MM', $identity->mail, $registryNo));
                 $this->logger->debug('Trace', ['registryNo' => $registryNo, 'mmId' => $mmId, 'identity' => $identity->toArray()]);
                 return $this->logoutAndRediret($res, sprintf('Το σχολείο με κωδικό %s δεν βρέθηκε στο Μητρώο Μονάδων του ΠΣΔ.  <a href="%s" title="SSO logout">SSO Logout</a>', $registryNo, $this->ssoLogoutUrl));
             }
             $data = ['id' => '', 'registry_no' => $registryNo, 'name' => $unit['name'], 'street_address' => $unit['street_address'], 'postal_code' => $unit['postal_code'], 'phone_number' => $unit['phone_number'], 'fax_number' => $unit['fax_number'], 'email' => $identity->mail, 'municipality' => $unit['municipality'], 'schooltype_id' => $unit['unit_type_id'], 'prefecture_id' => $unit['prefecture_id'], 'educationlevel_id' => $unit['education_level_id'], 'eduadmin_id' => $unit['edu_admin_id'], 'creator' => $identity->mail];
             $filtered = call_user_func($this->schoolInputFilter, $data);
             if (!$filtered['is_valid']) {
                 $this->logger->error('Invalid data', $filtered);
                 throw new Exception('Invalid data');
             }
             $school = $this->schoolService->createSchool($filtered['values']);
             $this->logger->info(sprintf('School %s imported from MM to database', $registryNo), $filtered['values']);
         }
         $user = R::load('user', $identity->id);
         $user->school_id = $school['id'];
         R::store($user);
         $this->logger->info(sprintf('Set school %s to user %s', $registryNo, $identity->mail));
     } catch (Exception $e) {
         $this->logger->error(sprintf('Problem inserting school %s form MM in database', $registryNo));
         $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
         return $this->logoutAndRediret($res, sprintf('A problem occured fetching school data. <a href="%s" title="SSO logout">SSO Logout</a>', $this->ssoLogoutUrl));
     }
     return $res;
 }
示例#27
0
 public function getTeacherById($id)
 {
     $teacher = R::load('teacher', $id);
     return $this->export($teacher);
 }
示例#28
0
 public static function load($id)
 {
     $model = new static();
     $model->_bean = R::load($model->_table, $id);
     return $model;
 }
示例#29
0
            R::trash($collapsed);
            $jsonResponse->message = 'Expanded lane ' . $lane->name;
        } else {
            $collapsed = R::dispense('collapsed');
            $collapsed->userId = $user->id;
            $collapsed->laneId = $laneId;
            R::store($collapsed);
            $jsonResponse->message = 'Collapsed lane ' . $lane->name;
        }
        $jsonResponse->addBeans(getBoards());
    }
    $app->response->setBody($jsonResponse->asJson());
})->conditions(['laneId' => '\\d+']);
// Numbers only.
$app->post('/boards/:boardId/toggleActive', function ($boardId) use($app, $jsonResponse) {
    if (validateToken()) {
        $user = getUser();
        if ($user->isAdmin) {
            $board = R::load('board', $boardId);
            $before = $board->export();
            $board->active = !$board->active;
            R::store($board);
            $state = $board->active ? 'active' : 'inactive';
            $jsonResponse->message = 'Set board ' . $board->name . ' ' . $state;
            $jsonResponse->addBeans(getBoards());
            logAction($user->username . ' changed active status of board ' . $board->name, $before, $board->export());
        }
    }
    $app->response->setBody($jsonResponse->asJson());
})->conditions(['boardId' => '\\d+']);
// Numbers only.
示例#30
-1
 public function editRota(Request $request, Response $response, array $args)
 {
     $id = $this->authenticator->getIdentity();
     if (strtolower($id['name']) != 'admin') {
         $this->flash->addMessage('flash', 'Access Denied');
         return $response->withRedirect($this->router->pathFor('homepage'));
     }
     $name = $args['name'];
     if (empty($name)) {
         $this->flash->addMessage('flash', 'No rota specified');
         return $response->withRedirect($this->router->pathFor('rotas'));
     }
     if ($name != 'new') {
         $rota = R::findOrCreate('rotas', ['name' => $name]);
     } else {
         $rota = R::dispense('rotas');
     }
     if ($request->isPost()) {
         $data = $request->getParams();
         //$username = $request->getParam('username');
         $rota->import($data, 'name,fullname,title,comment');
         $rota->sharedUsersList = [];
         foreach ($data['users'] as $checkUserID) {
             $rotaUser = R::load('users', $checkUserID);
             $rota->sharedUsersList[] = $rotaUser;
         }
         $id = R::store($rota);
         try {
             $fieldtest = R::inspect($rota->name);
         } catch (\Exception $e) {
             //thaw for creation
             R::freeze(['users']);
             $rotaUser = R::load('users', 1);
             $rotaDay = R::findOrCreate($rota->name, ['day' => 29, 'month' => 2, 'year' => 2015]);
             $rotaUser = R::load('users', 1);
             $rotaDay->name = $rotaUser;
             $rotaDay->who = $rotaUser;
             $rotaDay->stamp = date("Y-m-d H:i:s");
             R::store($rotaDay);
             R::freeze(true);
         }
         $this->flash->addMessage('flash', "{$rota->name} updated");
         return $response->withRedirect($this->router->pathFor('rotas'));
     }
     $userList = R::findAll('users');
     $data = $rota->export();
     $data['userList'] = $userList;
     $users = [];
     $userRota = $rota->sharedUsersList;
     foreach ($userRota as $userCheck) {
         $users[$userCheck->id] = 'checked';
     }
     $data['userCheck'] = $users;
     $this->view->render($response, 'rota.twig', $data);
     return $response;
 }