Quellcode durchsuchen

Bring up to genorate command for print and some compat stuff

Aaron Speer vor 6 Jahren
Ursprung
Commit
2a6fa6a231
5 geänderte Dateien mit 186 neuen und 10 gelöschten Zeilen
  1. 28 2
      app/Controllers/HomeController.php
  2. 2 0
      config/config.example.php
  3. 1 0
      public/index.php
  4. 70 5
      views/home.twig
  5. 85 3
      views/upload.twig

+ 28 - 2
app/Controllers/HomeController.php

@@ -31,15 +31,41 @@ class HomeController extends Controller {
 
     if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder)){
       $targetfolder = str_replace(" ", "\ ", $targetfolder);
+      $tf = $targetfolder;
       $cmd = "sudo /usr/bin/unoconv --output=".$targetfolder." -f pdf ".$targetfolder;
-      exec($cmd);
+
+      $file_parts = pathinfo($tf);
+      if($file_parts["extension"] == "pdf")
+      {
+        exec("ls");
+      }
+      else{
+        exec($cmd);
+      }
+
+      global $config;
+
       echo $this->twig->render('upload.twig', array(
   			"messages" => $this->model->getMessages(),
-        "link" => $address
+        "link" => $address,
+        "printers" => $config["printers"],
+        "path" => escapeshellcmd($address)
       ));
     }
     else {
       echo "Problem uploading file";
     }
   }
+
+  public function print(){
+    $printer = $_POST["printer"];
+    $copies = $_POST["copies"];
+    $path = $_POST["path"];
+    $printer=escapeshellcmd($printer);
+    $copies=escapeshellcmd($copies);
+    $path=str_replace(" ", "\ ", escapeshellcmd($path));
+    $path = __DIR__."/../../public".$path;
+    $cmd = "lp -d ".$printer." -n ".$copies." ".$path;
+    echo $cmd;
+  }
 }

+ 2 - 0
config/config.example.php

@@ -0,0 +1,2 @@
+printers[PDF] = "Print to PDF"
+printers[CPL-320] = "Study CLP-320"

+ 1 - 0
public/index.php

@@ -33,6 +33,7 @@ $router = new AltoRouter();
 $router->setBasePath('');
 $router->map('GET','/', "App\Controllers\HomeController#index", 'home');
 $router->map('GET|POST','/upload', "App\Controllers\HomeController#upload", 'upload');
+$router->map('GET|POST','/print', "App\Controllers\HomeController#print", 'print');
 $match = $router->match();
 
 

+ 70 - 5
views/home.twig

@@ -8,17 +8,82 @@
   {{ makeError(message[0], message[1], message[2]) | raw }}
 {% endfor %}
 
+<div class="row">
 
-<form action="/upload" method="post" enctype="multipart/form-data">
+  <div class="col-md-6">
+    <div class="panel panel-warning">
+      <div class="panel-heading">Printing Instructions</div>
+      <div class="panel-body">
+        <ol>
+          <li>Select the file you wish to print using the button on this page. PDFs work best, however most simple Word files should work.</li>
+          <li>If you have a .pages (Apple Pages), or more complex Word file (i.e. Formatted Notepaper) please export it as a PDF, or use the public PCs on the 2nd floor</li>
+          <li>Press the "Preview and Print" button</li>
+          <li>You will then be prompted to view the file, enter number of copies and select printer</li>
+          <li>Your document will then be added to the print queue</li>
+        </ol>
+      </div>
+    </div>
+  </div>
 
-<input type="file" name="file" size="500" />
+  <div class="col-md-6">
+    <div id="upbox" class="panel panel-info">
+      <div class="panel-heading">Please select the file you wish to print</div>
+      <div class="panel-body">
+        <span class="text-success" style="font-weight: bold;">Supported Formats:</span> PDF (.pdf)<br>
+        <span class="text-info" style="font-weight: bold;">Partially Supported Formats:</span> Microsoft Word (.docx), Microsoft Word (.doc), Open Office (.odt) and most other formats<br>
+        <span class="text-danger" style="font-weight: bold;">Unsupported Formats:</span> Apple Pages (.pages)
+        <br><br>
+        <form action="/upload" method="post" enctype="multipart/form-data">
+          <label id="button" class="btn btn-success btn-file">
+            Select File<input type="file" name="file" size="500" style="display: none;">
+          </label>
+          <br>
+          <p id="uploaded"></p>
+          <input type="submit" class="btn btn-success" value="Preview and Print" />
+        </form>
+      </div>
+    </div>
+  </div>
 
-<br />
+</div>
 
-<input type="submit" value="Upload" />
 
