EGOCMS  18.0
EGOTEC Content-Managament-System
Ego_Input_Store.php
gehe zur Dokumentation dieser Datei
1 <?php
8 require_once('base/Ego_Store.php');
9 
15 class Ego_Input_Store extends Ego_Store {
21  protected $name = '';
22 
28  protected $value = '';
29 
35  protected $data = null;
36 
43  public function __construct($params = array(), $query = array()) {
44  parent::__construct($params, $query);
45 
46  $this->name = str_replace(
47  array('*', '. . '),
48  array('%', ''),
49  (string) $_REQUEST['name']
50  );
51  $this->value = (string) $_REQUEST['value'];
52  $this->data = $_REQUEST['data'];
53  }
54 
60  public function getData() {
61  switch ($this->data) {
62  // Benutzer ermitteln
63  case 'user':
64  $db = new_db_connection();
65 
66  // Nur anzeigen, wenn der Benutzer einer der übergebenen Gruppen/Rollen angehört
67  $join = array();
68  $bind = array();
69  $where = '';
70  if ($this->params['rights']) {
71  $join[] = 'egotec_user_group ON egotec_user.user_id = egotec_user_group.user_id';
72  $rights_or = array();
73  foreach (explode(';', $this->params['rights']) as $n => $right) {
74  list($group, $role) = explode(',', $right);
75  $rights_or[] = '(egotec_user_group.group_id = :group_id'.$n.' AND egotec_user_group.role_id = :role_id'.$n.')';
76  $bind['group_id'.$n] = $group;
77  $bind['role_id'.$n] = $role;
78  }
79  $where = '('.implode(' OR ', $rights_or).') AND ';
80  }
81 
82  if (empty($this->value)) {
83  if (!$this->isValidSearch($this->name)) {
84  return;
85  }
86  $query = array(
87  'table' => 'egotec_user',
88  'where' => $where.'egotec_user.deleted = 0 AND LOWER(egotec_user.username) LIKE :username',
89  'join' => $join,
90  'order' => 'egotec_user.username ASC',
91  'bind' => array_merge($bind, array(
92  'username' => mb_strtolower($this->name)
93  ))
94  );
95  if ($this->limit > 0) {
96  $query['limit'] = "{$this->start},{$this->limit}";
97  }
98  $db->select($this->buildQuery($query));
99  } else {
100  $db->select($this->buildQuery(array(
101  'table' => 'egotec_user',
102  'where' => $where.'egotec_user.user_id = :user_id',
103  'join' => $join,
104  'bind' => array_merge($bind, array(
105  'user_id' => $this->value
106  ))
107  )));
108  }
109  while ($db->nextRecord()) {
110  $user = new User_SQL($db->Record['user_id']);
111 
112  // Nur anzeigen, wenn man berechtigt ist diesen Benutzer zu sehen
113  if (
114  empty($this->value)
115  && !$this->params['all_users']
116  && !$GLOBALS['auth']->hasSuperuserPermission()
117  ) {
118  $found = false;
119  foreach ($user->getGroupRoleRelations() as $group => $roles) {
120  foreach (explode(',', $roles) as $role) {
121  if ($GLOBALS['auth']->hasPermission($group, $role)) {
122  $found = true;
123  break 2;
124  }
125  }
126  }
127  if (!$found) {
128  continue;
129  }
130  }
131 
132  $icon = $GLOBALS['egotec_conf']['url_dir'].'bin/admin_skin/egotec/sitemap_img/';
133  if ($user->isInactive()) {
134  continue;
135  } else {
136  // Nur Benutzer, die sich im Adminbereich anmelden dürfen
137  if ($this->params['no_admin'] && $user->field['no_admin']) {
138  continue;
139  }
140 
141  // Nur Benutzer, die sich auf dem Liveserver anmelden dürfen
142  if ($this->params['liveserver'] && $GLOBALS['egotec_conf']['liveserver'] && !$user->extra['liveserver']) {
143  continue;
144  }
145 
146  if ($user->extra['gender'] == 'female') {
147  $icon .= 'user_female.png';
148  } else {
149  $icon .= 'user_male.png';
150  }
151  }
152  $this->addItem(array(
153  self::IDENTIFIER => $db->Record['user_id'],
154  'name' => $user->getFullname(),
155  'icon' => $icon
156  ));
157  }
158  break;
159 
160  // Gruppe ermitteln
161  case 'group':
162  $db = new_db_connection();
163  if (empty($this->value)) {
164  if (trim($this->name, '%') != '') {
165  // Suche
166  if (!$this->isValidSearch($this->name)) {
167  return;
168  }
169 
170  $where = '';
171  if (!$GLOBALS['auth']->hasSuperuserPermission()) {
172  // Nur die Gruppen anzeigen denen man selbst angehört
173  $groups = $GLOBALS['auth']->user->getAllGroups();
174  $group_ids = array();
175  foreach ($groups as $group) {
176  $group_ids[] = $group->field['group_id'];
177  }
178  $where = "group_id IN ('" . implode("','", $group_ids) . "') AND ";
179  }
180 
181  $query = array(
182  'table' => 'egotec_group',
183  'where' => $where . 'LOWER(group_name) LIKE :group_name',
184  'order' => 'links ASC',
185  'bind' => array(
186  'group_name' => mb_strtolower($this->name)
187  )
188  );
189  if ($this->limit > 0) {
190  $query['limit'] = "{$this->start},{$this->limit}";
191  }
192  $db->select($this->buildQuery($query));
193  } else {
194  // Alle Gruppen
195  require_once('rights/Group_SQL.php');
196  $parent = new Group_SQL($GLOBALS['egotec_conf']['superuser']['group']);
197 
198  $group_ids = array();
199  if (!$GLOBALS['auth']->hasSuperuserPermission()) {
200  // Nur die Gruppen anzeigen denen man selbst angehört
201  $groups = $GLOBALS['auth']->user->getAllGroups();
202  foreach ($groups as $group) {
203  $group_ids[] = $group->field['group_id'];
204  }
205  }
206 
207  // Gruppe "Alle" ist auswählbar
208  if ($this->params['all_group']) {
209  $this->addItem(array(
210  self::IDENTIFIER => '*',
211  'name' => '(' . $GLOBALS['auth']->translate('Alle') . ')',
212  'icon' => $GLOBALS['egotec_conf']['url_dir'].'bin/admin_skin/egotec/img/16x16/user-unknown2.png',
213  'indent' => 0
214  ));
215  }
216 
217  $this->getNS($parent, $group_ids, 'group_id', 'group_name', 'groups.png');
218  return;
219  }
220  } else {
221  $db->select($this->buildQuery(array(
222  'table' => 'egotec_group',
223  'where' => 'group_id = :group_id',
224  'bind' => array(
225  'group_id' => $this->value
226  )
227  )));
228  }
229  while ($db->nextRecord()) {
230  $group = new Group_SQL($db->Record['group_id'], $db->Record);
231  $name = $db->Record['group_name'];
232  $this->addItem(array(
233  self::IDENTIFIER => $db->Record['group_id'],
234  'name' => $name,
235  'icon' => $GLOBALS['egotec_conf']['url_dir'].'bin/admin_skin/egotec/img/16x16/groups.png',
236  'indent' => $db->Record['tiefe'],
237  'hover' => ltrim($group->getPath(true).'/'.$name, '/')
238  ));
239  }
240  break;
241 
242  // Rolle ermitteln
243  case 'role':
244  $db = new_db_connection();
245  if (empty($this->value)) {
246  if (trim($this->name, '%') != '') {
247  // Suche
248  if (!$this->isValidSearch($this->name)) {
249  return;
250  }
251 
252  $where = '';
253  if (!$GLOBALS['auth']->hasSuperuserPermission()) {
254  // Nur die Rollen anzeigen denen man selbst angehört
255  $roles = $GLOBALS['auth']->user->getAllRoles();
256  $role_ids = array();
257  foreach ($roles as $role) {
258  $role_ids[] = $role->field['role_id'];
259  }
260  $where = "role_id IN ('".implode("','", $role_ids)."') AND ";
261  }
262 
263  $query = array(
264  'table' => 'egotec_role',
265  'where' => $where.'LOWER(role_name) LIKE :role_name',
266  'order' => 'links ASC',
267  'bind' => array(
268  'role_name' => mb_strtolower($this->name)
269  )
270  );
271  if ($this->limit > 0) {
272  $query['limit'] = "{$this->start},{$this->limit}";
273  }
274  $db->select($this->buildQuery($query));
275  } else {
276  // Alle Rollen
277  require_once('rights/Role_SQL.php');
278  $parent = new Role_SQL($GLOBALS['egotec_conf']['superuser']['role']);
279 
280  $role_ids = array();
281  if (!$GLOBALS['auth']->hasSuperuserPermission()) {
282  // Nur die Rollen anzeigen denen man selbst angehört
283  $roles = $GLOBALS['auth']->user->getAllRoles();
284  $role_ids = array();
285  foreach ($roles as $role) {
286  $role_ids[] = $role->field['role_id'];
287  }
288  }
289 
290  $this->getNS($parent, $role_ids, 'role_id', 'role_name', 'roles.png');
291  return;
292  }
293  } else {
294  $db->select($this->buildQuery(array(
295  'table' => 'egotec_role',
296  'where' => 'role_id = :role_id',
297  'bind' => array(
298  'role_id' => $this->value
299  )
300  )));
301  }
302  while ($db->nextRecord()) {
303  $role = new Role_SQL($db->Record['role_id'], $db->Record);
304  $name = $db->Record['role_name'];
305  $this->addItem(array(
306  self::IDENTIFIER => $db->Record['role_id'],
307  'name' => $name,
308  'icon' => $GLOBALS['egotec_conf']['url_dir'].'bin/admin_skin/egotec/img/16x16/roles.png',
309  'indent' => $db->Record['tiefe'],
310  'hover' => ltrim($role->getPath(true).'/'.$name, '/')
311  ));
312  }
313  break;
314 
315  // Seite ermitteln
316  case 'page':
317  if (empty($this->value)) {
318  if (!$this->isValidSearch($this->name)) {
319  return;
320  }
321 
322  if (!isset($this->params['query'])) {
323  $this->params['query'] = array();
324  }
325  if (!isset($this->params['query']['bind'])) {
326  $this->params['query']['bind'] = array();
327  }
328  if (!isset($this->params['param'])) {
329  $this->params['param'] = array();
330  }
331  if ($this->limit > 0) {
332  $this->params['query']['limit'] = "{$this->start},{$this->limit}";
333  }
334  $this->params['query']['where'] = ($this->params['query']['where']
335  ? $this->params['query']['where'] . ' AND '
336  : '')."LOWER(name) LIKE :name";
337  $this->params['query']['bind']['name'] = mb_strtolower($this->name);
338  $this->site->setRights(array('edit', 'view'));
339  if ($parent = $this->site->getPage($this->params['id'])) {
340  $pages = $parent->getChildren(
341  $this->buildQuery($this->params['query']),
342  $this->params['param']
343  );
344  } else {
345  $pages = array();
346  }
347  } else {
348  $pages = array(Ego_System::urltopage($this->value));
349  }
350  foreach ($pages as $page) {
351  if ($page) {
352  $this->addItem(array(
353  self::IDENTIFIER => ltrim($page->getUrl(array('nonactive' => false)), $GLOBALS['egotec_conf']['url_dir']),
354  'name' => $page->field['name'],
355  'icon' => $page->getIconUrl()
356  ));
357  }
358  }
359  break;
360 
361  // Seitentyp ermitteln
362  case 'types':
363  $search = str_replace(array('*', '%'), '', $this->name);
364  $site = $this->params['from'] ? new Site($this->params['from']) : ($this->site ? $this->site : new Site());
365  $types = $this->params['type_list'] ? $this->params['type_list'] : $site->getTypes();
366  foreach ($types as $type) {
367  if (
368  $site->admin['enabled_types'][$type['type']]
369  || !$type['global']
370  || $type['system']
371  ) {
372  if (empty($this->value)) {
373  if (
374  !empty($search)
375  && (empty($type['active'])
376  || mb_stripos($type['fullname'], $search) === false)
377  ) {
378  continue;
379  }
380  } elseif ($type['type'] != $this->value) {
381  continue;
382  }
383 
384  $this->addItem(array(
385  self::IDENTIFIER => $type['type'],
386  'name' => Ego_System::filterNonUtf8($type['fullname']),
387  'label' => Ego_System::filterNonUtf8(empty($search) ? $type['name'] : ''),
388  'icon' => $this->page && $this->page->field['type'] == $type['type']
389  ? $this->page->getIconUrl()
390  : ($type['icon']
391  ? $type['icon']
392  : $GLOBALS['egotec_conf']['url_dir'].'bin/admin_skin/egotec/img/16x16/'
393  .($type['type'] == 'multimedia/category'
394  ? 'folder.png'
395  : 'page.png')
396  ),
397  'disabled' => empty($type['active']) && $this->page->canChangeType(),
398  'indent' => empty($search) ? $type['depth'] : 0
399  ));
400  if (!empty($this->value)) {
401  break;
402  }
403  }
404  }
405  }
406  }
407 
418  private function getNS($parent, $ids, $id_key, $name_key, $icon) {
419  if (empty($ids) || in_array($parent->field[$id_key], $ids)) {
420  $this->addItem(array(
421  self::IDENTIFIER => $parent->field[$id_key],
422  'name' => $parent->field[$name_key],
423  'icon' => $GLOBALS['egotec_conf']['url_dir'].'bin/admin_skin/egotec/img/16x16/'.$icon,
424  'indent' => $parent->field['tiefe'],
425  'hover' => ltrim($parent->getPath(true).'/'.$parent->field[$name_key], '/')
426  ));
427  }
428 
429  foreach ($parent->getChildren() as $child) {
430  $this->getNS($child, $ids, $id_key, $name_key, $icon);
431  }
432  }
433 }
434 ?>
static urltopage($url, $params=array(), $only_site=false, $error_page=false, $commit_params=false)
__construct($params=array(), $query=array())
static filterNonUtf8($s, $substitute="", $strict=false)
Definition: Ego_System.php:320
Definition: Site.php:29