+ if ($a->argc>2) {
+ $uid = $a->argv[3];
+ $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
+ if (count($user)==0){
+ notice( 'User not found' . EOL);
+ goaway($a->get_baseurl() . '/admin/users' );
+ return; // NOTREACHED
+ }
+ switch($a->argv[2]){
+ case "delete":{
+ // delete user
+ require_once("include/Contact.php");
+ user_remove($uid);
+
+ notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
+ }; break;
+ case "block":{
+ q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
+ intval( 1-$user[0]['blocked'] ),
+ intval( $uid )
+ );
+ notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
+ }; break;
+ }
+ goaway($a->get_baseurl() . '/admin/users' );
+ return; // NOTREACHED
+
+ }
+
+ /* get pending */
+ $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
+ FROM `register`
+ LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
+ LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
+
+ /* get users */
+
+ $total = q("SELECT count(*) as total FROM `user` where 1");
+ if(count($total)) {
+ $a->set_pager_total($total[0]['total']);
+ $a->set_pager_itemspage(100);
+ }
+
+ $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
+ FROM
+ (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
+ FROM `item`
+ WHERE `item`.`type` = 'wall'
+ GROUP BY `item`.`uid`) AS `lastitem`
+ RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
+ `contact`
+ WHERE
+ `user`.`uid` = `contact`.`uid`
+ AND `user`.`verified` =1
+ AND `contact`.`self` =1
+ ORDER BY `contact`.`name` LIMIT %d, %d
+ ",
+ intval($a->pager['start']),
+ intval($a->pager['itemspage'])
+ );
+
+ function _setup_users($e){
+ $accounts = Array(
+ t('Normal Account'),
+ t('Soapbox Account'),
+ t('Community/Celebrity Account'),
+ t('Automatic Friend Account')
+ );
+ $e['page-flags'] = $accounts[$e['page-flags']];
+ $e['register_date'] = relative_date($e['register_date']);
+ $e['login_date'] = relative_date($e['login_date']);
+ $e['lastitem_date'] = relative_date($e['lastitem_date']);
+ return $e;
+ }
+ $users = array_map("_setup_users", $users);
+
+ $t = get_markup_template("admin_users.tpl");
+ $o = replace_macros($t, array(
+ // strings //
+ '$title' => t('Administration'),
+ '$page' => t('Users'),
+ '$submit' => t('Submit'),
+ '$select_all' => t('select all'),
+ '$h_pending' => t('User registrations waiting for confirm'),
+ '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
+ '$no_pending' => t('No registrations.'),
+ '$approve' => t('Approve'),
+ '$deny' => t('Deny'),
+ '$delete' => t('Delete'),
+ '$block' => t('Block'),
+ '$unblock' => t('Unblock'),
+
+ '$h_users' => t('Users'),
+ '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
+
+ '$confirm_delete_multi' => t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
+ '$confirm_delete' => t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
+
+
+ // values //
+ '$baseurl' => $a->get_baseurl(),
+
+ '$pending' => $pending,
+ '$users' => $users,
+ ));
+ $o .= paginate($a);
+ return $o;