Пример #1
0
 function nav_save()
 {
     G2_User::init();
     if (G()->logged_in() && !empty($_POST)) {
         if (!empty($_POST['items']) && !empty($_POST['identity'])) {
             // Delete all current navigation details
             $navitems = R::findAll('navitem', 'identity=:id', ['id' => $_POST['identity']]);
             R::trashAll($navitems);
             foreach ($_POST['items'] as $new_item) {
                 $nav = R::dispense('navitem');
                 $nav->identity = $_POST['identity'];
                 $nav->label = $new_item['label'];
                 $nav->href = !$new_item['href'] ? null : $new_item['href'];
                 $nav->order = $new_item['order'];
                 //@todo parent node support
                 R::store($nav);
             }
             echo json_encode(['success' => true, 'message' => 'Content Saved Successfully']);
         } else {
             echo json_encode(['success' => false, 'message' => 'Data sent not correct']);
         }
     } else {
         echo json_encode(['success' => false, 'message' => 'Not Logged in']);
     }
     die;
 }
Пример #2
0
 /**
  * Make a confirmation code and store it in the database
  *
  * @param object	$context The context bean
  * @param object	$bn	 A User bean
  * @param string	$kind
  *
  * @return string
  */
 private function makecode($context, $bn, $kind)
 {
     R::trashAll(R::find('confirm', 'user_id=?', array($bn->getID())));
     $code = hash('sha256', $bn->getID . $bn->email . $bn->login . uniqid());
     $conf = R::dispense('confirm');
     $conf->code = $code;
     $conf->issued = $context->utcnow();
     $conf->kind = $kind;
     $conf->user = $bn;
     R::store($conf);
     return $code;
 }
Пример #3
0
 function get_areas($html)
 {
     //Load the html into a dom document
     //		$dom = new DOMDocument("4.0", 'UTF-8');
     //		$dom->loadHTML($html);
     $dom = HtmlPageCrawler::create($html);
     //Look for html nodes that has the mvc:edit attribute
     //		$nodes = $this->find_editable($dom);
     $nodes = $dom->filter('[mvc-edit]');
     $instance =& $this;
     $area_beans = $nodes->each(function ($node) use($nodes_c, $instance) {
         $field_name = $node->getAttribute('mvc-edit');
         /* @var $node HtmlPageCrawler */
         $field_type = $node->getAttribute('mvc-type');
         $starting_html = $node->saveHTML();
         return $instance->load_area($instance->page->id, $field_name, $field_type, $starting_html);
     });
     // Delete all areas that are not relevant but connected to this page
     $areas = R::findAll('area', 'page_id = :page', ['page' => $this->page->id]);
     $not_loaded = [];
     foreach ($areas as $area) {
         $bid = $area->id;
         foreach ($area_beans as $area_b) {
             if ($area_b->id == $bid) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $not_loaded[] = $area;
         }
     }
     R::trashAll($not_loaded);
     // Convert these nodes to area beens
     //		$area_beans = $this->nodes_to_beans($nodes);
     return $area_beans;
 }
 /**
  * Authenticate 
  *
  * @param   string  $username   The HTTP Authentication username
  * @param   string  $password   The HTTP Authentication password     
  *
  */
 public function authenticate($username, $password)
 {
     if (!ctype_alnum($username)) {
         return false;
     }
     if (isset($username) && isset($password)) {
         $user = R::findOne('users', 'login="******" AND password="******"');
         if ($user) {
             /*
              * Deleting all beans older then 5mn
              */
             $date2 = time() - 60;
             $date = date('Y-m-d h:i:s', $date2);
             $beans = R::findAll('log', 'date<"' . $date . '"');
             R::trashAll($beans);
             /*
              * checking if the users can do more requests
              */
             $number = R::count('log', 'user_id= ?', [$user->id]);
             if ($number > 250) {
                 return false;
             } else {
                 /*
                  * saving the logs in the database
                  */
                 $log = R::dispense('log');
                 $log->date = date('Y-m-d h:i:s');
                 $log->user = $user;
                 R::store($log);
                 return true;
             }
         }
     } else {
         return false;
     }
 }
Пример #5
0
 function delete($f3)
 {
     if (!($user = \R::findOne('users', 'username=?', array(strtolower($f3->get('POST.username')))))) {
         throw new \Exception('Could not find user');
     }
     if (!($tool = \R::findOne('tools', 'name=?', array(strtolower($f3->get('POST.tool')))))) {
         throw new \Exception('Could not find tool');
     }
     if (!($records = \R::find('trainings', 'users_id=? AND tools_id=? AND level=?', array($user->id, $tool->id, strtoupper($f3->get('POST.level')))))) {
         throw new \Exception('Could not any training records for this user on this tool at this level.');
     }
     \R::trashAll($records);
     $f3->set('messages', array('All Records of User ' . $user->username . ' on Tool ' . $tool->name . ' at Level ' . strtoupper($f3->get('POST.level')) . ' deleted.'));
     show_page($f3, 'messages');
 }
