summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2016-06-14 00:14:28 -0400
committerSolomon Peachy <pizza@shaftnet.org>2016-06-14 00:14:28 -0400
commitecc48d6437a980516d82d009cc7b5e0e73e148fb (patch)
tree4de4758b76273b6254fdb402833cd8fb372141dd
parent54f988cd458ca8560215614aac877fbfa075b21a (diff)
downloadpo-ecc48d6437a980516d82d009cc7b5e0e73e148fb.tar.gz
po-ecc48d6437a980516d82d009cc7b5e0e73e148fb.tar.bz2
po-ecc48d6437a980516d82d009cc7b5e0e73e148fb.zip
[add] Initial support for printing directly to a system printer.
-rw-r--r--CHANGES1
-rw-r--r--src/album.php1
-rw-r--r--src/folder.content.php12
-rw-r--r--src/folder.php2
-rw-r--r--src/import.log.php1
-rw-r--r--src/include/common.php51
-rw-r--r--src/include/config.php5
-rw-r--r--src/include/config_site.php.dist11
-rw-r--r--src/include/print.printer.php206
-rw-r--r--src/install.php1
-rw-r--r--src/lang/en_US.php11
-rw-r--r--src/photo.move.php10
-rw-r--r--src/photo.php21
-rw-r--r--src/photo.worker.php82
-rw-r--r--src/printer.php104
-rw-r--r--src/search.tags.php1
-rw-r--r--src/search.text.advanced.php1
-rw-r--r--src/search.text.general.php3
-rw-r--r--src/sql/po.upgrade.2.37.c.to.2.38.a.sql42
-rw-r--r--src/themes/aqua/theme.php1
-rw-r--r--src/themes/blackwater/theme.php1
-rw-r--r--src/user.php2
22 files changed, 543 insertions, 27 deletions
diff --git a/CHANGES b/CHANGES
index ad49665..d1910b2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -35,6 +35,7 @@ v2.38 (Unreleased)
[misc] Allow photo worker to recover from a failed database connection
[fix] Errors upon emptying the trash weren't displayed properly
[fix] Unescaped search strings could lead to XSS bugs.
+ [add] Ability to natively print images to a direct-attached printer.
v2.37.1 (December 3, 2012)
diff --git a/src/album.php b/src/album.php
index ed1178f..27b8d19 100644
--- a/src/album.php
+++ b/src/album.php
@@ -217,6 +217,7 @@ if ($checkboxes) {
if ($po_user['type'] >= PO_USER_TYPE_CLIENT) {
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
+ print emit_print_actions($database, $po_user['id']);
}
print "</div>";
diff --git a/src/folder.content.php b/src/folder.content.php
index d741219..e054a0f 100644
--- a/src/folder.content.php
+++ b/src/folder.content.php
@@ -37,7 +37,8 @@ $move_f_request = isset($_REQUEST['move_to_f']);
$link_a_request = isset($_REQUEST['link_to_a']);
$move_a_request = isset($_REQUEST['move_to_a']);
-$print_request = isset($_REQUEST['print_req']);
+$print_request = isset($_REQUEST['print_req']);
+$printer_request = isset($_REQUEST['printer_req']);
$spool_request = isset($_REQUEST['spool_req']);
$export_request = isset($_REQUEST['export_req']);
$bulk_update_request = isset($_REQUEST['bulk_update_req']);
@@ -69,12 +70,19 @@ if ($export_request) {
}
/* Doesn't take arguments */
-if ($print_request != "") {
+if ($print_request) {
site_epilog($database);
header("Location: print.php?print_type=$_REQUEST[print_type]");
exit();
}
+/* Doesn't take arguments */
+if ($printer_request) {
+ site_epilog($database);
+ header("Location: printer.php?printer=$_REQUEST[printer]");
+ exit();
+}
+
if ($add_photo_request) {
header("Location: photo.add.php?folder=$source_folder");
exit();
diff --git a/src/folder.php b/src/folder.php
index ec8b31a..19d9414 100644
--- a/src/folder.php
+++ b/src/folder.php
@@ -147,6 +147,7 @@ if ($num_of_photos == 0) {
print "</div>";
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
+ print emit_print_actions($database, $po_user['id']);
print "</form>";
site_display_random_photos($database, 'folder', $folder_id, 10, FALSE);
@@ -242,6 +243,7 @@ if ($checkboxes) {
if ($po_user['type'] >= PO_USER_TYPE_CLIENT) {
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
+ print emit_print_actions($database, $po_user['id']);
}
print "</div>";
diff --git a/src/import.log.php b/src/import.log.php
index 8e38a4a..2f59afb 100644
--- a/src/import.log.php
+++ b/src/import.log.php
@@ -51,6 +51,7 @@ for ($i = 0 ; $i < pg_num_rows($data) ; $i++) {
}
print emit_import_actions($database, $po_user['id']);
+print emit_print_actions($database, $po_user['id']);
if (pg_num_rows($data)) {
print "<div align=\"center\">";
diff --git a/src/include/common.php b/src/include/common.php
index 6b82908..1a2b1e7 100644
--- a/src/include/common.php
+++ b/src/include/common.php
@@ -606,6 +606,7 @@ function emit_spool_actions($database, $userid) {
$rval .= emit_a(generate_link('album', $po_user['spool_album']), $strings['spool_view']) ." | ".emit_a("spool.empty.php", $strings['spool_empty'])." | ".emit_a("my.tools.php?selector=1&amp;type=spool", $strings['generic_bulk_update']);
$rval .= emit_printto();
$rval .= emit_export();
+ $rval .= emit_printtoprinter();
$rval .= "</span>";
return $rval;
@@ -634,6 +635,30 @@ function emit_import_actions($database, $userid) {
return $rval;
}
+function emit_print_actions($database, $userid) {
+ global $po_user;
+ global $strings;
+
+ $photos_in_import = pg_fetch_row(pg_query($database, "select count(identifier) from pending_prints where users = $userid"));
+ $num_photos = $photos_in_import[0];
+
+ $results_import = pg_fetch_row(pg_query($database, "select count(identifier) from print_results where users = $userid"));
+ $num_photos2 = $results_import[0];
+
+ $rval = "";
+
+ if ($num_photos > 0 || $num_photos2 > 0) {
+ $rval .= "<br/>";
+ $rval .= "<span>";
+ $rval .= "<b><a href=\"print.log.php\">".$strings['print_results'].": $num_photos2&nbsp;</a></b> ";
+ $rval .= "<b>".$strings['import_remaining'].": $num_photos&nbsp;</b> ";
+ $rval .= "</span>";
+ }
+
+ return $rval;
+}
+
+
function emit_printto() {
global $strings;
global $thm_elem;
@@ -652,6 +677,32 @@ function emit_printto() {
return $rval;
}
+function emit_printtoprinter() {
+ global $strings;
+ global $thm_elem;
+ global $po_options;
+
+ $count = 0;
+ $rval = "";
+
+ $rval .= "<span>";
+ $rval .= $thm_elem['button.printer'];
+ $rval .= "<select name=\"printer\">\n";
+ $rval .= emit_option("", '&nbsp;', TRUE);
+ foreach ($po_options['printers'] as $name => $printer) {
+ $rval .= emit_option($name, $name, FALSE);
+ $count++;
+ }
+ $rval .= "</select>\n";
+ $rval .= "</span>\n";
+
+ if ($count > 0)
+ return $rval;
+ else
+ return "";
+}
+
+
function emit_export() {
global $thm_elem;
global $strings;
diff --git a/src/include/config.php b/src/include/config.php
index 455dcea..18d7c59 100644
--- a/src/include/config.php
+++ b/src/include/config.php
@@ -119,6 +119,8 @@ $sys_dcm2pnm = "/usr/local/dicom/bin/dcm2pnm";
// Darktable RAW decoder
$sys_darktable = "/usr/local/bin/darktable-cli";
+// LP utility for printing
+$sys_lp = "/usr/bin/lp";
// PS2PDF - converts PS documents into PDF ones
$sys_ps2pdf = "/usr/bin/ps2pdf";
@@ -282,6 +284,9 @@ $po_options['scan_bitdepths'] = '8, 12, 14, 15, 16, 18, 24, 32, 36, 48';
$po_options['scan_multiscans'] = '1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16';
$po_options['scan_resolutions'] = '50, 75, 90, 93, 96, 100, 103, 107, 111, 126, 120, 126, 131, 138, 145, 150, 152, 161, 170, 181, 193, 207, 223, 241, 263, 290, 300, 322, 362, 414, 483, 580, 600, 725, 800, 966, 1000, 1200, 1450, 1600, 1800, 2000, 2200, 2400, 2700, 2820, 2900, 3600, 4000, 4800, 9600';
+/* Printing support. */
+$po_options['printers'] = array();
+
/* We need this to track changes */
$po_options_default = array();
diff --git a/src/include/config_site.php.dist b/src/include/config_site.php.dist
index e1eb9ed..2279109 100644
--- a/src/include/config_site.php.dist
+++ b/src/include/config_site.php.dist
@@ -29,4 +29,15 @@ $po_options['lang'] = "en_US";
// set this to 0 once your installation is finished.
$install_enabled = 1;
+// An example printer
+//$po_options['printers']['laser'] = array(
+// 'queue_name' => 'laser',
+// 'target_x' => 1200,
+// 'target_y' => 1800,
+// 'pagesize' => 'Letter',
+// 'options' => array (),
+// 'sharpen_sigma' => 0.4,
+// 'sharpen_amount' => 1.4,
+// 'sharpen_threshold' => 0.05,
+// );
?>
diff --git a/src/include/print.printer.php b/src/include/print.printer.php
new file mode 100644
index 0000000..4955922
--- /dev/null
+++ b/src/include/print.printer.php
@@ -0,0 +1,206 @@
+<?php
+
+// Copyright (C) 2016 Solomon Peachy (pizza@shaftnet.org)
+
+// This program 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.
+
+// This program 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 this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+include_once "config.php";
+include_once "common.php";
+include_once "site.php";
+
+function photo_print_queue_one($database, $photo, $version, $printer) {
+ global $strings;
+ global $po_user;
+ global $passwords;
+
+ $output = "";
+
+ $photo_data = pg_fetch_assoc(pg_query($database, "select users, hide_original, title, can_access_photo(photo.identifier, $po_user[id], '{".$passwords."}') as ok from photo where identifier = $photo"));
+
+ /* Make sure we can access it! */
+ if (($photo_data['users'] != $po_user['id']) &&
+ !($po_user['type'] == PO_USER_TYPE_ADMIN)) {
+ if (($photo_data['ok'] != 't') || ($photo_data['hide_original'] != 't')) {
+ return "XXX permission denied: $photo \n";
+ }
+ }
+
+ $output .= "<li>".sprintf($strings['print_queueing'], "$photo:$version")."</li>\n";
+
+ $element = array();
+ $element['version'] = $version;
+ $element['photo'] = $photo;
+ $element['title'] = $photo_data['title'];
+ $element['user'] = $po_user;
+ $element['owner'] = $photo_data['users'];
+ $element['printer'] = $printer;
+ $element['size'] = 4;
+
+ $serialized = base64_encode(serialize($element));
+
+ /* This is implicitly ROW EXCLUSIVE locked */
+ pg_query($database, "INSERT INTO pending_prints(identifier, users, version, print_data)
+ VALUES (nextval('pending_prints_sequence'), $po_user[id],
+ $version, '$serialized')");
+
+ return $output;
+}
+
+function photo_print_single($database, $single) {
+ global $strings;
+ global $image_repository_path;
+ global $sys_convert;
+ global $sys_gm;
+ global $use_gm;
+ global $sys_lp;
+ global $tmp_volume_path;
+
+ $retval = FALSE;
+ $output = "";
+
+ $printer = $single['printer'];
+ $version = $single['version'];
+ $title = $single['title'];
+ if ($title == "")
+ $title = $strings['photo_no_title'] ." - $single[photo]";
+
+ $photo_version_data = pg_query($database, "
+ select f.path as original_path, v.original_image_name, f.x_res, f.y_res
+ from photo_version v, files f
+ where v.identifier = $version and v.identifier = f.version and f.size = $single[size]");
+
+ $photo_version_single = pg_fetch_assoc($photo_version_data, 0);
+ $file_name = $image_repository_path."/".$photo_version_single['original_path'];
+ $native_x = $photo_version_single['x_res'];
+ $native_y = $photo_version_single['y_res'];
+ $original_name = $photo_version_single['original_image_name'];
+
+ /* check for the source file's existence */
+ if (!is_file($file_name)) {
+ $output .= err_str($strings['errors_file_not_found'] ." : ". sprintf($strings['export_skipped'],emit_a(generate_link('photo', $single['photo']), $title)));
+ return $output;
+ }
+
+ $output .= "<li>Printing $original_name - $single[photo]:$single[version]:$single[size]</li>\n";
+
+ # Size relations
+ $target_max = ($printer['target_x'] > $printer['target_y']) ? $printer['target_x'] : $printer['target_y'];
+
+ # generate sane filename
+ $tmp_filename = tempnam($tmp_volume_path, "po.print.");
+ unlink($tmp_filename);
+ $tmp_filename .= ".ppm";
+
+ # set up processing
+ if ($use_gm) {
+ $cmdline = "$sys_gm convert ";
+ } else {
+ $cmdline = "$sys_convert";
+ }
+
+ $cmdline .= " " . escapeshellarg($file_name) ." ";
+
+ # scale to native proportions
+ $cmdline .= " -resize ".$target_max."x".$target_max." ";
+
+ # rotate if needed
+ if (($printer['target_x'] > $printer['target_y'] && $native_x < $native_y) ||
+ ($printer['target_x'] < $printer['target_y'] && $native_x > $native_y)) {
+ $cmdline .= " -rotate 90 ";
+ }
+
+ # crop to final
+ $cmdline .= " -crop ".$printer['target_x']."x".$printer['target_y']."+0+0 +repage -gravity center ";
+
+ # sharpen as needed
+ $cmdline .= " -unsharp ". escapeshellarg("0x". $printer['sharpen_sigma'] ."+". $printer['sharpen_amount'] ."+". $printer['sharpen_threshold']) . " ";
+
+ # XXX color transform?
+
+ $cmdline .= " " . escapeshellarg($tmp_filename);
+
+// $output .= "<pre>$cmdline</pre>\n";
+ system($cmdline, $retval);
+
+ if ($retval) {
+ $output .= err_str("FAILED: >>><pre>$cmdline</pre><<< $retval\n");
+ return $output;
+ }
+
+ # Set up printing.
+ $cmdline = "$sys_lp -d '$printer[queue_name]' ";
+ $cmdline .= " -t '$single[photo]:$single[version]:$original_name' ";
+ $cmdline .= " -o PageSize=$printer[pagesize] -o PageRegion=$printer[pagesize] -o ImageableArea=$printer[pagesize] -o PaperDimension=$printer[pagesize] ";
+ foreach ($printer['options'] as $opt) {
+ $cmdline .= " -o '$opt' ";
+ }
+ $cmdline .= " $tmp_filename ";
+
+ if (!$retval) {
+// $output .= "<pre>$cmdline</pre>\n";
+ system($cmdline, $retval);
+
+ if ($retval) {
+ $output .= err_str("FAILED: >>><pre>$cmdline</pre><<< $retval\n");
+ return $output;
+ }
+ }
+
+ unlink($tmp_filename);
+ return $output;
+}
+
+function photo_print_worker($database, $userid = FALSE, $background = TRUE) {
+
+ while (TRUE) {
+ $output = '';
+
+ $add = '';
+ if ($userid !== FALSE) {
+ $add = " where users = $userid ";
+ }
+
+ /* Obtain a row from the database */
+ pg_query($database, "BEGIN");
+ $result = pg_query($database, "LOCK TABLE pending_prints IN SHARE ROW EXCLUSIVE MODE");
+ if ($result === FALSE) {
+ pg_query($database, "ABORT");
+ break;
+ }
+ $data = pg_query($database, "select identifier, print_data from pending_prints $add order by identifier LIMIT 1");
+ if ($data !== FALSE && pg_num_rows($data) >= 1) {
+ $row = pg_fetch_row($data);
+ pg_query($database, "delete from pending_prints where identifier = $row[0]");
+ $result = pg_query($database, "COMMIT");
+ } else {
+ $result = pg_query($database, "ABORT");
+ break;
+ }
+ if ($result === FALSE) # Just in case!
+ break;
+
+ $single = unserialize(base64_decode($row[1]));
+
+ $output .= photo_print_single($database, $single);
+
+ if ($background) {
+ $po_user = $single['user'];
+ $output = pg_escape_string($output);
+ $foo = pg_query($database, "insert into print_results(users, log_data) values ($po_user[id], '$output')");
+ } else {
+ print $output;
+ }
+ }
+}
diff --git a/src/install.php b/src/install.php
index 75eda6e..f130fa4 100644
--- a/src/install.php
+++ b/src/install.php
@@ -51,6 +51,7 @@ $versions = array("(none)" => array("function" => "po_new_install"),
"2.36.D" => array("file" => "po.upgrade.2.36.d.to.2.37.a.sql"),
"2.37.A" => array("file" => "po.upgrade.2.37.a.to.2.37.b.sql"),
"2.37.B" => array("file" => "po.upgrade.2.37.b.to.2.37.c.sql"),
+ "2.37.C" => array("file" => "po.upgrade.2.37.c.to.2.38.a.sql"),
);
// to prepare a dump, perform a new install + upgrade, and then do this:
diff --git a/src/lang/en_US.php b/src/lang/en_US.php
index 19137a9..145de7d 100644
--- a/src/lang/en_US.php
+++ b/src/lang/en_US.php
@@ -460,7 +460,15 @@ $strings['import_remaining'] = 'Images remaining';
$strings['import_results'] = 'Images imported';
$strings['import_log'] = 'Import log';
- /* Generic stuff */
+/* Printing */
+$strings['print_queueing'] = "Queueing <strong>'%s'</strong> for printing.";
+$strings['print_all_queued'] = 'images queued for printing.';
+$strings['print_all_complete'] = 'All images printed.';
+$strings['print_results'] = 'Images printed';
+$strings['print_log'] = 'Print log';
+$strings['print_invalid'] = 'Invalid Printer Selected';
+
+/* Generic stuff */
$strings['generic_username'] = "Username";
$strings['generic_password'] = "Password";
@@ -655,6 +663,7 @@ $strings['generic_empty_trash'] = 'Empty Trash';
$strings['generic_is_empty'] = 'There are no viewable images';
$strings['generic_print'] = 'Print';
+$strings['generic_printer'] = 'Printer';
$strings['generic_brochure'] = 'Brochure';
$strings['generic_empty'] = 'Empty';
$strings['generic_plain'] = 'Plain';
diff --git a/src/photo.move.php b/src/photo.move.php
index bffef76..66ae3a0 100644
--- a/src/photo.move.php
+++ b/src/photo.move.php
@@ -52,6 +52,7 @@ $transform = pg_escape_string($_REQUEST['transform']);
$transform_request = isset($_REQUEST['rotate_req']);
$export_request = isset($_REQUEST['export_req']);
$print_request = isset($_REQUEST['print_req']);
+$printer_request = isset($_REQUEST['printer_req']);
$spool_request = isset($_REQUEST['spool_req']);
$watermark_request = isset($_REQUEST['watermark_req']);
@@ -79,7 +80,14 @@ if ($print_request) {
site_epilog($database);
header("Location: print.php?print_type=$_REQUEST[print_type]");
exit();
- }
+}
+
+/* Doesn't take arguments */
+if ($printer_request) {
+ site_epilog($database);
+ header("Location: printer.php?printer=$_REQUEST[printer]&photo_id=$_REQUEST[photo_id]&version_id=$_REQUEST[version]");
+ exit();
+}
/* Doesn't take arguments */
if ($goto_f_request && ($destination_folder != "")) {
diff --git a/src/photo.php b/src/photo.php
index 91ffdeb..059cc9c 100644
--- a/src/photo.php
+++ b/src/photo.php
@@ -973,7 +973,6 @@ if ($po_user['id'] == $owner_id || $po_user['type'] == PO_USER_TYPE_ADMIN) {
}
print "<span>";
-
if ($po_user['id'] == $owner_id || $po_user['type'] == PO_USER_TYPE_ADMIN) {
print sprintf($thm_elem['button.edit'], "photo.edit.php?photo=$photo_id&amp;album=$album_id");
@@ -984,15 +983,20 @@ if ($po_user['id'] == $owner_id || $po_user['type'] == PO_USER_TYPE_ADMIN) {
if ($album_id)
print $thm_elem['button.set.thumb.a'];
- }
+}
if ($po_user['type'] > PO_USER_TYPE_CLIENT) {
print $thm_elem['button.set.as.watermark'];
- }
+}
if ($po_user['type'] >= PO_USER_TYPE_CLIENT) {
print $thm_elem['button.add.to.spool'];
- }
+}
+
+if ($po_user['type'] >= PO_USER_TYPE_CLIENT) {
+ print emit_printtoprinter();
+}
+
print "</span>\n";
if ($po_user['id'] == $owner_id || $po_user['type'] == PO_USER_TYPE_ADMIN) {
@@ -1005,10 +1009,13 @@ if ($po_user['type'] >= PO_USER_TYPE_CLIENT) {
if (count($album_all)) {
print emit_album_actions($album_all, $album_id);
}
- print emit_spool_actions($database, $po_user['id']);
- print emit_import_actions($database, $po_user['id']);
+ print "</form>\n";
+
+// print emit_spool_actions($database, $po_user['id']);
+// print emit_import_actions($database, $po_user['id']);
+// print emit_print_actions($database, $po_user['id']);
}
-print "</form>\n";
+
print "</div>";
diff --git a/src/photo.worker.php b/src/photo.worker.php
index 24979ac..479990f 100644
--- a/src/photo.worker.php
+++ b/src/photo.worker.php
@@ -22,9 +22,11 @@ chdir(__DIR__); // Ensures all includes work
include_once "include/config.php";
include_once "include/site.php";
include_once "include/import.php";
+include_once "include/print.printer.php";
$database = FALSE;
-$children = array();
+$workers = array();
+$printers = array();
$memcache = FALSE;
if (!$external_workers) {
@@ -32,14 +34,14 @@ if (!$external_workers) {
exit(1);
}
-function child_fn() {
+function child_fn_worker() {
global $database;
global $memcache;
global $po_memcache;
global $po_worker;
global $site_url;
- print "Starting Worker\n";
+ print "Starting Import Worker\n";
/* Connect to the memcache */
if (count($po_memcache)) {
@@ -57,20 +59,63 @@ function child_fn() {
}
}
-function dofork() {
- global $children;
+function child_fn_printer() {
+ global $database;
+ global $memcache;
+ global $po_memcache;
+ global $po_worker;
+ global $site_url;
+
+ print "Starting Printer Worker\n";
+
+ /* Connect to the memcache */
+ if (count($po_memcache)) {
+ $memcache = new Memcached($site_url);
+ $memcache->addServers($po_memcache);
+ }
+
+ while (TRUE) {
+ $database = po_dbconnect();
+
+ photo_print_worker($database);
+ sleep(10);
+
+ site_epilog($database);
+ }
+}
+
+function dofork_worker() {
+ global $workers;
+
+ $pid = pcntl_fork();
+ /* Child */
+ if ($pid == -1) {
+ /* Gadzooks, something went wrong! */
+ } else if ($pid == 0) {
+ child_fn_worker();
+ exit();
+ } else {
+ /* Parent */
+ $workers["$pid"] = $pid;
+ po_log("Photo import worker started (total ".sizeof($workers) .") PID $pid ");
+ }
+ return $pid;
+}
+
+function dofork_printer() {
+ global $printers;
$pid = pcntl_fork();
/* Child */
if ($pid == -1) {
/* Gadzooks, something went wrong! */
} else if ($pid == 0) {
- child_fn();
+ child_fn_printer();
exit();
} else {
/* Parent */
- $children["$pid"] = $pid;
- po_log("Photo worker started (total ".sizeof($children) .") PID $pid ");
+ $printers["$pid"] = $pid;
+ po_log("Photo printer worker started (total ".sizeof($printers) .") PID $pid ");
}
return $pid;
}
@@ -104,18 +149,25 @@ if ((posix_getuid() != 0) &&
posix_setgid($ginfo['gid']);
posix_setuid($uinfo['uid']);
-/* Start up new children. */
+/* Start up new workers. */
for ($i = 0 ; $i < $num_of_workers ; $i++) {
- $pid = dofork();
+ $pid = dofork_worker();
}
+$pid = dofork_printer();
-/* Clean up after the children and restart them as necessary */
+/* Clean up after the workers and restart them as necessary */
while(TRUE) {
- $foo = pcntl_wait($status, WUNTRACED);
- if ($foo > 0) {
- unset($children["$pid"]);
+ $pid = pcntl_wait($status, WUNTRACED);
+ if ($pid > 0) {
+ if ($workers["$pid"]) {
+ unset($workers["$pid"]);
+ $pid = dofork_worker();
+ }
+ if ($printers["$pid"]) {
+ unset($printers["$pid"]);
+ $pid = dofork_worker();
+ }
}
- $pid = dofork();
}
exit();
diff --git a/src/printer.php b/src/printer.php
new file mode 100644
index 0000000..639e50e
--- /dev/null
+++ b/src/printer.php
@@ -0,0 +1,104 @@
+<?php
+
+// Copyright (C) 2016 Solomon Peachy (pizza@shaftnet.org)
+
+// This program 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.
+
+// This program 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 this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+include_once "include/config.php";
+include_once "include/common.php";
+include_once "include/site.php";
+include_once "include/print.printer.php";
+
+// Disable compression
+$compress_pages = false;
+
+// let page run until completion
+set_time_limit(0);
+ini_set("max_execution_time", 0);
+
+// Try to turn off caching
+header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+header("Cache-Control: no-store, no-cache, must-revalidate");
+header("Cache-Control: post-check=0, pre-check=0", false);
+header("Pragma: no-cache");
+
+$count = 0;
+$database = site_prolog(PO_USER_TYPE_USER);
+
+# Whee!
+$printer_name = $_REQUEST['printer'];
+
+/*----------*/
+
+/* Sanity Check */
+if (!array_key_exists($printer_name, $po_options['printers'])) {
+ site_push_error($strings['print_invalid']);
+ site_epilog($database);
+ header("Location: $_SERVER[HTTP_REFERER]");
+ exit();
+}
+$printer = $po_options['printers'][$printer_name];
+
+if (isset($_REQUEST['photo_id']) && isset($_REQUEST['version_id'])) {
+ $version = pg_escape_string($_REQUEST['version_id']);
+ $photo = pg_escape_string($_REQUEST['photo_id']);
+ photo_print_queue_one($database, $photo, $version, $printer);
+ site_epilog($database);
+ header("Location: $_SERVER[HTTP_REFERER]");
+ exit();
+}
+
+site_header($strings['generic_print']);
+site_navigator(10);
+
+$user_display_string = disp_user_string($database, $po_user['id']);
+site_navigator_status("$user_display_string : ".$strings['generic_print'], "");
+
+print "<div class=\"content\">\n";
+
+
+/* Get list of photos to print */
+$photos_in_spooler = pg_query($database, "
+ select photo, version from album_content where album = $po_user[spool_album] group by photo, version order by photo, version");
+
+$num_photos = pg_num_rows($photos_in_spooler);
+
+print "Queueing photos for printing...\n";
+print "<ul>\n";
+
+for ($index = 0; $index < $num_photos; $index++) {
+ $row = pg_fetch_assoc($photos_in_spooler, $index);
+
+ $output = photo_print_queue_one($database, $row['photo'], $row['version'], $printer);
+ print $output;
+
+ $count++;
+}
+print "<p>$count ".$strings['print_all_queued']."</p>";
+
+print "</ul>\n";
+
+if (!$external_workers) {
+ print "<ul>\n";
+ photo_print_worker($database, $po_user['id'], FALSE);
+ print "</ul>\n";
+ print "<p>".$strings['print_all_complete']."</p>";
+}
+
+print "</div>\n";
+site_footer($database);
+site_epilog($database);
+
+?>
diff --git a/src/search.tags.php b/src/search.tags.php
index b1215b2..39d8b0f 100644
--- a/src/search.tags.php
+++ b/src/search.tags.php
@@ -187,6 +187,7 @@ if ($checkboxes > 0 && $po_user['id']) {
if ($po_user['id']) {
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
+ print emit_print_actions($database, $po_user['id']);
}
print "</div>";
diff --git a/src/search.text.advanced.php b/src/search.text.advanced.php
index 413adc1..5710898 100644
--- a/src/search.text.advanced.php
+++ b/src/search.text.advanced.php
@@ -401,6 +401,7 @@ if ($checkboxes > 0 && $po_user['id']) {
if ($po_user['id']) {
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
+ print emit_print_actions($database, $po_user['id']);
}
print "</div>";
diff --git a/src/search.text.general.php b/src/search.text.general.php
index f930bdb..8c280b4 100644
--- a/src/search.text.general.php
+++ b/src/search.text.general.php
@@ -242,7 +242,8 @@ if ($checkboxes > 0 && $po_user['id']) {
if ($po_user['id']) {
print emit_spool_actions($database, $po_user['id']);
print emit_import_actions($database, $po_user['id']);
- }
+ print emit_print_actions($database, $po_user['id']);
+}
print "</div>";
print "</form>";
diff --git a/src/sql/po.upgrade.2.37.c.to.2.38.a.sql b/src/sql/po.upgrade.2.37.c.to.2.38.a.sql
new file mode 100644
index 0000000..3969543
--- /dev/null
+++ b/src/sql/po.upgrade.2.37.c.to.2.38.a.sql
@@ -0,0 +1,42 @@
+-- Copyright (c) 2009 Solomon Peachy (pizza@shaftnet.org)
+
+-- This program 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.
+
+-- This program 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 this program; if not, write to the Free Software
+-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+----------------------------------------------------------
+-- v2.37.C to 2.38.A patch
+----------------------------------------------------------
+
+------ to deal with imports
+
+CREATE SEQUENCE pending_prints_sequence START 1;
+
+CREATE TABLE pending_prints (
+ identifier integer NOT NULL PRIMARY KEY,
+ users integer references users(identifier) NOT NULL,
+ version integer references photo_version(identifier),
+ print_data TEXT
+);
+
+CREATE SEQUENCE print_results_sequence START 1;
+
+CREATE TABLE print_results (
+ identifier integer NOT NULL PRIMARY KEY DEFAULT nextval('print_results_sequence'),
+ users integer references users(identifier) NOT NULL,
+ log_data TEXT
+);
+
+-- version update
+update version set identifier=3, description='2.38 Development release',
+ major=2, minor=38, variation='A';
diff --git a/src/themes/aqua/theme.php b/src/themes/aqua/theme.php
index f010b5a..ed45576 100644
--- a/src/themes/aqua/theme.php
+++ b/src/themes/aqua/theme.php
@@ -304,6 +304,7 @@ function theme_generate_buttons() {
$thm_elem['button.set.thumb.f'] = make_button("thumb_f", "submit", $strings['generic_set_thumb_f']);
$thm_elem['button.set.thumb.a'] = make_button("thumb_a", "submit", $strings['generic_set_thumb_a']);
$thm_elem['button.print'] = make_button("print_req", "submit", $strings['generic_print']);
+ $thm_elem['button.printer'] = make_button("printer_req", "submit", $strings['generic_printer']);
$thm_elem['button.export'] = make_button("export_req", "submit", $strings['generic_export']);
$thm_elem['button.add.to.spool'] = make_button("spool_req", "submit", $strings['generic_add_to_spool']);
$thm_elem['button.bulk.update'] = make_button("bulk_update_req", "submit", $strings['generic_bulk_update']);
diff --git a/src/themes/blackwater/theme.php b/src/themes/blackwater/theme.php
index 109383a..8cc66f0 100644
--- a/src/themes/blackwater/theme.php
+++ b/src/themes/blackwater/theme.php
@@ -303,6 +303,7 @@ function theme_generate_buttons() {
$thm_elem['button.set.thumb.f'] = make_button("thumb_f", "submit", $strings['generic_set_thumb_f']);
$thm_elem['button.set.thumb.a'] = make_button("thumb_a", "submit", $strings['generic_set_thumb_a']);
$thm_elem['button.print'] = make_button("print_req", "submit", $strings['generic_print']);
+ $thm_elem['button.printer'] = make_button("printer_req", "submit", $strings['generic_printer']);
$thm_elem['button.export'] = make_button("export_req", "submit", $strings['generic_export']);
$thm_elem['button.add.to.spool'] = make_button("spool_req", "submit", $strings['generic_add_to_spool']);
$thm_elem['button.bulk.update'] = make_button("bulk_update_req", "submit", $strings['generic_bulk_update']);
diff --git a/src/user.php b/src/user.php
index c61bc12..640fc11 100644
--- a/src/user.php
+++ b/src/user.php
@@ -99,6 +99,8 @@ if (($owner_id == 0) || ($owner_type < PO_USER_TYPE_CLIENT)) {
print "<input type=\"hidden\" name=\"return\" value=\"".generate_link('user', $owner_id)."\"/>";
print "<input type=\"hidden\" name=\"user\" value=\"$owner_id\"/>";
print emit_spool_actions($database, $po_user['id']);
+ print emit_import_actions($database, $po_user['id']);
+ print emit_print_actions($database, $po_user['id']);
print "</form>";
print "</div>";
}