Exemple #1
0
function delete_event($id)
{
    $event = R::load('events', $id);
    //reloads our event
    R::trash($event);
    //for one bean
}
 public static function clean($f3, $filename)
 {
     $total_filesize = R::getCell('select sum(filesize) as total_filesize from cache');
     $cache_total_filesize_limit = $f3->get("UPLOAD.cache_total_size_limit");
     $cache_total_filesize_limit = PFH_File_helper::convert_filesize_in_bytes($cache_total_filesize_limit);
     if ($total_filesize > $cache_total_filesize_limit) {
         $caches = R::find("cache", "ORDER BY datetime");
         $count = count($caches);
         // 只有一個不刪除
         //if ($count < 2) {
         //    return;
         //}
         foreach ($caches as $key => $cache) {
             //不刪除最後一個
             //if ($key > $count - 1) {
             //    return;
             //}
             if ($cache->path === $filename) {
                 continue;
             }
             //throw new Exception("$key $cache->path");
             //echo $cache->path . "<br />";
             if (is_file($cache->path)) {
                 unlink($cache->path);
             }
             $total_filesize = $total_filesize - $cache->filesize;
             R::trash($cache);
             if ($total_filesize < $cache_total_filesize_limit) {
                 break;
             }
         }
     }
 }
Exemple #3
0
function delete_news($id)
{
    $news = R::load('news', $id);
    //reloads our event
    R::trash($news);
    //for one bean
}
Exemple #4
0
 public static function doDeleteById($id)
 {
     $user = R::dispense('user');
     $user->id = $id;
     R::trash($user);
     //for one bean
 }
 public function deleteFromList($id)
 {
     $ban = R::load('banlist', $id);
     $value = $ban->value;
     R::trash($ban);
     return $value;
 }
 /**
  * Test SQLite table rebuilding.
  * 
  * @return void
  */
 public function testRebuilder()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     R::dependencies(array('page' => array('book')));
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->ownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->ownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->ownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->ownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     $book->added = 2;
     R::store($book);
     $book->added = 'added';
     R::store($book);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
 }
 /**
  * Check for a role
  *
  * @param string	$contextname    The name of a context...
  * @param string	$rolename       The name of a role....
  *
  * @return void
  */
 public function delrole($contextname, $rolename)
 {
     $cname = R::findOne('rolecontext', 'name=?', array($contextname));
     $rname = R::findOne('rolename', 'name=?', array($rolename));
     $bn = R::findOne('role', 'rolecontext_id=? and rolename_id=? and user_id=? and start <= UTC_TIMESTAMP() and (end is NULL or end >= UTC_TIMESTAMP())', array($cname->getID(), $rname->getID(), $this->bean->getID()));
     if (is_object($bn)) {
         R::trash($bn);
     }
 }
Exemple #8
0
 public static function eliminar()
 {
     if (isset($_GET['id'])) {
         $user = R::load('user', $_GET['id']);
         $username = $user->name;
         R::trash($user);
         //$_SESSION['flash'] = "Usuario $username eliminado exitosamente";
     }
 }
Exemple #9
0
 public static function destruir()
 {
     global $session, $logged;
     if (isset($logged) && isset($session)) {
         R::trash($session);
         setcookie("logged", "", time() - 1);
         $_SESSION['flash'] = 'Ha cerrado sesión correctamente';
     }
     header('Location:/');
 }
 /**
  * Function to clear invalid login attempts 
  * @param string $username email or username of user
  * @return int login attempts left
  * **/
 public function clearInvalidLoginAttempts($username)
 {
     $userRow = \R::findOne('users', 'email=:ui OR user_name = :ui', array(':ui' => $username));
     if ($userRow) {
         $userAttemptRow = \R::findOne($this->_name, 'user_id = :ui', array(':ui' => $userRow->id));
         if ($userAttemptRow) {
             \R::trash($userAttemptRow);
         }
     }
 }
