PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/rmcommon/trunk/class/fields/formuser.class.php

http://bitcero-modules.googlecode.com/
PHP | 158 lines | 100 code | 20 blank | 38 comment | 15 complexity | 1280f20c5584803aeabecc6749daf99e MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: formuser.class.php 934 2012-02-17 16:35:33Z i.bitcero $
  3. // --------------------------------------------------------------
  4. // EXM System
  5. // Content Management System
  6. // Author: Eduardo Cortés <i.bitcero@gmail.com>
  7. // Email: i.bitcero@gmail.com
  8. // License: GPL 2.0
  9. // --------------------------------------------------------------
  10. /**
  11. * @desc Clase para el manejo de campos de formulario de tipo usuarios
  12. */
  13. class RMFormUser extends RMFormElement
  14. {
  15. private $selected = array();
  16. private $limit = 100;
  17. private $multi = false;
  18. private $width = 600;
  19. private $height = 500;
  20. private $showall = 0;
  21. private $can_change = true; // Show search users button?
  22. // Eventos
  23. private $_onchange = '';
  24. /**
  25. * @param string Texto del campo
  26. * @param string Nombre del Campo
  27. * @param bool Seleccion múltiple
  28. * @param array Valores seleccionados por defecto
  29. * @param int Limite de resultados por página de usuarios
  30. * @param int Ancho de la ventana
  31. * @param int Alto de la ventana
  32. */
  33. public function __construct($caption, $name, $multi = false, $select=array(), $limit=36, $width=600,$height=300, $showall = 0, $enable=true){
  34. $this->selected = is_array($select) ? $select : array($select);
  35. $this->limit = $limit;
  36. $this->multi = $multi;
  37. $this->setCaption($caption);
  38. $this->setName($name);
  39. $this->width = $width<=0 ? 600 : $width;
  40. $this->height = $height<=0 ? 500 : $height;
  41. $this->showall = $showall;
  42. $this->can_change = $enable;
  43. !defined('RM_FRAME_USERS_CREATED') ? define('RM_FRAME_USERS_CREATED', 1) : '';
  44. }
  45. public function button($enable){
  46. $this->can_change = $enable;
  47. }
  48. /**
  49. * @desc Crea un manejador para el evento onchange
  50. */
  51. public function onChange($action){
  52. $this->_onchange = base64_encode(addslashes($action));
  53. }
  54. /**
  55. * Show the Users field
  56. * This field needs that form.css, jquery.css and forms.js would be included.
  57. */
  58. public function render(){
  59. RMTemplate::get()->add_script(RMCURL.'/include/js/forms.js');
  60. RMTemplate::get()->add_script(RMCURL.'/include/js/jquery.validate.min.js');
  61. RMTemplate::get()->add_style('forms.css','rmcommon');
  62. if (function_exists("xoops_cp_header")){
  63. RMTemplate::get()->add_style('jquery.css','rmcommon');
  64. } else {
  65. RMTemplate::get()->add_xoops_style('jquery.css','rmcommon');
  66. }
  67. $rtn = "<div id='".$this->getName()."-users-container'".($this->getExtra()!='' ? " ".$this->getExtra() : '')." class='form_users_container'>
  68. <ul id='".$this->getName()."-users-list'>";
  69. $db = XoopsDatabaseFactory::getDatabaseConnection();
  70. if ($this->showall && in_array(0, $this->selected)){
  71. $rtn .= "<li id='".$this->getName()."-exmuser-0'>\n
  72. <label><input type='".($this->multi ? 'checkbox' : 'radio')."' name='".($this->multi ? $this->getName().'[]' : $this->getName())."' id='".$this->getName()."-0'
  73. value='0' checked='checked' /> ".__('All Users','rmcommon')."
  74. <a href='javascript:;' onclick=\"users_field_name='".$this->getName()."'; usersField.remove(0);\"><span>delete</span></a>
  75. </label></li>";
  76. }
  77. if (is_array($this->selected) && !empty($this->selected) && !(count($this->selected)==1 && $this->selected[0]==0)){
  78. $sql = "SELECT uid,uname FROM ".$db->prefix("users")." WHERE ";
  79. $sql1 = '';
  80. if ($this->multi){
  81. foreach ($this->selected as $id){
  82. if ($id!=0) $sql1 .= $sql1 == '' ? "uid='$id'" : " OR uid='$id'";
  83. }
  84. } else {
  85. if ($this->selected[0]!=0) $sql1 = "uid='".$this->selected[0]."'";
  86. }
  87. $result = $db->query($sql.$sql1);
  88. $selected = '';
  89. while ($row = $db->fetchArray($result)){
  90. $rtn .= "<li id='".$this->getName()."-exmuser-$row[uid]'>\n
  91. <label style='overflow: hidden;'>
  92. <input type='".($this->multi ? 'checkbox' : 'radio')."' name='".($this->multi ? $this->getName().'[]' : $this->getName())."' id='".$this->getName()."-".$row['uid']."'
  93. value='$row[uid]' checked='checked' />
  94. $row[uname]";
  95. $rtn .= $this->can_change ? " <a href='javascript:;' onclick=\"users_field_name='".$this->getName()."'; usersField.remove($row[uid]);\"><span>delete</span></a>" : '';
  96. $rtn .= "</label></li>";
  97. }
  98. }
  99. $rtn .= "</ul></div><br />";
  100. if ($this->can_change){
  101. $rtn .= "<input type='button' value='".__('Search Users','rmcommon')."' onclick=\"usersField.form_search_users('".$this->getName()."',".$this->width.",".$this->height.",".$this->limit.",".intval($this->multi).",'".XOOPS_URL."');\" />
  102. <div id='".$this->getName()."-dialog-search' title='".__('Search Users','rmcommon')."' style='display: none;'>
  103. </div>";
  104. }
  105. return $rtn;
  106. }
  107. }
  108. class RMFormFormUserSelect extends RMFormElement
  109. {
  110. private $selected = array();
  111. private $limit = 100;
  112. private $width = 600;
  113. private $height = 300;
  114. private $showall = 0;
  115. // Eventos
  116. private $_onchange = '';
  117. /**
  118. * @param string Texto del campo
  119. * @param string Nombre del Campo
  120. * @param bool Seleccion múltiple
  121. * @param array Valores seleccionados por defecto
  122. * @param int Limite de resultados por página de usuarios
  123. * @param int Ancho de la ventana
  124. * @param int Alto de la ventana
  125. */
  126. public function __construct($caption, $name, $select=array(), $limit=36, $width=600,$height=300, $showall = 0){
  127. $this->selected = $select;
  128. $this->limit = $limit;
  129. $this->setCaption($caption);
  130. $this->setName($name);
  131. $this->width = $width<=0 ? 600 : $width;
  132. $this->height = $height<=0 ? 300 : $height;
  133. $this->showall = $showall;
  134. !defined('RM_FRAME_USERS_CREATED') ? define('RM_FRAME_USERS_CREATED', 1) : '';
  135. }
  136. public function render(){
  137. }
  138. }