XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
avatar.class.php
Go to the documentation of this file.
1 <?php
2 // $Id: avatar.class.php 825 2011-12-09 00:06:11Z i.bitcero $
3 // --------------------------------------------------------------
4 // RMSOFT Common Utilities
5 // Utilidades comunes para módulos de Red México
6 // CopyRight © 2005 - 2006. Red México
7 // Autor: BitC3R0
8 // http://www.redmexico.com.mx
9 // http://www.exmsystem.net
10 // --------------------------------------------
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public
22 // License along with this program; if not, write to the Free
23 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 // MA 02111-1307 USA
25 // --------------------------------------------------------------
26 // @copyright: 2007 - 2008. Red México
27 // @author: BitC3R0
28 
33 {
34  private $_multi = 0;
35  private $_size = 5;
36  private $_select = array();
37  private $_showtype = 0;
38  private $_showdesc = 0;
39  private $_cols = 2;
44  private $_onlyuser = 0;
51  function __construct($caption, $name, $multi=0, $type=0, $cols=2, $select=array(), $user=0){
52  $this->setCaption($caption);
53  $this->setName($name);
54  if (isset($_REQUEST[$name])) $this->_select = $_REQUEST[$name];
55  $this->_multi = $multi;
56  $this->_showtype = $type;
57  $this->_cols = $cols;
58  $this->_onlyuser = $user;
59 
60  if (isset($_REQUEST[$this->getName()])){
61  $this->_select = $_REQUEST[$this->getName()];
62  } else {
63  $this->_select = $select;
64  }
65  }
72  public function setMulti($value){
73  if ($value==0 || $value==1){
74  $this->_multi = $value;
75  }
76  }
80  public function getMulti(){
81  return $this->_multi;
82  }
91  public function setSelect($value){
92  if (is_array($value)){
93  $this->_select = $value;
94  } else {
95  $this->_select = explode(',',$value);
96  }
97  }
103  public function getSelect(){
104  return $this->_select;
105  }
111  public function setShowType($value){
112  if ($value==0 || $value==1) $this->_showtype = $value;
113  }
118  public function getShowType(){
119  return $this->_showtype;
120  }
127  public function setCols($value){
128  if ($value>0) $this->_cols = $value;
129  }
134  public function getCols(){
135  return $this->_cols;
136  }
141  public function render(){
142  $db = EXMDatabase::get();
143  $sql = "SELECT * FROM ".$db->prefix("avatar");
144  if ($this->_onlyuser){
145  global $exmUser;
146  if ($exmUser){
147  $useravatar = $exmUser->getVar('user_avatar');
148  $sql .= " WHERE avatar_display='1' AND (avatar_type='0' OR (avatar_type='1' AND avatar_file='$useravatar'))";
149  unset($useravatar);
150  }
151  }
152  $sql .= " ORDER BY avatar_name";
153  $result = $db->query($sql);
154  $rtn = '';
155  $col = 1;
156 
157  $typeinput = $this->_multi ? 'checkbox' : 'radio';
158  $name = $this->_multi ? $this->getName().'[]' : $this->getName();
159 
160  if ($this->_showtype){
161  $rtn = "<div style='height: 200px; overflow: auto;'><table cellspacing='2' cellpadding='3' border='0'>";
162  $rtn .= "<tr>";
163  $rtn .= "<td align='left'><label><input type='$typeinput' name='$name' id='$name' value=''";
164  if (empty($this->_select)) $rtn .= " checked='checked'";
165  $rtn .= ">"._RMS_CF_NOAVATAR."</label></td>";
166  $col++;
167  while ($row = $db->fetchArray($result)){
168 
169  if ($col>$this->_cols){
170  $rtn .= "</tr><tr>";
171  $col = 1;
172  }
173 
174  $rtn .= "<td align='left'><label><img src='".ABSURL."/uploads/avatars/$row[avatar_file]' align='absmiddle' /> <input type='$typeinput' name='$name' id='$name' value='$row[avatar_file]'";
175  if (is_array($this->_select)){
176  if (in_array($row['avatar_file'], $this->_select)){
177  $rtn .= " checked='checked'";
178  }
179  }
180  $rtn .= ">$row[avatar_name]</label>";
181 
182  $rtn .= "</td>";
183 
184  $col++;
185 
186  }
187  $rtn .= "</tr>";
188  $rtn .= "</table></div>";
189  } else {
190  $rtn = "<script type='text/javascript'>
191  function showImageAvatar(){
192  sel = $('$name');
193  var img = sel.options[sel.selectedIndex].value;
194  div = $('avatarimg');
195  div.innerHTML = \"<img src='".ABSURL."/uploads/avatars/\"+img+\"' />\";
196  }
197 
198 
199  </script>";
200  $rtn .= "<div id='avatarimg' style='float: right;'>";
201  if (count($this->_select)>0){
202  $rtn .= "<img src='".ABSURL."/uploads/avatars/".$this->_select[0]."' border='0' alt='' />";
203  }
204  $rtn .= "</div>
205  <select name='$name' id='".$this->id()."' onchange='showImageAvatar();'";
206  $rtn .= $this->_multi ? " multiple='multiple' size='5'" : "";
207  $rtn .= "><option value='0'";
208  if (is_array($this->_select)){
209  if (in_array(0, $this->_select)){
210  $rtn .= " selected='selected'";
211  }
212  } else {
213  $rtn .= " selected='selected'";
214  }
215 
216  $rtn .= ">"._RMS_CF_ALL."</option>";
217 
218  while ($row = $db->fetchArray($result)){
219  $rtn .= "<option value='$row[avatar_file]'";
220  if (is_array($this->_select)){
221  if (in_array($row['avatar_file'], $this->_select)){
222  $rtn .= " selected='selected'";
223  }
224  }
225  $rtn .= ">".$row['avatar_name']."</option>";
226  }
227 
228  $rtn .= "</select>";
229  }
230 
231  return $rtn;
232  }
233 }
234 
235 ?>