Commit 03b36c86 authored by Leif Andersson's avatar Leif Andersson
Browse files

Moved action.defaultadmin.php, erroneously placed in lib.

parent f22a4277
......@@ -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);
}
/**
......
<?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');
?>
<?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);
}
?>
<?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');
?>
<?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
<?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
<?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 {
......
<?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;
}
}
?>
<?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;