<?php require_once 'autoload.php'; //load app classes require_once 'lib/limonade.php'; dispatch('/css/:css', 'AssetController::css'); dispatch('/js/:js', 'AssetController::js'); //ROUTES dispatch_get('/', 'PostController::index'); dispatch_get('/new', 'PostController::neew'); //R dispatch_get('/edit/:post', 'PostController::edit'); //R dispatch_post('/:post', 'PostController::save'); //C, U dispatch_get('/:post', 'PostController::post'); dispatch_post('/remove/:post', 'PostController::remove'); //D run();
/** * Define a POST route for AJAX POST with token validation * @param string $route * @param \Closure $closure */ public static function post($route, \Closure $closure, $getNewStuff = true) { if (!\CODOF\User\CurrentUser\CurrentUser::loggedIn()) { $getNewStuff = false; //not available for guests } dispatch_post($route, function () use($closure, $getNewStuff) { Request::processReq($closure, $getNewStuff, func_get_args()); }); }
return html('index.html.php'); } dispatch('/info', 'info'); function info() { return html('info.html.php'); } dispatch('/book', 'book'); function book() { // $event = option('tito')->getEvent('funconf'); // set('event', $event->event); // set('ticket_types', $event->event->ticket_types); return html('book.html.php'); } dispatch_post('/book', 'book_post'); function book_post() { $event = option('tito')->getEvent('funconf'); set('event', $event->event); set('ticket_types', $event->event->ticket_types); $ticketInfo = new stdClass(); $ticketInfo->{1} = new stdClass(); $ticketInfo->{1}->ticket_type_id = $_POST['ticket_type_id']; $ticketInfo->{1}->release_id = $_POST['release_id']; $ticketInfo->{1}->quantity = $_POST['quantity']; // Here you set your own data. $name = $_POST['name']; $email = $_POST['email']; // The first param is the event to add the ticket to. The second parameter // is the array of information to pass. See the ticketInfo hack above, this has
if ($choice == "3") { $tropo->say("You picked the Star Wars prequels. Stop calling this number, Mr. Lucas, we know it's you."); } if ($choice == "4") { $tropo->say("You picked the Matrix. Dude, woe."); } // Tell Tropo what to do next. This redirects to the instructions under dispatch_post('/hangup', 'app_hangup'). $tropo->on(array("event" => "continue", "next" => "favorite-movie-webapi.php?uri=hangup")); // Tell Tropo what to do if there's an problem, like a timeout. This redirects to the instructions under dispatch_post('/incomplete', 'app_incomplete'). $tropo->on(array("event" => "incomplete", "next" => "favorite-movie-webapi.php?uri=incomplete")); // Render the JSON for the Tropo WebAPI to consume. return $tropo->RenderJson(); } dispatch_post('/hangup', 'app_hangup'); function app_hangup() { $tropo = new Tropo(); $tropo->say("Thanks for voting!"); $tropo->hangup(); return $tropo->RenderJson(); } dispatch_post('/incomplete', 'app_incomplete'); function app_error() { $tropo = new Tropo(); $tropo->say("Something has gone wrong, please call back."); $tropo->hangup(); return $tropo->RenderJson(); } // Run this sucker! run();
dispatch('/', 'index'); function index() { $o = "HELLO"; if (array_key_exists('sort', $_GET)) { $o .= " | sort=" . $_GET['sort']; } return $o; } dispatch('/books/:lang', 'books'); function books() { $o = "lang=" . params('lang'); if (array_key_exists('sort', $_GET)) { $o .= " | sort=" . $_GET['sort']; } if (array_key_exists('page', $_GET)) { $o .= " | page=" . $_GET['page']; } return $o; } dispatch_post('/books', 'create'); function create() { $o = ''; if (array_key_exists('title', $_POST)) { $o = "title=" . $_POST['title']; } return $o; } run();
<?php require 'tropo.class.php'; require 'limonade/lib/limonade.php'; error_reporting(0); dispatch_post('/', 'app_start'); function app_start() { $tropo = new Tropo(); $tropo->call("+14071234321", array("machineDetection" => "This is just a test to see if you are a human or a machine. PLease hold while we determine. Almost finished. Thank you!", "voice" => "Kate")); $tropo->on(array("event" => "continue", "next" => "your_app.php?uri=continue")); $tropo->RenderJson(); } dispatch_post('/continue', 'app_continue'); function app_continue() { $tropo = new Tropo(); @($result = new Result()); $userType = $result->getUserType(); $tropo->say("You are a {$userType}"); $tropo->RenderJson(); } run();
<?php # render a view for connecting roles with services dispatch('/roles_services', 'roles_services_index'); function roles_services_index() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $arrRoles = fetchRolesServices(); set('roles', $arrRoles); $arrServices = $db->select("SELECT {$cfg['tblService']}.id as sid,\n {$cfg['tblService']}.`desc` as service_desc,\n {$cfg['tblDaemon']}.name as daemon_name,\n {$cfg['tblServer']}.fqdn as fqdn\n FROM {$cfg['tblService']}\n LEFT OUTER JOIN {$cfg['tblServer']}\n ON {$cfg['tblServer']}.id = {$cfg['tblService']}.server_id\n LEFT OUTER JOIN {$cfg['tblDaemon']}\n ON {$cfg['tblDaemon']}.id = {$cfg['tblService']}.daemon_id\n ORDER BY {$cfg['tblDaemon']}.name ASC"); set('services', $arrServices); return html('roles_services/index.html.php'); } # associate a role with a service dispatch_post('/roles_services', 'roles_services_create'); function roles_services_create() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $role_id = intval($_POST['role_id']); $service_id = intval($_POST['service_id']); $connect = isset($_POST['connect']) ? true : false; $result = $db->insert("INSERT INTO {$cfg['tblAccess']}\n (rolle_id, dienst_id) VALUES\n ('{$role_id}', '{$service_id}')"); if (!$result) { halt(SERVER_ERROR); return; } if (isAjaxRequest() && $connect) { $arrRoles = fetchRolesServices("WHERE {$cfg['tblRole']}.id = {$role_id}"); return js('roles_services/role.js.php', null, array('role' => array_pop($arrRoles)));
<?php require_once 'lib/limonade.php'; require_once 'lib/php-activerecord/ActiveRecord.php'; require_once "lib/JBBCode/Parser.php"; require_once 'ServiceLocator.php'; //My own locator ActiveRecord\Config::initialize(function ($cfg) { $cfg->set_model_directory('models'); $cfg->set_connections(array('development' => 'mysql://root@localhost/xii')); }); dispatch('/', 'PostController::index'); //visitors dispatch('/blog/:user_id', 'PostController::blog'); //dispatch('/blog/:user_id/:id', 'PostController::post'); //AUTH dispatch('/google-auth', 'GoogleAuthController::auth'); dispatch('/logout', 'GoogleAuthController::logout'); //POST CRUD dispatch('/new', 'PostController::newpost'); dispatch('/:id', 'PostController::post'); dispatch('/:id/edit', 'PostController::edit'); dispatch_post('/:id/save', 'PostController::save'); dispatch('/:id/delete', 'PostController::delete'); run();
<?php require_once "lib/limonade.php"; dispatch_get("/", "redirect_data"); dispatch_get("/data", "data"); dispatch_get("/data/extract", "data_extract"); dispatch_get("/document", "document"); dispatch_get("/promo", "promo"); dispatch_post("/document", "add_document"); dispatch_post("/promo", "add_promo"); dispatch_put("/data/:dataid", "alter_data"); dispatch_put("/document/:documentid", "alter_document"); dispatch_put("/promo/:promoid", "alter_promo"); dispatch_delete("/document/:fileid", "delete_document"); dispatch_delete("/promo/:promoid", "delete_promo"); try { run(); } catch (Exception $e) { error_log($e); }
<?php function configure() { option('app_dir', file_path(dirname(option('root_dir')), 'app')); option('lib_dir', file_path(option('app_dir'), 'lib')); option('views_dir', file_path(option('app_dir'), 'views')); option('session', "app_session"); option('debug', false); setlocale(LC_TIME, "ro_RO"); } /** * Start the logic */ dispatch('/', 'index'); dispatch('/creare', 'creare'); dispatch_post('/creare', 'cont_nou'); dispatch('/contact', 'contact'); dispatch_post('/contact', 'trimite'); run();
option('env', $env); option('dsn', $dsn); option('db_conn', $db); option('debug', true); } function after($output) { $time = number_format((double) substr(microtime(), 0, 10) - LIM_START_MICROTIME, 6); $output .= "<!-- page rendered in {$time} sec., on " . date(DATE_RFC822) . "-->"; return $output; } layout('layout/default.html.php'); // main controller dispatch('/', 'main_page'); // books controller dispatch_get('books', 'books_index'); dispatch_post('books', 'books_create'); dispatch_get('books/new', 'books_new'); dispatch_get('books/:id/edit', 'books_edit'); dispatch_get('books/:id', 'books_show'); dispatch_put('books/:id', 'books_update'); dispatch_delete('books/:id', 'books_destroy'); // authors controller dispatch_get('authors', 'authors_index'); dispatch_post('authors', 'authors_create'); dispatch_get('authors/new', 'authors_new'); dispatch_get('authors/:id/edit', 'authors_edit'); dispatch_get('authors/:id', 'authors_show'); dispatch_put('authors/:id', 'authors_update'); dispatch_delete('authors/:id', 'authors_destroy'); run();
$db = option('db_conn'); $user = get('user'); $stmt = $db->prepare('SELECT id, content, is_private, created_at, updated_at FROM memos WHERE user = :user ORDER BY created_at DESC'); $stmt->bindValue(':user', $user['id']); $stmt->execute(); $memos = $stmt->fetchAll(PDO::FETCH_ASSOC); set('memos', $memos); return html('mypage.html.php'); }); dispatch_post('/memo', function () { $db = option('db_conn'); $user = get('user'); $content = $_POST["content"]; $is_private = $_POST["is_private"] != 0 ? 1 : 0; $stmt = $db->prepare('INSERT INTO memos (user, content, is_private, created_at) VALUES (:user, :content, :is_private, now())'); $stmt->bindValue(':user', $user['id']); $stmt->bindValue(':content', $content); $stmt->bindValue(':is_private', $is_private); $stmt->execute(); $memo_id = $db->lastInsertId(); return redirect('/memo/' . $memo_id); }); dispatch_get('/memo/:id', function () { $db = option('db_conn'); $user = get('user'); $stmt = $db->prepare('SELECT id, user, content, is_private, created_at, updated_at FROM memos WHERE id = :id'); $stmt->bindValue(':id', params('id')); $stmt->execute(); $memo = $stmt->fetch(PDO::FETCH_ASSOC); if (!$memo) { return halt(404);
# matches GET /posts/1 dispatch('/posts/:id', 'blog_posts_show'); function blog_posts_show() { if ($post = post_find(params('id'))) { set('post', $post); # passing the post the the view return html('posts/show.html.php'); # rendering the view } else { halt(NOT_FOUND, "This post doesn't exists"); # raises error / renders an error page } } # matches POST /posts dispatch_post('/posts', 'blog_posts_create'); function blog_posts_create() { if ($post_id = post_create($_POST['post'])) { redirect_to('posts', $post_id); # redirects to the show page of this newly created post } else { halt(SERVER_ERROR, "AN error occured while trying to create a new post"); # raises error / renders an error page } } # matches GET /posts/1/edit dispatch('/posts/:id/edit', 'blog_posts_edit'); function blog_posts_edit() { if ($post = post_find(params('id'))) {
$argstr = $args; } logit("calling " . "return {$name}::{$message}({$argstr});"); $result = eval("return {$name}::{$message}({$argstr});"); } logit("result", $result); return json_encode(array($result)); } catch (LoadError $e) { halt(422, json_encode(array("exception" => "LoadError", "error" => $e->getMessage()))); } catch (Exception $e) { logit('Exception ' . $e->getMessage()); halt(422, json_encode(array("exception" => get_class($e), "error" => $e->getMessage()))); // return json_encode(array('error' => $e->getMessage())); } } dispatch_post('/class/:name', 'new_object'); function new_object() { try { $name = params('name'); $args = $_POST['args']; $argstr = $args; logit('POST: args ', $args); if (is_null($args) || $args == '[]') { logit("calling new {$name}()"); $object = new $name(); logit("got object:" . get_class($object)); } else { logit('args b4 decode', $args); $args = json_decode($args, true); logit('args after decode', $args);
set('seat_id', $seat_id); return html('complete.html.php'); } else { $db->rollback(); return html('soldout.html.php'); } }); dispatch('/admin', function () { return html('admin.html.php'); }); dispatch_post('/admin', function () { $db = option('db_conn'); $fh = fopen(realpath(__DIR__ . '/../config/database/initial_data.sql'), 'r'); while ($sql = fgets($fh)) { $sql = rtrim($sql); if (!empty($sql)) { $db->exec($sql); } } fclose($fh); redirect_to('/admin'); }); dispatch('/admin/order.csv', function () { $db = option('db_conn'); $stmt = $db->query(<<<SQL SELECT order_request.*, stock.seat_id, stock.variation_id, stock.updated_at FROM order_request JOIN stock ON order_request.id = stock.order_id ORDER BY order_request.id ASC SQL ); $body = ''; $orders = $stmt->fetchAll(PDO::FETCH_ASSOC);
*/ dispatch_post('/end', 'zip_end'); function zip_end() { // Create a new instance of the result object and get the value of the user input. $result = new Result(); $zip = $result->getValue(); // Create a new instance of the Tropo object. $tropo = new Tropo(); // Get the weather information for the entered zip code. formatWeatherResponse($tropo, $zip); // Render the JSON for the Tropo WebAPI to consume. return $tropo->RenderJson(); } /** * If an error occurs, end the session. */ dispatch_post('/error', 'zip_error'); function zip_error() { // Step 1. Create a new instance of the Tropo object. $tropo = new Tropo(); // Step 2. This is the last thing the user will be told before the session ends. $tropo->say("Please try your request again later."); // Step 3. End the session. $tropo->hangup(); // Step 4. Render the JSON for the Tropo WebAPI to consume. return $tropo->renderJSON(); } // Run this sucker! run();
{ (int) $id; return $id / $divider; } dispatch('/route9/*', 'MyController::staticMethod'); dispatch('/route9b/*', 'MyController::staticMethod', array('params' => array(10))); dispatch(array('/route10/*', array('id')), 'MyController::staticMethod'); dispatch(array('/route10b/*', array('id')), 'MyController::staticMethod', array('params' => array('id' => 10))); /* http methods dispatching */ dispatch_get('/route11', 'test_route11'); function test_route11() { header('X-LIM-CTL: route11'); return "GET"; } dispatch_post('/route11', 'test_route11post'); function test_route11post() { //header('Content-length: 4'); return "POST"; } dispatch_put('/route11', 'test_route11put'); function test_route11put() { return "PUT"; } dispatch_delete('/route11', 'test_route11delete'); function test_route11delete() { return "DELETE"; }
//dispatch_put('/domain/changeMain', 'changeMain'); /** * => controllers/app.php */ //dispatch('/app', 'apps'); //dispatch('/app/list', 'listApps'); //dispatch('/app/:operation/:app', 'operateApp'); //dispatch('/app/:operation/:app/ajax', 'operateAppAjax'); /** * => controllers/user.php */ dispatch('/user', 'user'); dispatch('/user/list', 'listUser'); dispatch('/user/details/:user', 'userDetails'); dispatch('/user/add', 'addUserForm'); dispatch_post('/user/add', 'addUser'); dispatch('/user/delete/:user', 'deleteUserForm'); dispatch_delete('/user/delete', 'deleteUser'); //dispatch('/user/update/:user', 'updateUserForm'); //dispatch_put('/user/update/:user', 'updateUser'); //dispatch('/user/mailaliases/:user', 'updateMailAliasesUserForm'); //dispatch_put('/user/mailaliases/:user', 'updateMailAliasesUser'); //dispatch('/user/password/:user', 'updatePasswordUserForm'); //dispatch_put('/user/password/:user', 'updatePasswordUser'); /** * => controllers/tools.php */ //dispatch('/tools', 'tools'); //dispatch('/tools/log/:service/:logFile', 'watchLog'); //dispatch('/tools/chat', 'getChat'); //dispatch('/tools/chat/enable', 'enableChat');
} set('daemons', $arrDaemons); return html('daemons/index.html.php'); } # show form for new daemon dispatch('/daemons/new', 'daemons_new'); function daemons_new() { if (isAjaxRequest()) { return html('daemons/new.js.php', null); } else { halt(HTTP_NOT_IMPLEMENTED); } } # save new daemon dispatch_post('/daemons', 'daemons_create'); function daemons_create() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $name = $db->escape($_POST['name']); $result = $db->insert("INSERT INTO {$cfg['tblDaemon']}\n (name) VALUES\n ('{$name}')"); if (!$result) { halt(SERVER_ERROR); return; } redirect_to('daemons'); } # edit form dispatch('/daemons/:id/edit', 'daemons_edit'); function daemons_edit()
$logs = get_log($advertiser_id); foreach ($reports as $ad_id => $report) { $log = fetch($logs, $ad_id, []); $report['clicks'] = count($log); $breakdown = array('gender' => (object) [], 'agents' => (object) [], 'generations' => (object) []); foreach ($log as $click) { incr_hash($breakdown['gender'], $click['gender']); incr_hash($breakdown['agents'], $click['agent']); if (isset($click['age']) && !empty($click['age'])) { $generation = intval($click['age'] / 10); } else { $generation = 'unknown'; } incr_hash($breakdown['generations'], $generation); } $report['breakdown'] = $breakdown; $reports[$ad_id] = $report; } return json((object) $reports); }); dispatch_post('/initialize', function () { $redis = option('redis'); $keys = $redis->keys('isu4:*'); foreach ($keys as $key) { $redis->del($key); } array_map('unlink', glob(get_dir('log') . '/*')); content_type('text/plain'); return 'OK'; }); run();
<?php // iSearch DEMO v.0.1 - 05/23/2009 // by imehesz@gmail.com (http://mehesz.net) // I found limonade couple of days ago (and iUI pretty much the same time) // wanted to create something very VERY simple, which helps me and // hopefully other people, to understand how the basic functionalities work // in this micro-framework // limonade - a PHP micro-framework ( http://www.sofa-design.net/limonade ) // iUI - iPhone User Interface Framework ( http://code.google.com/p/iui/ ) // download the source from http://mehesz.net/downloads/projects/isearch.zip // let's load the limonade lib include_once 'lib/limonade.php'; // we call the menu_show() function if someone comes to / dispatch('/', 'menu_show'); // calling the country_list dispatch('/country/list', 'country_list'); dispatch('/country/search', 'country_search'); dispatch_post('/country/search', 'country_search_results'); // we use a POST method for example, but normally in REST, POST is // for creating new resource. So we should use a GET method here // let's run() run();
// Player's Picks dispatch('/commissioner/players/picks', 'AdminPlayerPicksController::players'); dispatch('/commissioner/player/:uid/picks', 'AdminPlayerPicksController::player_picks'); dispatch('/commissioner/player/:uid/picks/:week', 'AdminPlayerPicksController::player_picks_week'); dispatch_post('/commissioner/player/:uid/picks/:week', 'AdminPlayerPicksController::save_player_picks_week'); /* * == UserController == * Method Path Controller * GET /login UserController::show_login * POST /login UserController::do_login * GET /logout UserController::do_logout * GET /my-account UserController::show_account * PUT /my-account UserController::edit_account */ dispatch('/login', 'UserController::show_login'); dispatch_post('/login', 'UserController::do_login'); dispatch('/logout', 'UserController::do_logout'); dispatch('/my-account', 'UserController::show_account'); dispatch_put('/my-account', 'UserController::edit_account'); /* * == MessengerController == * Method Path Controller * GET /messages MessengerController::show * POST /messages MessengerController::create * Coming Soon * PUT /messages/:id MessengerController::edit * DELETE /messages/:id MessengerController::delete */ dispatch('/messages', 'MessengerController::show'); dispatch_post('/messages', 'MessengerController::create');
$tropo->on(array("event" => "error", "next" => "WeatherDemo.php?uri=error", "say" => "You seem to be having trouble.")); return $tropo->RenderJson(); } // Get the zip code submitted by the user and look up the weather in that area. dispatch_post('/end', 'demo_end'); function demo_end() { $result = new Result(); $zip = $result->getValue(); $weather_info = getWeather($zip); $city = array_pop($weather_info); $tropo = new Tropo(); $tropo->say("The current weather for {$city} is..."); foreach ($weather_info as $info) { $tropo->say("{$info}."); } $tropo->say("Thank you for calling. Goodbye."); $tropo->hangup(); return $tropo->RenderJson(); } // If an error occurs, tell the user and bail. dispatch_post('/error', 'demo_error'); function demo_error() { $tropo = new Tropo(); $tropo->say("Please try your request again later."); $tropo->hangup(); return $tropo->renderJSON(); } // Run this sucker! run();
function people_roles_new() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $role_id = intval(params('id')); set('role', array('id' => $role_id)); $arrPeople = $db->select("SELECT *\n FROM {$cfg['tblPerson']}\n ORDER BY nachname ASC"); set('people', $arrPeople); if (isAjaxRequest()) { return js('people_roles/new.js.php', null); } else { halt(HTTP_NOT_IMPLEMENTED); } } # associate a person with a role dispatch_post('/people_roles', 'people_roles_create'); function people_roles_create() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $role_id = intval($_POST['role_id']); $person_id = intval($_POST['person_id']); $connect = isset($_POST['connect']) ? true : false; $result = $db->insert("INSERT INTO {$cfg['tblPersonHasRole']}\n (person_id, rolle_id) VALUES\n ('{$person_id}', '{$role_id}')"); if (!$result) { halt(SERVER_ERROR); return; } if (isAjaxRequest()) { if ($connect) { $arrRoles = fetchRoles("WHERE {$cfg['tblRole']}.id = {$role_id}");
dispatch_post('sso/authorize', function () { //CSRF protection if (\CODOF\Access\Request::valid($_POST['token'])) { //$id = $_POST['uid']; $user = $_POST['sso']; $posted_token = $user['token']; $secret = CODOF\Util::get_opt('sso_secret'); if (!empty($user)) { unset($user['token']); $sso_token = md5(urlencode(json_encode($user)) . $secret . $_POST['timestamp']); } $username = $user['name']; $mail = $user['mail']; if ($sso_token != $posted_token) { echo 'error'; exit; } $db = DB::getPDO(); if (!CODOF\User\User::mailExists($mail)) { //this user does not have an account in codoforum $reg = new \CODOF\User\Register($db); if (\CODOF\User\User::usernameExists($username)) { $username .= time(); } $reg->username = $username; $reg->name = $username; $reg->mail = $mail; $reg->user_status = 1; $ret = $reg->register_user(); $reg->login(); if (!empty($ret)) { echo "error"; } } else { CODOF\User\User::loginByMail($mail); } } });
} } set('people', $arrPersonen); return html('people/index.html.php'); } # show form for new person dispatch('/people/new', 'people_new'); function people_new() { if (isAjaxRequest()) { return html('people/new.js.php', null); } return html('people/new.html.php'); } # do stuff with newly created person dispatch_post('/people', 'people_create'); function people_create() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $vorname = $db->escape($_POST['vorname']); $nachname = $db->escape($_POST['nachname']); $result = $db->insert("INSERT INTO {$cfg['tblPerson']}\n (vorname, nachname) VALUES\n ('{$vorname}', '{$nachname}')"); if ($result) { redirect_to('people'); } else { halt(SERVER_ERROR); } } # edit form dispatch('/people/:id/edit', 'people_edit');
<?php session_start(); require_once 'lib/limonade.php'; require_once 'controller/controller.php'; require_once 'bootstrap.php'; /* Index */ dispatch('/', 'index'); dispatch('/sport/:sport_name', 'sport'); dispatch('/evenements/', 'evenements'); dispatch('/admin/', 'admin'); dispatch_post('/users/add', 'useradd'); dispatch('/users/delete/:id', 'userdelete'); dispatch_post('/sports/add', 'sportadd'); dispatch('/sports/delete/:id', 'sportdelete'); dispatch_post('/sports/modify/photos', 'sportpicture'); dispatch_post('/sports/modify/referent', 'sportreferent'); dispatch_post('/events/add', 'eventadd'); dispatch('/events/delete/:id', 'eventdelete'); dispatch_post('/events/modify/photos', 'eventpicture'); run();
$result = mysql_query($query) or die(mysql_error()); } } return classes(); } /** * Edit class function. * * @param String oldLibelleShort * @param String newLibelle * @param String newLibelleShort * * @author paul.michaud * @author loic.bothorel */ dispatch_post('/editClass', 'editPromo'); function editPromo() { $oldShortcut = mysql_real_escape_string($_POST['oldShortcut']); $newName = mysql_real_escape_string($_POST['newName']); $newShortcut = mysql_real_escape_string($_POST['newShortcut']); //Si on modifie la clé primaire on commence par vérifier si le newlibelleShort existe (clé primaire) si il existe on quitte if (strcmp($newShortcut, $oldShortcut) != 0) { $query = "SELECT shortcut FROM promo"; $result = mysql_query($query) or die(mysql_error()); while ($data = mysql_fetch_array($result)) { if ($data['shortcut'] == $newShortcut) { $_SESSION['classError'] = true; return classes(); //Il y a déjà une promos avec comme shortcut $newLibelleShort }
function fz_dispatch_post($path_or_array, $controller, $action) { return dispatch_post($path_or_array, 'fz_dispatcher', array('params' => array('controller' => $controller, 'action' => $action))); }
function access_new() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $role_id = intval(params('role_id')); set('role', array('id' => $role_id)); $arrServices = $db->select("SELECT {$cfg['tblService']}.id as dienst_id,\n {$cfg['tblService']}.`desc` as dienst_desc,\n {$cfg['tblDaemon']}.name as daemon_name,\n {$cfg['tblServer']}.fqdn as fqdn\n FROM {$cfg['tblService']}\n LEFT OUTER JOIN {$cfg['tblServer']}\n ON {$cfg['tblServer']}.id = {$cfg['tblService']}.server_id\n LEFT OUTER JOIN {$cfg['tblDaemon']}\n ON {$cfg['tblDaemon']}.id = {$cfg['tblService']}.daemon_id\n ORDER BY {$cfg['tblServer']}.fqdn ASC"); set('services', $arrServices); if (isAjaxRequest()) { return js('access/new.js.php', null); } else { halt(HTTP_NOT_IMPLEMENTED); } } # save new role-service association dispatch_post('/access', 'access_create'); function access_create() { $cfg = $GLOBALS['cfg']; $db = $GLOBALS['db']; $role_id = intval($_POST['role_id']); $dienst_id = intval($_POST['service_id']); $result = $db->insert("INSERT INTO {$cfg['tblAccess']}\n (dienst_id, rolle_id) VALUES\n ('{$dienst_id}', '{$role_id}')"); if (!$result) { halt(SERVER_ERROR); return; } $arrService = $db->select("SELECT {$cfg['tblService']}.id as dienst_id,\n {$cfg['tblService']}.`desc` as dienst_desc,\n {$cfg['tblDaemon']}.name as daemon_name,\n {$cfg['tblServer']}.fqdn as fqdn\n FROM {$cfg['tblService']}\n LEFT OUTER JOIN {$cfg['tblServer']}\n ON {$cfg['tblServer']}.id = {$cfg['tblService']}.server_id\n LEFT OUTER JOIN {$cfg['tblDaemon']}\n ON {$cfg['tblDaemon']}.id = {$cfg['tblService']}.daemon_id\n WHERE {$cfg['tblService']}.id={$dienst_id}"); if (!$arrService) { halt(SERVER_ERROR); return;