PageRenderTime 69ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/inc/class.uiaccounts.inc.php

https://github.com/muchael/expressolivre
PHP | 1328 lines | 1166 code | 109 blank | 53 comment | 92 complexity | d89b98e170dccefaddd43a9dcea88b9a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-2-Clause, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. /**************************************************************************\
  3. * eGroupWare - account administration *
  4. * http://www.egroupware.org *
  5. * -------------------------------------------- *
  6. * This program is free software; you can redistribute it and/or modify it *
  7. * under the terms of the GNU General Public License as published by the *
  8. * Free Software Foundation; either version 2 of the License, or (at your *
  9. * option) any later version. *
  10. \**************************************************************************/
  11. class uiaccounts
  12. {
  13. var $public_functions = array
  14. (
  15. 'list_groups' => True,
  16. 'list_users' => True,
  17. 'add_group' => True,
  18. 'add_user' => True,
  19. 'delete_group' => True,
  20. 'delete_user' => True,
  21. 'edit_user' => True,
  22. 'edit_user_hook' => True,
  23. 'edit_group' => True,
  24. 'view_user' => True,
  25. 'edit_view_user_hook' => True,
  26. 'group_manager' => True,
  27. );
  28. var $bo;
  29. var $nextmatchs;
  30. var $apps_with_acl = array(
  31. 'addressbook' => True,
  32. 'todo' => True,
  33. 'calendar' => True,
  34. 'notes' => True,
  35. 'projects' => True,
  36. 'phonelog' => True,
  37. 'infolog' => True,
  38. 'filemanager' => True,
  39. 'tts' => True,
  40. 'bookmarks' => True,
  41. 'img' => True,
  42. 'netsaint' => True,
  43. 'inv' => True,
  44. 'phpbrain' => True,
  45. );
  46. function uiaccounts()
  47. {
  48. $this->bo = createobject('admin.boaccounts');
  49. $this->nextmatchs = createobject('phpgwapi.nextmatchs');
  50. @set_time_limit(300);
  51. }
  52. function row_action($action,$type,$account_id)
  53. {
  54. return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
  55. 'menuaction' => 'admin.uiaccounts.'.$action.'_'.$type,
  56. 'account_id' => $account_id
  57. )).'"> '.lang($action).' </a>';
  58. }
  59. function list_groups()
  60. {
  61. if ($GLOBALS['phpgw']->acl->check('group_access',1,'admin'))
  62. {
  63. $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
  64. }
  65. $GLOBALS['cd'] = ($_GET['cd']?$_GET['cd']:0);
  66. if(isset($_POST['query']))
  67. {
  68. // limit query to limit characters
  69. if(preg_match('/^[a-z_0-9]+$/i',$_POST['query']))
  70. $GLOBALS['query'] = $_POST['query'];
  71. }
  72. if(isset($_POST['start']))
  73. {
  74. $start = (int)$_POST['start'];
  75. }
  76. else
  77. {
  78. $start = 0;
  79. }
  80. switch($_GET['order'])
  81. {
  82. case 'account_lid':
  83. $order = $_GET['order'];
  84. break;
  85. default:
  86. $order = 'account_lid';
  87. break;
  88. }
  89. switch($_GET['sort'])
  90. {
  91. case 'ASC':
  92. case 'DESC':
  93. $sort = $_GET['sort'];
  94. break;
  95. default:
  96. $sort = 'ASC';
  97. break;
  98. }
  99. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  100. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  101. if(!@is_object($GLOBALS['phpgw']->js))
  102. {
  103. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  104. }
  105. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  106. $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['admin']['title'].' - '.
  107. lang('User groups');
  108. $GLOBALS['phpgw']->common->phpgw_header();
  109. $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  110. $p->set_file(
  111. array(
  112. 'groups' => 'groups.tpl'
  113. )
  114. );
  115. $p->set_block('groups','list','list');
  116. $p->set_block('groups','row','row');
  117. $p->set_block('groups','row_empty','row_empty');
  118. if (! $GLOBALS['phpgw']->acl->check('account_access',2,'admin'))
  119. {
  120. $account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order, $GLOBALS['query']);
  121. }
  122. else
  123. {
  124. $account_info = $GLOBALS['phpgw']->accounts->get_list('groups',$start,$sort, $order);
  125. }
  126. $total = $GLOBALS['phpgw']->accounts->total;
  127. $var = Array(
  128. 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
  129. 'left_next_matchs' => $this->nextmatchs->left('/index.php',$start,$total,'menuaction=admin.uiaccounts.list_groups'),
  130. 'right_next_matchs' => $this->nextmatchs->right('/index.php',$start,$total,'menuaction=admin.uiaccounts.list_groups'),
  131. 'lang_groups' => lang('%1 - %2 of %3 user groups',$start+1,$start+count($account_info),$total),
  132. 'sort_name' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('name'),'menuaction=admin.uiaccounts.list_groups'),
  133. 'header_edit' => lang('Edit'),
  134. 'header_delete' => lang('Delete')
  135. );
  136. $p->set_var($var);
  137. if (!count($account_info) || !$total)
  138. {
  139. $p->set_var('message',lang('No matches found'));
  140. $p->parse('rows','row_empty',True);
  141. }
  142. else
  143. {
  144. if (! $GLOBALS['phpgw']->acl->check('group_access',8,'admin'))
  145. {
  146. $can_view = True;
  147. }
  148. if (! $GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
  149. {
  150. $can_edit = True;
  151. }
  152. if (! $GLOBALS['phpgw']->acl->check('group_access',32,'admin'))
  153. {
  154. $can_delete = True;
  155. }
  156. foreach($account_info as $account)
  157. {
  158. $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
  159. $var = Array(
  160. 'tr_color' => $tr_color,
  161. 'group_name' => (!$account['account_lid']?'&nbsp;':$account['account_lid']),
  162. 'delete_link' => $this->row_action('delete','group',$account['account_id'])
  163. );
  164. $p->set_var($var);
  165. if ($can_edit)
  166. {
  167. $p->set_var('edit_link',$this->row_action('edit','group',$account['account_id']));
  168. }
  169. else
  170. {
  171. $p->set_var('edit_link','&nbsp;');
  172. }
  173. if ($can_delete)
  174. {
  175. $p->set_var('delete_link',$this->row_action('delete','group',$account['account_id']));
  176. }
  177. else
  178. {
  179. $p->set_var('delete_link','&nbsp;');
  180. }
  181. $p->fp('rows','row',True);
  182. }
  183. }
  184. $var = Array(
  185. 'new_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.add_group'),
  186. 'search_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups')
  187. );
  188. $p->set_var($var);
  189. if (! $GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
  190. {
  191. $p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">');
  192. }
  193. if (! $GLOBALS['phpgw']->acl->check('group_access',2,'admin'))
  194. {
  195. $p->set_var('input_search',lang('Search') . '&nbsp;<input name="query" value="'.htmlspecialchars(stripslashes($GLOBALS['query'])).'">');
  196. }
  197. $p->pfp('out','list');
  198. }
  199. function list_users($param_cd='')
  200. {
  201. if ($GLOBALS['phpgw']->acl->check('account_access',1,'admin'))
  202. {
  203. $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/admin/index.php'));
  204. }
  205. if (!is_object($GLOBALS['phpgw']->html))
  206. {
  207. $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
  208. }
  209. if($param_cd)
  210. {
  211. $cd = $param_cd;
  212. }
  213. if(isset($_REQUEST['query']))
  214. {
  215. // limit query to limit characters
  216. if(preg_match('/^[a-z_0-9]+$/i',$_REQUEST['query']))
  217. $GLOBALS['query'] = $_REQUEST['query'];
  218. }
  219. if(isset($_REQUEST['start']))
  220. {
  221. $start = (int)$_REQUEST['start'];
  222. }
  223. else
  224. {
  225. $start = 0;
  226. }
  227. switch($_REQUEST['order'])
  228. {
  229. case 'account_lastname':
  230. case 'account_firstname':
  231. case 'account_lid':
  232. case 'account_email':
  233. $order = $_REQUEST['order'];
  234. break;
  235. default:
  236. $order = 'account_lid';
  237. break;
  238. }
  239. switch($_REQUEST['sort'])
  240. {
  241. case 'ASC':
  242. case 'DESC':
  243. $sort = $_REQUEST['sort'];
  244. break;
  245. default:
  246. $sort = 'ASC';
  247. break;
  248. }
  249. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  250. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  251. if(!@is_object($GLOBALS['phpgw']->js))
  252. {
  253. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  254. }
  255. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  256. $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['admin']['title'].' - '.
  257. lang('User accounts');
  258. $GLOBALS['phpgw']->common->phpgw_header();
  259. $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  260. $p->set_file(
  261. Array(
  262. 'list' => 'accounts.tpl'
  263. )
  264. );
  265. $p->set_block('list','row','rows');
  266. $p->set_block('list','row_empty','row_empty');
  267. $p->set_block('list','letter_search','letter_search_cells');
  268. $search_param = array(
  269. 'type' => (int)$_REQUEST['group_id'] > 0 ? $_REQUEST['group_id'] : 'accounts',
  270. 'start' => $start,
  271. 'sort' => $sort,
  272. 'order' => $order,
  273. 'query_type' => $_REQUEST['query_type'],
  274. );
  275. if (!$GLOBALS['phpgw']->acl->check('account_access',2,'admin'))
  276. {
  277. $search_param['query'] = $GLOBALS['query'];
  278. }
  279. $account_info = $GLOBALS['phpgw']->accounts->search($search_param);
  280. $total = $GLOBALS['phpgw']->accounts->total;
  281. $link_data = array(
  282. 'menuaction' => 'admin.uiaccounts.list_users',
  283. 'group_id' => $_REQUEST['group_id'],
  284. 'query_type' => $_REQUEST['query_type'],
  285. );
  286. $uiaccountsel = CreateObject('phpgwapi.uiaccountsel');
  287. $p->set_var(array(
  288. 'left_next_matchs' => $this->nextmatchs->left('/index.php',$start,$total,$link_data),
  289. 'lang_showing' => ($_REQUEST['group_id'] ? $GLOBALS['phpgw']->common->grab_owner_name($_REQUEST['group_id']).': ' : '').
  290. ($GLOBALS['query'] ? lang("Search %1 '%2'",lang($uiaccountsel->query_types[$_REQUEST['query_type']]),$GLOBALS['query']).': ' : '')
  291. .$this->nextmatchs->show_hits($total,$start),
  292. 'right_next_matchs' => $this->nextmatchs->right('/index.php',$start,$total,$link_data),
  293. 'lang_loginid' => $this->nextmatchs->show_sort_order($sort,'account_lid',$order,'/index.php',lang('LoginID'),$link_data),
  294. 'lang_lastname' => $this->nextmatchs->show_sort_order($sort,'account_lastname',$order,'/index.php',lang('last name'),$link_data),
  295. 'lang_firstname' => $this->nextmatchs->show_sort_order($sort,'account_firstname',$order,'/index.php',lang('first name'),$link_data),
  296. 'lang_email' => $this->nextmatchs->show_sort_order($sort,'account_email',$order,'/index.php',lang('email'),$link_data),
  297. 'lang_edit' => lang('edit'),
  298. 'lang_delete' => lang('delete'),
  299. 'lang_view' => lang('view'),
  300. 'lang_search' => lang('search')
  301. ));
  302. $link_data += array(
  303. 'order' => $order,
  304. 'sort' => $sort,
  305. );
  306. $p->set_var(array(
  307. 'query_type' => is_array($uiaccountsel->query_types) ? $GLOBALS['phpgw']->html->select('query_type',$_REQUEST['query_type'],$uiaccountsel->query_types) : '',
  308. 'lang_group' => lang('group'),
  309. 'group' => $uiaccountsel->selection('group_id','admin_uiaccount_listusers_group_id',$_REQUEST['group_id'],'groups',0,False,'','this.form.submit();',lang('all')),
  310. 'accounts_url' => $GLOBALS['phpgw']->link('/index.php',$link_data),
  311. ));
  312. $letters = lang('alphabet');
  313. $letters = explode(',',substr($letters,-1) != '*' ? $letters : 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
  314. $link_data['query_type'] = 'start';
  315. foreach($letters as $letter)
  316. {
  317. $link_data['query'] = $letter;
  318. $p->set_var(array(
  319. 'letter' => $letter,
  320. 'link' => $GLOBALS['phpgw']->link('/index.php',$link_data),
  321. 'class' => $GLOBALS['query'] == $letter && $_REQUEST['query_type'] == 'start' ? 'letter_box_active' : 'letter_box',
  322. ));
  323. $p->fp('letter_search_cells','letter_search',True);
  324. }
  325. unset($link_data['query']);
  326. unset($link_data['query_type']);
  327. $p->set_var(array(
  328. 'letter' => lang('all'),
  329. 'link' => $GLOBALS['phpgw']->link('/index.php',$link_data),
  330. 'class' => $_REQUEST['query_type'] != 'start' || !in_array($GLOBALS['query'],$letters) ? 'letter_box_active' : 'letter_box',
  331. ));
  332. $p->fp('letter_search_cells','letter_search',True);
  333. if (! $GLOBALS['phpgw']->acl->check('account_access',4,'admin'))
  334. {
  335. $p->set_var('new_action',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.add_user'));
  336. $p->set_var('input_add','<input type="submit" value="' . lang('Add') . '">');
  337. }
  338. if (!count($account_info) || !$total)
  339. {
  340. $p->set_var('message',lang('No matches found'));
  341. $p->parse('rows','row_empty',True);
  342. }
  343. else
  344. {
  345. if (! $GLOBALS['phpgw']->acl->check('account_access',8,'admin'))
  346. {
  347. $can_view = True;
  348. }
  349. if (! $GLOBALS['phpgw']->acl->check('account_access',16,'admin'))
  350. {
  351. $can_edit = True;
  352. }
  353. if (! $GLOBALS['phpgw']->acl->check('account_access',32,'admin'))
  354. {
  355. $can_delete = True;
  356. }
  357. foreach($account_info as $account)
  358. {
  359. $p->set_var('class',$this->nextmatchs->alternate_row_color('',True));
  360. $p->set_var($account);
  361. if ($can_edit)
  362. {
  363. $p->set_var('row_edit',$this->row_action('edit','user',$account['account_id']));
  364. }
  365. else
  366. {
  367. $p->set_var('row_edit','&nbsp;');
  368. }
  369. if ($can_delete)
  370. {
  371. $p->set_var('row_delete',($GLOBALS['phpgw_info']['user']['userid'] != $account['account_lid']?$this->row_action('delete','user',$account['account_id']):'&nbsp'));
  372. }
  373. else
  374. {
  375. $p->set_var('row_delete','&nbsp;');
  376. }
  377. if ($can_view)
  378. {
  379. $p->set_var('row_view',$this->row_action('view','user',$account['account_id']));
  380. }
  381. else
  382. {
  383. $p->set_var('row_view','&nbsp;');
  384. }
  385. $p->parse('rows','row',True);
  386. }
  387. } // End else
  388. $p->pfp('out','list');
  389. }
  390. function add_group()
  391. {
  392. if ($GLOBALS['phpgw']->acl->check('group_access',4,'admin'))
  393. {
  394. $this->list_groups();
  395. return False;
  396. }
  397. $group_info = Array(
  398. 'account_id' => $_GET['account_id'],
  399. 'account_name' => '',
  400. 'account_user' => Array(),
  401. 'account_apps' => Array()
  402. );
  403. $this->create_edit_group($group_info);
  404. }
  405. function add_user()
  406. {
  407. if ($GLOBALS['phpgw']->acl->check('account_access',4,'admin'))
  408. {
  409. $this->list_users();
  410. }
  411. else
  412. {
  413. $this->create_edit_user(0);
  414. }
  415. }
  416. function delete_group()
  417. {
  418. if ($_POST['no'] || $_POST['yes'] || !@isset($_GET['account_id']) || !@$_GET['account_id'] || $GLOBALS['phpgw']->acl->check('group_access',32,'admin'))
  419. {
  420. if ($_POST['yes'])
  421. {
  422. $this->bo->delete_group();
  423. }
  424. $this->list_groups();
  425. return False;
  426. }
  427. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  428. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  429. if(!@is_object($GLOBALS['phpgw']->js))
  430. {
  431. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  432. }
  433. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  434. $GLOBALS['phpgw']->common->phpgw_header();
  435. $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  436. $p->set_file(
  437. Array(
  438. 'body' => 'delete_common.tpl',
  439. 'message_row' => 'message_row.tpl',
  440. 'form_button' => 'form_button_script.tpl'
  441. )
  442. );
  443. $p->set_var('message_display',lang('Are you sure you want to delete this group ?'));
  444. $p->parse('messages','message_row');
  445. $old_group_list = $GLOBALS['phpgw']->acl->get_ids_for_location((int)$_GET['account_id'],1,'phpgw_group');
  446. if($old_group_list)
  447. {
  448. $group_name = $GLOBALS['phpgw']->accounts->id2name($_GET['account_id']);
  449. $p->set_var('message_display','<br />');
  450. $p->parse('messages','message_row',True);
  451. $user_list = '';
  452. while (list(,$id) = each($old_group_list))
  453. {
  454. $user_list .= '<a href="' . $GLOBALS['phpgw']->link('/index.php',
  455. Array(
  456. 'menuaction' => 'admin.uiaccounts.edit_user',
  457. 'account_id' => $id
  458. )
  459. ) . '">' . $GLOBALS['phpgw']->common->grab_owner_name($id) . '</a><br />';
  460. }
  461. $p->set_var('message_display',$user_list);
  462. $p->parse('messages','message_row',True);
  463. $p->set_var('message_display',lang("Sorry, the above users are still a member of the group %1",$group_name)
  464. . '.<br />' . lang('They must be removed before you can continue'). '.<br />' . lang('Remove all users from this group').'?');
  465. $p->parse('messages','message_row',True);
  466. }
  467. $var = Array(
  468. 'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.delete_group'),
  469. 'hidden_vars' => '<input type="hidden" name="account_id" value="'.$_GET['account_id'].'">',
  470. 'yes' => lang('Yes'),
  471. 'no' => lang('No')
  472. );
  473. $p->set_var($var);
  474. /*
  475. $p->parse('yes','form_button');
  476. $var = Array(
  477. 'submit_button' => lang('Submit'),
  478. 'action_url_button' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiaccounts.list_groups'),
  479. 'action_text_button' => ' '.lang('No'),
  480. 'action_confirm_button' => '',
  481. 'action_extra_field' => ''
  482. );
  483. $p->set_var($var);
  484. $p->parse('no','form_button');
  485. */
  486. $p->pparse('phpgw_body','body');
  487. }
  488. function delete_user()
  489. {
  490. if ($GLOBALS['phpgw']->acl->check('account_access',32,'admin') || $GLOBALS['phpgw_info']['user']['account_id'] == $_GET['account_id'])
  491. {
  492. $this->list_users();
  493. return False;
  494. }
  495. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  496. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  497. if(!@is_object($GLOBALS['phpgw']->js))
  498. {
  499. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  500. }
  501. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  502. $GLOBALS['phpgw']->common->phpgw_header();
  503. $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  504. $t->set_file(
  505. Array(
  506. 'form' => 'delete_account.tpl'
  507. )
  508. );
  509. $var = Array(
  510. 'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.boaccounts.delete_user'),
  511. 'account_id' => $_GET['account_id']
  512. );
  513. // the account can have special chars/white spaces, if it is a ldap dn
  514. $account_id = rawurlencode($_GET['account_id']);
  515. // Find out who the new owner is of the deleted users records...
  516. $users = $GLOBALS['phpgw']->accounts->get_list('accounts');
  517. $c_users = count($users);
  518. $str = '';
  519. for($i=0;$i<$c_users;++$i)
  520. {
  521. $str .= '<option value='.$users[$i]['account_id'].'>'.$GLOBALS['phpgw']->common->display_fullname($users[$i]['account_lid'],$users[$i]['account_firstname'],$users[$i]['account_lastname']).'</option>'."\n";
  522. }
  523. $var['lang_new_owner'] = lang('Who would you like to transfer ALL records owned by the deleted user to?');
  524. $var['new_owner_select'] = '<select name="new_owner" size="5">'."\n".'<option value=0 selected>'.lang('Delete All Records').'</option>'."\n".$str.'</select>'."\n";
  525. $var['cancel'] = lang('cancel');
  526. $var['delete'] = lang('delete');
  527. $t->set_var($var);
  528. $t->pparse('out','form');
  529. }
  530. function edit_group($cd='',$account_id='')
  531. {
  532. if ($GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
  533. {
  534. $this->list_groups();
  535. return False;
  536. }
  537. $cdid = $cd;
  538. settype($cd,'integer');
  539. $cd = ($_GET['cd']?$_GET['cd']:(int)$cdid);
  540. $accountid = $account_id;
  541. settype($account_id,'integer');
  542. $account_id = ($_GET['account_id'] ? $_GET['account_id'] : (int)$accountid);
  543. // todo
  544. // not needed if i use the same file for new groups too
  545. if (! $account_id)
  546. {
  547. $this->list_groups();
  548. }
  549. else
  550. {
  551. $group_info = Array(
  552. 'account_id' => (int)$_GET['account_id'],
  553. 'account_name' => $GLOBALS['phpgw']->accounts->id2name($_GET['account_id']),
  554. 'account_user' => $this->bo->load_group_users($_GET['account_id']),
  555. 'account_apps' => $this->bo->load_group_apps($_GET['account_id'])
  556. );
  557. $this->create_edit_group($group_info);
  558. }
  559. }
  560. function edit_view_user_hook()
  561. {
  562. if (!$GLOBALS['phpgw']->acl->check('current_sessions_access',1,'admin')) // no rights to view
  563. {
  564. $GLOBALS['menuData'][] = array(
  565. 'description' => 'Login History',
  566. 'url' => '/index.php',
  567. 'extradata' => 'menuaction=admin.uiaccess_history.list_history'
  568. );
  569. }
  570. // not sure if this realy belongs here, or only in edit_user
  571. if ($_GET['account_id'] && // can't set it on add
  572. !$GLOBALS['phpgw']->acl->check('account_access',64,'admin')) // no rights to set ACL-rights
  573. {
  574. $GLOBALS['menuData'][] = array(
  575. 'description' => 'ACL Rights',
  576. 'url' => '/index.php',
  577. 'extradata' => 'menuaction=admin.uiaclmanager.list_apps'
  578. );
  579. }
  580. }
  581. function edit_user($cd='',$account_id='')
  582. {
  583. if ($GLOBALS['phpgw']->acl->check('account_access',16,'admin'))
  584. {
  585. $this->list_users();
  586. return False;
  587. }
  588. $cdid = $cd;
  589. settype($cd,'integer');
  590. $cd = ($_GET['cd']?$_GET['cd']:(int)$cdid);
  591. $accountid = $account_id;
  592. settype($account_id,'integer');
  593. $account_id = (int)($_GET['account_id'] ? $_GET['account_id'] : $accountid);
  594. // todo
  595. // not needed if i use the same file for new users too
  596. if (! $account_id)
  597. {
  598. $this->list_users();
  599. return False;
  600. }
  601. else
  602. {
  603. $this->create_edit_user($account_id);
  604. }
  605. }
  606. function view_user()
  607. {
  608. if ($GLOBALS['phpgw']->acl->check('account_access',8,'admin') || ! $_GET['account_id'])
  609. {
  610. $this->list_users();
  611. return False;
  612. }
  613. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  614. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  615. if(!@is_object($GLOBALS['phpgw']->js))
  616. {
  617. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  618. }
  619. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  620. $GLOBALS['phpgw']->common->phpgw_header();
  621. $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  622. $t->set_unknowns('remove');
  623. $t->set_file(
  624. Array(
  625. 'account' => 'account_form.tpl'
  626. )
  627. );
  628. $t->set_block('account','form','form');
  629. $t->set_block('account','form_logininfo');
  630. $t->set_block('account','link_row');
  631. $var = Array(
  632. 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
  633. 'tr_color1' => $GLOBALS['phpgw_info']['theme']['row_on'],
  634. 'tr_color2' => $GLOBALS['phpgw_info']['theme']['row_off'],
  635. 'lang_action' => lang('View user account'),
  636. 'lang_loginid' => lang('LoginID'),
  637. 'lang_account_active' => lang('Account active'),
  638. 'lang_lastname' => lang('Last Name'),
  639. 'lang_groups' => lang('Groups'),
  640. 'lang_anonymous' => lang('Anonymous user (not shown in list sessions)'),
  641. 'lang_changepassword'=> lang('Can change password'),
  642. 'lang_firstname' => lang('First Name'),
  643. 'lang_lastlogin' => lang('Last login'),
  644. 'lang_lastloginfrom' => lang('Last login from'),
  645. 'lang_expires' => lang('Expires')
  646. );
  647. $t->parse('password_fields','form_logininfo',True);
  648. $account = CreateObject('phpgwapi.accounts',(int)$_GET['account_id'],'u');
  649. $userData = $account->read_repository();
  650. $var['account_lid'] = $userData['account_lid'];
  651. $var['account_firstname'] = $userData['firstname'];
  652. $var['account_lastname'] = $userData['lastname'];
  653. $acl = CreateObject('phpgwapi.acl',(int)$_GET['account_id']);
  654. $var['anonymous'] = $acl->check('anonymous',1,'phpgwapi') ? '&nbsp;&nbsp;X' : '&nbsp;';
  655. $var['changepassword'] = $acl->check('changepassword',0xFFFF,'preferences') ? '&nbsp;&nbsp;X' : '&nbsp;';
  656. unset($acl);
  657. if ($userData['status'])
  658. {
  659. $var['account_status'] = lang('Enabled');
  660. }
  661. else
  662. {
  663. $var['account_status'] = '<b>' . lang('Disabled') . '</b>';
  664. }
  665. // Last login time
  666. if ($userData['lastlogin'])
  667. {
  668. $var['account_lastlogin'] = $GLOBALS['phpgw']->common->show_date($userData['lastlogin']);
  669. }
  670. else
  671. {
  672. $var['account_lastlogin'] = lang('Never');
  673. }
  674. // Last login IP
  675. if ($userData['lastloginfrom'])
  676. {
  677. $var['account_lastloginfrom'] = $userData['lastloginfrom'];
  678. }
  679. else
  680. {
  681. $var['account_lastloginfrom'] = lang('Never');
  682. }
  683. // Account expires
  684. if ($userData['expires'] != -1)
  685. {
  686. $var['input_expires'] = $GLOBALS['phpgw']->common->show_date($userData['expires']);
  687. }
  688. else
  689. {
  690. $var['input_expires'] = lang('Never');
  691. }
  692. // Find out which groups they are members of
  693. $usergroups = $account->membership((int)$_GET['account_id']);
  694. if(!@is_array($usergroups))
  695. {
  696. $var['groups_select'] = lang('None');
  697. }
  698. else
  699. {
  700. while (list(,$group) = each($usergroups))
  701. {
  702. $group_names[] = $group['account_name'];
  703. }
  704. $var['groups_select'] = implode(', ',$group_names);
  705. }
  706. $account_lastlogin = $userData['account_lastlogin'];
  707. $account_lastloginfrom = $userData['account_lastloginfrom'];
  708. $account_status = $userData['account_status'];
  709. // create list of available app
  710. $i = 0;
  711. $availableApps = $GLOBALS['phpgw_info']['apps'];
  712. @asort($availableApps);
  713. @reset($availableApps);
  714. foreach($availableApps as $app => $data)
  715. {
  716. if ($data['enabled'] && $data['status'] != 2)
  717. {
  718. $perm_display[$i]['appName'] = $app;
  719. $perm_display[$i]['title'] = $data['title'];
  720. ++$i;
  721. }
  722. }
  723. // create apps output
  724. $apps = CreateObject('phpgwapi.applications',(int)$_GET['account_id']);
  725. $db_perms = $apps->read_account_specific();
  726. @reset($db_perms);
  727. $perm_display_count = count($perm_display);
  728. for ($i=0;$i<$perm_display_count;++$i)
  729. {
  730. if ($perm_display[$i]['title'])
  731. {
  732. $part1 = sprintf("<td>%s</td><td>%s</td>",$perm_display[$i]['title'],($_userData['account_permissions'][$perm_display[$i]['appName']] || $db_perms[$perm_display[$i]['appName']]?'&nbsp;&nbsp;X':'&nbsp'));
  733. }
  734. ++$i;
  735. if ($perm_display[$i]['title'])
  736. {
  737. $part2 = sprintf("<td>%s</td><td>%s</td>",$perm_display[$i]['title'],($_userData['account_permissions'][$perm_display[$i]['appName']] || $db_perms[$perm_display[$i]['appName']]?'&nbsp;&nbsp;X':'&nbsp'));
  738. }
  739. else
  740. {
  741. $part2 = '<td colspan="2">&nbsp;</td>';
  742. }
  743. $appRightsOutput .= sprintf("<tr bgcolor=\"%s\">$part1$part2</tr>\n",$GLOBALS['phpgw_info']['theme']['row_on']);
  744. }
  745. $var['permissions_list'] = $appRightsOutput;
  746. // create the menu on the left, if needed
  747. // $menuClass = CreateObject('admin.uimenuclass');
  748. // This is now using ExecMethod()
  749. $var['rows'] = ExecMethod('admin.uimenuclass.createHTMLCode','view_user');
  750. $t->set_var($var);
  751. $t->pfp('out','form');
  752. }
  753. function group_manager($cd='',$account_id='')
  754. {
  755. if ($GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
  756. {
  757. $this->list_groups();
  758. return False;
  759. }
  760. $cdid = $cd;
  761. settype($cd,'integer');
  762. $cd = ($_GET['cd']?$_GET['cd']:(int)$cdid);
  763. $accountid = $account_id;
  764. settype($account_id,'integer');
  765. $account_id = (int)($_GET['account_id'] ? $_GET['account_id'] : $accountid);
  766. // todo
  767. // not needed if i use the same file for new groups too
  768. if (! $account_id)
  769. {
  770. $this->list_groups();
  771. }
  772. else
  773. {
  774. $group_info = Array(
  775. 'account_id' => (int)$_GET['account_id'],
  776. 'account_name' => $GLOBALS['phpgw']->accounts->id2name($_GET['account_id']),
  777. 'account_user' => $GLOBALS['phpgw']->accounts->member($_GET['account_id']),
  778. 'account_managers' => $this->bo->load_group_managers($_GET['account_id'])
  779. );
  780. $this->edit_group_managers($group_info);
  781. }
  782. }
  783. function create_edit_group($group_info,$_errors='')
  784. {
  785. $sbox = createobject('phpgwapi.sbox');
  786. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  787. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  788. if(!@is_object($GLOBALS['phpgw']->js))
  789. {
  790. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  791. }
  792. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  793. $GLOBALS['phpgw']->common->phpgw_header();
  794. $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  795. $p->set_file(Array('edit' => 'group_form.tpl'));
  796. $p->set_block('edit','select');
  797. $p->set_block('edit','popwin');
  798. $accounts = CreateObject('phpgwapi.accounts',$group_info['account_id'],'g');
  799. if (!is_object($GLOBALS['phpgw']->uiaccountsel))
  800. {
  801. $GLOBALS['phpgw']->uiaccountsel = CreateObject('phpgwapi.uiaccountsel');
  802. }
  803. $p->set_var('accounts',$GLOBALS['phpgw']->uiaccountsel->selection('account_user[]','admin_uiaccounts_user',$group_info['account_user'],'accounts',min(3+count($group_info['account_user']),10)));
  804. $var = Array(
  805. 'form_action' => $GLOBALS['phpgw']->link('/index.php','menuaction=admin.boaccounts.'.($group_info['account_id']?'edit':'add').'_group'),
  806. 'hidden_vars' => '<input type="hidden" name="account_id" value="' . $group_info['account_id'] . '">',
  807. 'lang_group_name' => lang('group name'),
  808. 'group_name_value' => $group_info['account_name'],
  809. 'lang_include_user' => lang('Select users for inclusion'),
  810. 'error' => (!$_errors?'':'<center>'.$GLOBALS['phpgw']->common->error_list($_errors).'</center>'),
  811. 'lang_permissions' => lang('Permissions this group has')
  812. );
  813. $p->set_var($var);
  814. $group_repository = $accounts->read_repository();
  815. if (!$group_repository['file_space'])
  816. {
  817. $group_repository['file_space'] = $GLOBALS['phpgw_info']['server']['vfs_default_account_size_number'] . "-" . $GLOBALS['phpgw_info']['server']['vfs_default_account_size_type'];
  818. }
  819. /*
  820. $file_space_array = explode ('-', $group_repository['file_space']);
  821. $account_file_space_types = array ('gb', 'mb', 'kb', 'b');
  822. while (list ($num, $type) = each ($account_file_space_types))
  823. {
  824. $account_file_space_select .= '<option value="'.$type.'"'.($type==$file_space_array[1]?' selected':'').'>'.strtoupper ($type).'</option>'."\n";
  825. }
  826. $p->set_var ('lang_file_space', lang('File space'));
  827. $p->set_var ('account_file_space', '<input type=text name="account_file_space_number" value="'.trim($file_space_array[0]).'" size="7">');
  828. $p->set_var ('account_file_space_select','<select name="account_file_space_type">'."\n".$account_file_space_select.'</select>'."\n");
  829. */
  830. reset($GLOBALS['phpgw_info']['apps']);
  831. $sorted_apps = $GLOBALS['phpgw_info']['apps'];
  832. @asort($sorted_apps);
  833. @reset($sorted_apps);
  834. while ($permission = each($sorted_apps))
  835. {
  836. if ($permission[1]['enabled'] && $permission[1]['status'] != 3)
  837. {
  838. $perm_display[] = Array(
  839. $permission[0],
  840. $permission[1]['title']
  841. );
  842. }
  843. }
  844. $perm_html = '<td width="35%">'.lang('Application').'</td><td width="15%">'.lang('enabled').' / '.lang('ACL').'</td>';
  845. $perm_html = '<tr class="th">'.
  846. $perm_html.$perm_html."</tr>\n";
  847. $tr_color = $GLOBALS['phpgw_info']['theme']['row_off'];
  848. $perm_display_count = count($perm_display);
  849. for ($i=0;$i < $perm_display_count;++$i)
  850. {
  851. $app = $perm_display[$i][0];
  852. if(!($i & 1))
  853. {
  854. $tr_color = $this->nextmatchs->alternate_row_color();
  855. $perm_html .= '<tr bgcolor="'.$tr_color.'">';
  856. }
  857. $perm_html .= '<td>' . $perm_display[$i][1] . '</td>'
  858. . '<td><input type="checkbox" name="account_apps['
  859. . $perm_display[$i][0] . ']" value="True"'.($group_info['account_apps'][$app]?' checked':'').'> '
  860. . ($this->apps_with_acl[$app] && $group_info['account_id']?'<a href="'.$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$app.'&owner='.$group_info['account_id'])
  861. . '"><img src="'.$GLOBALS['phpgw']->common->image('phpgwapi','edit').'" border="0" hspace="3" align="absmiddle" title="'
  862. . lang('Grant Access').': '.lang("edit group ACL's").'" /></a>':'&nbsp;').'</td>'.($i & 1?'</tr>':'')."\n";
  863. }
  864. if($i & 1)
  865. {
  866. $perm_html .= '<td colspan="4">&nbsp;</td></tr>';
  867. }
  868. $var = Array(
  869. 'permissions_list' => $perm_html,
  870. 'lang_submit_button' => lang('submit changes')
  871. );
  872. $p->set_var($var);
  873. // create the menu on the left, if needed
  874. $p->set_var('rows',ExecMethod('admin.uimenuclass.createHTMLCode','group_manager'));
  875. $p->set_var('select','');
  876. $p->set_var('popwin','');
  877. $p->pfp('out','edit');
  878. }
  879. function create_edit_user($_account_id,$_userData='',$_errors='')
  880. {
  881. $sbox = createobject('phpgwapi.sbox');
  882. $jscal = CreateObject('phpgwapi.jscalendar');
  883. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  884. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  885. if(!@is_object($GLOBALS['phpgw']->js))
  886. {
  887. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  888. }
  889. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  890. $GLOBALS['phpgw']->common->phpgw_header();
  891. $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  892. $t->set_unknowns('remove');
  893. if ($GLOBALS['phpgw_info']['server']['ldap_extra_attributes'] && ($GLOBALS['phpgw_info']['server']['account_repository'] == 'ldap'))
  894. {
  895. $t->set_file(array('account' => 'account_form_ldap.tpl'));
  896. }
  897. else
  898. {
  899. $t->set_file(array('account' => 'account_form.tpl'));
  900. }
  901. $t->set_block('account','form','form');
  902. $t->set_block('account','form_passwordinfo','form_passwordinfo');
  903. $t->set_block('account','form_buttons_','form_buttons_');
  904. $t->set_block('account','link_row','link_row');
  905. print_debug('Type : '.gettype($_userData).'<br />_userData(size) = "'.$_userData.'"('.strlen($_userData).')');
  906. if (is_array($_userData))
  907. {
  908. $userData = Array();
  909. $userData=$_userData;
  910. $userData['firstname'] = $userData['account_firstname'];
  911. $userData['lastname'] = $userData['account_lastname'];
  912. @reset($userData['account_groups']);
  913. while (list($key, $value) = @each($userData['account_groups']))
  914. {
  915. $userGroups[$key]['account_id'] = $value;
  916. }
  917. $account = CreateObject('phpgwapi.accounts');
  918. $allGroups = $account->get_list('groups');
  919. }
  920. elseif(is_string($_userData) && $_userData=='')
  921. {
  922. if($_account_id)
  923. {
  924. $account = CreateObject('phpgwapi.accounts',(int)$_account_id,'u');
  925. $userData = $account->read_repository();
  926. $userGroups = $account->membership($_account_id);
  927. $acl = CreateObject('phpgwapi.acl',$_account_id);
  928. $acl->read_repository();
  929. $userData['anonymous'] = $acl->check('anonymous',1,'phpgwapi');
  930. $userData['changepassword'] = $acl->check('changepassword',0xFFFF,'preferences');
  931. unset($acl);
  932. }
  933. else
  934. {
  935. $account = CreateObject('phpgwapi.accounts');
  936. $userData = Array();
  937. $userData['status'] = 'A';
  938. $userGroups = Array();
  939. $userData['anonymous'] = False;
  940. $userData['changepassword'] = True;
  941. }
  942. $allGroups = $account->get_list('groups');
  943. }
  944. $page_params['menuaction'] = 'admin.boaccounts.'.($_account_id?'edit':'add').'_user';
  945. if($_account_id)
  946. {
  947. $page_params['account_id'] = $_account_id;
  948. $page_params['old_loginid'] = rawurlencode($userData['account_lid']);
  949. }
  950. $var = Array(
  951. 'form_action' => $GLOBALS['phpgw']->link('/index.php',$page_params),
  952. 'error_messages' => (!$_errors?'':'<center>'.$GLOBALS['phpgw']->common->error_list($_errors).'</center>'),
  953. 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
  954. 'tr_color1' => $GLOBALS['phpgw_info']['theme']['row_on'],
  955. 'tr_color2' => $GLOBALS['phpgw_info']['theme']['row_off'],
  956. 'lang_action' => ($_account_id?lang('Edit user account'):lang('Add new account')),
  957. 'lang_loginid' => lang('LoginID'),
  958. 'lang_account_active' => lang('Account active'),
  959. 'lang_email' => lang('email'),
  960. 'lang_password' => lang('Password'),
  961. 'lang_reenter_password' => lang('Re-Enter Password'),
  962. 'lang_lastname' => lang('Last Name'),
  963. 'lang_groups' => lang('Groups'),
  964. 'lang_primary_group' => lang('primary Group'),
  965. 'lang_expires' => lang('Expires'),
  966. 'lang_firstname' => lang('First Name'),
  967. 'lang_anonymous' => lang('Anonymous User (not shown in list sessions)'),
  968. 'lang_changepassword' => lang('Can change password'),
  969. 'lang_button' => ($_account_id?lang('Save'):lang('Add'))
  970. /* 'lang_file_space' => lang('File Space') */
  971. );
  972. $t->set_var($var);
  973. $t->parse('form_buttons','form_buttons_',True);
  974. if ($GLOBALS['phpgw_info']['server']['ldap_extra_attributes']) {
  975. $lang_homedir = lang('home directory');
  976. $lang_shell = lang('login shell');
  977. $homedirectory = '<input name="homedirectory" value="'
  978. . ($_account_id?$userData['homedirectory']:$GLOBALS['phpgw_info']['server']['ldap_account_home'].$account_lid)
  979. . '">';
  980. $loginshell = '<input name="loginshell" value="'
  981. . ($_account_id?$userData['loginshell']:$GLOBALS['phpgw_info']['server']['ldap_account_shell'])
  982. . '">';
  983. }
  984. else
  985. {
  986. $lang_homedir = '';
  987. $lang_shell = '';
  988. $homedirectory = '';
  989. $loginshell = '';
  990. }
  991. $account_file_space = '';
  992. /*
  993. if (!$userData['file_space'])
  994. {
  995. $userData['file_space'] = $GLOBALS['phpgw_info']['server']['vfs_default_account_size_number'] . "-" . $GLOBALS['phpgw_info']['server']['vfs_default_account_size_type'];
  996. }
  997. $file_space_array = explode ('-', $userData['file_space']);
  998. $account_file_space_number = $file_space_array[0];
  999. $account_file_space_type = $file_space_array[1];
  1000. $account_file_space_type_selected[$account_file_space_type] = ' selected';
  1001. $account_file_space = '<input type=text name="account_file_space_number" value="' . trim($account_file_space_number) . '" size="7">';
  1002. $account_file_space_select ='<select name="account_file_space_type">';
  1003. $account_file_space_types = array ('gb', 'mb', 'kb', 'b');
  1004. while (list ($num, $type) = each ($account_file_space_types))
  1005. {
  1006. $account_file_space_select .= '<option value="'.$type.'"' . $account_file_space_type_selected[$type] . '>' . strtoupper ($type) . '</option>';
  1007. }
  1008. $account_file_space_select .= '</select>';
  1009. $var = Array(
  1010. 'lang_file_space' => 'File space',
  1011. 'account_file_space' => $account_file_space,
  1012. 'account_file_space_select' => $account_file_space_select
  1013. );
  1014. $t->set_var($var);
  1015. */
  1016. $accountPrefix = '';
  1017. if(isset($GLOBALS['phpgw_info']['server']['account_prefix']))
  1018. {
  1019. $accountPrefix = $GLOBALS['phpgw_info']['server']['account_prefix'];
  1020. if (preg_match ("/^$accountPrefix(.*)/i", $userData['account_lid'], $matches))
  1021. {
  1022. $userData['account_lid'] = $matches[1];
  1023. }
  1024. }
  1025. $var = Array(
  1026. 'input_expires' => $jscal->input('expires',$userData['expires']<0?'':($userData['expires']?$userData['expires']:time()+(60*60*24*7))),
  1027. 'lang_never' => lang('Never'),
  1028. 'account_lid' => $accountPrefix.'<input name="account_lid" value="' . $userData['account_lid'] . '">',
  1029. 'lang_homedir' => $lang_homedir,
  1030. 'lang_shell' => $lang_shell,
  1031. 'homedirectory' => $homedirectory,
  1032. 'loginshell' => $loginshell,
  1033. 'anonymous' => '<input type="checkbox" name="anonymous" value="1"'.($userData['anonymous'] ? ' checked' : '').'>',
  1034. 'changepassword'=> '<input type="checkbox" name="changepassword" value="1"'.($userData['changepassword'] ? ' checked' : '').'>',
  1035. 'account_status' => '<input type="checkbox" name="account_status" value="A"'.($userData['status']?' checked':'').'>',
  1036. 'account_firstname' => '<input name="account_firstname" value="' . $userData['firstname'] . '">',
  1037. 'account_lastname' => '<input name="account_lastname" value="' . $userData['lastname'] . '">',
  1038. 'account_email' => '<input name="account_email" size="32" value="' . $userData['email'] . '">',
  1039. 'account_passwd' => $userData['account_passwd'],
  1040. 'account_passwd_2' => $userData['account_passwd_2'],
  1041. 'account_file_space' => $account_file_space
  1042. );
  1043. if($userData['expires'] == -1)
  1044. {
  1045. $var['never_expires'] = '<input type="checkbox" name="never_expires" value="True" checked>';
  1046. }
  1047. else
  1048. {
  1049. $var['never_expires'] = '<input type="checkbox" name="never_expires" value="True">';
  1050. }
  1051. $t->set_var($var);
  1052. $t->parse('password_fields','form_passwordinfo',True);
  1053. $groups_select = '';
  1054. $primary_group_select = '';
  1055. reset($allGroups);
  1056. while (list($key,$value) = each($allGroups))
  1057. {
  1058. $groups_select .= '<option value="' . $value['account_id'] . '"';
  1059. $userGroups_count = count($userGroups);
  1060. for ($i=0; $i<$userGroups_count; ++$i)
  1061. {
  1062. /* print "Los1:".$userData["account_id"].$userGroups[$i]['account_id']." : ".$value['account_id']."<br />"; */
  1063. if (@$userGroups[$i]['account_id'] == $value['account_id'])
  1064. {
  1065. $groups_select .= ' selected';
  1066. }
  1067. }
  1068. $groups_select .= '>' . $value['account_lid'] . '</option>'."\n";
  1069. }
  1070. if (!$userData['account_primary_group'])
  1071. {
  1072. $userData['account_primary_group'] = @$userGroups[0]['account_id'] ? @$userGroups[0]['account_id'] : $account->name2id('Default');
  1073. }
  1074. foreach($allGroups as $key => $value)
  1075. {
  1076. # print "<br />$key =>";
  1077. # _debug_array($userGroups);
  1078. $primary_group_select .= '<option value="' . $value['account_id'] . '"';
  1079. #print $value['account_id'].''.$value['account_primary_group']
  1080. if ($value['account_id'] == $userData['account_primary_group'])
  1081. {
  1082. $primary_group_select .= ' selected="1"';
  1083. }
  1084. $primary_group_select .= '>' . $value['account_lid'] . '</option>'."\n";
  1085. }
  1086. /* create list of available apps */
  1087. $apps = CreateObject('phpgwapi.applications',$_account_id);
  1088. $db_perms = $apps->read_account_specific();
  1089. $availableApps = $GLOBALS['phpgw_info']['apps'];
  1090. uasort($availableApps,create_function('$a,$b','return strcasecmp($a["title"],$b["title"]);'));
  1091. $appRightsOutput = '';
  1092. $i = 0;
  1093. foreach($availableApps as $app => $data)
  1094. {
  1095. if (!$data['enabled'] || $data['status'] == 3)
  1096. {
  1097. continue;
  1098. }
  1099. $checked = (@$userData['account_permissions'][$app] || @$db_perms[$app]) && $_account_id ? ' checked="1"' : '';
  1100. $part[$i&1] = sprintf('<td>%s</td><td><input type="checkbox" name="account_permissions[%s]" value="True"%s>',
  1101. $data['title'],$app,$checked).
  1102. ($this->apps_with_acl[$app] && $_account_id?'<a href="'.$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$app.'&owner='.$_account_id)
  1103. . '"><img src="'.$GLOBALS['phpgw']->common->image('phpgwapi','edit').'" border="0" hspace="3" align="absmiddle" title="'
  1104. . lang('Grant Access').'" /></a>':'&nbsp;').'</td>';
  1105. if ($i & 1)
  1106. {
  1107. $appRightsOutput .= sprintf('<tr bgcolor="%s">%s%s</tr>',$this->nextmatchs->alternate_row_color(), $part[0], $part[1]);
  1108. }
  1109. ++$i;
  1110. }
  1111. if ($i & 1)
  1112. {
  1113. $part[1] = '<td colspan="3">&nbsp;</td>';
  1114. $appRightsOutput .= sprintf('<tr bgcolor="%s">%s%s</tr>',$this->nextmatchs->alternate_row_color(), $part[0], $part[1]);
  1115. }
  1116. $var = Array(
  1117. 'groups_select'
  1118. => '<select name="account_groups[]" multiple>'."\n".$groups_select.'</select>'."\n",
  1119. 'primary_group_select'
  1120. => '<select name="account_primary_group">'."\n".$primary_group_select.'</select>'."\n",
  1121. 'permissions_list'
  1122. => $appRightsOutput,
  1123. 'lang_app' => lang('application'),
  1124. 'lang_acl' => lang('enabled').' / '.lang('ACL'),
  1125. );
  1126. $t->set_var($var);
  1127. // create the menu on the left, if needed
  1128. // $menuClass = CreateObject('admin.uimenuclass');
  1129. // This is now using ExecMethod()
  1130. $GLOBALS['account_id'] = $_account_id;
  1131. $t->set_var('rows',ExecMethod('admin.uimenuclass.createHTMLCode','edit_user'));
  1132. echo $t->fp('out','form');
  1133. }
  1134. function edit_group_managers($group_info,$_errors='')
  1135. {
  1136. if ($GLOBALS['phpgw']->acl->check('group_access',16,'admin'))
  1137. {
  1138. $this->list_groups();
  1139. return False;
  1140. }
  1141. $accounts = CreateObject('phpgwapi.accounts',$group_info['account_id'],'u');
  1142. $account_list = $accounts->member($group_info['account_id']);
  1143. $user_list = '';
  1144. while (list($key,$entry) = each($account_list))
  1145. {
  1146. $user_list .= '<option value="' . $entry['account_id'] . '"'
  1147. . $group_info['account_managers'][(int)$entry['account_id']] . '>'
  1148. . $GLOBALS['phpgw']->common->grab_owner_name($entry['account_id'])
  1149. . '</option>'."\n";
  1150. }
  1151. unset($GLOBALS['phpgw_info']['flags']['noheader']);
  1152. unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
  1153. if(!@is_object($GLOBALS['phpgw']->js))
  1154. {
  1155. $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
  1156. }
  1157. $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
  1158. $GLOBALS['phpgw']->common->phpgw_header();
  1159. $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
  1160. $t->set_unknowns('remove');
  1161. $t->set_file(
  1162. Array(
  1163. 'manager' =>'group_manager.tpl'
  1164. )
  1165. );
  1166. $t->set_block('manager','form','form');
  1167. $t->set_block('manager','link_row','link_row');
  1168. $var['th_bg'] = $GLOBALS['phpgw_info']['user']['theme']['th_bg'];
  1169. $var['lang_group'] = lang('Group');
  1170. $var['group_name'] = $group_info['account_name'];
  1171. $var['tr_color1'] = $GLOBALS['phpgw_info']['user']['theme']['row_on'];
  1172. $var['form_action'] = $GLOBALS['phpgw']->link('/index.php','menuaction=admin.boaccounts.set_group_managers');
  1173. $var['hidden'] = '<input type="hidden" name="account_id" value="'.$group_info['account_id'].'">';
  1174. $var['lang_select_managers'] = lang('Select Group Managers');
  1175. $var['group_members'] = '<select name="managers[]" size="'.(count($account_list)<5?count($account_list):5).'" multiple>'.$user_list.'</select>';
  1176. $var['form_buttons'] = '<tr align="center"><td colspan="2"><input type="submit" name="submit" value="'.lang('Submit').'">&nbsp;&nbsp;'
  1177. . '<input type="submit" name="cancel" value="'.lang('Cancel').'"><td></tr>';
  1178. $t->set_var($var);
  1179. // create the menu on the left, if needed
  1180. $t->set_var('rows',ExecMethod('admin.uimenuclass.createHTMLCode','edit_group'));
  1181. $t->pfp('out','form');
  1182. }
  1183. }
  1184. ?>