From 45649f508becbd2776d6830744a357e12c0a74b2 Mon Sep 17 00:00:00 2001
From: Leif Andersson <leif.andersson@control.lth.se>
Date: Mon, 16 Nov 2015 18:11:56 +0100
Subject: [PATCH] Lade till printICE

---
 action.add_edit_Group.php    |  9 ++++++-
 action.editGroups.php        |  1 +
 action.printICE.php          | 50 ++++++++++++++++++++++++++++++++++++
 lib/class.Groups.php         |  4 +--
 lib/class.Person.php         |  2 +-
 templates/groupEditPanel.tpl |  2 +-
 6 files changed, 63 insertions(+), 5 deletions(-)
 create mode 100644 action.printICE.php

diff --git a/action.add_edit_Group.php b/action.add_edit_Group.php
index 8bc150a..0a6bdff 100644
--- a/action.add_edit_Group.php
+++ b/action.add_edit_Group.php
@@ -4,7 +4,7 @@ if (!isset($gCms)) exit;
 
 $ID='';
 $paramKeys = array_keys($params);
-$print = 'print_';
+$print = 'print_'; $ICE = 'ICE_';
 foreach ($paramKeys as $key) {
   $pos = strpos($key,$print);
   if ($pos === false) continue;
@@ -12,6 +12,13 @@ foreach ($paramKeys as $key) {
   $this->Redirect($id, 'printGroup', $returnid, array('ID'=>$ID));
   return;
 }
+foreach ($paramKeys as $key) {
+  $pos = strpos($key,$ICE);
+  if ($pos === false) continue;
+  $ID = substr($key,strlen($ICE));
+  $this->Redirect($id, 'printICE', $returnid, array('ID'=>$ID));
+  return;
+}
 if (isset($params['back'])) {
   $this->Redirect($id, 'defaultadmin', $returnid, array());
 }
diff --git a/action.editGroups.php b/action.editGroups.php
index 68c70e5..dd564dd 100644
--- a/action.editGroups.php
+++ b/action.editGroups.php
@@ -25,6 +25,7 @@ foreach ($groups as $group) {
     $group->change = '';
   }
   $group->print = $this->CreateInputSubmit($id, 'print_'.$group->ID, 'Skriv ut');
+  $group->ICE = $this->CreateInputSubmit($id, 'ICE_'.$group->ID, 'ICE');
 }
 $place = $this->CreateInputSubmit($id, 'back', 'Tillbaka');
 $smarty->assign('backButton',$place);
diff --git a/action.printICE.php b/action.printICE.php
new file mode 100644
index 0000000..c5b73d3
--- /dev/null
+++ b/action.printICE.php
@@ -0,0 +1,50 @@
+<?php
+if (!isset($gCms)) exit;
+//echo '<pre>'; print_r($params); echo '</pre>';
+
+$ID = $params['ID'];
+
+$HEAD = <<<EOS
+<!doctype html>
+<html lang="en" dir="ltr">
+<head>
+<meta charset="utf-8" />
+<title>Grupp $ID</title>
+<meta http-equiv="Content-Type" content="text/plain"/>
+</head>
+EOS;
+
+
+$members = Person::getGroupMembers($ID);
+$addresses = array();
+foreach ($members as $member) {
+  $rec = '';
+  if (trim($member->Namn)) $rec .= $member->Namn.PHP_EOL;
+  if ($member->Telefon) $rec .=
+	    '    Telefon Kontor: ' . $member->Telefon.PHP_EOL;
+  if ($member->TelefonMobil) $rec .=
+	    '    Telefon Mobil: ' . $member->TelefonMobil.PHP_EOL;
+  if ($member->ICE) {
+    $rec .= '    ICE:'.PHP_EOL;
+    $ICErows = explode(PHP_EOL, $member->ICE);
+    foreach ($ICErows as $row) {
+      $rec .= '          ' . $row . PHP_EOL;
+    }
+  }
+    
+  $records[] = $rec;
+}
+  
+  
+
+
+
+echo $HEAD;
+echo '<body>'.PHP_EOL;
+echo '<pre>';
+foreach ($records as $rec) echo $rec.PHP_EOL;
+ echo '</pre>';
+echo '</body></html>';
+
+exit;
+?>
diff --git a/lib/class.Groups.php b/lib/class.Groups.php
index 23ce468..f3c191b 100644
--- a/lib/class.Groups.php
+++ b/lib/class.Groups.php
@@ -38,7 +38,7 @@ EOS;
     
   //public static $groupFields = array('ID', 'Gruppnamn', 'GruppInfo');
   public static $groupFields;
-  private static $buttonFields = array('change','print');
+  private static $buttonFields = array('change','print','ICE');
 
   private static $instance;
 
@@ -64,7 +64,7 @@ EOS;
     $count = $result->RecordCount();
     switch ($count) {
     case 0:
-      die(sprintf('Bad group ID %s'.PHP_EOL,$adressID));
+      die(sprintf('Bad group ID %s'.PHP_EOL,$param[0]));
       break;
     case 1:
       $row = $result->FetchRow();
diff --git a/lib/class.Person.php b/lib/class.Person.php
index e67127a..fe6f8fd 100644
--- a/lib/class.Person.php
+++ b/lib/class.Person.php
@@ -6,7 +6,7 @@ class Person {
     select distinct Adresser.ID, concat(Fornamn, ' ', Efternamn) as Namn,
     case when SkolaForetag is not null then SkolaForetag
        when Adress is not null then Adress else Hem end as ForetagAdress,
-    Avdelning from Adresser,GruppAdress where 
+    Avdelning, Telefon, TelefonMobil, ICE from Adresser,GruppAdress where 
 EOT;
 
   private static $queryOne = <<<EOT
diff --git a/templates/groupEditPanel.tpl b/templates/groupEditPanel.tpl
index b85cbc4..8b26188 100644
--- a/templates/groupEditPanel.tpl
+++ b/templates/groupEditPanel.tpl
@@ -9,7 +9,7 @@
 {foreach $Groups as $group}
 <tr><td>{$group->ID}</td><td>{$group->Gruppnamn}</td>
     <td>{$group->GruppInfo}</td><td>{$group->change}</td>
-    <td>{$group->print}</td></tr>
+    <td>{$group->print}</td><td>{$group->ICE}</td></tr>
 {/foreach}
 {/if}
 <tr><td colspan="5" style="text-align: center;">{$newButton}&nbsp;
-- 
GitLab