source: extensions/AddUsersNotes/initadmin.php @ 14201

Last change on this file since 14201 was 12447, checked in by ddtddt, 12 years ago

[extensions] - AddUsersNotes - First commit

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