Commit 315d42a7 authored by Leif Andersson's avatar Leif Andersson
Browse files

Lade till "Radera adress"

parent a34f89ef
......@@ -32,7 +32,7 @@ $areaFields = array(
if (isset($params['submit'])) {
$record = new Person($params);
//echo '<pre>'; print_r($record); echo '</pre>';
//echo '<pre>'; print_r($record); echo '</pre>'; exit;
$record->updateRecord();
$paramsB['module_message'] = 'Adressinformation ändrad';
foreach (Person::$firstFields as $field) {
......@@ -55,6 +55,9 @@ if (isset($params['doGroups'])) {
$this->Redirect($id, 'changeGroups', $returnid, $paramsB);
}
if (isset($params['ID'])) {
$ID = $params['ID'];
$person = new Person($ID);
......@@ -63,6 +66,21 @@ if (isset($params['ID'])) {
$ID = null;
}
$deleteRecord = False;
if (isset($params['deleteRecord'])) {
if (!$ID) die('Strange error in deleteRecord. No ID'.PHP_EOL);
$deleteRecord = True;
$canChangeRecord = False;
}
if (isset($params['confirmDelete'])) {
if (!$ID) die('Strange error in deleteRecord. No ID'.PHP_EOL);
Person::deleteRecord($ID);
$paramsB['module_message'] = 'Adress raderad.';
$this->Redirect($id, 'defaultadmin', $returnid, $paramsB);
return;
}
if (isset($params['cancelUpdate'])) {
$paramsB = array();
foreach (Person::$firstFields as $field) {
......@@ -81,7 +99,10 @@ $smarty = $this->smarty;
$headline = $person->Fornamn . ' ' .$person->Efternamn;
if (strlen($headline) == 1) $headline = $person->SkolaForetag;
if ($canChangeRecord) { $headline = 'Redigera adress: ' . $headline; }
if ($canChangeRecord) { $headline = 'Ändra adress: ' . $headline; }
if ($deleteRecord) { $headline = 'Bekräfta radera: ' . $headline; }
$smarty->assign('headline',$headline);
......@@ -148,6 +169,16 @@ if ($canChangeRecord) {
}
$smarty->assign('submitButton',$place);
if ($canChangeRecord) {
$place = $this->CreateInputSubmit($id, 'deleteRecord', 'Radera adress');
} else {
$place = '';
}
if ($deleteRecord) {
$place = $this->CreateInputSubmit($id, 'confirmDelete', 'Bekräfta radera');
}
$smarty->assign('deleteConfirmButton',$place);
$place = $this->CreateInputSubmit($id, 'cancelUpdate', 'Avbryt');
$smarty->assign('cancelButton',$place);
......
......@@ -28,11 +28,14 @@ EOS;
Adresser.ID = AdressID and GruppID = ?
EOS;
private static $queryUpdate = <<<EOS
update Grupper set where ID = ?
EOS;
/* private static $queryUpdate = <<<EOS */
/* update Grupper set where ID = ? */
/* EOS; */
private static $queryRemoveGruppadress = <<<EOS
delete from GruppAdress where AdressID = ?
EOS;
//public static $groupFields = array('ID', 'Gruppnamn', 'GruppInfo');
public static $groupFields;
private static $buttonFields = array('change','print');
......@@ -196,5 +199,14 @@ EOS;
}
// exit;
}
public static function removeAddress($AdressID = null) {
global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
if (is_null($AdressID))
die('Strange error in removeAddress. No ID.'.PHP_EOL);
$values = array($AdressID);
$result = $db->Execute(self::$queryRemoveGruppadress,$values);
if (!$result) { die("Database error!<br>" . $db->ErrorMsg()); }
}
}
?>
......@@ -22,6 +22,10 @@ EOT;
select distinct *, concat(Fornamn, ' ', Efternamn) as Namn
from Adresser,GruppAdress where Adresser.ID=AdressID and GruppID=?
EOS;
private static $queryDelete = <<<EOS
delete from Adresser where ID=?
EOS;
public static $firstFields = array(
'ID','fornamn', 'efternamn', 'foretag','avdelning', 'adress', 'Grupp');
......@@ -189,5 +193,15 @@ EOS;
}
return $records;
}
public static function deleteRecord($ID = null) {
global $gCms; if (!isset($gCms)) exit;
$db = AddressDB::getDB();
if (is_null($ID)) die('Strange error in deleteRecord. No ID.'.PHP_EOL);
$values = array($ID);
$result = $db->Execute(self::$queryDelete,$values);
if (!$result) { die("Database error!<br>" . $db->ErrorMsg()); }
Groups::removeAddress($ID);
}
}
?>
\ No newline at end of file
......@@ -47,8 +47,8 @@
{$title_Andrad}:</td><td>{$value_Andrad}</td><td></td></tr>
<td colspan = "4" style="text-align: center;">
{$submitButton}{$cancelButton}</td><td></td></tr>
<tr><td colspan = "4" style="text-align: right;">
{$deleteConfirmButton}</td></tr>
</tbody></table>
{if isset($hidden)}{$hidden}{/if}
{$end_form}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment