action.defaultadmin.php 3.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
<?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:
 */ 
13
// require_once 'lib/class.Group.php';
14
15
if (!isset($gCms)) exit;

16
//echo '<pre>'; print_r($params); echo '</pre>';
17
18
19
20
21
22

/** 
 * 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:
*/ 
23
24
25
26
27
/* if (! $this->CheckPermission('Use ReglerAddress')) { */
/*   return $this->DisplayErrorPage($id, $params, $returnid, */
/* 				 'ReglerAddress access denied.'); */
/* } */
$canChangeRecord = $this->CheckPermission('Use ReglerAddress');
28
29
30
31
32
/**
 * After this, the code is identical to the code that would otherwise be
 * wrapped in the DisplayAdminPanel() method in the module body.
 */
 
33
$groups = Groups::getGroupList(); 
Leif Andersson's avatar
A    
Leif Andersson committed
34
//echo '<pre>'; print_r($groups); echo '</pre>'; exit;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

$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());
}

Leif Andersson's avatar
B    
Leif Andersson committed
57
58
59
60
if (isset($params['groupChange'])) {
  $this->Redirect($id,'editGroups',$returnid,array());
}
	
61
62
63
64
65
66
67
68
69
70
71
72
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);

73
74
75
76
77
if ($canChangeRecord) {
  $place = $this->CreateInputSubmit($id, 'new', 'Ny post');
} else {
  $place = '';
}
78
79
$smarty->assign('newButton',$place);

Leif Andersson's avatar
B    
Leif Andersson committed
80
81
$place =  $this->CreateInputSubmit($id, 'groupChange', 'Hantera grupper');
$smarty->assign('groupButton',$place);
82
83

$name = 'Grupp';
Leif Andersson's avatar
A    
Leif Andersson committed
84
85
86
87
$groupNames = array(' ' => 'None');
foreach ($groups as $group) {
  $groupNames[$group->Gruppnamn] = $group->ID;
}
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
$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>';

?>