XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
language.class.php
Go to the documentation of this file.
1 <?php
2 // $Id: language.class.php 825 2011-12-09 00:06:11Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
12 {
13  private $multi = 0;
14  private $type = 0;
15  private $selected = array();
16  private $cols = 2;
17 
28  function __construct($caption, $name, $multi = 0, $type = 0, $selected = null, $cols = 2){
29  $this->setName($name);
30  $this->setCaption($caption);
31  $this->multi = $multi;
32  $this->type = $type;
33  $this->cols = $cols;
34  $this->selected = $selected;
35  }
36  function multi(){
37  return $this->multi;
38  }
39  function setMulti($value){
40  return $this->multi = $value;
41  }
42  function type(){
43  return $this->type;
44  }
45  function setType($value){
46  return $this->type = $value;
47  }
48  function selected(){
49  return $this->selected;
50  }
51  function setSelected($value){
52  return $this->selected = $value;
53  }
54 
55  function render(){
56  $files = XoopsLists::getFileListAsArray(XOOPS_ROOT_PATH.'/modules/rmcommon/lang', '');
57  $langs = array();
58  $langs['en_US'] = 'en';
59  foreach($files as $file => $v){
60 
61  if(substr($file, -3)!='.mo') continue;
62 
63  $langs[substr($file, 0, -3)] = substr($file, 0, -3);
64 
65  }
66  if ($this->type){
67  $rtn = '<ul class="rmoptions_container">';
68  $i = 1;
69  foreach ($langs as $k){
70  if ($this->multi){
71  $rtn .= "<li><label><input type='checkbox' value='$k' name='".$this->getName()."[]' id='".$this->id()."[]'".(is_array($this->selected) ? (in_array($k, $this->selected) ? " checked='checked'" : '') : '')." /> $k</label></li>";
72  } else {
73  $rtn .= "<li><label><input type='radio' value='$k' name='".$this->getName()."' id='".$this->id()."'".(!empty($this->selected) ? ($k == $this->selected ? " checked='checked'" : '') : '')." /> $k</label></li>";
74  }
75  $i++;
76  }
77  $rtn .= "</ul>";
78  } else {
79  if ($this->multi){
80  $rtn = "<select name='".$this->getName()."[]' id='".$this->id()."[]' size='$this->cols' multiple='multiple'>";
81  foreach ($langs as $k){
82  $rtn .= "<option value='$k'".(is_array($this->selected) ? (in_array($k, $this->selected) ? " selected='selected'" : '') : '').">$k</option>";
83  }
84  $rtn .= "</select>";
85  } else {
86  $rtn = "<select name='".$this->getName()."' id='".$this->id()."'>";
87  foreach ($langs as $k){
88  $rtn .= "<option value='$k'".(!empty($this->selected) ? ($k==$this->selected ? " selected='selected'" : '') : '').">$k</option>";
89  }
90  $rtn .= "</select>";
91  }
92  }
93 
94  return $rtn;
95 
96  }
97 }