summaryrefslogtreecommitdiff
path: root/public/xx-catalog.php
blob: 1e62e3bfc7df6671b23532f070d79a8fb930ecbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
// 01. Initialize --------------------------------------------------------------
// include paremetres and libraries, init timezome, init variables
////////////////////////////////////////////////////////////////////////////////

include("config/parametres.php");
include("includes/sessions.php");
include("includes/functions.php");
date_default_timezone_set('Europe/Athens');
setlocale(LC_ALL, 'el_GR.UTF-8', 'grc');

$totals = get_totals();   // get totals of categories
$formARRAY = json_decode(FORMJSON);   // list of fields
$items = array();         // items to print



// 02. Parse arguments and intitialize behaviout flags -------------------------
// CCODE -> ccode [ certain id: ##.##  --or--  0 = any id ]
// COVER -> (yes|no) print cover-page (default: no)
// ID -> record id
// ---
// Call options:
// ? ccode=ac.1 [& cover=no]    : call for category; no cover
// ? ccode=0 & cover=yes        : all items; print cover
// ? id=123                     : specific item (no cover / no header)
////////////////////////////////////////////////////////////////////////////////

if ((isset($_GET['ccode'])) && (mb_strlen($_GET['ccode']) < 6)) {
  $ccid = $_GET['ccode'];    // category id passed
  $doSearch = true;
  define("PRINT_MODE", 'book');
  define("RENDER_COVER", ((isset($_GET['cover'])) && ($_GET['cover'] == 'yes')) ? true : false );
  define("RENDER_HF", true);    // render header + footer
}
else if ((isset($_GET['id'])) && (strlen($_GET['id']) < 5)) {
  $iid = $_GET['id'];
  define("PRINT_MODE", 'page');
  define("RENDER_COVER", false);    // do not include cover-page
  define("RENDER_HF", true);        // do not render header + footer
}
else {
  echo "Wrong call; Nothing to print"; die();
}


// 03. Get data to print -------------------------------------------------------
// init database connection, prepare SELECT, fetch data
////////////////////////////////////////////////////////////////////////////////

$_dbc = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DBMS);
if ($_dbc->connect_errno) {
  echo "Database connection failed; Please try in a few minutes. ";
  if (TESTING) echo $_dbc->connect_error;
  $_dbc->close(); die();
}
$_dbc->set_charset("utf8");

// prepare statemet
if (isset($iid)) {
  $_stm = $_dbc->prepare("SELECT id, img, ccode, identity, summary, operator, `timestamp`, record FROM items WHERE id = ?");
  $_stm->bind_param("d", $iid);
}
else if ($ccid != '0') {
  $_stm = $_dbc->prepare("SELECT id, img, ccode, identity, summary, operator, `timestamp`, record FROM items WHERE ccode = ?");
  $_stm->bind_param("s", $ccid);
}
else if (isset($ccid)) {
  $_stm = $_dbc->prepare("SELECT id, img, ccode, identity, summary, operator, `timestamp`, record FROM items");
}
else {
  echo "Wrong call; Nothing to print"; die();
}
$_stm->execute();               // execute query
$_stm->store_result();          // store result

if ($_stm->num_rows) {

  $_stm->bind_result($id, $imgfile, $ccode, $idnt, $sum, $opr, $tm, $serREC);   // bind result variables

  while ($_stm->fetch()) {
    $record = unserialize($serREC);
    $it_id = explode('.', $idnt);

    // calculate record
    $record['id'] = $id;
    $record['ccode'] = $ccode;
    $record['img'] = ( (strlen($imgfile) > 9) ? ("/". UPLOAD_DIR . intdiv($id,500) ."/". $imgfile) : "" );
    $record['identity'] = $idnt;
    $record['operator'] = $opr;
    $record['itemid'] = end($it_id);
    $record['totalitems'] = $totals[$record['ccode']];
    $record['timestamp'] = local_dt($tm);
    $record['summary'] = $sum;

    $items[] = $record;
    unset($record);
  }
}

$_stm->close();     // close statement
$_dbc->close();     // close connection

// print_r($items); die();

// 03. Prepare PDF to print ----------------------------------------------------
// include printing php script
////////////////////////////////////////////////////////////////////////////////

include("print-book.php");