static function get_menus() { $db = new DB\SQL('mysql:host=localhost;dbname=MealDB', 'root', ''); $menuInst = new DB\SQL\Mapper($db, "MENU"); $menus = array(); $menuInst->load(''); while (!$menuInst->dry()) { $id = $menuInst->id; $name = $menuInst->name; $menus[$id] = $name; $menuInst->next(); } return $menus; }
function order() { $return = ""; $domain = $this->f3->get("domain"); //$ID = (isset($_GET['ID'])) ? $_GET['ID'] : ""; $f3 = \Base::instance(); $list = $_POST['id']; $a = new \DB\SQL\Mapper($f3->get("DB"), "dir_categories"); $sort = array(); foreach ($list as $id => $parentId) { $a->load("ID='{$id}'"); $a->parentID = $parentId; if (!$a->dry()) { $a->save(); } $a->reset(); } test_array($sort); return $GLOBALS["output"]['data'] = $return; }
function post_delete_food($f3) { $orm = new DB\SQL\Mapper($f3->get('DB'), 'MEAL'); $selectIds = $f3->get('POST.selectId'); $redirect = $f3->get("POST.destination"); if (isset($selectIds)) { foreach ($selectIds as $meal) { $orm->load(array('id = ?', $meal)); if (!$orm->dry()) { $orm->erase(); } $orm->reset(); } AlertControl::message_info("Valitut annokset on poistettu"); $f3->reroute($redirect); } $menuId = $f3->get('POST.menuId'); $id = $f3->get('PARAMS.id'); $orm->load(array('id=?', $id)); $meal_name = $orm->name; $orm->erase(); AlertControl::message_info("Annos {$meal_name} on poistettu"); $f3->reroute("/menu/{$menuId}"); }
public function moveCategory($catID = 0, $direction = NULL, $parent = NULL) { if ($parent === NULL) { $sql = "SELECT C.parent_cid \r\n\t\t\t\t\t\tFROM `tbl_categories`C \r\n\t\t\t\t\t\tWHERE C.`cid`= :catID"; $data = $this->exec($sql, [":catID" => $catID]); if (empty($data[0]) or !is_numeric($data[0]['parent_cid'])) { return FALSE; } $parent = $data[0]['parent_cid']; } $categories = new \DB\SQL\Mapper($this->db, $this->prefix . 'categories'); $categories->load(["parent_cid = ?", $parent], ['order' => "inorder " . ($direction == "up" ? "DESC" : "ASC")]); $elements = $categories->count(["parent_cid = ?", $parent]); // when moving elements upwards, we need to invert the entire logic if ($direction == "up") { $i = $elements + 1; } else { $i = 0; } // init vacant spot $vacant = -1; while (!$categories->dry()) { // gets dry when we passed the last record if ($direction == "up") { $i--; } else { $i++; } if ($categories->cid == $catID and $direction !== NULL) { if ($direction == "up") { $categories->inorder = max(1, $i - 1); } else { $categories->inorder = min($elements, $i + 1); } // remember the vacant spot $vacant = $i; } elseif ($direction == "down" and $i == $vacant + 1) { $categories->inorder = $i - 1; } elseif ($direction == "up" and $i == $vacant - 1) { $categories->inorder = $i + 1; } else { $categories->inorder = $i; } $categories->save(); // moves forward even when the internal pointer is on last record $categories->next(); } return $parent; }
require dirname(__FILE__) . '/hybridauth/Hybrid/Auth.php'; $provider_name = $f3->get('PARAMS.action'); if (empty($provider_name)) { die("no provider"); } // then grab the user profile try { $hybridauth = new Hybrid_Auth($hauth_config); $adapter = $hybridauth->authenticate($provider_name); $user_profile = $adapter->getUserProfile(); $_SESSION['logged_in'] = 'ok'; $username = $user_profile->email; $f3->set('SESSION.logged_in', 'ok'); $user = new DB\SQL\Mapper($db, 'memos'); $user->load(array('email = :username LIMIT 0,1', ':username' => $username)); if ($user->dry()) { $user->role = 'subscriber'; $user->created = date('Y-m-d H:i:s'); // Send email to Admin with the good news: a new user! $smtp = new SMTP(SMTP_SERVER, SMTP_PORT, SMTP_PROTOCOL, SMTP_USERNAME, SMTP_PASSWORD); $smtp->set('From', '"Do Not Forget Me" <' . ADMIN_EMAIL . '>'); $smtp->set('To', '<' . ADMIN_EMAIL . '>'); $smtp->set('Subject', 'Yay, New DNFM User : '******'Errors-to', '<' . ADMIN_EMAIL . '>'); $message = "On " . date('Y-m-d at H:i') . ", a new user subscribed to Do Not Forget Me!"; $message .= "\n\nname: " . $user_profile->displayName; $message .= "\nemail: " . $user_profile->email; $message .= "\n\n\nPop up the champaign!"; $sent = $smtp->send($message, TRUE); $mylog = $smtp->log(); }
} // home $f3->route('GET /', function (\Base $f3) { $f3->set('sub_tmpl', 'index.html'); echo \Template::instance()->render('layout.html'); }); // view paste $f3->route('GET @view: /view/@uuid', function (\Base $f3, $params) { $mapper = new \DB\SQL\Mapper($f3->get('DB'), $f3->get('db_table')); if ($f3->get('DELETE_ON_ACCESS')) { $mapper->load(array('uuid = ?', $params['uuid'])); } else { // don't load deleted $mapper->load(array('uuid = ? and lifetime > ?', $params['uuid'], date('Y-m-d H:i:s'))); } if ($mapper->dry()) { $f3->error(404, 'This document does not exist.'); } // delete on access if ($f3->get('DELETE_ON_ACCESS') && strtotime($mapper->lifetime) <= time()) { $mapper->erase(); $f3->error(404, 'This document does not exist.'); } $f3->set('paste', $mapper); $f3->set('sub_tmpl', 'view.html'); echo \Template::instance()->render('layout.html'); }); // save new $f3->route('POST /create', function (\Base $f3) { $mapper = new \DB\SQL\Mapper($f3->get('DB'), $f3->get('db_table')); if ($f3->get('AJAX')) {