XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
modules.class.php
Go to the documentation of this file.
1 <?php
2 // $Id: modules.class.php 1064 2012-09-17 16:46:12Z 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 
11 
13 {
14  private $multi = 0;
15  private $type = 0;
16  private $selected = null;
17  private $cols = 2;
18  private $inserted = array();
19  private $dirnames = true;
20  private $subpages = 0;
21  private $selectedSubPages = array();
22 
36  function __construct($caption, $name, $multi = 0, $type = 0, $selected = null, $cols = 2, $insert = null, $dirnames = true, $subpages = 0){
37  $this->setName($multi ? str_replace('[]', '', $name) : $name);
38  $this->setCaption($caption);
39  $this->multi = $multi;
40  $this->type = $type;
41  $this->cols = $cols;
42  $this->selected = isset($_REQUEST[$name]) ? $_REQUEST[$name] : $selected;
43  $this->inserted = $insert;
44  $this->dirnames = $dirnames;
45  $this->subpages = $subpages;
46  !defined('RM_FRAME_APPS_CREATED') ? define('RM_FRAME_APPS_CREATED', 1) : '';
47  }
48  public function multi(){
49  return $this->multi;
50  }
51  public function setMulti($value){
52  if ($value==0 || $value==1){
53  //$this->setName($value ? str_replace('[]','',$this->getName()).'[]' : str_replace('[]','',$this->getName()));
54  $this->multi = $value;
55  }
56  }
57  public function type(){
58  return $this->type;
59  }
60  public function setType($value){
61  return $this->type = $value;
62  }
63  public function selected(){
64  return $this->selected;
65  }
66  public function setSelected($value){
67  return $this->selected = $value;
68  }
69  public function sizeOrCols(){
70  return $this->cols;
71  }
72  public function setSizeOrCols($value){
73  return $this->cols = $value;
74  }
75  public function inserted(){
76  return $this->inserted;
77  }
82  public function setInserted($value){
83  $this->inserted = array();
84  $this->inserted = $value;
85  }
86 
87  public function dirnames(){
88  return $this->dirnames;
89  }
96  public function setDirNames($value = true){
97  $this->dirnames = $value;
98  }
103  public function subpages($subs){
104  $this->selectedSubPages = $subs;
105  }
106 
107  function render(){
108  $module_handler =& xoops_gethandler('module');
109  $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
110  $criteria->add(new Criteria('isactive', 1));
111  if($this->subpages) $criteria->add(new Criteria('dirname', 'system'), 'OR');
112  $modules = array();
113  $modules[0] = __('All','rmcommon');
114  if (is_array($this->inserted)) $modules = $this->inserted;
115  foreach ($module_handler->getList($criteria, $this->dirnames) as $k => $v){
116  $modules[$k] = $v;
117  }
118 
119  if ($this->type){
120  // Add js script
121  RMTemplate::get()->add_local_script('modules_field.js', 'rmcommon', 'include');
122 
123  $rtn = '<div class="modules_field">';
124 
125  $i = 1;
126  foreach ($modules as $k => $v){
127  $app = RMFunctions::load_module($k);
128  $rtn .= "<div class=\"mod_item\">";
129  $name = $this->multi ? $this->getName()."[$k]" : $this->getName();
130  if ($this->multi){
131  $rtn .= "<label id=\"modlabel-$k\" class='field_module_names'><input type='checkbox' value='$k' name='".$name."' id='".$this->id()."-$k'".(is_array($this->selected) ? (in_array($k, $this->selected) ? " checked='checked'" : '') : '')." /> $v</label>";
132  } else {
133  $rtn .= "<label id=\"modlabel-$k\" class=\"field_module_names\"><input type='radio' value='$k' name='".$this->getName()."' id='".$this->id()."-$k'".(!empty($this->selected) ? ($k == $this->selected ? " checked='checked'" : '') : '')." /> $v</label>";
134  }
135 
139  if ($this->subpages && $k>0){
140  if($app->dirname()=='system'){
141  $subpages = array(
142  'home-page' => __('Home Page','rmcommon'),
143  'user' => __('User page','dtransport'),
144  'profile' => __('User profile page','rmcommon'),
145  'register' => __('Users registration','rmcommon'),
146  'edit-user' => __('Edit user','rmcommon'),
147  'readpm' => __('Read PM','rmcommon'),
148  'pm' => __('Private messages','rmcomon')
149  );
150  } else {
151  $subpages = $app->getInfo('subpages');
152  }
153  if(!empty($subpages)){
155  $cr = 0;
156  $rtn.="<div id=\"subpages-".$k."\" class=\"subpages_container\">
157  <div class='sp_title'><span id=\"close-$k\"></span>".__('Inner pages','rmcommon')."</div>";
158  $j = 2;
159  $cr = 2;
160  if (!is_array($subpages)) $subpages = array();
161 
162  foreach ($subpages as $page=>$caption){
163  $rtn.="<div class=\"sub_item\"><label><input type='checkbox' name='".$name."[subpages][$page]' id='subpages[$k][$page]' value='$page'".(is_array($subpages) && @in_array($page, $selected[$k]) ? " checked='checked'" : '')." onclick=\"checkSubpageClick('subpages[$k][$page]', $k);\" /> $caption</label></div>";
164  $j++;
165  $cr++;
166  }
167  $rtn.='</div>';
168  }
169 
170  }
171 
172  $rtn .= "</div>";
173  $i++;
174  }
175 
176  $rtn .= "</div>";
177  } else {
178  if ($this->multi){
179  $name = $this->getName()."[$k]";
180  $rtn = "<select name='".$name."' id='".$this->id()."' size='$this->cols' multiple='multiple'>";
181  foreach ($modules as $k => $v){
182  $rtn .= "<option value='$k'".(is_array($this->selected) ? (in_array($k, $this->selected) ? " selected='selected'" : '') : '').">$v</option>";
183  }
184  $rtn .= "</select>";
185  } else {
186  $rtn = "<select name='".$this->getName()."' id='".$this->getName()."'>";
187  foreach ($modules as $k => $v){
188  $rtn .= "<option value='$k'".(!empty($this->selected) ? ($k==$this->selected ? " selected='selected'" : '') : '').">$v</option>";
189  }
190  $rtn .= "</select>";
191  }
192  }
193 
194  return $rtn;
195 
196  }
197 }