Exemple #11
0
 public function delete_page($args)
 {
     $page_id = array_shift($args);
     if ($page = R::load('page', $page_id)) {
         $old = clone $page;
         R::trash($page);
         Audit::create($old, NULL, 'Developer deleted page from system');
     }
     $this->redirect(PACKAGE_URL);
 }
 public function deleteMessage($user_id, $m_id)
 {
     $message = R::findOne('message', '  recipient_id = ? && id = ? ', [$user_id, $m_id]);
     if ($message == NULL) {
         return NULL;
     }
     R::trash($message);
     $data = array("rc" => 0);
     return json_encode($data);
 }
 public function deleteCity()
 {
     $count = R::count('jobs', " city=:city ", array(':city' => $this->_id));
     if (!$count) {
         $city = R::load('cities', $this->_id);
         R::trash($city);
         return true;
     }
     return false;
 }
 public function show_deleteUser()
 {
     if ($this->user->password != Framework::hash($_POST['password'])) {
         $this->error('Das Passwort war falsch!');
     }
     R::trash($this->user);
     $this->show_Logoff();
     $this->output('deleted', true);
     $this->output('message', 'Der Account wurde gelöscht.');
 }
 public function deleteCategory()
 {
     $count = R::count('jobs', " category=:category ", array(':category' => $this->_id));
     if (!$count) {
         $category = R::load('categories', $this->_id);
         R::trash($category);
         return true;
     }
     return false;
 }
Exemple #16
0
 public function delete($args)
 {
     $posttype = array_shift($args);
     $id = array_shift($args);
     $post = current(R::findOrDispense('post', 'id = :id', ['id' => $id]));
     if ($post->getID()) {
         R::trash($post);
     }
     $this->redirect(PACKAGE_URL . "posts/view/{$posttype}");
 }
 private function handleChanges()
 {
     if (!isset($_POST['entryAction'])) {
         return;
     }
     if ($_POST['entryAction'] == 'add') {
         $bean = R::dispense($this->currentTable);
     } elseif ($_POST['entryAction'] == 'edit' && is_numeric($_POST['entryId'])) {
         $bean = R::load($this->currentTable, $_POST['entryId']);
         if (!$bean->id) {
             die('Invalid ID');
         }
     } elseif ($_POST['entryAction'] == 'delete' && is_numeric($_POST['entryId'])) {
         $bean = R::load($this->currentTable, $_POST['entryId']);
         if (!$bean->id) {
             die('Invalid ID');
         }
         R::trash($bean);
         Framework::Redir("game/db_admin");
         return;
     } elseif ($_POST['entryAction'] == 'duplicate' && is_numeric($_POST['entryId'])) {
         $bean = R::load($this->currentTable, $_POST['entryId']);
         if (!$bean->id) {
             die('Invalid ID');
         }
         $newBean = R::dispense($this->currentTable);
         foreach ($this->dbTables[$this->currentTable] as $f) {
             $newBean->{$f} = $bean->{$f};
         }
         R::store($newBean);
         Framework::Redir("game/db_admin");
         return;
     } else {
         Framework::Redir("game/db_admin");
         return;
     }
     // load stuff into bean
     $bean->import($_POST['entry'], implode(",", $this->dbTables[$this->currentTable]));
     // check if any special prehooks defined for current table
     $beanHook = 'prehook' . ucfirst($this->currentTable);
     if (method_exists($this, $beanHook)) {
         $this->{$beanHook}($bean);
     }
     // store bean
     R::store($bean);
     // post hook
     $beanHook = 'posthook' . ucfirst($this->currentTable);
     if (method_exists($this, $beanHook)) {
         $this->{$beanHook}($bean);
     }
     Framework::Redir("game/db_admin");
 }
 /**
  * Tests dependencies (variation).
  * 
  * @return void
  */
 public function testDependency4()
 {
     R::dependencies(array('bean' => array('can')));
     $can = $this->createCanForBean();
     asrt(R::count('bean'), 1);
     R::trash($can);
     asrt(R::count('bean'), 0);
     R::dependencies(array());
     $can = $this->createCanForBean();
     asrt(R::count('bean'), 1);
     R::trash($can);
     asrt(R::count('bean'), 1);
 }
 /**
  * Test for issue90.
  * Checking 'own' relationship, makes it impossible to trash a bean.
  *
  * @return void
  */
 public function testIssue90()
 {
     $s = R::dispense('box');
     $s->name = 'a';
     $f = R::dispense('bottle');
     $s->ownBottle[] = $f;
     R::store($s);
     $s2 = R::dispense('box');
     $s2->name = 'a';
     R::store($s2);
     R::trash($s2);
     pass();
 }
Exemple #20
0
 public static function completar()
 {
     //global $logged;
     if (isset($_POST['id'])) {
         $request = R::load('request', $_POST['id']);
         $completed = R::dispense('completed');
         $completed->import($request->export(), 'name, user_id');
         $completed->date = R::isoDateTime();
         $completed->agregado = $request->date;
         $id = R::store($completed);
         R::trash($request);
         echo json_encode(["exito" => 1]);
     }
 }
