1<?php 2/* 3 * User Manager 4 * 5 * Dokuwiki Admin Plugin 6 * 7 * This version of the user manager has been modified to only work with 8 * objectified version of auth system 9 * 10 * @author neolao <neolao@neolao.com> 11 * @author Chris Smith <chris@jalakai.co.uk> 12 */ 13// must be run within Dokuwiki 14if(!defined('DOKU_INC')) die(); 15 16if(!defined('DOKU_PLUGIN_IMAGES')) define('DOKU_PLUGIN_IMAGES',DOKU_BASE.'lib/plugins/usermanager/images/'); 17 18/** 19 * All DokuWiki plugins to extend the admin function 20 * need to inherit from this class 21 */ 22class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { 23 24 var $_auth = null; // auth object 25 var $_user_total = 0; // number of registered users 26 var $_filter = array(); // user selection filter(s) 27 var $_start = 0; // index of first user to be displayed 28 var $_last = 0; // index of the last user to be displayed 29 var $_pagesize = 20; // number of users to list on one page 30 var $_edit_user = ''; // set to user selected for editing 31 var $_edit_userdata = array(); 32 var $_disabled = ''; // if disabled set to explanatory string 33 34 /** 35 * Constructor 36 */ 37 function admin_plugin_usermanager(){ 38 global $auth; 39 40 $this->setupLocale(); 41 42 if (!isset($auth)) { 43 $this->disabled = $this->lang['noauth']; 44 } else if (!$auth->canDo('getUsers')) { 45 $this->disabled = $this->lang['nosupport']; 46 } else { 47 48 // we're good to go 49 $this->_auth = & $auth; 50 51 } 52 } 53 54 /** 55 * return prompt for admin menu 56 */ 57 function getMenuText($language) { 58 59 if (!is_null($this->_auth)) 60 return parent::getMenuText($language); 61 62 return $this->getLang('menu').' '.$this->disabled; 63 } 64 65 /** 66 * return sort order for position in admin menu 67 */ 68 function getMenuSort() { 69 return 2; 70 } 71 72 /** 73 * handle user request 74 */ 75 function handle() { 76 global $INPUT; 77 if (is_null($this->_auth)) return false; 78 79 // extract the command and any specific parameters 80 // submit button name is of the form - fn[cmd][param(s)] 81 $fn = $INPUT->param('fn'); 82 83 if (is_array($fn)) { 84 $cmd = key($fn); 85 $param = is_array($fn[$cmd]) ? key($fn[$cmd]) : null; 86 } else { 87 $cmd = $fn; 88 $param = null; 89 } 90 91 if ($cmd != "search") { 92 $this->_start = $INPUT->int('start', 0); 93 $this->_filter = $this->_retrieveFilter(); 94 } 95 96 switch($cmd){ 97 case "add" : $this->_addUser(); break; 98 case "delete" : $this->_deleteUser(); break; 99 case "modify" : $this->_modifyUser(); break; 100 case "edit" : $this->_editUser($param); break; 101 case "search" : $this->_setFilter($param); 102 $this->_start = 0; 103 break; 104 case "export" : $this->_export(); break; 105 } 106 107 $this->_user_total = $this->_auth->canDo('getUserCount') ? $this->_auth->getUserCount($this->_filter) : -1; 108 109 // page handling 110 switch($cmd){ 111 case 'start' : $this->_start = 0; break; 112 case 'prev' : $this->_start -= $this->_pagesize; break; 113 case 'next' : $this->_start += $this->_pagesize; break; 114 case 'last' : $this->_start = $this->_user_total; break; 115 } 116 $this->_validatePagination(); 117 } 118 119 /** 120 * output appropriate html 121 */ 122 function html() { 123 global $ID; 124 125 if(is_null($this->_auth)) { 126 print $this->lang['badauth']; 127 return false; 128 } 129 130 $user_list = $this->_auth->retrieveUsers($this->_start, $this->_pagesize, $this->_filter); 131 $users = array_keys($user_list); 132 133 $page_buttons = $this->_pagination(); 134 $delete_disable = $this->_auth->canDo('delUser') ? '' : 'disabled="disabled"'; 135 136 $editable = $this->_auth->canDo('UserMod'); 137 $export_label = empty($this->_filter) ? $this->lang['export_all'] : $this->lang[export_filtered]; 138 139 print $this->locale_xhtml('intro'); 140 print $this->locale_xhtml('list'); 141 142 ptln("<div id=\"user__manager\">"); 143 ptln("<div class=\"level2\">"); 144 145 if ($this->_user_total > 0) { 146 ptln("<p>".sprintf($this->lang['summary'],$this->_start+1,$this->_last,$this->_user_total,$this->_auth->getUserCount())."</p>"); 147 } else { 148 ptln("<p>".sprintf($this->lang['nonefound'],$this->_auth->getUserCount())."</p>"); 149 } 150 ptln("<form action=\"".wl($ID)."\" method=\"post\">"); 151 formSecurityToken(); 152 ptln(" <div class=\"table\">"); 153 ptln(" <table class=\"inline\">"); 154 ptln(" <thead>"); 155 ptln(" <tr>"); 156 ptln(" <th> </th><th>".$this->lang["user_id"]."</th><th>".$this->lang["user_name"]."</th><th>".$this->lang["user_mail"]."</th><th>".$this->lang["user_groups"]."</th>"); 157 ptln(" </tr>"); 158 159 ptln(" <tr>"); 160 ptln(" <td class=\"rightalign\"><input type=\"image\" src=\"".DOKU_PLUGIN_IMAGES."search.png\" name=\"fn[search][new]\" title=\"".$this->lang['search_prompt']."\" alt=\"".$this->lang['search']."\" class=\"button\" /></td>"); 161 ptln(" <td><input type=\"text\" name=\"userid\" class=\"edit\" value=\"".$this->_htmlFilter('user')."\" /></td>"); 162 ptln(" <td><input type=\"text\" name=\"username\" class=\"edit\" value=\"".$this->_htmlFilter('name')."\" /></td>"); 163 ptln(" <td><input type=\"text\" name=\"usermail\" class=\"edit\" value=\"".$this->_htmlFilter('mail')."\" /></td>"); 164 ptln(" <td><input type=\"text\" name=\"usergroups\" class=\"edit\" value=\"".$this->_htmlFilter('grps')."\" /></td>"); 165 ptln(" </tr>"); 166 ptln(" </thead>"); 167 168 if ($this->_user_total) { 169 ptln(" <tbody>"); 170 foreach ($user_list as $user => $userinfo) { 171 extract($userinfo); 172 $groups = join(', ',$grps); 173 ptln(" <tr class=\"user_info\">"); 174 ptln(" <td class=\"centeralign\"><input type=\"checkbox\" name=\"delete[".$user."]\" ".$delete_disable." /></td>"); 175 if ($editable) { 176 ptln(" <td><a href=\"".wl($ID,array('fn[edit]['.hsc($user).']' => 1, 177 'do' => 'admin', 178 'page' => 'usermanager', 179 'sectok' => getSecurityToken())). 180 "\" title=\"".$this->lang['edit_prompt']."\">".hsc($user)."</a></td>"); 181 } else { 182 ptln(" <td>".hsc($user)."</td>"); 183 } 184 ptln(" <td>".hsc($name)."</td><td>".hsc($mail)."</td><td>".hsc($groups)."</td>"); 185 ptln(" </tr>"); 186 } 187 ptln(" </tbody>"); 188 } 189 190 ptln(" <tbody>"); 191 ptln(" <tr><td colspan=\"5\" class=\"centeralign\">"); 192 ptln(" <span class=\"medialeft\">"); 193 ptln(" <input type=\"submit\" name=\"fn[delete]\" ".$delete_disable." class=\"button\" value=\"".$this->lang['delete_selected']."\" id=\"usrmgr__del\" />"); 194 ptln(" </span>"); 195 ptln(" <span class=\"mediaright\">"); 196 ptln(" <input type=\"submit\" name=\"fn[start]\" ".$page_buttons['start']." class=\"button\" value=\"".$this->lang['start']."\" />"); 197 ptln(" <input type=\"submit\" name=\"fn[prev]\" ".$page_buttons['prev']." class=\"button\" value=\"".$this->lang['prev']."\" />"); 198 ptln(" <input type=\"submit\" name=\"fn[next]\" ".$page_buttons['next']." class=\"button\" value=\"".$this->lang['next']."\" />"); 199 ptln(" <input type=\"submit\" name=\"fn[last]\" ".$page_buttons['last']." class=\"button\" value=\"".$this->lang['last']."\" />"); 200 ptln(" </span>"); 201 if (!empty($this->_filter)) { 202 ptln(" <input type=\"submit\" name=\"fn[search][clear]\" class=\"button\" value=\"".$this->lang['clear']."\" />"); 203 } 204 ptln(" <input type=\"submit\" name=\"fn[export]\" class=\"button\" value=\"".$export_label."\" />"); 205 ptln(" <input type=\"hidden\" name=\"do\" value=\"admin\" />"); 206 ptln(" <input type=\"hidden\" name=\"page\" value=\"usermanager\" />"); 207 208 $this->_htmlFilterSettings(2); 209 210 ptln(" </td></tr>"); 211 ptln(" </tbody>"); 212 ptln(" </table>"); 213 ptln(" </div>"); 214 215 ptln("</form>"); 216 ptln("</div>"); 217 218 $style = $this->_edit_user ? " class=\"edit_user\"" : ""; 219 220 if ($this->_auth->canDo('addUser')) { 221 ptln("<div".$style.">"); 222 print $this->locale_xhtml('add'); 223 ptln(" <div class=\"level2\">"); 224 225 $this->_htmlUserForm('add',null,array(),4); 226 227 ptln(" </div>"); 228 ptln("</div>"); 229 } 230 231 if($this->_edit_user && $this->_auth->canDo('UserMod')){ 232 ptln("<div".$style." id=\"scroll__here\">"); 233 print $this->locale_xhtml('edit'); 234 ptln(" <div class=\"level2\">"); 235 236 $this->_htmlUserForm('modify',$this->_edit_user,$this->_edit_userdata,4); 237 238 ptln(" </div>"); 239 ptln("</div>"); 240 } 241 ptln("</div>"); 242 } 243 244 245 /** 246 * @todo disable fields which the backend can't change 247 */ 248 function _htmlUserForm($cmd,$user='',$userdata=array(),$indent=0) { 249 global $conf; 250 global $ID; 251 252 $name = $mail = $groups = ''; 253 $notes = array(); 254 255 if ($user) { 256 extract($userdata); 257 if (!empty($grps)) $groups = join(',',$grps); 258 } else { 259 $notes[] = sprintf($this->lang['note_group'],$conf['defaultgroup']); 260 } 261 262 ptln("<form action=\"".wl($ID)."\" method=\"post\">",$indent); 263 formSecurityToken(); 264 ptln(" <div class=\"table\">",$indent); 265 ptln(" <table class=\"inline\">",$indent); 266 ptln(" <thead>",$indent); 267 ptln(" <tr><th>".$this->lang["field"]."</th><th>".$this->lang["value"]."</th></tr>",$indent); 268 ptln(" </thead>",$indent); 269 ptln(" <tbody>",$indent); 270 271 $this->_htmlInputField($cmd."_userid", "userid", $this->lang["user_id"], $user, $this->_auth->canDo("modLogin"), $indent+6); 272 $this->_htmlInputField($cmd."_userpass", "userpass", $this->lang["user_pass"], "", $this->_auth->canDo("modPass"), $indent+6); 273 $this->_htmlInputField($cmd."_username", "username", $this->lang["user_name"], $name, $this->_auth->canDo("modName"), $indent+6); 274 $this->_htmlInputField($cmd."_usermail", "usermail", $this->lang["user_mail"], $mail, $this->_auth->canDo("modMail"), $indent+6); 275 $this->_htmlInputField($cmd."_usergroups","usergroups",$this->lang["user_groups"],$groups,$this->_auth->canDo("modGroups"),$indent+6); 276 277 if ($this->_auth->canDo("modPass")) { 278 $notes[] = $this->lang['note_pass']; 279 if ($user) { 280 $notes[] = $this->lang['note_notify']; 281 } 282 283 ptln("<tr><td><label for=\"".$cmd."_usernotify\" >".$this->lang["user_notify"].": </label></td><td><input type=\"checkbox\" id=\"".$cmd."_usernotify\" name=\"usernotify\" value=\"1\" /></td></tr>", $indent); 284 } 285 286 ptln(" </tbody>",$indent); 287 ptln(" <tbody>",$indent); 288 ptln(" <tr>",$indent); 289 ptln(" <td colspan=\"2\">",$indent); 290 ptln(" <input type=\"hidden\" name=\"do\" value=\"admin\" />",$indent); 291 ptln(" <input type=\"hidden\" name=\"page\" value=\"usermanager\" />",$indent); 292 293 // save current $user, we need this to access details if the name is changed 294 if ($user) 295 ptln(" <input type=\"hidden\" name=\"userid_old\" value=\"".$user."\" />",$indent); 296 297 $this->_htmlFilterSettings($indent+10); 298 299 ptln(" <input type=\"submit\" name=\"fn[".$cmd."]\" class=\"button\" value=\"".$this->lang[$cmd]."\" />",$indent); 300 ptln(" </td>",$indent); 301 ptln(" </tr>",$indent); 302 ptln(" </tbody>",$indent); 303 ptln(" </table>",$indent); 304 ptln(" </div>",$indent); 305 306 foreach ($notes as $note) 307 ptln("<div class=\"fn\">".$note."</div>",$indent); 308 309 ptln("</form>",$indent); 310 } 311 312 function _htmlInputField($id, $name, $label, $value, $cando, $indent=0) { 313 $class = $cando ? '' : ' class="disabled"'; 314 echo str_pad('',$indent); 315 316 if($name == 'userpass'){ 317 $fieldtype = 'password'; 318 $autocomp = 'autocomplete="off"'; 319 }elseif($name == 'usermail'){ 320 $fieldtype = 'email'; 321 $autocomp = ''; 322 }else{ 323 $fieldtype = 'text'; 324 $autocomp = ''; 325 } 326 327 328 echo "<tr $class>"; 329 echo "<td><label for=\"$id\" >$label: </label></td>"; 330 echo "<td>"; 331 if($cando){ 332 echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" value=\"$value\" class=\"edit\" $autocomp />"; 333 }else{ 334 echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />"; 335 echo "<input type=\"$fieldtype\" id=\"$id\" name=\"$name\" value=\"$value\" class=\"edit disabled\" disabled=\"disabled\" />"; 336 } 337 echo "</td>"; 338 echo "</tr>"; 339 } 340 341 function _htmlFilter($key) { 342 if (empty($this->_filter)) return ''; 343 return (isset($this->_filter[$key]) ? hsc($this->_filter[$key]) : ''); 344 } 345 346 function _htmlFilterSettings($indent=0) { 347 348 ptln("<input type=\"hidden\" name=\"start\" value=\"".$this->_start."\" />",$indent); 349 350 foreach ($this->_filter as $key => $filter) { 351 ptln("<input type=\"hidden\" name=\"filter[".$key."]\" value=\"".hsc($filter)."\" />",$indent); 352 } 353 } 354 355 function _addUser(){ 356 global $INPUT; 357 if (!checkSecurityToken()) return false; 358 if (!$this->_auth->canDo('addUser')) return false; 359 360 list($user,$pass,$name,$mail,$grps) = $this->_retrieveUser(); 361 if (empty($user)) return false; 362 363 if ($this->_auth->canDo('modPass')){ 364 if (empty($pass)){ 365 if($INPUT->has('usernotify')){ 366 $pass = auth_pwgen($user); 367 } else { 368 msg($this->lang['add_fail'], -1); 369 return false; 370 } 371 } 372 } else { 373 if (!empty($pass)){ 374 msg($this->lang['add_fail'], -1); 375 return false; 376 } 377 } 378 379 if ($this->_auth->canDo('modName')){ 380 if (empty($name)){ 381 msg($this->lang['add_fail'], -1); 382 return false; 383 } 384 } else { 385 if (!empty($name)){ 386 return false; 387 } 388 } 389 390 if ($this->_auth->canDo('modMail')){ 391 if (empty($mail)){ 392 msg($this->lang['add_fail'], -1); 393 return false; 394 } 395 } else { 396 if (!empty($mail)){ 397 return false; 398 } 399 } 400 401 if ($ok = $this->_auth->triggerUserMod('create', array($user,$pass,$name,$mail,$grps))) { 402 403 msg($this->lang['add_ok'], 1); 404 405 if ($INPUT->has('usernotify') && $pass) { 406 $this->_notifyUser($user,$pass); 407 } 408 } else { 409 msg($this->lang['add_fail'], -1); 410 } 411 412 return $ok; 413 } 414 415 /** 416 * Delete user 417 */ 418 function _deleteUser(){ 419 global $conf, $INPUT; 420 421 if (!checkSecurityToken()) return false; 422 if (!$this->_auth->canDo('delUser')) return false; 423 424 $selected = $INPUT->arr('delete'); 425 if (empty($selected)) return false; 426 $selected = array_keys($selected); 427 428 if(in_array($_SERVER['REMOTE_USER'], $selected)) { 429 msg("You can't delete yourself!", -1); 430 return false; 431 } 432 433 $count = $this->_auth->triggerUserMod('delete', array($selected)); 434 if ($count == count($selected)) { 435 $text = str_replace('%d', $count, $this->lang['delete_ok']); 436 msg("$text.", 1); 437 } else { 438 $part1 = str_replace('%d', $count, $this->lang['delete_ok']); 439 $part2 = str_replace('%d', (count($selected)-$count), $this->lang['delete_fail']); 440 msg("$part1, $part2",-1); 441 } 442 443 // invalidate all sessions 444 io_saveFile($conf['cachedir'].'/sessionpurge',time()); 445 446 return true; 447 } 448 449 /** 450 * Edit user (a user has been selected for editing) 451 */ 452 function _editUser($param) { 453 if (!checkSecurityToken()) return false; 454 if (!$this->_auth->canDo('UserMod')) return false; 455 456 $user = cleanID(preg_replace('/.*:/','',$param)); 457 $userdata = $this->_auth->getUserData($user); 458 459 // no user found? 460 if (!$userdata) { 461 msg($this->lang['edit_usermissing'],-1); 462 return false; 463 } 464 465 $this->_edit_user = $user; 466 $this->_edit_userdata = $userdata; 467 468 return true; 469 } 470 471 /** 472 * Modify user (modified user data has been recieved) 473 */ 474 function _modifyUser(){ 475 global $conf, $INPUT; 476 477 if (!checkSecurityToken()) return false; 478 if (!$this->_auth->canDo('UserMod')) return false; 479 480 // get currently valid user data 481 $olduser = cleanID(preg_replace('/.*:/','',$INPUT->str('userid_old'))); 482 $oldinfo = $this->_auth->getUserData($olduser); 483 484 // get new user data subject to change 485 list($newuser,$newpass,$newname,$newmail,$newgrps) = $this->_retrieveUser(); 486 if (empty($newuser)) return false; 487 488 $changes = array(); 489 if ($newuser != $olduser) { 490 491 if (!$this->_auth->canDo('modLogin')) { // sanity check, shouldn't be possible 492 msg($this->lang['update_fail'],-1); 493 return false; 494 } 495 496 // check if $newuser already exists 497 if ($this->_auth->getUserData($newuser)) { 498 msg(sprintf($this->lang['update_exists'],$newuser),-1); 499 $re_edit = true; 500 } else { 501 $changes['user'] = $newuser; 502 } 503 } 504 505 // generate password if left empty and notification is on 506 if($INPUT->has('usernotify') && empty($newpass)){ 507 $newpass = auth_pwgen($olduser); 508 } 509 510 if (!empty($newpass) && $this->_auth->canDo('modPass')) 511 $changes['pass'] = $newpass; 512 if (!empty($newname) && $this->_auth->canDo('modName') && $newname != $oldinfo['name']) 513 $changes['name'] = $newname; 514 if (!empty($newmail) && $this->_auth->canDo('modMail') && $newmail != $oldinfo['mail']) 515 $changes['mail'] = $newmail; 516 if (!empty($newgrps) && $this->_auth->canDo('modGroups') && $newgrps != $oldinfo['grps']) 517 $changes['grps'] = $newgrps; 518 519 if ($ok = $this->_auth->triggerUserMod('modify', array($olduser, $changes))) { 520 msg($this->lang['update_ok'],1); 521 522 if ($INPUT->has('usernotify') && $newpass) { 523 $notify = empty($changes['user']) ? $olduser : $newuser; 524 $this->_notifyUser($notify,$newpass); 525 } 526 527 // invalidate all sessions 528 io_saveFile($conf['cachedir'].'/sessionpurge',time()); 529 530 } else { 531 msg($this->lang['update_fail'],-1); 532 } 533 534 if (!empty($re_edit)) { 535 $this->_editUser($olduser); 536 } 537 538 return $ok; 539 } 540 541 /** 542 * send password change notification email 543 */ 544 function _notifyUser($user, $password) { 545 546 if ($sent = auth_sendPassword($user,$password)) { 547 msg($this->lang['notify_ok'], 1); 548 } else { 549 msg($this->lang['notify_fail'], -1); 550 } 551 552 return $sent; 553 } 554 555 /** 556 * retrieve & clean user data from the form 557 * 558 * @return array (user, password, full name, email, array(groups)) 559 */ 560 function _retrieveUser($clean=true) { 561 global $auth; 562 global $INPUT; 563 564 $user[0] = ($clean) ? $auth->cleanUser($INPUT->str('userid')) : $INPUT->str('userid'); 565 $user[1] = $INPUT->str('userpass'); 566 $user[2] = $INPUT->str('username'); 567 $user[3] = $INPUT->str('usermail'); 568 $user[4] = explode(',',$INPUT->str('usergroups')); 569 570 $user[4] = array_map('trim',$user[4]); 571 if($clean) $user[4] = array_map(array($auth,'cleanGroup'),$user[4]); 572 $user[4] = array_filter($user[4]); 573 $user[4] = array_unique($user[4]); 574 if(!count($user[4])) $user[4] = null; 575 576 return $user; 577 } 578 579 function _setFilter($op) { 580 581 $this->_filter = array(); 582 583 if ($op == 'new') { 584 list($user,$pass,$name,$mail,$grps) = $this->_retrieveUser(false); 585 586 if (!empty($user)) $this->_filter['user'] = $user; 587 if (!empty($name)) $this->_filter['name'] = $name; 588 if (!empty($mail)) $this->_filter['mail'] = $mail; 589 if (!empty($grps)) $this->_filter['grps'] = join('|',$grps); 590 } 591 } 592 593 function _retrieveFilter() { 594 global $INPUT; 595 596 $t_filter = $INPUT->arr('filter'); 597 598 // messy, but this way we ensure we aren't getting any additional crap from malicious users 599 $filter = array(); 600 601 if (isset($t_filter['user'])) $filter['user'] = $t_filter['user']; 602 if (isset($t_filter['name'])) $filter['name'] = $t_filter['name']; 603 if (isset($t_filter['mail'])) $filter['mail'] = $t_filter['mail']; 604 if (isset($t_filter['grps'])) $filter['grps'] = $t_filter['grps']; 605 606 return $filter; 607 } 608 609 function _validatePagination() { 610 611 if ($this->_start >= $this->_user_total) { 612 $this->_start = $this->_user_total - $this->_pagesize; 613 } 614 if ($this->_start < 0) $this->_start = 0; 615 616 $this->_last = min($this->_user_total, $this->_start + $this->_pagesize); 617 } 618 619 /* 620 * return an array of strings to enable/disable pagination buttons 621 */ 622 function _pagination() { 623 624 $disabled = 'disabled="disabled"'; 625 626 $buttons['start'] = $buttons['prev'] = ($this->_start == 0) ? $disabled : ''; 627 628 if ($this->_user_total == -1) { 629 $buttons['last'] = $disabled; 630 $buttons['next'] = ''; 631 } else { 632 $buttons['last'] = $buttons['next'] = (($this->_start + $this->_pagesize) >= $this->_user_total) ? $disabled : ''; 633 } 634 635 return $buttons; 636 } 637 638 /* 639 * export a list of users in csv format using the current filter criteria 640 */ 641 function _export() { 642 // list of users for export - based on current filter criteria 643 $user_list = $this->_auth->retrieveUsers(0, 0, $this->_filter); 644 $column_headings = array( 645 $this->lang["user_id"], 646 $this->lang["user_name"], 647 $this->lang["user_mail"], 648 $this->lang["user_groups"] 649 ); 650 651 // ============================================================================================== 652 // GENERATE OUTPUT 653 // normal headers for downloading... 654 header('Content-type: text/csv;charset=utf-8'); 655 header('Content-Disposition: attachment; filename="wikiusers.csv"'); 656# // for debugging assistance, send as text plain to the browser 657# header('Content-type: text/plain;charset=utf-8'); 658 659 // output the csv 660 $fd = fopen('php://output','w'); 661 fputcsv($fd, $column_headings); 662 foreach ($user_list as $user => $info) { 663 $line = array($user, $info['name'], $info['mail'], join(',',$info['grps'])); 664 fputcsv($fd, $line); 665 } 666 fclose($fd); 667 die; 668 } 669} 670