<?php

ini_set('display_errors', 'ON');
require_once '../autoload.php';
date_default_timezone_set('GMT');
// -- get requested url --
$currentEnv = realpath('.currentEnv') ? file_get_contents('.currentEnv') : 'production';
$baseUrl = $currentEnv == 'production' ? '/btcapi/' : '/';
$baseDir = __DIR__;
define("APPLICATION_BASE", $baseUrl);
define("APPLICATION_DIR", $baseDir);
$objEventsModel = new models\Events();
$timeToDeleteBeans = time();
$beansToDelete = \R::findAll('events', 'end_time+(24*60*60) <= :time', array(':time' => $timeToDeleteBeans));
\R::trashAll($beansToDelete);
Пример #7
0
<?php

include_once 'phpcode/secureSession.php';
include_once 'phpcode/config.php';
sec_session_start();
check_logged();
?>


<?php 
if (isset($_GET['id']) && intval($_GET['id']) > 0) {
    //delete the album
    $album = R::dispense('albums');
    $album = R::load('albums', $_GET['id']);
    R::trash($album);
    $dirname = 'UploadedImages/' . preg_replace('/\\s+/', '', $album['name']);
    deleteDir($dirname . '/' . 'thumb');
    deleteDir($dirname);
    //delete images from db
    $images = R::dispense('images');
    $images = R::find('images', 'album_id=?', array($_GET['id']));
    R::trashAll($images);
    redirect("editAlbum.php");
} else {
    //go back
    redirect("editAlbum.php");
}
Пример #8
0
 /**
  * deletes beans with transactions
  * @param object $beans 
  */
 public static function deleteBeans($beans)
 {
     R::begin();
     try {
         R::trashAll($beans);
         R::commit();
     } catch (Exception $e) {
         R::rollback();
     }
 }
Пример #9
0
 /**
  * Delete pairs with user
  * @param int $user_id
  * @return boolean $res
  */
 public function deletePairByUserId($user_id)
 {
     // No pair - we thrash all pairs with user
     //return;
     $pairs = R::findAll('pair', 'user_a = ? OR user_b = ?', [$user_id, $user_id]);
     R::trashAll($pairs);
     $this->deleteHalvFromUserId($user_id);
 }
Пример #10
0
 /**
  * Test trashAll().
  */
 public function testMultiDeleteUpdate()
 {
     testpack('test multi delete and multi update');
     $beans = R::dispenseLabels('bean', array('a', 'b'));
     $ids = R::storeAll($beans);
     asrt((int) R::count('bean'), 2);
     R::trashAll(R::batch('bean', $ids));
     asrt((int) R::count('bean'), 0);
     testpack('test assocManager check');
     $rb = new RedBean_OODB(R::$writer);
     try {
         $rb->getAssociationManager();
         fail();
     } catch (RedBean_Exception_Security $e) {
         pass();
     }
 }
Пример #11
0
function checksession()
{
    global $systemURL;
    $sessions = R::find('sessions', 'timestamp<=?', [time()]);
    R::trashAll($sessions);
    if (isset($_COOKIE["loguserid"]) and isset($_COOKIE["logsession"])) {
        $session = R::findOne('sessions', 'userid=:userid AND sessionid=:sessionid AND timestamp>:timestamp', [':userid' => $_COOKIE["loguserid"], ':sessionid' => $_COOKIE["logsession"], ':timestamp' => time()]);
        if (!empty($session)) {
            $session->timestamp = time() + 86400 * 14;
            R::store($session);
            R::commit();
            R::begin();
        } else {
            $sessions = R::find('sessions', 'userid=:userid OR sessionid=:sessionid', [':userid' => $_COOKIE["loguserid"], ':sessionid' => $_COOKIE["logsession"]]);
            R::trashAll($sessions);
            R::commit();
            setcookie("loguserid", "", time() - 86400);
            setcookie("logsession", "", time() - 86400);
            header("HTTP/1.1 301 Moved permanently");
            header("Location: " . $systemURL . "?error=2&time=" . time());
            header("Connection: close");
            exit;
        }
    } else {
        header("HTTP/1.1 301 Moved permanently");
        header("Location: " . $systemURL . "?error=2&time=" . time());
        header("Connection: close");
        exit;
    }
}