XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
formuser.class.php
Go to the documentation of this file.
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 
15 {
16  private $selected = array();
17  private $limit = 100;
18  private $multi = false;
19  private $width = 600;
20  private $height = 500;
21  private $showall = 0;
22  private $can_change = true; // Show search users button?
23 
24  // Eventos
25  private $_onchange = '';
26 
36  public function __construct($caption, $name, $multi = false, $select=array(), $limit=36, $width=600,$height=300, $showall = 0, $enable=true){
37  $this->selected = is_array($select) ? $select : array($select);
38  $this->limit = $limit;
39  $this->multi = $multi;
40  $this->setCaption($caption);
41  $this->setName($name);
42  $this->width = $width<=0 ? 600 : $width;
43  $this->height = $height<=0 ? 500 : $height;
44  $this->showall = $showall;
45  $this->can_change = $enable;
46 
47  !defined('RM_FRAME_USERS_CREATED') ? define('RM_FRAME_USERS_CREATED', 1) : '';
48  }
49 
50  public function button($enable){
51  $this->can_change = $enable;
52  }
53 
57  public function onChange($action){
58  $this->_onchange = base64_encode(addslashes($action));
59  }
60 
65  public function render(){
66 
67  RMTemplate::get()->add_script(RMCURL.'/include/js/forms.js');
68  RMTemplate::get()->add_script(RMCURL.'/include/js/jquery.validate.min.js');
69  RMTemplate::get()->add_style('forms.css','rmcommon');
70 
71  if (function_exists("xoops_cp_header")){
72  RMTemplate::get()->add_style('jquery.css','rmcommon');
73  } else {
74  RMTemplate::get()->add_xoops_style('jquery.css','rmcommon');
75  }
76 
77  $rtn = "<div id='".$this->id()."-users-container'".($this->getExtra()!='' ? " ".$this->getExtra() : '')." class='form_users_container'>
78  <ul id='".$this->id()."-users-list'>";
79  $db = XoopsDatabaseFactory::getDatabaseConnection();
80 
81  if ($this->showall && in_array(0, $this->selected)){
82  $rtn .= "<li id='".$this->id()."-exmuser-0'>\n
83  <label><input type='".($this->multi ? 'checkbox' : 'radio')."' name='".($this->multi ? $this->getName().'[]' : $this->getName())."' id='".$this->id()."-0'
84  value='0' checked='checked' /> ".__('All Users','rmcommon')."
85  <a href='javascript:;' onclick=\"users_field_name='".$this->id()."'; usersField.remove(0);\"><span>delete</span></a>
86  </label></li>";
87  }
88 
89  if (is_array($this->selected) && !empty($this->selected) && !(count($this->selected)==1 && $this->selected[0]==0)){
90  $sql = "SELECT uid,uname FROM ".$db->prefix("users")." WHERE ";
91  $sql1 = '';
92  if ($this->multi){
93  foreach ($this->selected as $id){
94  if ($id!=0) $sql1 .= $sql1 == '' ? "uid='$id'" : " OR uid='$id'";
95  }
96  } else {
97  if ($this->selected[0]!=0) $sql1 = "uid='".$this->selected[0]."'";
98  }
99  $result = $db->query($sql.$sql1);
100  $selected = '';
101  while ($row = $db->fetchArray($result)){
102  $rtn .= "<li id='".$this->id()."-exmuser-$row[uid]'>\n
103  <label style='overflow: hidden;'>
104  <input type='".($this->multi ? 'checkbox' : 'radio')."' name='".($this->multi ? $this->getName().'[]' : $this->getName())."' id='".$this->id()."-".$row['uid']."'
105  value='$row[uid]' checked='checked' />
106  $row[uname]";
107  $rtn .= $this->can_change ? " <a href='javascript:;' onclick=\"users_field_name='".$this->id()."'; usersField.remove($row[uid]);\"><span>delete</span></a>" : '';
108  $rtn .= "</label></li>";
109  }
110  }
111 
112  $rtn .= "</ul></div><br />";
113  if ($this->can_change){
114  $rtn .= "<input type='button' value='".__('Search Users','rmcommon')."' onclick=\"usersField.form_search_users('".$this->id()."',".$this->width.",".$this->height.",".$this->limit.",".intval($this->multi).",'".XOOPS_URL."');\" />
115  <div id='".$this->id()."-dialog-search' title='".__('Search Users','rmcommon')."' style='display: none;'>
116 
117  </div>";
118  }
119 
120  return $rtn;
121  }
122 }
123 
125 {
126  private $selected = array();
127  private $limit = 100;
128  private $width = 600;
129  private $height = 300;
130  private $showall = 0;
131 
132  // Eventos
133  private $_onchange = '';
134 
144  public function __construct($caption, $name, $select=array(), $limit=36, $width=600,$height=300, $showall = 0){
145  $this->selected = $select;
146  $this->limit = $limit;
147  $this->setCaption($caption);
148  $this->setName($name);
149  $this->width = $width<=0 ? 600 : $width;
150  $this->height = $height<=0 ? 300 : $height;
151  $this->showall = $showall;
152  !defined('RM_FRAME_USERS_CREATED') ? define('RM_FRAME_USERS_CREATED', 1) : '';
153  }
154 
155  public function render(){
156 
157  }
158 }