Changeset 27697
- Timestamp:
- Mar 11, 2014, 11:25:49 PM (10 years ago)
- Location:
- extensions/AddUsersNotes
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/AddUsersNotes/main.inc.php
r12447 r27697 13 13 global $prefixeTable; 14 14 15 define('USERNOTES_DIR' , basename(dirname(__FILE__))); 16 define('USERNOTES_PATH' , PHPWG_PLUGINS_PATH . USERNOTES_DIR . '/'); 17 define('USERNOTES_TABLE' , $prefixeTable . 'user_notes'); 15 // +-----------------------------------------------------------------------+ 16 // | Define plugin constants | 17 // +-----------------------------------------------------------------------+ 18 18 19 // Plugin for admin 20 if (script_basename() == 'admin') 19 define('USERNOTES_ID', basename(dirname(__FILE__))); 20 define('USERNOTES_PATH', PHPWG_PLUGINS_PATH.USERNOTES_ID.'/'); 21 define('USERNOTES_VERSION', 'auto'); 22 23 // init the plugin 24 add_event_handler('init', 'usernotes_init'); 25 26 /** 27 * plugin initialization 28 * - check for upgrades 29 * - load language 30 */ 31 function usernotes_init() 21 32 { 22 include_once(dirname(__FILE__).'/initadmin.php'); 33 // apply upgrade if needed 34 include_once(USERNOTES_PATH.'maintain.inc.php'); 35 $maintain = new AddUsersNotes_maintain(USERNOTES_ID); 36 $maintain->autoUpdate(USERNOTES_VERSION, 'install'); 37 38 // load plugin language file 39 load_language('plugin.lang', USERNOTES_PATH); 23 40 } 24 41 42 add_event_handler('loc_begin_admin_page', 'usernotes_add_column'); 43 function usernotes_add_column() 44 { 45 global $template; 46 47 $template->set_prefilter('user_list', 'usernotes_add_column_prefilter'); 48 } 49 50 function usernotes_add_column_prefilter($content, &$smarty) 51 { 52 // add the "Notes" column in the user table 53 $search = '<th>{\'registration date\'|@translate}</th>'; 54 $content = str_replace($search, $search.'<th>{\'Notes\'|@translate}</th>', $content); 55 56 // add the "Notes" field in user profile form 57 $search = '#</div>\s*<div class="userPropertiesSet userPrefs">#ms'; 58 $replace = '<div class="userProperty"><strong>{\'Notes\'|translate}</strong><br><input type="text" name="usernotes" value="<%- user.usernotes %>" style="width:338px;"></div></div><div class="userPropertiesSet userPrefs">'; 59 $content = preg_replace($search, $replace, $content); 60 61 return $content; 62 } 63 64 add_event_handler('user_list_columns', 'usernotes_user_list_columns', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); 65 function usernotes_user_list_columns($aColumns) 66 { 67 $aColumns[] = 'usernotes'; 68 69 return $aColumns; 70 } 71 72 add_event_handler('ws_invoke_allowed', 'usernotes_ws_users_setInfo', EVENT_HANDLER_PRIORITY_NEUTRAL, 3); 73 function usernotes_ws_users_setInfo($res, $methodName, $params) 74 { 75 if ($methodName != 'pwg.users.setInfo') 76 { 77 return $res; 78 } 79 80 if (!isset($_POST['usernotes'])) 81 { 82 return $res; 83 } 84 85 if (count($params['user_id']) == 0) 86 { 87 return $res; 88 } 89 90 $updates = array(); 91 92 foreach ($params['user_id'] as $user_id) 93 { 94 $updates[] = array( 95 'user_id' => $user_id, 96 'usernotes' => $_POST['usernotes'], 97 ); 98 } 99 100 if (count($updates) > 0) 101 { 102 mass_updates( 103 USER_INFOS_TABLE, 104 array( 105 'primary' => array('user_id'), 106 'update' => array('usernotes') 107 ), 108 $updates 109 ); 110 } 111 112 return $res; 113 } 114 115 add_event_handler('ws_users_getList', 'usernotes_ws_users_getList', EVENT_HANDLER_PRIORITY_NEUTRAL, 1); 116 function usernotes_ws_users_getList($users) 117 { 118 $user_ids = array(); 119 foreach ($users as $user_id => $user) 120 { 121 $user_ids[] = $user_id; 122 } 123 124 if (count($user_ids) == 0) 125 { 126 return $users; 127 } 128 129 $query = ' 130 SELECT 131 user_id, 132 usernotes 133 FROM '.USER_INFOS_TABLE.' 134 WHERE user_id IN ('.implode(',', $user_ids).') 135 ;'; 136 $result = pwg_query($query); 137 while ($row = pwg_db_fetch_assoc($result)) 138 { 139 $users[$row['user_id']]['usernotes'] = $row['usernotes']; 140 } 141 142 return $users; 143 } 25 144 ?> -
extensions/AddUsersNotes/maintain.inc.php
r12447 r27697 1 1 <?php 2 3 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 4 3 5 function plugin_install() 4 class AddUsersNotes_maintain extends PluginMaintain 6 5 { 6 private $installed = false; 7 8 function __construct($plugin_id) 9 { 10 parent::__construct($plugin_id); 11 } 12 13 function install($plugin_version, &$errors=array()) 14 { 7 15 global $prefixeTable; 16 17 // add a new column to existing table 18 $result = pwg_query('SHOW COLUMNS FROM `'.USER_INFOS_TABLE.'` LIKE "usernotes";'); 19 if (!pwg_db_num_rows($result)) 20 { 21 pwg_query('ALTER TABLE `' . USER_INFOS_TABLE . '` ADD `usernotes` VARCHAR(255) DEFAULT NULL;'); 22 } 8 23 9 if (!defined('USERNOTES_TABLE')) define('USERNOTES_TABLE', $prefixeTable.'user_notes'); 10 $query = "CREATE TABLE IF NOT EXISTS ". USERNOTES_TABLE ." ( 11 user_id SMALLINT( 5 ) UNSIGNED NOT NULL , 12 note VARCHAR( 255 ) NOT NULL , 13 PRIMARY KEY (user_id))DEFAULT CHARSET=utf8;"; 14 $result = pwg_query($query); 15 24 // if we find the old table, we copy notes 25 $result = pwg_query('SHOW TABLES LIKE "'.$prefixeTable.'user_notes";'); 26 if (pwg_db_num_rows($result)) 27 { 28 $query = ' 29 UPDATE 30 '.USER_INFOS_TABLE.' AS ui, 31 '.$prefixeTable.'user_notes AS un 32 SET ui.usernotes = un.note 33 WHERE ui.user_id = un.user_id 34 AND LENGTH(note) > 0 35 ;'; 36 pwg_query($query); 37 38 pwg_query('DROP TABLE '.$prefixeTable.'user_notes;'); 39 } 40 41 $this->installed = true; 42 } 43 44 function activate($plugin_version, &$errors=array()) 45 { 46 if (!$this->installed) 47 { 48 $this->install($plugin_version, $errors); 49 } 50 } 51 52 function deactivate() 53 { 54 } 55 56 function uninstall() 57 { 58 pwg_query('ALTER TABLE `'. USER_INFOS_TABLE .'` DROP `usernotes`;'); 59 } 16 60 } 17 18 function plugin_uninstall()19 {20 global $prefixeTable;21 22 $q = 'DROP TABLE ' . $prefixeTable . 'user_notes;';23 pwg_query($q);24 }25 26 27 61 ?>
Note: See TracChangeset
for help on using the changeset viewer.