-</form>
 
 {% endblock %}
 {% block js %}
+<script>
+$(function() {
+
+  $(document).on('change', ':file', function() {
+    var input = $(this),
+        numFiles = input.get(0).files ? input.get(0).files.length : 1,
+        label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
+    input.trigger('fileselect', [numFiles, label]);
+  });
+
+  $(document).ready( function() {
+      $(':file').on('fileselect', function(event, numFiles, label) {
+
+          var input = $(this).parents('.input-group').find(':text'),
+              log = numFiles > 1 ? numFiles + ' files selected' : label;
+
+          if( input.length ) {
+              input.val(log);
+          } else {
+              var str2 = "File Selected: "
+              if( log ) {
+                document.getElementById("uploaded").innerHTML = str2.concat(log);
+                document.getElementById("button").classList.remove('btn-success');
+                document.getElementById("button").classList.add('btn-default');
+                document.getElementById("button").classList.add('disabled');
+                document.getElementById("upbox").classList.remove('panel-info');
+                document.getElementById("upbox").classList.add('panel-success');
+              }
+          }
+
+      });
+  });
+
+});
+</script>
 {% endblock %}

+ 85 - 3
views/upload.twig

@@ -2,15 +2,97 @@
 {% block content %}
 
 <div class="page-header">
-  <h1>Welcome to the SAIMUN 2019 Public Printing Web App</h1>
+  <h1>File Successfully Submitted</h1>
 </div>
 {% for message in messages %}
   {{ makeError(message[0], message[1], message[2]) | raw }}
 {% endfor %}
 
-<h1>File Successfully Submitted
-Please check the formatting by clicking <a href="{{ link }}" target="_blank">here</a></h1>
+<div class="col-md-6">
+  <div class="panel panel-warning">
+    <div class="panel-heading">Confirm Print Preview</div>
+    <div class="panel-body">
+      <label>Open print preview in new tab:</label><br>
+      <a class="btn btn-success" href="{{ link }}" target="_blank">View Print Preview</a><br><br>
+      <div class="radio">
+        <label><input id="ok" value="ok" type="radio" name="optradio"><span class="text-success" style="font-weight: bold;">Looks Good!</span></label>
+      </div>
+      <div class="radio">
+        <label><input id="no" value="no" type="radio" name="optradio"><span class="text-danger" style="font-weight: bold;">Somethings Wrong?</span></label>
+      </div>
+    </div>
+  </div>
+</div>
+
+<div class="col-md-6">
+  <div id="print" style="display: none" class="panel panel-success">
+    <div class="panel-heading">Success: Ready to Print</div>
+    <div class="panel-body">
+      <form action="/print" method="post">
+        <div class="form-group">
+          <label for="printer">Choose Printer:</label>
+          <select name="printer" class="form-control" id="printer">
+            {% for id, name in printers %}
+              <option value="{{id}}">{{name}}</option>
+            {% endfor %}
+          </select>
+          <label for="copies">Select number of copies:</label>
+          <select name="copies" class="form-control" id="copies">
+            <option>1</option>
+            <option>2</option>
+            <option>3</option>
+            <option>4</option>
+            <option>5</option>
+            <option>6</option>
+            <option>7</option>
+            <option>8</option>
+            <option>9</option>
+            <option>10</option>
+            <option>11</option>
+            <option>12</option>
+            <option>13</option>
+            <option>14</option>
+            <option>15</option>
+            <option>16</option>
+            <option>17</option>
+            <option>18</option>
+            <option>19</option>
+            <option>20</option>
+          </select>
+        <input type="hidden" name="path" value="{{path}}">
+        <br>
+        <input type="submit" value="Submit" class="btn btn-success">
+      </form>
+    </div>
+  </div>
+</div>
+
+<div class="col-md-6">
+  <div id="esc" style="display: none" class="panel panel-danger">
+    <div class="panel-heading">Failed!</div>
+    <div class="panel-body">
+      <p>Try uploading a PDF, or use the public PCs on the 2nd Floor</p>
+      <a href="/" class="btn btn-danger">Return to Homepage</a>
+    </div>
+  </div>
+</div>
 
 {% endblock %}
 {% block js %}
+<script>
+$('input:radio[name="optradio"]').change(function(){
+    if($(this).val() === 'ok'){
+       document.getElementById("print").style.display = "block";
+       document.getElementById("esc").style.display = "none";
+
+    }
+    if($(this).val() === 'no'){
+       document.getElementById("esc").style.display = "block";
+       document.getElementById("print").style.display = "none";
+
+    }
+});
+
+
+</script>
 {% endblock %}