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