PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/ser-0.9.6/serweb-0.9.4/application_layer/apu_subscribers.php

#
PHP | 354 lines | 220 code | 46 blank | 88 comment | 22 complexity | 6f41ad17c4236973ae14ad818fe18280 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /*
  3. * Application unit subscribers
  4. *
  5. * @author Karel Kozlik
  6. * @version $Id: apu_subscribers.php,v 1.2 2005/04/21 15:09:45 kozlik Exp $
  7. * @package serweb
  8. */
  9. /* Application unit subscribers
  10. *
  11. *
  12. * This application unit is used for get list of subscribers and looking for subscribers
  13. *
  14. * Configuration:
  15. * --------------
  16. *
  17. * 'use_chk_adminsonly' (bool) default: false
  18. * set to true if you want use checkbox 'adminsonly' for display only admins
  19. *
  20. * 'use_chk_onlineonly' (bool) default: false
  21. * set to true if you want use checkbox 'onlineonly' for display only online users
  22. *
  23. * 'def_chk_adminsonly' (bool) default: false
  24. * set to true if checkbox 'adminsonly' should be initialy checked
  25. *
  26. * 'def_chk_onlineonly' (bool) default: false
  27. * set to true if checkbox 'onlineonly' should be initialy checked
  28. *
  29. * 'only_from_same_domain' (bool) default: false
  30. * set to true for display only users from same domain as admin
  31. *
  32. * 'get_user_aliases' (bool) default: false
  33. * set to true if you want display aliases of users
  34. *
  35. * 'sess_seed' (int or string) default:0
  36. * this is used for distinguish session variables of multiple instances of this
  37. * APU on more pages. If you are useing this APU on more places, set for each
  38. * instance different 'sess_seed'
  39. *
  40. *
  41. * 'msg_delete' default: $lang_str['msg_user_deleted_s'] and $lang_str['msg_user_deleted_l']
  42. * message which should be showed on attributes update - assoc array with keys 'short' and 'long'
  43. *
  44. * 'form_name' (string) default: ''
  45. * name of html form
  46. *
  47. * 'form_submit' (assoc)
  48. * assotiative array describe submit element of form. For details see description
  49. * of method add_submit in class form_ext
  50. *
  51. * 'smarty_form' name of smarty variable - see below
  52. * 'smarty_action' name of smarty variable - see below
  53. *
  54. * Exported smarty variables:
  55. * --------------------------
  56. * opt['smarty_form'] (form)
  57. * phplib html form
  58. *
  59. * opt['smarty_action'] (action)
  60. * tells what should smarty display. Values:
  61. * 'default' -
  62. * 'was_deleted' - when subscriber was deleted
  63. *
  64. * opt['smarty_pager'] (pager)
  65. * associative array containing size of result and which page is returned
  66. *
  67. * opt['smarty_subscribers'] (users)
  68. * associative array containing subscribers
  69. * The array have same keys as function get_users (from data layer) returned.
  70. *
  71. *
  72. */
  73. class apu_subscribers extends apu_base_class{
  74. var $smarty_action='default';
  75. var $dele_user = null;
  76. /* return required data layer methods - static class */
  77. function get_required_data_layer_methods(){
  78. return array('get_users', 'delete_sip_user', 'check_admin_perms_to_user');
  79. }
  80. /* return array of strings - requred javascript files */
  81. function get_required_javascript(){
  82. return array();
  83. }
  84. /* constructor */
  85. function apu_subscribers(){
  86. global $lang_str, $sess_lang;
  87. parent::apu_base_class();
  88. /* set default values to $this->opt */
  89. $this->opt['use_chk_adminsonly'] = false;
  90. $this->opt['def_chk_adminsonly'] = false;
  91. $this->opt['use_chk_onlineonly'] = false;
  92. $this->opt['def_chk_onlineonly'] = false;
  93. $this->opt['sess_seed'] = 0;
  94. $this->opt['only_from_same_domain'] = false;
  95. $this->opt['get_user_aliases'] = false;
  96. /* message on attributes update */
  97. $this->opt['msg_delete']['short'] = &$lang_str['msg_user_deleted_s'];
  98. $this->opt['msg_delete']['long'] = &$lang_str['msg_user_deleted_l'];
  99. /*** names of variables assigned to smarty ***/
  100. /* form */
  101. $this->opt['smarty_form'] = 'form';
  102. /* smarty action */
  103. $this->opt['smarty_action'] = 'action';
  104. /* pager */
  105. $this->opt['smarty_pager'] = 'pager';
  106. $this->opt['smarty_subscribers'] = 'users';
  107. /* name of html form */
  108. $this->opt['form_name'] = '';
  109. $this->opt['form_submit']=array('type' => 'image',
  110. 'text' => $lang_str['b_find'],
  111. 'src' => get_path_to_buttons("btn_find.gif", $sess_lang));
  112. }
  113. function action_delete(&$errors){
  114. global $data, $lang_str, $serweb_auth;
  115. if ($this->opt['only_from_same_domain']){
  116. if (0 > ($pp=$data->check_admin_perms_to_user($serweb_auth, $this->dele_user, $errors))) return false;
  117. if (!$pp){
  118. $errors[]=$lang_str['err_admin_can_not_delete_user_1']." '".$this->dele_user->uname."' ".$lang_str['err_admin_can_not_delete_user_2'];
  119. return false;
  120. }
  121. }
  122. if (!$data->delete_sip_user($this->dele_user, $errors)) return false;
  123. return array("m_sc_user_deleted=".RawURLEncode($this->opt['instance_id']));
  124. // Header("Location: ".$sess->url("users.php?kvrk=".uniqID("")."&m_user_deleted=".RawURLEncode($usr->uname."@".$usr->domain)));
  125. }
  126. function action_default(&$errors){
  127. global $data, $sess, $sess_apu_sc, $serweb_auth;
  128. $data->set_act_row($sess_apu_sc[$this->opt['sess_seed']]['act_row']);
  129. $opt = array('only_domain' => $this->opt['only_from_same_domain']?
  130. $serweb_auth->domain:
  131. null,
  132. 'get_user_aliases' => $this->opt['get_user_aliases']);
  133. if (false === $this->subscribers =
  134. $data->get_users(
  135. $sess_apu_sc[$this->opt['sess_seed']]['filter'],
  136. $opt,
  137. $errors))
  138. return false;
  139. $this->pager['url']=$_SERVER['PHP_SELF']."?kvrk=".uniqid("")."&act_row=";
  140. $this->pager['pos']=$data->get_act_row();
  141. $this->pager['items']=$data->get_num_rows();
  142. $this->pager['limit']=$data->get_showed_rows();
  143. $this->pager['from']=$data->get_res_from();
  144. $this->pager['to']=$data->get_res_to();
  145. foreach($this->subscribers as $key=>$val){
  146. $this->subscribers[$key]['url_dele'] =
  147. $sess->url($_SERVER['PHP_SELF']."?kvrk=".uniqID("").
  148. "&sc_dele=".RawURLEncode($this->opt['instance_id']).
  149. "&".$val['get_param_d']);
  150. }
  151. return true;
  152. }
  153. /* this metod is called always at begining */
  154. function init(){
  155. global $sess, $sess_apu_sc;
  156. parent::init();
  157. /* registger session variable if still isn't registered */
  158. if (!$sess->is_registered('sess_apu_sc')) $sess->register('sess_apu_sc');
  159. /* set default value for session variable */
  160. if (!isset($sess_apu_sc[$this->opt['sess_seed']])){
  161. $tmp = array();
  162. $tmp['filter']['usrnm'] = '';
  163. $tmp['filter']['fname'] = '';
  164. $tmp['filter']['lname'] = '';
  165. $tmp['filter']['email'] = '';
  166. $tmp['filter']['domain'] = '';
  167. $tmp['filter']['onlineonly'] = $this->opt['def_chk_onlineonly'];
  168. $tmp['filter']['adminsonly'] = $this->opt['def_chk_adminsonly'];
  169. $tmp['act_row'] = 0;
  170. $sess_apu_sc[$this->opt['sess_seed']] = &$tmp;
  171. }
  172. if (isset($_GET['act_row']))
  173. $sess_apu_sc[$this->opt['sess_seed']]['act_row'] = $_GET['act_row'];
  174. }
  175. function set_filter_by_posts(){
  176. global $sess_apu_sc;
  177. /* show results from first row after form submit */
  178. $sess_apu_sc[$this->opt['sess_seed']]['act_row'] = 0;
  179. /* set search filter by values submited by form */
  180. $filter = &$sess_apu_sc[$this->opt['sess_seed']]['filter'];
  181. if (isset($_POST['usrnm'])) $filter['usrnm']=$_POST['usrnm'];
  182. if (isset($_POST['fname'])) $filter['fname']=$_POST['fname'];
  183. if (isset($_POST['lname'])) $filter['lname']=$_POST['lname'];
  184. if (isset($_POST['email'])) $filter['email']=$_POST['email'];
  185. if (isset($_POST['domain'])) $filter['domain']=$_POST['domain'];
  186. if ($this->opt['use_chk_onlineonly']){
  187. if (isset($_POST['onlineonly']))
  188. $filter['onlineonly']=$_POST['onlineonly'];
  189. else $filter['onlineonly']=0;
  190. }
  191. if ($this->opt['use_chk_adminsonly']){
  192. if (isset($_POST['adminsonly']))
  193. $filter['adminsonly']=$_POST['adminsonly'];
  194. else $filter['adminsonly']=0;
  195. }
  196. $this->f->load_defaults();
  197. }
  198. /* check _get and _post arrays and determine what we will do */
  199. function determine_action(){
  200. if (isset($_GET['sc_dele']) and $_GET['sc_dele'] == $this->opt['instance_id']){
  201. if (false !== $this->dele_user = get_userauth_from_get_param('d')){
  202. $this->action=array('action'=>"delete",
  203. 'validate_form'=>false,
  204. 'reload'=>true);
  205. return;
  206. }
  207. sw_log("user should be deleted, but can't get identificator from GET param", PEAR_LOG_DEBUG);
  208. }
  209. if ($this->was_form_submited()){ // Is there data to process?
  210. $this->action=array('action'=>"default",
  211. 'validate_form'=>true,
  212. 'reload'=>false);
  213. }
  214. else $this->action=array('action'=>"default",
  215. 'validate_form'=>false,
  216. 'reload'=>false);
  217. }
  218. /* create html form */
  219. function create_html_form(&$errors){
  220. global $sess_apu_sc;
  221. parent::create_html_form($errors);
  222. $filter = &$sess_apu_sc[$this->opt['sess_seed']]['filter'];
  223. $this->f->add_element(array("type"=>"text",
  224. "name"=>"usrnm",
  225. "size"=>11,
  226. "maxlength"=>50,
  227. "value"=>$filter['usrnm']));
  228. $this->f->add_element(array("type"=>"text",
  229. "name"=>"fname",
  230. "size"=>11,
  231. "maxlength"=>25,
  232. "value"=>$filter['fname']));
  233. $this->f->add_element(array("type"=>"text",
  234. "name"=>"lname",
  235. "size"=>11,
  236. "maxlength"=>45,
  237. "value"=>$filter['lname']));
  238. $this->f->add_element(array("type"=>"text",
  239. "name"=>"email",
  240. "size"=>11,
  241. "maxlength"=>50,
  242. "value"=>$filter['email']));
  243. $this->f->add_element(array("type"=>"text",
  244. "name"=>"domain",
  245. "size"=>11,
  246. "maxlength"=>128,
  247. "value"=>$filter['domain']));
  248. $this->f->add_element(array("type"=>"checkbox",
  249. "value"=>1,
  250. "checked"=>$filter['onlineonly'],
  251. "name"=>"onlineonly"));
  252. $this->f->add_element(array("type"=>"checkbox",
  253. "value"=>1,
  254. "checked"=>$filter['adminsonly'],
  255. "name"=>"adminsonly"));
  256. }
  257. /* validate html form */
  258. function validate_form(&$errors){
  259. if (false === parent::validate_form($errors)) return false;
  260. $this->set_filter_by_posts();
  261. return true;
  262. }
  263. /* add messages to given array */
  264. function return_messages(&$msgs){
  265. global $_GET;
  266. if (isset($_GET['m_sc_user_deleted']) and $_GET['m_sc_user_deleted'] == $this->opt['instance_id']){
  267. $msgs[]=&$this->opt['msg_delete'];
  268. $this->smarty_action="was_deleted";
  269. }
  270. }
  271. /* assign variables to smarty */
  272. function pass_values_to_html(){
  273. global $smarty;
  274. $smarty->assign_by_ref($this->opt['smarty_action'], $this->smarty_action);
  275. $smarty->assign_by_ref($this->opt['smarty_pager'], $this->pager);
  276. $smarty->assign_by_ref($this->opt['smarty_subscribers'], $this->subscribers);
  277. }
  278. /* return info need to assign html form to smarty */
  279. function pass_form_to_html(){
  280. return array('smarty_name' => $this->opt['smarty_form'],
  281. 'form_name' => $this->opt['form_name'],
  282. 'after' => '',
  283. 'before' => '');
  284. }
  285. }
  286. ?>