Commit eaa9602d authored by Mal's avatar Mal

Added Cron method to module interface, and changed Factory method

to take two parameters.
Config module now uses camel case for method names for consistency
with other modules. Also SetTimezone is now called as soons as
a Config module is instantiated, so modules don't need to do it.
Backup method has been moved from Invoice module to Control module.
Invoice module now checks for a parent organisations when Cron is
called, and sends collated ordering information for child system_groups
to the configured email address for the organisation.
Organiser module now provides MatchParents method used by Invoice
module when checking for organisations.
notify table now has a 'public' column used by rss.php to only show
public items.
New Notification module can create private notifications.
User module can now take option user and group parameters so that
SESSION variable doesn't have to be changed.
parent 2d4e3516
......@@ -10,6 +10,7 @@ php/modules/Graph.php
php/modules/Grid.php
php/modules/Invoice.php
php/modules/Manager.php
php/modules/Organiser.php
php/modules/Payment.php
php/modules/Player.php
php/modules/Post.php
......@@ -33,6 +34,7 @@ js/dobrado.graph.js
js/dobrado.grid.js
js/dobrado.invoice.js
js/dobrado.manager.js
js/dobrado.organiser.js
js/dobrado.payment.js
js/dobrado.player.js
js/dobrado.purchase.js
......
......@@ -149,7 +149,11 @@ class Banking extends Base {
$mysqli->close();
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......@@ -252,8 +256,6 @@ class Banking extends Base {
}
public function SaveNextWeek($us_next_week) {
// strtotime depends on the timezone.
$this->config->set_timezone();
// Use the configured day of the week for the co-op to find the next time
// the co-op will be held. Due to the way relative dates work, need to
// check if 'this (day)' is in the past, otherwise use 'next (day)'.
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -59,11 +59,11 @@ class Browser extends Base {
}
$size = $matches[1];
// TODO: max_upload needs to be a user property, not config.
if ((int)$size > $this->config->max_upload()) {
if ((int)$size > $this->config->MaxUpload()) {
$object["error"] = "Upload directory full.";
return $object;
}
$max_file_size = $this->config->max_file_size();
$max_file_size = $this->config->MaxFileSize();
if ($_FILES["upload"]["size"] > $max_file_size) {
$max_file_size /= 1000000;
$object["error"] = "Upload file is too large. (max ".
......@@ -207,7 +207,11 @@ class Browser extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
......@@ -375,7 +375,11 @@ class Cart extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -151,7 +151,11 @@ class Comment extends Base {
$mysqli->close();
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......@@ -167,6 +171,8 @@ class Comment extends Base {
$this->AppendScript($path, "dobrado.comment.js", true);
$mysqli = connect_db();
// TODO: To have a comments feed, this table structure needs to be
// similar to post table structure so that it can be queried by rss.php.
$query = 'CREATE TABLE IF NOT EXISTS comment ('.
'user VARCHAR(50) NOT NULL,'.
'box_id INT UNSIGNED NOT NULL,'.
......@@ -280,7 +286,6 @@ class Comment extends Base {
$remove = '<button id="remove-comment-'.$comment_id.
'" class="remove-comment"></button>';
}
$this->config->set_timezone();
return '<div class="comment-wrapper">'.
$remove.'<div class="comment-content">'.
nl2br(htmlspecialchars(stripslashes($content))).'</div>'.
......
......@@ -116,21 +116,24 @@ class Detail extends Base {
}
public function Factory($fn) {
if (is_array($fn)) {
$name = $fn[0];
public function Cron() {
}
public function Factory($fn, $p) {
if (is_array($p)) {
// Account module calls UpdateUser through module interface.
if ($name == "UpdateUser" && count($fn) == 5) {
$user = $fn[1];
$first = $fn[2];
$last = $fn[3];
$phone = $fn[4];
if ($fn == "UpdateUser" && count($p) == 4) {
$user = $p[0];
$first = $p[1];
$last = $p[2];
$phone = $p[3];
return $this->UpdateUser($user, $first, $last, $phone);
}
if ($name == "User" && count($fn) == 2) {
$user = $fn[1];
return $this->User($user);
}
return;
}
if ($fn == "User") {
return $this->User($p);
}
}
......@@ -204,10 +207,12 @@ class Detail extends Base {
public function AllUsers() {
$object = array();
$organiser = new Organiser($this->user, $this->owner, $this->config);
$mysqli = connect_db();
$query = 'SELECT users.user, email, first, last, phone FROM '.
'users LEFT JOIN user_detail ON users.user=user_detail.user WHERE '.
'users.system_group="'.$this->user->group.'"';
$organiser->GroupQuery();
if ($result = $mysqli->query($query)) {
while ($detail = $result->fetch_assoc()) {
$object[$detail["user"]] = array("first" => $detail["first"],
......
......@@ -109,7 +109,11 @@ class Gift extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -151,7 +151,11 @@ class Graph extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -45,7 +45,11 @@ class Grid extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
This diff is collapsed.
......@@ -177,7 +177,11 @@ class Manager extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
......@@ -32,12 +32,10 @@ class Organiser extends Base {
$action = $mysqli->escape_string($_POST["action"]);
if ($action == "show-organisations") {
// This is called on load, so ignore if user doesn't have permission.
if ($this->user->canEditSite) {
$object["list"] = $this->ShowOrganisations();
}
else {
$object["error"] = "Permission denied showing organisations.";
}
}
else if ($action == "show-members") {
if ($this->user->canEditSite) {
......@@ -125,7 +123,11 @@ class Organiser extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......@@ -214,6 +216,30 @@ class Organiser extends Base {
return $groups;
}
public function MatchParents($groups) {
$filtered = array();
$group_query = "";
for ($i = 0; $i < count($groups); $i++) {
if ($group_query != "") $group_query .= ' OR ';
$group_query .= 'system_group="'.$groups[$i].'"';
}
if ($group_query == "") return $filtered;
$mysqli = connect_db();
$query = 'SELECT system_group FROM organisation WHERE '.$group_query.
' GROUP BY name';
if ($result = $mysqli->query($query)) {
while ($organisation = $result->fetch_assoc()) {
$filtered[] = $organisation["system_group"];
}
}
else {
$this->Log('Organiser->MatchParents: '.$mysqli->error);
}
$mysqli->close();
return $filtered;
}
// Private functions below here ////////////////////////////////////////////
private function ShowOrganisations() {
......
......@@ -227,7 +227,11 @@ class Payment extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -83,7 +83,11 @@ class Player extends Base {
$this->CopyStyle($id, $old_owner, $old_id);
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
......@@ -108,12 +108,7 @@ class Post extends Base {
if ($_SESSION['page'] != $permalink) {
return false;
}
// TODO: Create a 'post_settings' table that is configurable by
// selecting the option: 'Configure Post Module' in the site editor.
// (Requires a new module method 'Configure' -- if it returns empty
// just don't include the module.) one of the options would be a text
// area to customise the format below.
$this->config->set_timezone();
// TODO: use Substitute() here.
$date = date("l F d, Y", $timestamp);
$title = $title === "" ? "" : '<h2>'.$title.'</h2>';
$author = $author === "" ? "" : 'By '.$author.' on ';
......@@ -157,7 +152,11 @@ class Post extends Base {
$this->CopyStyle($id, $old_owner, $old_id);
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......@@ -289,7 +288,6 @@ class Post extends Base {
}
// Only create a new permalink if the title was changed.
if (strcmp($title, $old_title) != 0) {
$this->config->set_timezone();
$date = date("Y-m-d", $time);
if ($title === "") {
$permalink = $date."-".mt_rand();
......@@ -384,7 +382,7 @@ class Post extends Base {
}
$mysqli->close();
copy_page($this->config->default_post(), $this->owner,
copy_page($this->config->DefaultPost(), $this->owner,
$permalink, $this->owner, $feed);
}
......
......@@ -28,9 +28,6 @@ class Purchase extends Base {
return $object;
}
// strtotime depends on the timezone.
$this->config->set_timezone();
$mysqli = connect_db();
$action = $mysqli->escape_string($_POST["action"]);
......@@ -295,7 +292,11 @@ class Purchase extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......@@ -422,19 +423,41 @@ class Purchase extends Base {
// Public functions that aren't part of interface here /////////////////////
public function AllData($timestamp, $array) {
public function AllData($timestamp, $array, $organisation = false) {
$object = array();
$query = "";
if ($organisation) {
$organiser = new Organiser($this->user, $this->owner, $this->config);
$query = 'SELECT system_group AS user, timestamp, name, '.
'SUM(quantity) AS quantity, price FROM purchase LEFT JOIN users ON '.
'purchase.user=users.user WHERE '.$organiser->GroupQuery().
' AND timestamp >= '.$timestamp.' AND name != "surcharge" '.
'GROUP BY system_group, name ORDER BY name, system_group';
}
else {
$query = 'SELECT purchase.user, timestamp, name, quantity, price FROM '.
'purchase LEFT JOIN users ON purchase.user=users.user WHERE '.
'users.system_group="'.$this->user->group.'" AND timestamp >= '.
$timestamp.' AND name != "surcharge" ORDER BY user, name';
}
$mysqli = connect_db();
$query = 'SELECT purchase.user, timestamp, name, quantity, price FROM '.
'purchase LEFT JOIN users ON purchase.user=users.user WHERE '.
'users.system_group="'.$this->user->group.'" AND timestamp >= '.
$timestamp.' AND name != "surcharge" ORDER BY user, timestamp, name';
if ($result = $mysqli->query($query)) {
while ($purchase = $result->fetch_assoc()) {
$user = $purchase["user"];
$name = $purchase["name"];
if (!is_array($object[$user])) {
$object[$user] = array();
if ($organisation) {
// When organisation is true, an array is created for each product.
// Note that this is not used with the $array parameter equal to
// true, so don't need to worry about that case.
if (!is_array($object[$name])) {
$object[$name] = array();
}
}
else {
if (!is_array($object[$user])) {
$object[$user] = array();
}
}
// The grid module requires this data as an indexed array, but when
// updating the data it's easier to do the comparison with an
......@@ -454,13 +477,25 @@ class Purchase extends Base {
"total" => $total,
"server" => true);
}
// Since this array is indexed by product name, keep the first value
// found so that purchases with later timestamps don't overwrite it.
else if (!is_array($object[$user][$name])) {
$object[$user][$name] =
array("date" => (int)$purchase["timestamp"],
"quantity" => (float)$purchase["quantity"],
"price" => (float)$purchase["price"]);
else {
// The query above is grouped by user (where user is an alias for
// system_group) so don't need to worry about duplicates in this case.
if ($organisation) {
$object[$name][$user] =
array("date" => (int)$purchase["timestamp"],
"quantity" => (float)$purchase["quantity"],
"price" => (float)$purchase["price"]);
}
else {
// Since this array is indexed by product name, keep the first value
// found so that purchases with later timestamps don't overwrite it.
if (!is_array($object[$user][$name])) {
$object[$user][$name] =
array("date" => (int)$purchase["timestamp"],
"quantity" => (float)$purchase["quantity"],
"price" => (float)$purchase["price"]);
}
}
}
}
$result->close();
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -26,8 +26,8 @@ class Reader extends Base {
$xml_url = "http://".$_SERVER['SERVER_NAME']."/";
$feed = "rss/index.php?page=".$_SESSION['page'];
$xml_url .= $this->owner == "admin" ? $feed : $this->owner."/".$feed;
$title = $this->config->title_includes_page() ?
$this->config->title().' - '.$_SESSION['page'] : $this->config->title();
$title = $this->config->TitleIncludesPage() ?
$this->config->Title().' - '.$_SESSION['page'] : $this->config->Title();
$mysqli = connect_db();
$query = 'INSERT INTO reader VALUES ("'.$this->owner.'","'.$id.'","'.
......@@ -57,7 +57,7 @@ class Reader extends Base {
}
$mysqli->close();
$this->config->set_timezone();
$this->config->SetTimezone();
// Note that SimplePie is only available to this function because it
// is called via request.php, where autoloader.php was included.
$feed = new SimplePie();
......@@ -150,7 +150,11 @@ class Reader extends Base {
// TODO: Copy from the reader table for the new module here.
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......@@ -238,8 +242,7 @@ class Reader extends Base {
$permalink = $item->get_permalink();
$date = $item->get_date();
// TODO: Provide site editor configuration option for format.
// (See same idea in Post->Content)
// TODO: use Substitute method here.
if ($title !== null) {
$content .= '<h4 class="reader-title">';
// Link the permalink to the title if it exists.
......@@ -266,7 +269,7 @@ class Reader extends Base {
}
private function PostsPerRequest() {
// Need a table lookup from reader config options.
// TODO: Use Substitute method here.
return 5;
}
......
......@@ -141,7 +141,11 @@ class Roster extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......@@ -204,9 +208,6 @@ class Roster extends Base {
// Public functions that aren't part of interface here /////////////////////
public function FirstName() {
// strtotime depends on the timezone.
$this->config->set_timezone();
$first = "";
$mysqli = connect_db();
$query = 'SELECT first FROM roster WHERE user="'.$this->user->name.'" '.
......@@ -226,9 +227,6 @@ class Roster extends Base {
}
public function Description($user = "") {
// strtotime depends on the timezone.
$this->config->set_timezone();
if ($user === "") {
$user = $this->user->name;
}
......@@ -286,9 +284,6 @@ class Roster extends Base {
$this->Log('Roster->Show 1: '.$mysqli->error);
}
// strtotime depends on the timezone.
$this->config->set_timezone();
// Get user details for autocomplete.
$detail = new Detail($this->user, $this->owner, $this->config);
$object["details"] = $detail->AllUsers();
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -83,7 +83,11 @@ class Slider extends Base {
$this->CopyStyle($id, $old_owner, $old_id);
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
......@@ -161,7 +161,11 @@ class Stock extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
......@@ -27,9 +27,6 @@ class Summary extends Base {
return $object;
}
// strtotime depends on the timezone.
$this->config->set_timezone();
$mysqli = connect_db();
$action = $mysqli->escape_string($_POST["action"]);
......@@ -86,9 +83,6 @@ class Summary extends Base {
return "";
}
// strtotime depends on the timezone.
$this->config->set_timezone();
$detail = new Detail($this->user, $this->owner, $this->config);
$user_details = $detail->User();
$name = "";
......@@ -169,7 +163,11 @@ class Summary extends Base {
$payment->NewUser();
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -83,7 +83,11 @@ class Turner extends Base {
$this->CopyStyle($id, $old_owner, $old_id);
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -86,7 +86,11 @@ class Writer extends Base {
}
public function Factory($fn) {
public function Cron() {
}
public function Factory($fn, $p) {
}
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -39,6 +39,7 @@ $object = array();
$user = new User();
$config = new Config();
$config->SetTimezone();
$module = new Module($user, $owner, $label, $config);
if (!$module->IsInstalled()) {
$object['error'] = '\''.$label.'\' module is not available';
......
<?php
// Dobrado Content Management System
// Copyright (C) 2012 Malcolm Blaney
// Copyright (C) 2013 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -43,10 +43,9 @@ include "module.php";
include "user.php";
$owner = $api['user'];
// The User class checks $_SESSION['user'] to set the name.
$_SESSION['user'] = $owner;
$user = new User();
$config = new Config();
$config->SetTimezone();
$user = new User($config, $owner);
$module = new Module($user, $owner, $api['label'], $config);
$module->Callback();
......
......@@ -16,33 +16,37 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
class Config {
public function Cron() {
return $this->Get("cron");
}
public function default_post() {