source: extensions/AddUsersNotes/initadmin.php @ 17824

Last change on this file since 17824 was 17648, checked in by plg, 12 years ago

bug fixed: [Administration > Configuration > Options > Guest User] screen was not loading/saving user note

File size: 2.8 KB
Line 
1<?php
2
3
4
5//add prefiter
6add_event_handler('loc_begin_admin', 'aun1', 55 );
7
8function aun1()
9 {
10        load_language('plugin.lang', USERNOTES_PATH);
11        load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
12 
13        global $template, $prefixeTable, $conf;
14        $template->set_prefilter('profile_content', 'aun2');
15        $template->set_filename('profile_aun', realpath(USERNOTES_PATH.'profile_addusersnotes.tpl'));
16
17        if ('configuration' == $_GET['page'] and 'default' == $_GET['section'])
18        {
19          $_GET['user_id'] = $conf['guest_id'];
20        }
21
22 if (isset($_GET['user_id']))
23        {
24        $query = '
25         select user_id,note
26         FROM ' . USERNOTES_TABLE . '
27         WHERE user_id = '.$_GET['user_id'].'
28         ;';
29        $result = pwg_query($query);
30        $row = mysql_fetch_array($result);
31        $note=$row['note'];
32
33
34        $template->assign(
35                array(
36                 'NOTESID' => $_GET['user_id'],
37                 'NOTESCONTENT' => htmlspecialchars($note),
38                ));
39        }       
40                $template->assign_var_from_handle('PROFILE_AUN', 'profile_aun');
41 }
42
43function aun2($content, &$smarty)
44 {
45 
46  $search = '<p class="bottomButtons">';
47  return str_replace($search, '{$PROFILE_AUN}'."\n".$search, $content);
48 }
49 
50add_event_handler('save_profile_from_post', 'aun3');
51
52function aun3()
53{
54global $prefixeTable;
55
56        $query = '
57DELETE
58  FROM ' . USERNOTES_TABLE . '
59  WHERE user_id = '.$_POST['inserID2'].'
60  ;';
61$result = pwg_query($query);
62
63        $q = '
64INSERT INTO ' . $prefixeTable . 'user_notes(user_id,note)VALUES ("'.$_POST['inserID2'].'","'.$_POST['inseraun'].'");';
65    pwg_query($q);
66}
67
68add_event_handler('delete_user', 'aun4');
69
70function aun4($user_id)
71{
72global $prefixeTable;
73
74        $query = '
75DELETE
76  FROM ' . USERNOTES_TABLE . '
77  WHERE user_id = '.$user_id.'
78  ;';
79$result = pwg_query($query);
80}
81
82add_event_handler('loc_visible_user_list', 'aun5');
83
84
85function aun5($visible_user_list)
86{
87  global $template;
88 
89  $template->append('plugin_user_list_column_titles', l10n('Notes'));
90 
91  $user_ids = array();
92 
93  foreach ($visible_user_list as $i => $user)
94  {
95    $user_ids[$i] = $user['id'];
96  }
97 
98  $user_nums = array_flip($user_ids);
99
100  if (!empty($user_ids))
101  {
102$query = '
103         select u.id, un.note
104         FROM ' . USERS_TABLE . ' AS u LEFT JOIN '.USERNOTES_TABLE.' AS un on u.id = un.user_id
105         WHERE u.id IN ('.implode(',', $user_ids).')
106;';
107
108 
109  $result = pwg_query($query); 
110
111            while ($row = mysql_fetch_array($result))
112    {
113               
114        if (!empty($row['note']))
115                {
116        $visible_user_list[$user_nums[$row['id']]]['plugin_columns'][] =$row['note'].' ';
117                }
118        if (empty($row['note']))
119                {
120        load_language('plugin.lang', USERNOTES_PATH);
121        load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
122                $noempty=l10n('no note');
123        $visible_user_list[$user_nums[$row['id']]]['plugin_columns'][] =$noempty;
124                }
125        }
126
127  }
128  return $visible_user_list;
129}
130
131
132
133?>
Note: See TracBrowser for help on using the repository browser.