Added support for adding jobs from past events
authorJoey Schulze <joey@infodrom.org>
Sun, 20 Mar 2005 15:10:45 +0000 (15:10 +0000)
committerJoey Schulze <joey@infodrom.org>
Sun, 20 Mar 2005 15:10:45 +0000 (15:10 +0000)
src/LinuxTag/2005/supporter/import.wml [new file with mode: 0644]
src/LinuxTag/2005/supporter/past.cfg [new file with mode: 0644]
src/LinuxTag/2005/supporter/submenu.inc
src/LinuxTag/2005/supporter/update.wml

diff --git a/src/LinuxTag/2005/supporter/import.wml b/src/LinuxTag/2005/supporter/import.wml
new file mode 100644 (file)
index 0000000..f6bfa28
--- /dev/null
@@ -0,0 +1,49 @@
+#include <lt2005.style>
+#include "../edit.style"
+#include "jobs.inc"
+#include "past.cfg"
+
+<page title="Supporter -- Import Jobs">
+
+<p>Jobs to import from past <past-event>:</p>
+
+<p><ul>
+<?
+  $dbh = pg_pconnect ("<dbconnstring>")
+               or die("Unable to connect to SQL server");
+  $pdbh = pg_pconnect ("<past-dbconnstring>")
+               or die("Unable to connect to SQL server");
+
+  pg_exec ($pdbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
+
+  $query = "SELECT id,title FROM job ORDER BY upper(title)";
+  $sth = pg_exec ($pdbh, $query) or die ("Datenbank-Abfrage!");
+
+  for ($nr = 0; $nr < pg_NumRows($sth); $nr++)
+  {
+    $row = pg_fetch_array($sth, $nr);
+    printf ("<li><a href=\"update.php3?type=copyjob&id=%d\">%s</a>",
+      $row['id'], $row['title']);
+
+    $query = sprintf ("SELECT id,title FROM job WHERE title = '%s'", $row['title']);
+    $sth2 = pg_exec ($dbh, $query) or die ("Datenbank-Abfrage!");
+    printf (" (<a href=\"%s%d\">details</a>", "<past-job-info>", $row['id']);
+
+    if (pg_NumRows($sth2) > 0) {
+      $srow = pg_fetch_array($sth2, 0);
+
+      printf (", <a href=\"job.php3?id=%d\">already copied</a>", $srow['id']);
+    }
+    echo (")\n");
+  }
+
+?>
+</ul></p>
+
+</page>
+
+# Local variables:
+# mode: text
+# mode: auto-fill
+# end:
+
diff --git a/src/LinuxTag/2005/supporter/past.cfg b/src/LinuxTag/2005/supporter/past.cfg
new file mode 100644 (file)
index 0000000..87fe5f2
--- /dev/null
@@ -0,0 +1,20 @@
+# ---------------- <ltp.conf>
+# ISO Date specification of the days, the event is happening on,
+# including preparation
+#
+<define-tag past-iso-event-date-3>2004-06-20</define-tag>
+<define-tag past-iso-event-date-2>2004-06-21</define-tag>
+<define-tag past-iso-event-date-1>2004-06-22</define-tag>
+<define-tag past-iso-event-date_0>2004-06-23</define-tag>
+<define-tag past-iso-event-date_1>2004-06-24</define-tag>
+<define-tag past-iso-event-date_2>2004-06-25</define-tag>
+<define-tag past-iso-event-date_3>2004-06-26</define-tag>
+<define-tag past-iso-event-date_4>2004-06-27</define-tag>
+
+<ifeq "$(WML_GEN_HOSTNAME)" "luonnotar" "
+   <define-tag past-dbconnstring>dbname=lt_2004</define-tag>
+">
+
+<define-tag past-event>LinuxTag 2004</define-tag>
+
+<define-tag past-job-info whitespace=delete>../../2004/supporter/job.php3?id=</define-tag>
index 856c6b1..bf29588 100644 (file)
@@ -4,6 +4,7 @@
 &nbsp;<menu-item base=edit text="Add Supporter" href=edit.php3><br>
 &nbsp;<menu-item base=edit_comment text="Add&nbsp;Comment" href=edit_comment.php3><br>
 &nbsp;<menu-item base=edit_job text="Add&nbsp;Job" href=edit_job.php3><br>
+&nbsp;<menu-item base=infomail text="Import" href="import.php3"><br>
 &nbsp;<menu-item base=infomail text="Infomail"><br>
 
 <p><line height=2>
index 63e4a83..1328b2c 100644 (file)
@@ -1,6 +1,7 @@
 #include <lt2005.style>
 #include "../phpfunctions.inc"
 #include "jobs.inc"
+#include "past.cfg"
 
 <when <not <string-eq "$(NILI)" "" />>>
 <insert_nili>
     }
   } elseif ($type == "loose") {
     $query = sprintf ("DELETE FROM assignment WHERE oid = %d", $assignment);
+  } elseif ($type == "copyjob") {
+    # Copy entire jobs from a past event
+
+    $pastdate['<past-iso-event-date-3>'] = '<iso-event-date-3>';
+    $pastdate['<past-iso-event-date-2>'] = '<iso-event-date-2>';
+    $pastdate['<past-iso-event-date-1>'] = '<iso-event-date-1>';
+    $pastdate['<past-iso-event-date_0>'] = '<iso-event-date_0>';
+    $pastdate['<past-iso-event-date_1>'] = '<iso-event-date_1>';
+    $pastdate['<past-iso-event-date_2>'] = '<iso-event-date_2>';
+    $pastdate['<past-iso-event-date_3>'] = '<iso-event-date_3>';
+    $pastdate['<past-iso-event-date_4>'] = '<iso-event-date_4>';
+
+    # Begin transaction
+    pg_exec($dbh, "BEGIN TRANSACTION") or die ("Could not start transaction.");
+
+    $pdbh = pg_pconnect ("<past-dbconnstring>")
+               or die("Unable to connect to SQL server");
+
+    $query = sprintf ("SELECT * FROM job WHERE id = %d", $id);
+    $psth = pg_exec($pdbh, $query) or die ("Couldn't look up old job.");
+    if (pg_NumRows($psth) <= 0) {
+      die ("Job not found in <past-event>");
+    }
+
+    $prow = pg_fetch_array($psth, 0);
+
+    $query = sprintf("INSERT INTO job (title, location, description, priority, comment, section) " .
+                    " VALUES ('%s', '%s', '%s', %d, '%s', '%s')",
+                    $prow['title'],
+                    $prow['location'],
+                    $prow['description'],
+                    $prow['priority'], 
+                    $prow['comment'],
+                    $prow['section']);
+
+    $sth = pg_exec($dbh, $query) or die ("Cannot add this job.");
+
+    $query = sprintf ("SELECT id FROM job WHERE oid = %d", pg_getlastoid ($sth));
+    $sth = pg_exec($dbh, $query) or die ("Cannot fetch id of new job.");
+    if (pg_NumRows ($sth) <= 0) {
+      die ("Cannot fetch id of new job.");
+    }
+    $row = pg_fetch_array($sth, 0);
+    # New job id for this year
+    $jobid = $row['id'];
+
+    $query = sprintf ("SELECT * from fragment WHERE job = %d", $id);
+    $psth = pg_exec($pdbh, $query) or die ("Cannot fetch fragments of old job.");
+
+    for ($nr=0; $nr < pg_NumRows ($psth); $nr++) {
+      $prow = pg_fetch_array ($psth, $nr);
+
+      # Convert the dates
+      $foo = explode (" ", $prow['starttime']);
+      $prow['starttime'] = $pastdate[$foo[0]] . " " . $foo[1];
+
+      $foo = explode (" ", $prow['endtime']);
+      $prow['endtime'] = $pastdate[$foo[0]] . " " . $foo[1];
+      
+      $query = sprintf ("INSERT INTO fragment (job, min, max, starttime, endtime, comment) "
+                      ."VALUES (%d, %d, %d, '%s', '%s', '%s')",
+                      $jobid,
+                      $prow['min'],
+                      $prow['max'],
+                      $prow['starttime'],
+                      $prow['endtime'],
+                      addslashes($prow['comment']));
+      pg_exec($dbh, $query) or die ("Cannot insert job fragment.");
+    }
+
+    # Finish transaction
+    pg_exec($dbh, "COMMIT") or die ("Could not finish transaction.");
+
+    # Only to ensure no query is executed later
+    $query = '';
+
   } else
   {
     echo ("<p><b>Unknown type!</b></p>");