Commit eed7135b authored by Malcolm Blaney's avatar Malcolm Blaney

Integrate timezones into cron process, which meant changes to the

user and config classes so that the correct timezone could be set
for each group. The main modules that use cron, (Invoice, Purchase
and Stock), required updating for this too. Some more changes for
updated jquery-ui and jquery-layout libraries, and layout changes
are now saved by layout_editor.php.
parent 25f03c0c
......@@ -74,68 +74,50 @@ class Invoice extends Base {
}
public function Cron() {
if (!$this->Run(date('H:00:00'))) return;
// Sending mail could take a long time, so remove the time limit.
set_time_limit(0);
$time = '11pm';
// Sending invoices is hard coded to run at 11pm, but other jobs can be
// customised to run at other times, see below.
if ($this->Run($time)) {
// Returns a list of groups where 'invoice-day' matches today's date.
$run_groups = $this->RunGroups('invoice-day', $time);
for ($i = 0; $i < count($run_groups); $i++) {
$group = $run_groups[$i];
$this->user = new User($this->owner, $group);
// Check if a surcharge is being added for this group, otherwise can
// just skip straight to getting the current purchase data.
$surcharge = $this->Substitute('surcharge') == 'true' ? true : false;
$data = $surcharge ? $this->AddSurcharge() : $this->Data(false);
$total = count($data['grid']);
if ($total == 0) continue;
$sent = 0;
for ($j = 0; $j < $total; $j++) {
$result = $this->SendInvoice($data['grid'][$j]);
if ($result['done'] !== true) {
// Add a notification for unsent invoices.
$description = 'Cron: '.$result['error'];
if ($group !== '') {
$description .= ' for '.ucfirst($group);
}
$this->Notification('invoice', 'Invoice', $description, 'system',
$group);
}
else {
$sent++;
}
}
if ($sent == 1) {
$description = 'Cron: sent <b>1</b> invoice';
// Returns a list of groups where 'invoice-day' matches today's date.
$run_groups = $this->RunGroups('invoice-day');
for ($i = 0; $i < count($run_groups); $i++) {
$group = $run_groups[$i]['group'];
$timezone = $run_groups[$i]['timezone'];
$this->user = new User($this->owner, $group, $timezone);
// Check if a surcharge is being added for this group, otherwise can
// just skip straight to getting the current purchase data.
$surcharge = $this->Substitute('surcharge') == 'true' ? true : false;
$data = $surcharge ? $this->AddSurcharge() : $this->Data(false);
$total = count($data['grid']);
if ($total == 0) continue;
$sent = 0;
for ($j = 0; $j < $total; $j++) {
$result = $this->SendInvoice($data['grid'][$j]);
if ($result['done'] !== true) {
// Add a notification for unsent invoices.
$description = 'Cron: '.$result['error'];
if ($group !== '') {
$description .= ' for '.ucfirst($group);
}
$this->Notification('invoice', 'Invoice', $description, 'system',
$group);
}
else if ($sent > 1) {
$description = 'Cron: sent <b>'.$sent.'</b> invoices';
if ($group !== '') {
$description .= ' for '.ucfirst($group);
}
$this->Notification('invoice', 'Invoice', $description, 'system',
$group);
else {
$sent++;
}
}
// Returns a list of groups where 'remove-orders' matches today's date.
$run_groups = $this->RunGroups('invoice-remove-orders', $time);
$total = count($run_groups);
for ($i = 0; $i < $total; $i++) {
$group = $run_groups[$i];
$this->user = new User($this->owner, $group);
$purchase = new Purchase($this->user, $this->owner);
$purchase->RemoveAllPurchases();
$description = 'Cron: removed group order';
if ($sent == 1) {
$description = 'Cron: sent <b>1</b> invoice';
if ($group !== '') {
$description .= ' for '.ucfirst($group);
}
$this->Notification('invoice', 'Invoice', $description, 'system',
$group);
}
else if ($sent > 1) {
$description = 'Cron: sent <b>'.$sent.'</b> invoices';
if ($group !== '') {
$description .= ' for '.ucfirst($group);
}
......@@ -143,15 +125,30 @@ class Invoice extends Base {
$group);
}
}
else if (!$this->Run(date('H:00:00'))) return;
// Returns a list of groups where 'remove-orders' matches today's date.
$run_groups = $this->RunGroups('invoice-remove-orders');
for ($i = 0; $i < count($run_groups); $i++) {
$group = $run_groups[$i]['group'];
$timezone = $run_groups[$i]['timezone'];
$this->user = new User($this->owner, $group, $timezone);
$purchase = new Purchase($this->user, $this->owner);
$purchase->RemoveAllPurchases();
$description = 'Cron: removed group order';
if ($group !== '') {
$description .= ' for '.ucfirst($group);
}
$this->Notification('invoice', 'Invoice', $description, 'system', $group);
}
// Return a list of groups where 'invoice-group-order' matches today's date.
// This is when the group orders are sent out, individual orders can be
// sent out on a different day if required, see 'invoice-send-orders'.
$run_groups = $this->RunGroups('invoice-group-order');
for ($i = 0; $i < count($run_groups); $i++) {
$group = $run_groups[$i];
$this->user = new User($this->owner, $group);
$group = $run_groups[$i]['group'];
$timezone = $run_groups[$i]['timezone'];
$this->user = new User($this->owner, $group, $timezone);
// If there's more than one group probably only want supplier files
// sent for the organisation.
$create_files =
......@@ -181,7 +178,9 @@ class Invoice extends Base {
$organiser = new Organiser($this->user, $this->owner);
$run_groups = $organiser->MatchParents($run_groups);
for ($i = 0; $i < count($run_groups); $i++) {
$this->user = new User($this->owner, $run_groups[$i]);
$group = $run_groups[$i]['group'];
$timezone = $run_groups[$i]['timezone'];
$this->user = new User($this->owner, $group, $timezone);
// Ignore a group in the organisation such as 'non-purchasing'.
$ignore_group = $this->Substitute('invoice-ignore-group');
$send_groups = $organiser->Siblings($ignore_group);
......@@ -213,7 +212,9 @@ class Invoice extends Base {
// Send the orders to individual members.
$run_groups = $this->RunGroups('invoice-send-orders');
for ($i = 0; $i < count($run_groups); $i++) {
$this->user = new User($this->owner, $run_groups[$i]);
$group = $run_groups[$i]['group'];
$timezone = $run_groups[$i]['timezone'];
$this->user = new User($this->owner, $group, $timezone);
$this->SendOrders();
}
}
......
......@@ -290,7 +290,9 @@ class Purchase extends Base {
$run_groups = $this->RunGroups('purchase-pre-order');
for ($i = 0; $i < count($run_groups); $i++) {
$this->user = new User($this->owner, $run_groups[$i]);
$group = $run_groups[$i]['group'];
$timezone = $run_groups[$i]['timezone'];
$this->user = new User($this->owner, $group, $timezone);
if ($this->Substitute('pre-order') == 'true') {
$banking = new Banking($this->user, $this->owner);
foreach ($banking->AllSettings(false) as $user => $settings) {
......@@ -1679,6 +1681,18 @@ class Purchase extends Base {
$object = array();
$price_query = 'price';
$order_query = 'ORDER BY user, timestamp DESC';
// Allow the export to be sorted by product (same as the orders email).
if ($this->Substitute('invoice-group-format') == 'product') {
$order_query = 'ORDER BY name, timestamp DESC';
}
// Special case: also export the description field from the user's details.
$all_users = array();
if ($this->Substitute('purchase-export-description') == 'true') {
$detail = new Detail($this->user, $this->owner);
$all_users = $detail->AllUsers();
}
$search = '';
// Need to specify table for user query due to join.
if ($user !== '') {
......@@ -1797,8 +1811,15 @@ class Purchase extends Base {
}
}
else {
$current_user = $purchase['user'];
if (isset($all_users[$current_user])) {
$description = $all_users[$current_user]['description'];
if ($description !== '') {
$current_user .= ' ('.$description.')';
}
}
$object[] = array('date' => $timestamp,
'user' => $purchase['user'],
'user' => $current_user,
'name' => $purchase['name'],
'supplier' => $purchase['supplier'],
'quantity' => $quantity,
......@@ -2393,7 +2414,7 @@ class Purchase extends Base {
// An end timestamp is required when pre-order is true, otherwise
// orders for next week will be shown when purchasing this week.
if ($this->Substitute('pre-order') == 'true') {
$end = strtotime('24 hours');
$end = strtotime('48 hours');
}
// Cast to object required for json in case of an empty array.
$object['data'] = (object)$this->AllData($start, $end, true);
......
......@@ -295,21 +295,26 @@ class Stock extends Base {
}
public function Cron() {
// Only run once per day at 11pm.
$time = '11pm';
if (!$this->Run($time)) return;
if (!$this->Run(date('H:00:00'))) return;
// Order availability is imported by the user and then used here to
// overwrite purchase availabilty.
$run_groups = $this->RunGroups('stock-order-update', $time);
$mysqli = connect_db();
$run_groups = $this->RunGroups('stock-order-update');
if (count($run_groups) == 0) return;
$group_query = '';
for ($i = 0; $i < count($run_groups); $i++) {
$query = 'UPDATE stock LEFT JOIN users ON stock.user = users.user SET '.
'purchase_available = order_available WHERE '.
'users.system_group = "'.$run_groups[$i].'"';
if (!$mysqli->query($query)) {
$this->Log('Stock->Cron: '.$mysqli->error);
if ($group_query !== '') {
$group_query .= ' OR ';
}
$group_query .= 'users.system_group = "'.$run_groups[$i]['group'].'"';
}
$mysqli = connect_db();
$query = 'UPDATE stock LEFT JOIN users ON stock.user = users.user SET '.
'purchase_available = order_available WHERE '.$group_query;
if (!$mysqli->query($query)) {
$this->Log('Stock->Cron: '.$mysqli->error);
}
$mysqli->close();
}
......
......@@ -45,10 +45,9 @@ function viewAllNotifications(){dobrado.log("Notifications loading...","info");$
var notification=JSON.parse(response);$("#notification-history .list").append(notification.history);$("#notification-settings").html(notification.settings);$(".remove-notification-group").button({icons:{primary:'ui-icon-closethick'},text:false}).click(removeFromGroup);$(".notification-dialog").dialog("open");if(notification.count==historyCount+10){$(".more-notifications").show();}
historyCount=notification.count;$(".notification-group .remove-default-group").button({icons:{primary:'ui-icon-closethick'},text:false}).click(removeDefaultGroup);$(".notification-default-group .submit").button().click(addDefaultGroup);});}
var historyCount=0;var notificationCount=$(".notification").length;if(notificationCount!==0){$(".notification-count").html(notificationCount);if(!$("#control-tools").is(":checked")){$(".notification-count").show();}
$(".notification").each(function(){var href=$(this).find("a").prop("href");if(!href){href="#";}
$(this).find("a").replaceWith(function(){return $(this).html();});var item='<li><a href="'+href+'">'+$(this).html()+'</a></li>';$(".notification-menu-wrapper .menu").append(item);});$(".notification-menu-wrapper .menu").append('<li>-</li>');}
$(".more-notifications").button().click(viewAllNotifications);var viewAll='<li><a href="#" id="all-notifications">'+'View all notifications</a></li>';if($(".writer").length!==0||$(".commenteditor").length!==0){var loadingNotification='<li><a href="#" id="loading-notification">'+'Loading...</a></li>';$(".notification-menu-wrapper .menu").append(loadingNotification);$(".notification-menu-wrapper .menu").menu("refresh");$.post("/php/request.php",{request:"notification",action:"exists",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"notifications exists")){return;}
$("#loading-notification").parent().remove();var notification=JSON.parse(response);if(!notification.exists){var addNotification='<li><a href="#" id="add-notification">'+'Add notification</a></li>';$(".notification-menu-wrapper .menu").append(addNotification);$("#add-notification").click(addToGroup);}
$(".notification").each(function(){var item='<li>'+$(this).html()+'</li>';$(".notification-menu-wrapper .menu").append(item);});$(".notification-menu-wrapper .menu").append('<li>-</li>');}
$(".more-notifications").button().click(viewAllNotifications);var viewAll='<li id="all-notifications">View all notifications</li>';if($(".writer").length!==0||$(".commenteditor").length!==0){var loadingNotification='<li id="loading-notification">Loading...</li>';$(".notification-menu-wrapper .menu").append(loadingNotification);$(".notification-menu-wrapper .menu").menu("refresh");$.post("/php/request.php",{request:"notification",action:"exists",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"notifications exists")){return;}
$("#loading-notification").parent().remove();var notification=JSON.parse(response);if(!notification.exists){var addNotification='<li id="add-notification">'+'Add notification</li>';$(".notification-menu-wrapper .menu").append(addNotification);$("#add-notification").click(addToGroup);}
$(".notification-menu-wrapper .menu").append(viewAll);$(".notification-menu-wrapper .menu").menu("refresh");$("#all-notifications").click(viewAllNotifications);});}
else{$(".notification-menu-wrapper .menu").append(viewAll);$(".notification-menu-wrapper .menu").menu("refresh");$("#all-notifications").click(viewAllNotifications);}}
function edit(){if($(".extended").dialog("isOpen")===true){if(dobrado.editMode){$("#control-edit").prop("checked",true);}
......@@ -56,16 +55,19 @@ else{$("#control-edit").prop("checked",false);}
return;}
if(dobrado.editMode){dobrado.closeEditor();dobrado.current="";dobrado.editMode=false;$(".editable").removeClass("border");$(".editable").attr("contenteditable",false);$.each(CKEDITOR.instances,function(){this.destroy();});}
else{dobrado.editMode=true;$(".editable").each(function(){dobrado.inlineEditor($(this).get(0));});}}
function layout(){var main=null;var header=$(".header").height();var footer=$(".footer").height();function resize(name){var difference=0;if(name==="north"){if(header!==$(".header").height()){difference=$(".header").height()-header;$(".main").css("height",$(".main").height()+difference);header=$(".header").height();main.resizeAll();}}
function layout(){var main=null;var header=$(".header").height();var footer=$(".footer").height();var left=$(".middle").css("margin-left");var right=$(".middle").css("margin-right");if(left==="0px"){left=$(".left").width();}
else{left=parseInt(left,10);}
if(right==="0px"){right=$(".right").width();}
else{right=parseInt(right,10);}
function resize(name){var difference=0;function saveLayout(name){$.post("/php/layout_editor.php",{name:name,difference:difference,url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"saveLayout")){return;}});}
if(name==="north"){if(header!==$(".header").height()){difference=$(".header").height()-header;$(".main").css("height",$(".main").height()+difference);header=$(".header").height();main.resizeAll();saveLayout("header");}}
else if(name==="south"){if(footer!==$(".footer").height()){difference=$(".footer").height()-footer;$(".main").css("height",$(".main").height()+difference);footer=$(".footer").height();if(difference>0){window.scrollBy(0,difference);}
main.resizeAll();}}}
main.resizeAll();saveLayout("footer");}}
else if(name==="east"){if(right!==$(".right").width()){difference=$(".right").width()-right;right=$(".right").width();saveLayout("right");}}
else if(name==="west"){if(left!==$(".left").width()){difference=$(".left").width()-left;left=$(".left").width();saveLayout("left");}}}
if(dobrado.layoutMode){dobrado.layoutMode=false;$(".sortable > *").css("cursor","default");$(".sortable").sortable("option","disabled",true);$(".ui-layout-resizer").css("display","none");$(".ui-layout-toggler").css("display","none");}
else{dobrado.layoutMode=true;$(".sortable > *").css("cursor","move");$(".sortable").sortable("option","disabled",false);$(".ui-layout-resizer").css("display","block");$(".ui-layout-toggler").css("display","block");if(!main){var height=$(".main").height();if(height<400){height=400;}
$(".main").css("height",height);var left=$(".middle").css("margin-left");var right=$(".middle").css("margin-right");if(left==="0px"){left=$(".left").width();}
else{left=left.substring(0,left.length-2);}
if(right==="0px"){right=$(".right").width();}
else{right=right.substring(0,right.length-2);}
main=$(".main").layout({east:{size:right},west:{size:left},onresize:resize});}}}
$(".main").css("height",height);main=$(".main").layout({east:{size:right},west:{size:left},closable:false,onresize:resize});}}}
function copy(){dobrado.hideOtherMenu("copy-menu-wrapper");dobrado.toggleMenu("copy-menu-wrapper");$("body").one("click",hideMenu);return false;}
function tools(){if(dobrado.editorLoading||$(".extended").dialog("isOpen")===true){if($("#control-tools").is(":checked")){$("#control-tools").prop("checked",false);}
else{$("#control-tools").prop("checked",true);}
......
......@@ -265,29 +265,18 @@ if (!this.dobrado.control) {
$(".notification-count").show();
}
$(".notification").each(function() {
// Find an anchor element to link to in the notification, and then
// remove all anchors from the content to preserve menu formatting.
var href = $(this).find("a").prop("href");
if (!href) {
href = "#";
}
$(this).find("a").replaceWith(function() {
return $(this).html();
});
var item = '<li><a href="' + href + '">' + $(this).html() + '</a></li>';
var item = '<li>' + $(this).html() + '</li>';
$(".notification-menu-wrapper .menu").append(item);
});
$(".notification-menu-wrapper .menu").append('<li>-</li>');
}
$(".more-notifications").button().click(viewAllNotifications);
var viewAll = '<li><a href="#" id="all-notifications">' +
'View all notifications</a></li>';
var viewAll = '<li id="all-notifications">View all notifications</li>';
// If there's a writer or commenteditor module on the page add a menu
// option to add notifications for the current page.
if ($(".writer").length !== 0 || $(".commenteditor").length !== 0) {
var loadingNotification = '<li><a href="#" id="loading-notification">' +
'Loading...</a></li>';
var loadingNotification = '<li id="loading-notification">Loading...</li>';
$(".notification-menu-wrapper .menu").append(loadingNotification);
$(".notification-menu-wrapper .menu").menu("refresh");
......@@ -302,8 +291,8 @@ if (!this.dobrado.control) {
$("#loading-notification").parent().remove();
var notification = JSON.parse(response);
if (!notification.exists) {
var addNotification = '<li><a href="#" id="add-notification">' +
'Add notification</a></li>';
var addNotification = '<li id="add-notification">' +
'Add notification</li>';
$(".notification-menu-wrapper .menu").append(addNotification);
$("#add-notification").click(addToGroup);
}
......@@ -355,33 +344,80 @@ if (!this.dobrado.control) {
function layout() {
// main is used to refer to the layout.
// main is used to refer to the layout object.
var main = null;
// Store the values of resizable areas to compare to on resize events.
var header = $(".header").height();
var footer = $(".footer").height();
// If the middle div has non-zero values for "margin-left" and
// "margin-right", use them to set the widths of left and right divs.
var left = $(".middle").css("margin-left");
var right = $(".middle").css("margin-right");
if (left === "0px") {
left = $(".left").width();
}
else {
left = parseInt(left, 10);
}
if (right === "0px") {
right = $(".right").width();
}
else {
right = parseInt(right, 10);
}
function resize(name) {
var difference = 0;
function saveLayout(name) {
$.post("/php/layout_editor.php", { name: name,
difference: difference,
url: location.href,
token: dobrado.token },
function(response) {
if (dobrado.checkResponseError(response, "saveLayout")) {
return;
}
});
}
if (name === "north") {
// Want to change the height of the main div when the header is changed.
if (header !== $(".header").height()) {
difference = $(".header").height() - header;
// Change the height of the main div when the header is changed.
$(".main").css("height", $(".main").height() + difference);
header = $(".header").height();
main.resizeAll();
saveLayout("header");
}
}
else if (name === "south") {
// Also change the height of the main div when the footer is changed.
if (footer !== $(".footer").height()) {
difference = $(".footer").height() - footer;
// Change the height of the main div when the footer is changed.
$(".main").css("height", $(".main").height() + difference);
footer = $(".footer").height();
if (difference > 0) {
// Scroll the window otherwise it looks like nothing changed.
window.scrollBy(0, difference);
}
main.resizeAll();
saveLayout("footer");
}
}
else if (name === "east") {
if (right !== $(".right").width()) {
difference = $(".right").width() - right;
right = $(".right").width();
saveLayout("right");
}
}
else if (name === "west") {
if (left !== $(".left").width()) {
difference = $(".left").width() - left;
left = $(".left").width();
saveLayout("left");
}
}
}
......@@ -407,26 +443,9 @@ if (!this.dobrado.control) {
height = 400;
}
$(".main").css("height", height);
// If the middle div has non-zero values for "margin-left" and
// "margin-right", use them to set the widths of left and right divs.
var left = $(".middle").css("margin-left");
var right = $(".middle").css("margin-right");
if (left === "0px") {
left = $(".left").width();
}
else {
// Remove "px" from the string.
left = left.substring(0, left.length - 2);
}
if (right === "0px") {
right = $(".right").width();
}
else {
// Remove "px" from the string.
right = right.substring(0, right.length - 2);
}
main = $(".main").layout({ east: { size: right },
west: { size: left },
closable: false,
onresize: resize });
}
}
......
......@@ -24,9 +24,14 @@ class Config {
date_default_timezone_set($this->Get('timezone'));
}
public function SetUser($user) {
public function SetUser($user, $timezone = '') {
$this->user = $user;
date_default_timezone_set($this->Get('timezone'));
if ($timezone === '') {
date_default_timezone_set($this->Get('timezone'));
}
else {
date_default_timezone_set($timezone);
}
}
// Allow tracking code to be added per install, added to every page.
......
<?php
// Dobrado Content Management System
// Copyright (C) 2011 Malcolm Blaney
// Copyright (C) 2015 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
......@@ -17,13 +17,13 @@
function write_file($filename, $content) {
// Remove a file if all relevant style rules have been removed.
if ($content === "") {
if ($content === '') {
if (file_exists($filename)) unlink($filename);
return;
}
$handle = fopen($filename, "w");
$handle = fopen($filename, 'w');
if (!$handle) {
error_log('Error opening file: '.$filename);
log_db('Error opening file: '.$filename);
return;
}
fwrite($handle, $content);
......@@ -36,36 +36,36 @@ function style($selector, $rules) {
$style = $selector." {\n";
foreach ($rules as $property => $value) {
// Add browser specific property names.
if ($property == "border-radius" || $property == "box-shadow") {
$style .= " -moz-".$property." : ".$value.";\n";
$style .= " -webkit-".$property." : ".$value.";\n";
if ($property == 'border-radius' || $property == 'box-shadow') {
$style .= ' -moz-'.$property.' : '.$value.";\n";
$style .= ' -webkit-'.$property.' : '.$value.";\n";
}
// IE compatability for opacity.
else if ($property == "opacity") {
else if ($property == 'opacity') {
$ie_value = $value * 100;
$style .= ' -ms-filter:"progid:DXImageTransform.Microsoft.Alpha'.
'(Opacity='.$ie_value.')"'.";\n";
$style .= " filter: alpha(opacity=".$ie_value.");\n";
$style .= ' filter: alpha(opacity='.$ie_value.");\n";
}
$style .= " ".$property." : ".$value.";\n";
$style .= ' '.$property.' : '.$value.";\n";
}
$style .= "}\n";
return $style;
}
function fetch_style($result) {
$style = "";
$style = '';
// Selectors using the 'hover' pseudo-class go at the end of each group.
$hover_style = "";
$media = "";
$selector = "";
$hover_style = '';
$media = '';
$selector = '';
$rules = array();
while ($fetch_style = $result->fetch_assoc()) {
if ($selector != $fetch_style['selector'] ||
$media != $fetch_style['media']) {
// The media query or current selector has changed, so format
// the current style block for inclusion in a css file.
if (preg_match("/a:hover$/", $selector)) {
if (preg_match('/a:hover$/', $selector)) {
$hover_style .= style($selector, $rules);
}
else {
......@@ -84,13 +84,13 @@ function fetch_style($result) {
// Group hover_style in with the current block before starting
// the new media query.
$style .= $hover_style;
$hover_style = "";
$hover_style = '';
// Close the last media query group if it exists.
if ($media != "" && $style != "") {
if ($media != '' && $style != '') {
$style .= "}\n";
}
$media = $fetch_style['media'];
if ($media != "") {
if ($media != '') {
$style .= $media." {\n";
}
}
......@@ -100,7 +100,7 @@ function fetch_style($result) {
$style .= $hover_style;
// Close the last media query group if it exists.
if ($media != "" && $style != "") {
if ($media != '' && $style != '') {
$style .= "}\n";
}
return $style;
......@@ -111,46 +111,83 @@ function write_site_style() {
$query = 'SELECT media, selector, property, value FROM site_style '.
'ORDER BY media, selector, property';
if ($result = $mysqli->query($query)) {
write_file("../site.css", fetch_style($result));
write_file('../site.css', fetch_style($result));
$result->close();
}
else {
error_log('write_site_style: '.$mysqli->error);
log_db('write_site_style: '.$mysqli->error);
}
$mysqli->close();
}
function write_page_style($user, $file) {
preg_match("/([^\/]+)\.css$/", $file, $matches);
preg_match('/([^\/]+)\.css$/', $file, $matches);
$page = $matches[1];
if ($page === "") return;
if ($page === '') return;
$mysqli = connect_db();
$query = 'SELECT media, selector, property, value FROM page_style '.
'WHERE user="'.$user.'" AND name="'.$page.
'" ORDER BY media, selector, property';
$query = 'SELECT media, selector, property, value FROM page_style WHERE '.
'user = "'.$user.'" AND name = "'.$page.'" ORDER BY media, selector, '.
'property';
if ($result = $mysqli->query($query)) {
write_file($file, fetch_style($result));
$result->close();
}
else {
error_log('write_page_style: '.$mysqli->error);
log_db('write_page_style: '.$mysqli->error, $user, '', $page);
}
$mysqli->close();
}
function write_box_style($user, $file) {
$mysqli = connect_db();
$query = 'SELECT media, selector, property, value FROM box_style '.
'WHERE user="'.$user.'" ORDER BY media, selector, property';
$query = 'SELECT media, selector, property, value FROM box_style WHERE '.
'user = "'.$user.'" ORDER BY media, selector, property';
if ($result = $mysqli->query($query)) {
write_file($file, fetch_style($result));
$result->close();
}
else {
error_log('write_box_style: '.$mysqli->error);
log_db('write_box_style: '.$mysqli->error, $user);
}
$mysqli->close();
}
function page_value($user, $page, $selector, $property, $media = '') {
$value = '';
$mysqli = connect_db();
$query = 'SELECT value FROM page_style WHERE user = "'.$user.'" AND '.
'name = "'.$page.'" AND media = "'.$media.'" AND '.
'selector = "'.$selector.'" AND property = "'.$property.'"';
if ($result = $mysqli->query($query)) {
if ($page_style = $result->fetch_assoc()) {
$value = $page_style['value'];
}
$result->close();
}
else {
log_db('page_value: '.$mysqli->error, $user, '', $page);
}
$mysqli->close();
return $value;
}
function site_value($selector, $property, $media = '') {
$value = '';
$mysqli = connect_db();
$query = 'SELECT value FROM site_style WHERE media = "'.$media.'" AND '.
'selector = "'.$selector.'" AND property = "'.$property.'"';
if ($result = $mysqli->query($query)) {
if ($site_style = $result->fetch_assoc()) {
$value = $site_style['value'];
}
$result->close();
}
else {
log_db('site_value: '.$mysqli->error);
}
$mysqli->close();
return $value;
}
?>
......@@ -89,7 +89,7 @@ if ($result = $mysqli->query($query)) {
// force an update of the module.
$query = 'UPDATE installed_modules SET version = "'.$version.'", '.
'title = "'.$title.'", description = "'.$description.'", '.
'display = "'.$display.'" WHERE user = "'.$_SESSION["user"].'" AND '.
'display = "'.$display.'" WHERE user = "'.$user->name.'" AND '.
'label = "'.$label.'"';
if (!$mysqli->query($query)) {
log_db("installer 1: ".$mysqli->error);
......@@ -97,7 +97,7 @@ if ($result = $mysqli->query($query)) {
$update = true;
}
else {
$query = 'INSERT INTO installed_modules VALUES ("'.$_SESSION["user"].'", '.
$query = 'INSERT INTO installed_modules VALUES ("'.$user->name.'", '.
'"'.$label.'", "'.$version.'", "'.