You should have received a copy of the GNU General Public License along with Print Master. If not, see <http://www.gnu.org/licenses/>. */ // Include initialisation file include_once 'inc/core.php'; // Get action from query string $action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete')); /** * Default action - show list of consumables */ if ($action == 'list') { // Set the users to be sortable by name or email, defaulting to name $sort = fCRUD::getSortColumn(array('consumables.name', 'consumables.qty', 'consumables.cost')); // Set the sorting to default to ascending $dir = fCRUD::getSortDirection('asc'); // Redirect the user if one of the values was loaded from the session fCRUD::redirectWithLoadedValues(); // Get recordset object from tables $sql = "SELECT\n\t\t\t\tconsumables.*,\n\t\t\t\t( round( ( (consumables.qty) / (SELECT MAX(qty) FROM consumables) ) * 100 ) ) AS qty_percent,\n\t\t\t\tGROUP_CONCAT(DISTINCT CAST(CONCAT(manufacturers.name, ' ', models.name) AS CHAR) SEPARATOR ', ') AS model,\n\t\t\t\tCOUNT(printers.id) AS printer_count\n\t\t\tFROM\n\t\t\t\tconsumables\n\t\t\tLEFT JOIN\n\t\t\t\tconsumables_models\n\t\t\t\tON consumables.id = consumables_models.consumable_id\n\t\t\tLEFT JOIN\n\t\t\t\tmodels\n\t\t\t\tON consumables_models.model_id = models.id\n\t\t\tLEFT JOIN\n\t\t\t\tmanufacturers\n\t\t\t\tON models.manufacturer_id = manufacturers.id\n\t\t\tLEFT JOIN\n\t\t\t\tprinters\n\t\t\t\tON consumables_models.model_id = printers.model_id\n\t\t\tGROUP BY\n\t\t\t\tconsumables.id\n\t\t\tORDER BY\n\t\t\t\t{$sort} {$dir}"; $consumables = $db->query($sql)->asObjects(); #$consumables = fRecordSet::build('Consumable', NULL, array($sort => $dir)); #$models = fRecordSet::build('Model', NULL, array('name' => 'asc')); #$models->precreateManufacturers(); // Include page to show table include 'views/consumables/index.php'; } /** * Add a new consumable */ if ($action == 'add') {
<?php include 'inc/init.php'; fAuthorization::requireLoggedIn(); $breadcrumbs[] = array('name' => 'Subscription', 'url' => Subscription::makeURL('list'), 'active' => true); $action = fRequest::getValid('action', array('list', 'add', 'edit', 'delete')); $sort = fCRUD::getSortColumn(array('name', 'status', 'method', 'state')); $sort_order = fCRUD::getSortDirection('asc'); $subscription_id = fRequest::get('subscription_id', 'integer'); $check_id = fRequest::get('check_id', 'integer'); $manage_url = $_SERVER['SCRIPT_NAME']; // --------------------------------- // if ('delete' == $action) { $class_name = 'Subscription'; try { $obj = new Subscription($subscription_id); $check = new Check($obj->getCheckId()); $delete_text = 'Are you sure you want to delete your subscription to <strong>' . $check->getName() . '</strong>?'; if (fRequest::isPost()) { fRequest::validateCSRFToken(fRequest::get('token')); $obj->delete(); fMessaging::create('success', $manage_url, 'The subscription for ' . $check->getName() . ' was successfully deleted'); fURL::redirect($manage_url); } } catch (fNotFoundException $e) { fMessaging::create('error', $manage_url, 'The subscription requested, ' . fHTML::encode($date) . ', could not be found'); fURL::redirect($manage_url); } catch (fExpectedException $e) { fMessaging::create('error', fURL::get(), $e->getMessage()); } include VIEW_PATH . '/delete.php';