Commit b155fadc authored by Cédric Houbart's avatar Cédric Houbart
Browse files

Initial import

parents
config.php
<?php
// Pastèque Web back office
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
// API is the entry point for all API calls.
namespace Pasteque;
const ABSPATH = __DIR__; // Base path. Also to check if a call
// originates from api.php
// Load
require_once(ABSPATH . "/inc/load.php");
// Check credentials
// Call API
<?php
// Pastèque Web back office, general configuration
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
//////////////////
// Core modules //
//////////////////
// Don't forget to set the configuration file in each module if it has one.
// The values must match a directory in the core module directory
// I.e. core_ident must match a directory under core_modules/ident/
$config['core_ident'] = "openbar";
$config['core_database'] = "static";
$config['core_modules'] = "static";
// Template
// Must match a directory in templates/
$config['template'] = "pasteque";
Database module
Handles database url and connection
<?php
// Pastèque Web back office, Static database module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace StaticDB;
$config['type'] = "mysql";
$config['host'] = "localhost";
$config['port'] = 3306;
$config['name'] = "database name";
$config['user'] = "user";
$config['password'] = "password";
?>
<?
// Pastèque Web back office, Static database module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque {
if (@constant("\Pasteque\ABSPATH") === NULL) {
die();
}
}
namespace StaticDB {
require_once(dirname(__FILE__) . "/config.php");
function type() { global $config; return $config['type']; }
function host() { global $config; return $config['host']; }
function port() { global $config; return $config['port']; }
function name() { global $config; return $config['name']; }
function user() { global $config; return $config['user']; }
function passwd() { global $config; return $config['password']; }
}
namespace Pasteque {
function get_db_type($user_id) {
return \StaticDB\type();
}
function get_db_host($user_id) {
return \StaticDB\host();
}
function get_db_port($user_id) {
return \StaticDB\port();
}
function get_db_name($user_id) {
return \StaticDB\name();
}
function get_db_user($user_id) {
return \StaticDB\user();
}
function get_db_password($user_id) {
return \StaticDB\passwd();
}
}
Ident module
Handles user authentication
<?php
// Pastèque Web back office, Open bar ident module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
// Open bar! Free for all! Come as you are!
namespace Pasteque;
if (@constant("\Pasteque\ABSPATH") === NULL) {
die();
}
function is_user_logged_in() {
return TRUE;
}
function show_login_page() {
return NULL;
}
function get_user_id() {
return 0;
}
?>
<?php
// Pastèque Web back office, WordPress ident module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// POS-Tech is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// POS-Tech is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with POS-Tech. If not, see <http://www.gnu.org/licenses/>.
// WordPress ident module
// Use WordPress for login and user management.
// You must put Pasteque back-office as a subdirectory of WordPress for
// the login to work
namespace WordPress;
// Base path of your WordPress
$config['wordpress_base_path'] = "/<path>/<to>/<wordpress>";
?>
<?php
// Pastèque Web back office, WordPress ident module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque {
if (@constant("\Pasteque\ABSPATH") === NULL) {
die();
}
require_once(dirname(__FILE__) . "/config.php");
}
namespace WordPress {
require_once($config['wordpress_base_path'] . "/wp-load.php");
function logged_in() {
return is_user_logged_in();
}
function show_login() {
auth_redirect();
}
function get_user_id() {
return get_current_user_id();
}
}
namespace Pasteque {
function is_user_logged_in() {
return \WordPress\logged_in();
}
function show_login_page() {
return \WordPress\show_login();
}
function get_user_id() {
if (!is_user_logged_in()) {
return NULL;
} else {
return \WordPress\get_user_id();
}
}
}
?>
Core module for extension modules
Manages regular modules and their activation
<?php
// POS-Tech Web back office, Static module management module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of POS-Tech.
//
// POS-Tech is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// POS-Tech is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with POS-Tech. If not, see <http://www.gnu.org/licenses/>.
// Set the list of activated modules in the array. The module name must match
// the directory under modules/
$config['modules'] = array(
"base_products",
"base_users",
);
?>
<?php
// Pastèque Web back office, Static module manager
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque {
if (@constant("\Pasteque\ABSPATH") === NULL) {
die();
}
}
namespace StaticMM {
require_once(dirname(__FILE__) . "/config.php");
function modules() { global $config; return $config['modules']; }
}
namespace Pasteque {
function get_loaded_modules($user_id) {
return \StaticMM\modules();
}
}
?>
<?php
// Pastèque Web back office
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
echo("Welcome!!");
?>
<?php
// Pastèque Web back office
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
class MenuEntry {
private $nameDomain;
private $name;
private $action;
public function __construct($name, $action, $domain = NULL) {
$this->name = $name;
$this->action = $action;
$this->nameDomain = $domain;
}
public function getName() { return $this->name; }
public function getNameDomain() { return $this->nameDomain; }
public function getAction() { return $this->action; }
}
class Menu {
private $entries;
public function __construct() {
$this->entries = array();
$this->entries[] = new MenuEntry("Home", "home");
}
public function register_module_entry($module_name, $name, $action) {
$this->entries[] = new MenuEntry($name,
get_module_action($module_name, $action),
$module_name);
}
public function get_entries() {
return $this->entries;
}
}
$MENU = new Menu();
?>
<?php
// Pastèque Web back office
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
class PDOBuilder {
/** Get PDO from the loaded database core module */
public static function getPDO() {
$uid = get_user_id();
switch (get_db_type($uid)) {
case 'mysql':
$dsn = "mysql:dbname=" . get_db_name($uid) . ";host="
. get_db_host($uid) . ";port=" . get_db_port($uid);
try {
return new \PDO($dsn, get_db_user($uid), get_db_password($uid),
array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
} catch (\PDOException $e) {
die("Connexion error " . $e);
}
default:
die("Config error");
}
}
}
?>
<?php
// Pastèque Web back office
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pastèque.
//
// Pastèque is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Pastèque is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque;
const URL_ACTION_PARAM = "p";
?>
<?php
// POS-Tech API
//
// Copyright (C) 2012 Scil (http://scil.coop)
//
// This file is part of POS-Tech.
//
// POS-Tech is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// POS-Tech is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with POS-Tech. If not, see <http://www.gnu.org/licenses/>.
require_once(dirname(dirname(__FILE__)) . "/services/AttributesService.php");
$action = $_GET['action'];
$ret = null;
switch ($action) {
case 'get':
if (!isset($_GET['id'])) {
$ret = false;
break;
}
$ret = AttributesService::get($_GET['id']);
break;
case 'getAll':
$ret = AttributesService::getAll();
break;
case 'createVal':
if (!isset($_GET['label']) || !isset($_GET['attr_id'])) {
$ret = false;
break;
}
$val = new AttributeValue($_GET['label']);
$ret = AttributesService::createValue($val, $_GET['attr_id']);
break;
case 'deleteVal':
if (!isset($_GET['id'])) {
$ret = false;
break;
}
$ret = AttributesService::deleteValue($_GET['id']);
break;
case 'updateVal':
if (!isset($_GET['id']) || !isset($_GET['label'])) {
$ret = false;
break;
}
$val = AttributeValue::__build($_GET['id'], $_GET['label']);
$ret = AttributesService::updateValue($val);
break;
case 'createAttr':
if (!isset($_GET['label'])) {
$ret = false;
}
$attr = new Attribute($_GET['label']);
$ret = AttributesService::createAttribute($attr);
break;
case 'deleteAttr':
if (!isset($_GET['id'])) {
$ret = false;
break;
}
$ret = AttributesService::deleteAttribute($_GET['id']);
break;
case 'updateAttr':
if (!isset($_GET['id']) || !isset($_GET['label'])) {
$ret = false;
break;
}
$attr = Attribute::__build($_GET['id'], $_GET['label']);
$ret = AttributesService::updateAttribute($attr);
break;
}
echo(json_encode($ret));