diff --git a/ReglerAddress.module.php b/ReglerAddress.module.php index 9baa73c9007a503525249b642d77bea6ffa422bc..518d0cdd1c73ed59bf3d95890938ae67f8aec37e 100644 --- a/ReglerAddress.module.php +++ b/ReglerAddress.module.php @@ -178,9 +178,20 @@ class ReglerAddress extends CMSModule $this->RegisterModulePlugin(); $this->RestrictUnknownParams(); - $this->RegisterRoute('#Publication/(?P<artkey>.+$)#', - array('action'=>'showpublication', 'returnid'=>'60')); + $this->CreateParameter('fornamn','','fornamn'); + $this->SetParameterType('fornamn',CLEAN_STRING); + + $this->CreateParameter('efternamn','','fornamn'); + $this->SetParameterType('efternamn',CLEAN_STRING); + + $this->CreateParameter('foretag','','foretag'); + $this->SetParameterType('fornamn',CLEAN_STRING); + + $this->CreateParameter('avdelning','','avdelning'); + $this->SetParameterType('avdelning',CLEAN_STRING); + $this->CreateParameter('adress','','adress'); + $this->SetParameterType('adress',CLEAN_STRING); } /** diff --git a/action.add_edit.php b/action.add_edit.php new file mode 100644 index 0000000000000000000000000000000000000000..ee043c33099b4270adb6665b56a16a6ba861a516 --- /dev/null +++ b/action.add_edit.php @@ -0,0 +1,119 @@ +<?php +if (!isset($gCms)) exit; +echo '<pre>'; print_r($params); echo '</pre>'; + +if (! $this->CheckPermission('Use ReglerAddress')) { + return $this->DisplayErrorPage($id, $params, $returnid, + 'ReglerAddress access denied.'); +} + +$fields = array( + 'ID', 'Fornamn', 'Efternamn', 'Titel', 'Personnummer', 'SkolaForetag', + 'Avdelning', 'Adress', 'Besok', 'Hem', 'Epost', 'Telefon', 'TelefonMobil', + 'TelefonHem', 'URL', 'AnknytningTillInst', 'DiverseInfo'); + +$simpleFields = array( + 'ID' => 'ID', + 'Fornamn' => 'Förnamn', + 'Efternamn' => 'Efternamn', + 'Titel' => 'Titel', + 'Personnummer' => 'Personnummer', + 'SkolaForetag' => 'Skola/Företag', + 'Avdelning' => 'Avdelning', + 'Epost' => 'Epost', + 'Telefon' => 'Telefon', + 'TelefonMobil' => 'Mobiltelefon', + 'TelefonHem'=> 'Telefon Hem', + 'URL' => 'URL', + 'AnknytningTillInst' => 'Anknytning till inst.', +); + +$areaFields = array( + 'Adress' => 'Adress', + 'Besok' => 'Besöksadress', + 'Hem' => 'Hemadress', + 'DiverseInfo' => 'Diverse info.' +); + + +if (isset($params['ID'])) { + $ID = $params['ID']; + $person = new Person($ID); +} else { + $person = new Person(); +} +$smarty = $this->smarty; + +$headline = $person->Fornamn . ' ' .$person->Efternamn; +if (strlen($headline) == 1) $headline = $person->SkolaForetag; +$headline = 'Redigera post: ' . $headline; + +$smarty->assign('headline',$headline); + + +$place = $this->CreateFormStart($id, 'changeDatabase', $returnid); +$smarty->assign('start_form', $place); +$smarty->assign('end_form', $this->CreateFormEnd()); + + +foreach ($simpleFields as $key => $name) { + $smarty->assign('title_'.$key,$name); + $place = $this->CreateInputText($id,$key,$person->$key,30); + $smarty->assign('input_'.$key,$place); +} + $smarty->assign('title_Andrad','Ändrad'); +$smarty->assign('value_Andrad', $person->Andrad); + +foreach ($areaFields as $key => $name) { + $smarty->assign('title_'.$key,$name); + $place = $this->CreateTextArea(false,$id,$person->$key,$key, + 'width:auto; height:auto;','','','',30,3); + $place = str_replace('class','style', $place); + $smarty->assign('text_'.$key,$place); +} + +$smarty->assign('title_Grupper', 'Medlem av grupper'); +$name = 'Grupper'; +$place = $this->CreateInputSelectList($id, $name, $person->Grupper, + array(), 5, '', false); +$smarty->assign('select_Grupper', $place); +$place = $this->CreateInputSubmit($id, 'doGroups', 'Ändra grupper'); +$smarty->assign('groupsButton', $place); + + + +$place = ''; +foreach (Person::$firstFields as $field) { + if (isset($params[$field])) { + $place .= $this->CreateInputHidden($id, $field,$params[$field]); + } +} +$smarty->assign('hidden',$place); + + +$place = $this->CreateInputSubmit($id, 'submit', 'Uppdatera'); +$smarty->assign('submitButton',$place); + +$place = $this->CreateInputSubmit($id, 'cancelUpdate', 'Avbryt'); +$smarty->assign('cancelButton',$place); + + + + + + +$smarty->assign('person',$person); + +echo '<pre>'; print_r($person); echo '</pre>'; + + + + + + +echo $this->ProcessTemplate('editpanel.tpl'); + + + + +?> diff --git a/action.changeDatabase.php b/action.changeDatabase.php new file mode 100644 index 0000000000000000000000000000000000000000..f376222442db68da3b86de3f75a69dc1acbf02e1 --- /dev/null +++ b/action.changeDatabase.php @@ -0,0 +1,50 @@ +<?php +if (!isset($gCms)) exit; +// echo '<pre>'; print_r($params); echo '</pre>'; exit; + +if (! $this->CheckPermission('Use ReglerAddress')) { + return $this->DisplayErrorPage($id, $params, $returnid, + 'ReglerAddress access denied.'); +} + +if (isset($params['doGroups'])) { + $paramsB = array(); + foreach (Person::$firstFields as $field) { + if (isset($params[$field])) { + $paramsB[$field] = $params[$field]; + } + } + $this->Redirect($id, 'changeGroups', $returnid, $paramsB); +} + + +if (isset($params['cancelUpdate'])) { + $paramsB = array(); + foreach (Person::$firstFields as $field) { + if (isset($params[$field])) { + $paramsB[$field] = $params[$field]; + } + } + $paramsB['module_message'] = 'Adressändring avbruten'; + $this->Redirect($id, 'defaultadmin', $returnid, $paramsB); + return; +} + + +if (isset($params['submit'])) { + $record = new Person($params); + echo '<pre>'; print_r($record); echo '</pre>'; + $record->updateRecord(); + $paramsB['module_message'] = 'Adressinformation ändrad'; + foreach (Person::$firstFields as $field) { + if (isset($params[$field])) { + $paramsB[$field] = $params[$field]; + } + } + $this->Redirect($id, 'defaultadmin', $returnid, $paramsB); +} + + + + +?> diff --git a/action.changeGroups.php b/action.changeGroups.php new file mode 100644 index 0000000000000000000000000000000000000000..9d42a78c2de405bdd47ffdfec8dda96fa18b60ca --- /dev/null +++ b/action.changeGroups.php @@ -0,0 +1,77 @@ +<?php +if (!isset($gCms)) exit; +echo '<pre>'; print_r($params); echo '</pre>'; + +if (! $this->CheckPermission('Use ReglerAddress')) { + return $this->DisplayErrorPage($id, $params, $returnid, + 'ReglerAddress access denied.'); +} +require_once 'lib/class.Group.php'; + +if (isset($params['back'])) { + $paramsB = array(); + foreach (Person::$firstFields as $field) { + if (isset($params[$field])) { + $paramsB[$field] = $params[$field]; + } + } + $this->Redirect($id, 'add_edit', $returnid, $paramsB); + // return; +} + +$ID = $params['ID']; + +if (isset($params['setMember'])) { + $GroupID = $params['nonmembers']; + Group::setMember($ID,$GroupID); +} + +if (isset($params['unsetMember'])) { + $GroupID = $params['members']; + Group::UnsetMember($ID,$GroupID); +} + +$members = Group::getMembers($ID); +$nonmembers = Group::getNonMembers($ID); + +// echo '<pre>'; print_r($nonmembers); echo '</pre>'; + +$place = $this->CreateFormStart($id, 'changeGroups', $returnid); +$smarty->assign('start_form', $place); +$smarty->assign('end_form', $this->CreateFormEnd()); + + + +$selected = array(); +$groupNames = array(' ' => 'None') + $members; +$place = $this->CreateInputSelectList($id, 'members', $groupNames, +// $selecteditems = array(), $size = 10, $addttext = '', $multiple = false); + $selected, 10, '', false); +$smarty->assign('members',$place); + +$groupNames = array(' ' => 'None') + $nonmembers; +$place = $this->CreateInputSelectList($id, 'nonmembers', $groupNames, +// $selecteditems = array(), $size = 10, $addttext = '', $multiple = false); + $selected, 10, '', false); +$smarty->assign('nonmembers',$place); + +$place = $this->CreateInputSubmit($id, 'setMember', '<—'); +$smarty->assign('setMember',$place); + +$place = $this->CreateInputSubmit($id, 'unsetMember', '—>'); +$smarty->assign('setNonmember',$place); + +$place = $this->CreateInputSubmit($id, 'back', 'Tillbaka'); +$smarty->assign('back',$place); + +$place = ''; +foreach (Person::$firstFields as $field) { + if (isset($params[$field])) { + $place .= $this->CreateInputHidden($id, $field,$params[$field]); + } +} +$smarty->assign('hidden',$place); + +echo $this->ProcessTemplate('groupMembers.tpl'); + +?> diff --git a/action.defaultadmin.php b/action.defaultadmin.php new file mode 100644 index 0000000000000000000000000000000000000000..2c10ea4d063cca26e52ffc0db9f7899271adff2a --- /dev/null +++ b/action.defaultadmin.php @@ -0,0 +1,110 @@ +<?php +/** + * DisplayAdminPanel($id, $params, $returnid, $message) + * NOT PART OF THE MODULE API + * + */ + +/** + * For separated methods, you'll always want to start with the following + * line which check to make sure that method was called from the module + * API, and that everything's safe to continue: + */ +require_once 'lib/class.Group.php'; +if (!isset($gCms)) exit; + +echo '<pre>'; print_r($params); echo '</pre>'; + +/** + * For separated methods, you won't be able to do permission checks in + * the DoAction method, so you'll need to do them as needed in your + * method: +*/ +if (! $this->CheckPermission('Use ReglerAddress')) { + return $this->DisplayErrorPage($id, $params, $returnid, + 'ReglerAddress access denied.'); +} + +/** + * After this, the code is identical to the code that would otherwise be + * wrapped in the DisplayAdminPanel() method in the module body. + */ + +$groups = Group::getGroup(); +//echo '<pre>'; print_r($groups); echo '</pre>'; + +//file_put_contents("/tmp/defaultadmin.txt",print_r($params,TRUE)); +$addrDB = AddressDB::getDB(); +$smarty = $this->smarty; +// echo '<pre>'; print_r($params); echo '</pre>'; + +$place = $this->CreateFormStart($id, 'defaultadmin', $returnid); +$smarty->assign('start_form', $place); +$smarty->assign('end_form', $this->CreateFormEnd()); + +$fields = array( + 'fornamn' => 'Förnamn', + 'efternamn' => 'Efternamn', + 'foretag' => 'Skola/Företag', + 'avdelning' => 'Avdelning', + 'adress' => 'Adress', + ); +$smarty->assign('fields',$fields); + +if (isset($params['new'])) { + $this->Redirect($id, 'add_edit', $returnid, array()); +} + +foreach ($fields as $key => $res) { + $value = ''; + if (isset($params[$key])) {$value = trim($params[$key]); } + $smarty->assign('title_'.$key,$res); + $place = $this->CreateInputText($id,$key,$value,40); + $smarty->assign('input_'.$key,$place); +} + + +$place = $this->CreateInputSubmit($id, 'search', 'Sök'); +$smarty->assign('searchButton',$place); + +$place = $this->CreateInputSubmit($id, 'new', 'Ny post'); +$smarty->assign('newButton',$place); + + +$name = 'Grupp'; +$groupNames = array(' ' => 'None') + $groups; +$selected = array(); +if (isset($params[$name])) $selected[] = $params[$name]; +$place = $this->CreateInputSelectList($id, $name, $groupNames, +// $selecteditems = array(), $size = 10, $addttext = '', $multiple = false); + $selected, 10, '', false); +$smarty->assign('selectgroup',$place); + +$formValues = array(); $hiddenParameters = ''; +foreach ($params as $key => $value) { + if ($key == 'search' || $key == 'action') continue; + if ($key == 'Grupp' && $value == 'None') continue; + if ($key == 'module_message') continue; + if ($value != '') { + $formValues[$key] = $value; + $hiddenParameters[$key] = $value; + } +} +$Persons = array(); +if (count($formValues) > 0) $Persons = Person::searchPersons($formValues); +foreach ($Persons as $person) { + $params = array('ID' => $person->ID) + $hiddenParameters; + $person->link = $this->CreateLink($id, 'add_edit', '', 'Visa', $params); +} + +if (isset($params['module_message'])) { + $smarty->assign('module_message',$params['module_message']); +} + +$smarty->assign('Persons',$Persons); + +echo $this->ProcessTemplate('adminpanel.tpl'); + +//echo '<pre>'; print_r($Persons); echo '</pre>'; + +?> \ No newline at end of file diff --git a/lib/action.defaultadmin.php b/lib/action.defaultadmin.php deleted file mode 100644 index 0d1665c75b931645ede3c1a81861252f53e63cbb..0000000000000000000000000000000000000000 --- a/lib/action.defaultadmin.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php -/** - * DisplayAdminPanel($id, $params, $returnid, $message) - * NOT PART OF THE MODULE API - * - */ - -/** - * For separated methods, you'll always want to start with the following - * line which check to make sure that method was called from the module - * API, and that everything's safe to continue: - */ -if (!isset($gCms)) exit; - - -/** - * For separated methods, you won't be able to do permission checks in - * the DoAction method, so you'll need to do them as needed in your - * method: -*/ -if (! $this->CheckPermission('Use ReglerAddress')) { - return $this->DisplayErrorPage($id, $params, $returnid, - 'ReglerAddress access denied.'); -} - -/** - * After this, the code is identical to the code that would otherwise be - * wrapped in the DisplayAdminPanel() method in the module body. - */ - -if (FALSE == empty($params['active_tab'])) - { - $tab = $params['active_tab']; - } else { - $tab = ''; - } - -//file_put_contents("/tmp/defaultadmin.txt",print_r($params,TRUE)); -$semDB = AddressDB::getDB(); -/* $orderby = ' date desc, start desc'; */ -/* $wheredate = ' date > SUBDATE(CURDATE(), 30) '; */ -/* $currentYear = date('Y'); */ -/* if (isset($params['year'])) { */ -/* $year = $params['year']; */ -/* $yearstart = $semDB->Quote(sprintf('%s-01-01',$year)); */ -/* $yearend = $semDB->Quote(sprintf('%s-12-31',$year)); */ -/* $wheredate = sprintf(' date > %s and date < %s', $yearstart, $yearend); */ -/* $previousYear = $year - 1; */ -/* $nextYear = $year + 1; */ -/* $place = $this->CreateInputSubmit($id, 'year', $previousYear); */ -/* $smarty->assign('previousSelect', $place); */ -/* if ($nextYear <= $currentYear) { */ -/* $place = $this->CreateInputSubmit($id, 'year', $nextYear); */ -/* $smarty->assign('nextSelect', $place); */ -/* } */ -/* } else { */ -/* $place = $this->CreateInputSubmit($id, 'year', $currentYear); */ -/* $smarty->assign('previousSelect', $place); */ -/* } */ - -/* $wheredate = $wheredate . ' and seminars.type=types.id '; */ -/* $records = Seminar::getSeminars($wheredate,$orderby); */ -/* foreach ($records as $rec) { */ -/* $link = $this->CreateFrontendLink($id, $returnid, 'add_edit','%s', */ -/* array('seminarID'=>$rec->id)); */ -/* $rec->setAdminLink($link); */ -/* } */ - - -/* // Expose the list to smarty. Use "by_ref" to save memory. */ -/* $smarty->assign_by_ref('records',$records); */ - -/* // and a count of records */ -/* $smarty->assign('title_num_records', */ -/* $this->Lang('title_num_records',array(count($records)))); */ - - -$place = $this->CreateFormStart($id, 'defaultadmin', $returnid); -$smarty->assign('start_form', $place); -$smarty->assign('end_form', $this->CreateFormEnd()); - -$title_fornamn = 'Förnamn'; -$place = $this->CreateInputText($id,'Fornamn', $fornamn,40); -$input_fornamn = $place; - -$title_efternamn = 'Efternamn'; -$place = $this->CreateInputText($id,'Efternamn', $efternamn,40); -$input_efternamn = $place; - - -/* $place = $this->CreateFormStart($id, 'add_edit', $returnid); */ -/* $smarty->assign('start_form', $place); */ -/* $types = array_flip(Util::$seminarTypes); */ -/* array_shift($types); */ -/* $place = $this->CreateInputSelectList($id,'numericType', */ -/* $types, */ -/* array(1),4,NULL,FALSE); */ -/* $smarty->assign('seminarType', $place); */ -/* $place = $this->CreateInputSubmit($id, 'newSeminar', 'New Seminar'); */ -/* $smarty->assign('submit', $place); */ - -/* if (isset($params['module_message'])) { */ -/* $this->smarty->assign('module_message',$params['module_message']); */ -/* } else { */ -/* $this->smarty->assign('module_message',''); */ -/* } */ - -/* // Display the populated template */ -/* $smarty->assign('end_form', $this->CreateFormEnd()); */ - -/* $place = $this->CreateFormStart($id, 'composeLetter', $returnid); */ -/* $smarty->assign('start_letter_form', $place); */ -/* $place = $this->CreateInputSubmit($id, 'composeLetter', 'Compose Letter'); */ -/* $smarty->assign('submit_letter', $place); */ -/* $smarty->assign('end_letter_form', $this->CreateFormEnd()); */ - -echo $this->ProcessTemplate('adminpanel.tpl'); - -?> \ No newline at end of file diff --git a/lib/class.AddressDB.php b/lib/class.AddressDB.php index 4e5d3f561aa8f0ec5f43e8409aeec8390f1ad55e..d17fda02dbf88d7f5861acac6f4d11ed04ed9ba0 100644 --- a/lib/class.AddressDB.php +++ b/lib/class.AddressDB.php @@ -1,6 +1,6 @@ <?php -class SeminarDB { +class AddressDB { private static $instance; private $PDB; private $database = 'addresses'; @@ -14,7 +14,7 @@ class SeminarDB { $result = $this->PDB->Connect($config['db_hostname'], $config['db_username'], $config['db_password'], - $database); + $this->database); if ($result) { $result = $this->PDB->Execute("SET NAMES 'utf8'"); } else { diff --git a/lib/class.Group.php b/lib/class.Group.php new file mode 100644 index 0000000000000000000000000000000000000000..23d39d3c5059f93c3db843282bc843df59bd3385 --- /dev/null +++ b/lib/class.Group.php @@ -0,0 +1,82 @@ +<?php + +class Group { + + private static $queryList = <<<EOS + select ID, Gruppnamn from Grupper order by Gruppnamn +EOS; + + private static $queryMembership = <<<EOS + select Grupper.ID, Gruppnamn from Grupper,GruppAdress where + GruppID = Grupper.ID and Adressid = ? order by Gruppnamn +EOS; + + private static $querySetGroup = <<<EOS + replace into GruppAdress set AdressID = ?, GruppID = ? +EOS; + + private static $queryUnsetGroup = <<<EOS + delete from GruppAdress where AdressID = ? and GruppID = ? +EOS; + + private static $instance; + + private $list; + + private function __construct() { + global $gCms; + if (!isset($gCms)) exit; + $ADB = AddressDB::getDB(); + $result = $ADB->Execute(self::$queryList,array()); + while ($row = $result->FetchRow()) { + $this->list[$row['Gruppnamn']] = $row['ID']; + } + } + + public static function getMembers($GruppID) { + global $gCms; if (!isset($gCms)) exit; + $db = AddressDB::getDB(); + $result = $db->Execute(self::$queryMembership,array($GruppID)); + if ($result === false) { die("Database error!<br>" . $db->ErrorMsg()); } + $list = array(); + while ($row = $result->FetchRow()) { + $list[$row['Gruppnamn']] = $row['ID']; + } + return $list; + } + + public static function getNonMembers($GruppID) { + $members = self::getMembers($GruppID); + $nonmembers = array_diff_assoc(self::getGroup(),$members); + return $nonmembers; + } + + public static function setMember($ID,$GroupID) { + global $gCms; if (!isset($gCms)) exit; + $db = AddressDB::getDB(); + $values = array($ID, $GroupID); + $result = $db->Execute(self::$querySetGroup,$values); + if ($result === false) {die("Database error!<br>" . $db->ErrorMsg()); } + } + + public static function unsetMember($ID,$GroupID) { + global $gCms; if (!isset($gCms)) exit; + $db = AddressDB::getDB(); + $values = array($ID, $GroupID); + // echo '<pre>'; print_r($queryUnsetGroup); print_r($values); echo '</pre>';exit; + + $result = $db->Execute(self::$queryUnsetGroup,$values); + if ($result === false) {die("Database error!<br>" . $db->ErrorMsg()); } + } + + public static function getGroup() { + if (!isset(self::$instance)) { + $c = __CLASS__; + self::$instance = new $c; + } + return self::$instance->list; + } + + +} +?> diff --git a/lib/class.Person.php b/lib/class.Person.php new file mode 100644 index 0000000000000000000000000000000000000000..0bebc217aec3fd75c837de09a2d780722649a54e --- /dev/null +++ b/lib/class.Person.php @@ -0,0 +1,180 @@ +<?php + +class Person { + + private static $queryPersons = <<<EOT + 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 +EOT; + + private static $queryOne = <<<EOT + select * from Adresser where ID=? +EOT; + + private static $queryGroups = <<<EOT + SELECT Grupper.ID,Gruppnamn FROM `Grupper`, GruppAdress WHERE + Grupper.ID=GruppID and AdressID = ? +EOT; + +/* private static $queryUpdate = <<<EOT */ +/* update Adresser set */ +/* EOT; */ + + public static $firstFields = array( + 'ID','fornamn', 'efternamn', 'foretag','avdelning', 'adress', 'Grupp'); + + + private static $personFields = array( + 'ID', 'Fornamn', 'Efternamn', 'Titel', 'Personnummer', 'SkolaForetag', + 'Avdelning', 'Adress', 'Besok', 'Hem', 'Epost', 'Telefon', 'TelefonMobil', + 'TelefonHem', 'URL', 'AnknytningTillInst', 'DiverseInfo', 'Andrad'); + + + public function __construct($param = NULL) { + global $gCms; + if (!isset($gCms)) exit; + foreach(self::$personFields as $field) { + $this->$field = ''; + } + $this->Namn = ''; $this->ForetagAdress = ''; + $this->Grupper = array(); + if (is_null($param)) return; + if (is_array($param)) { + if (isset($param['ID'])) $this->fromDB($param['ID']); + foreach (self::$personFields as $field) { + if ($field == 'ID') continue; + if (isset($param[$field])) $this->$field = $param[$field]; + } + return; + } + $this->fromDB($param); + } + + private function fromDB($adressID) { + global $gCms; if (!isset($gCms)) exit; + $db = AddressDB::getDB(); + $values = array($adressID); + $result = $db->Execute(self::$queryOne,$values); + if ($result === false) { die("Database error!<br>" . $db->ErrorMsg()); } + $count = $result->RecordCount(); + switch ($count) { + case 0: + die(sprintf('Bad address ID %s'.PHP_EOL,$adressID)); + break; + case 1: + $row = $result->FetchRow(); + $nn = self::$personFields; + foreach ($nn as $field) { + if (isset($row[$field])) $this->$field = $row[$field]; + } + break; + default: + die(sprintf( + 'Strange error. Exactly one address record expected for key %s', + $authkey)); + } + $this->getGroups($adressID); + } + + private function getGroups($adressID) { + global $gCms; if (!isset($gCms)) exit; + $db = AddressDB::getDB(); + $values = array($adressID); + $result = $db->Execute(self::$queryGroups,$values); + if (!$result) { die("Database error!<br>" . $db->ErrorMsg()); } + while($row = $result->FetchRow()) { + $this->Grupper[$row['Gruppnamn']] = $row['ID']; + } + } + + private function createRecord() { + $db = AddressDB::getDB(); + $query = 'insert into Adresser set Fornamn=?'; + $values = array('Förnamn'); + $result = $db->Execute($query,$values); + if ($result === false) {die("Database error!<br>" . $publDB->ErrorMsg()); } + $this->ID = $db->Insert_ID(); + } + + + + public function updateRecord() { + global $gCms; if (!isset($gCms)) exit; + $db = AddressDB::getDB(); + $query = 'update Adresser set '; + $qfields = array(); $values = array(); + if ($this->ID == '') { $this->createRecord(); } + foreach (self::$personFields as $field) { + if ($field == 'ID') continue; + if (!isset($this->$field)) $this->field = 'null'; + $val = trim($this->$field); + if (strlen($val) == 0) $val = null; + $qfields[] = sprintf('%s = ?',$field); + $values[] = $val; + } + $values[] = $this->ID; + $query .= join(', ',$qfields) . ' where ID=?'; + // echo '<pre>'; print_r($query); echo '</pre>'; + // echo '<pre>'; print_r($values); echo '</pre>'; + + $result = $db->Execute($query,$values); + if ($result === false) {die("Database error!<br>" . $db->ErrorMsg());} + } + + public static function searchPersons($formValues) { + global $gCms; if (!isset($gCms)) exit; + $andQuery = array(); $orQuery = ''; + $andValues = array(); $orValues = array(); + foreach ($formValues as $key => $value) { + switch ($key) { + case 'fornamn' : + $andQuery[] = 'Fornamn like ?'; + $andValues[] = '%'.$value.'%'; + break; + case 'efternamn': + $andQuery[] = 'Efternamn like ?'; + $andValues[] = '%'.$value.'%'; + break; + case 'foretag': + $andQuery[] = 'SkolaForetag like ?'; + $andValues[] = '%'.$value.'%'; + break; + case 'avdelning': + $andQuery[] = 'Avdelning like ?'; + $andValues[] = '%'.$value.'%'; + break; + case 'adress': + $andQuery[] = '(Adress like ? or Hem like ?)'; + $andValues[] = '%'.$value.'%'; + $andValues[] = '%'.$value.'%'; + break; + case 'Grupp': + $andQuery[] = 'AdressID=Adresser.ID and GruppID = ?'; + $andValues[] = $value; + break; + default: + } + $query = self::$queryPersons .' ' . join(' and ', $andQuery); + $values = $andValues; + } + // echo '<pre>'; echo $query; echo '</pre>'; + // echo '<pre>'; print_r($values); echo '</pre>'; + // return array(); + $db = AddressDB::getDB(); + $class = __CLASS__; + $records = array(); + $result = $db->Execute($query,$values); + if (!$result) { die("Database error!<br>" . $db->ErrorMsg()); } + while ($row = $result->FetchRow()) { + $person = new $class(); + foreach ($row as $key => $value) { + $person->$key = $value; + } + $records[] = $person; + } + return $records; + } +} +?> \ No newline at end of file diff --git a/templates/adminpanel.tpl b/templates/adminpanel.tpl index 3af68c8e490be40e421698c88f72b11927d00077..783dce86981105c1d68e06d42424aff722cd1e69 100644 --- a/templates/adminpanel.tpl +++ b/templates/adminpanel.tpl @@ -1,9 +1,22 @@ {$start_form} +<table align="center" bgcolor="#f0f0ff"><thead><tr><td colspan="2" style="text-align: center; font-size: 300%;">Adressregister</td></tr></thead><tbody> +<tr><td style="vertical-align:top;"> <table><tbody> -<tr><td style="text-align:right;">{$title_fornamn}</td> - <td>{$input_fornamn}</td></tr> -<tr><td style="text-align:right;">{$title_efternamn}</td> - <td>{$input_efternamn}</td></tr> +{foreach $fields as $key=>$val} +<tr ><td style="text-align:right;padding-right:1em;">{$title_{$key}}</td> + <td>{$input_{$key}}</td></tr> +{/foreach} </tbody></table> +</td> + +<td style="vertical-align:top;">{$selectgroup}</td></tr> +<tr><td colspan="2" style="text-align: center;">{$searchButton} {$newButton}</td> +</tr></tbody></table> {$end_form} +<table CELLPADDING="3" align="center"><tbody> +{foreach $Persons as $person} + <tr><td>{$person->Namn}</td><td>{$person->ForetagAdress}</td> + <td>{$person->Avdelning}</td><td>{$person->link}</td></tr> +{/foreach} +</tbody></table> \ No newline at end of file diff --git a/templates/editpanel.tpl b/templates/editpanel.tpl new file mode 100644 index 0000000000000000000000000000000000000000..119ca49bf836c7792b667f6c61f1b7d939dbf875 --- /dev/null +++ b/templates/editpanel.tpl @@ -0,0 +1,33 @@ + +{$start_form} +<table CELLPADDING="3" align="center" bgcolor="#f0f0ff"> +<thead><tr><td bgcolor="#000080" colspan="4" style="text-align: center; + font-size: 200%; font-weight:bold; color: white;">{$headline}</td></tr> + </thead> +<tbody> +<tr><td>{$title_Fornamn}</td><td>{$input_Fornamn}</td> + <td>{$title_Efternamn}</td><td>{$input_Efternamn}</td></tr> +<tr><td>{$title_Personnummer}</td><td>{$input_Personnummer}</td> + <td>{$title_Titel}</td><td>{$input_Titel}</td></tr> +<tr><td>{$title_SkolaForetag}</td><td>{$input_SkolaForetag}</td> + <td>{$title_Avdelning}</td><td>{$input_Avdelning}</td></tr> +<tr><td>{$title_Epost}</td><td>{$input_Epost}</td> + <td>{$title_URL}</td><td>{$input_URL}</td></tr> +<tr><td>{$title_Telefon}</td><td>{$input_Telefon}</td> + <td>{$title_TelefonMobil}</td><td>{$input_TelefonMobil}</td></tr> +<tr><td>{$title_TelefonHem}</td><td>{$input_TelefonHem}</td> + <td>{$title_AnknytningTillInst}</td><td>{$input_AnknytningTillInst}</td></tr> +<tr><td>{$title_Adress}</td><td>{$text_Adress}</td> + <td>{$title_Hem}</td><td>{$text_Hem}</td></tr> +<tr><td>{$title_Besok}</td><td>{$text_Besok}</td> + <td>{$title_DiverseInfo}</td><td>{$text_DiverseInfo}</td></tr> +<tr><td>{$title_Grupper}</td><td><table><tr> + <td>{$select_Grupper}</td><td>{$groupsButton}</td></tr></table></td> + <td>{$title_Andrad}</td><td>{$value_Andrad}</td></tr> + <td colspan = "4" style="text-align: center;"> + {$submitButton}{$cancelButton}</td><td></td></tr> + + +</tbody></table> +{$hidden} +{$end_form} diff --git a/templates/groupMembers.tpl b/templates/groupMembers.tpl new file mode 100644 index 0000000000000000000000000000000000000000..545632e6e7e46a9a9c54bf50afc72224a3c30569 --- /dev/null +++ b/templates/groupMembers.tpl @@ -0,0 +1,8 @@ +{$start_form} +<table CELLPADDING="3" align="center"><tbody> +<tr><td>Medlem av</td><td></td><td>Icke medlem av</td></tr> +<tr><td> {$members}</td><td style="font-weiht:bold;">{$setMember}<br />{$setNonmember}</td><td> {$nonmembers}</td></tr> +<tr><td colspan="3" style="text-align: center;">{$back}</td></tr> +</tbody></table> +{$hidden} +{$end_form}