Exemple #21
0
 public function Delete()
 {
     if (isset($_GET["id"])) {
         $user = R::load('user', $_GET['id']);
         if (!$user) {
             throw new Exception("Unknown user");
         } else {
             R::trash($user);
         }
     } else {
         throw new Exception("Unknown user");
     }
     return array();
 }
 public function after_update()
 {
     // check if amount == 0
     if ($this->amount <= 0) {
         R::trash($this->bean);
         return;
     }
     // check if merging two entries is possible
     $mergeTo = R::findOne('bank_locker', " param = ? AND user_id = ? AND item_id = ? AND id != ?", array($this->param, $this->user->id, $this->item->id, $this->id));
     if ($mergeTo != false) {
         R::exec("UPDATE bank_locker SET amount = ? WHERE id = ?", array($this->amount + $mergeTo->amount, $this->id));
         R::trash($mergeTo);
     }
 }
Exemple #23
0
 public static function removeChild($table, $parentBean, $bean)
 {
     //we still need 2 separate queries because the parent's left_id can't be updated...
     R::begin();
     try {
         R::trash($bean);
         R::exec('UPDATE ' . $table . ' SET left_id = left_id-2 WHERE left_id > ?', array($bean->right_id));
         R::exec('UPDATE ' . $table . ' SET right_id = right_id-2 WHERE right_id >= ?', array($bean->right_id));
         $parentBean->right_id -= 2;
         R::commit();
     } catch (Exception $e) {
         R::rollback();
         throw $e;
     }
 }
 public function show_Cancel()
 {
     if (!$this->user->hasPremium()) {
         $this->error('Nur für Premiumaccounts.');
     }
     if (!is_numeric($this->get(1)) || $this->get(1) < 1) {
         $this->error('Ungültige ID');
     }
     $crule = R::relatedOne($this->myCompany, 'crule', 'id = ?', array($this->get(1)));
     if (!$crule) {
         $this->error('Die ID wurde nicht gefunden.');
     }
     R::trash($crule);
     $this->output('load', 'show');
 }
 public function cancel()
 {
     $cs = Config::getConfig("company_quests");
     $details = $cs[$this->name];
     //$company = R::relatedOne($this->bean, 'company');
     $user = R::relatedOne($this->bean, 'user');
     if ($user == null) {
         R::trash($this->bean);
         return;
     }
     $company = R::findOne('company', 'user_id = ?', array($user->id));
     $company->balance -= floor($details["oncomplete"]["cash"] * 0.1);
     R::begin();
     R::trash($this->bean);
     R::store($company);
     R::commit();
 }
Exemple #26
0
 public function execute()
 {
     $this->template->heading('ORM Example');
     // Call ORM plugin.
     $this->factory('orm');
     // Will create a table called 'book';
     $book = R::dispense('example_book');
     // Deleting a record
     if (!empty($_GET['delete'])) {
         $sold = R::load("example_book", $_GET['delete']);
         R::trash($sold);
         $this->template->note(sprintf('Record %s was deleted', $_GET['delete']));
     }
     // Sell a book
     if (!empty($_GET['sell'])) {
         $title = urldecode($_GET['title']);
         $this->template->ok("Great, thanks for buying \"{$title}\". You are a little weird reading this, but who are we to judge.", false, false);
     }
     // To update a field, you need to provide the id (always id) like so;
     // $book->id = 1;
     // Will execute saving to database.
     if (!empty($_GET['sell'])) {
         $sold = $book->import($_GET, 'category,type,author,price,title');
         if ($sold) {
             $this->template->ok("That went well, we just sold another book.", false, false);
         }
         R::store($book);
     }
     // Reading from ORM is just as simple...
     $books = R::find('example_book');
     $book1 = $this->navigation->sefURL(null, 'sell=true&category=books&type=Sci-Fiction&author=Peter Viljoen&price=3.99&title=The Robot Rapist');
     $book2 = $this->navigation->sefURL(null, 'sell=true&category=books&type=Health&author=Samie Caster&price=2.99&title=Getting hard again');
     $book3 = $this->navigation->sefURL(null, 'sell=true&category=books&type=Horror&author=Lion Wessels&price=8.99&title=Cinderella goes rogue');
     // Please see http://redbeanphp.com/ for complete manual.
     // For all R methods see : http://www.redbeanphp.com/api/class_r.html
     $view = $this->factory('views');
     $view->set('delete', $this->navigation->sefURL(null, 'delete='));
     $view->set('special1', $book1);
     $view->set('special2', $book2);
     $view->set('special3', $book3);
     $view->set('books', $books);
     $view->show();
 }
 public function cancel_Order()
 {
     // when deleting an order, cash and ress must be returned to company
     $company = R::relatedOne($this->bean, 'company');
     if ($this->type == 'buy') {
         // buy order needs cash updated
         $company->balance += $this->r_amount * $this->price;
         R::store($company);
         R::trash($this->bean);
     } else {
         // sell order needs ress updated
         if ($this->r_type == 'resource') {
             $holder = R::findOne('company_ress', ' company_id = ?', array($company->id));
         } else {
             $holder = R::findOne('company_products', ' company_id = ?', array($company->id));
         }
         $holder->{$this->r_name} += $this->r_amount;
         R::store($holder);
         R::trash($this->bean);
     }
 }
    private function MoveItem($id, $direction)
    {
        $take = $direction == "take" ? "bank_locker" : "inventory";
        $put = $direction == "take" ? "inventory" : "bank_locker";
        $action = $direction == "take" ? "storage" : "store";
        $item = R::findOne($take, ' user_id = ? AND id = ?', array($this->user->getID(), $id));
        if (!$item) {
            $this->output('maintext', 'Ungültiges Item angegeben!');
            return;
        }
        $amount = isset($_POST["amount"]) && is_numeric($_POST["amount"]) ? $_POST["amount"] : -1;
        if ($item->amount > 1 && ($amount == -1 || $amount > $item->amount)) {
            $this->output('maintext', 'Wie oft möchtest du ' . htmlspecialchars($item->item->name) . '
			' . ($direction == "take" ? "mitnehmen" : "abgeben") . '?');
            $this->output('form', array('target' => $action . '/' . $item->id, 'elements' => array(array('desc' => 'Menge', 'type' => 'text', 'name' => 'amount', 'value' => $item->amount))));
            return;
        }
        if ($amount == -1 || $amount > $item->amount) {
            $amount = 1;
        }
        $locker = R::dispense($put);
        $locker->user = $this->user;
        $locker->item = $item->item;
        $locker->amount = $amount;
        $locker->param = $item->param;
        R::$adapter->startTransaction();
        R::store($locker);
        $item->amount -= $amount;
        if ($item->amount == 0) {
            R::trash($item);
        } else {
            R::store($item);
        }
        R::$adapter->commit();
        $this->output('maintext', 'Du hast das Item ' . htmlspecialchars($item->item->name) . '
		' . $amount . 'x
		' . ($direction == "take" ? "mitgenommen" : "abgegeben"));
        $this->output('options', array("interact" => "Zurück"));
        return;
    }
 /**
  * Test if RedBeanPHP can properly handle keywords.
  * 
  * @return void
  */
 public function testKeywords()
 {
     $keywords = array('anokeyword', 'znokeyword', 'group', 'DROP', 'inner', 'JOIN', 'select', 'table', 'int', 'cascade', 'float', 'CALL', 'in', 'status', 'order', 'limit', 'having', 'else', 'if', 'while', 'distinct', 'like');
     R::setStrictTyping(FALSE);
     RedBean_OODBBean::setFlagBeautifulColumnNames(FALSE);
     foreach ($keywords as $k) {
         R::nuke();
         $bean = R::dispense($k);
         $bean->{$k} = $k;
         $id = R::store($bean);
         $bean = R::load($k, $id);
         $bean2 = R::dispense('other');
         $bean2->name = $k;
         $bean->bean = $bean2;
         $bean->ownBean[] = $bean2;
         $bean->sharedBean[] = $bean2;
         $id = R::store($bean);
         R::trash($bean);
         pass();
     }
     RedBean_OODBBean::setFlagBeautifulColumnNames(TRUE);
     R::setStrictTyping(TRUE);
 }
 /**
  * Test boxing beans.
  * 
  * @return void
  */
 public function testBoxing()
 {
     R::nuke();
     $bean = R::dispense('boxedbean')->box();
     R::trash($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->sharedBoxbean = R::dispense('boxedbean')->box();
     R::store($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->ownBoxedbean = R::dispense('boxedbean')->box();
     R::store($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->other = R::dispense('boxedbean')->box();
     R::store($bean);
     pass();
     $bean = R::dispense('boxedbean');
     $bean->title = 'MyBean';
     $box = $bean->box();
     asrt($box instanceof Model_Boxedbean, TRUE);
     R::store($box);
 }