Gino Gmaps  1.0.1
Modulo di gestione di mappe interattive per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.gmapsCtg.php
Vai alla documentazione di questo file.
1 <?php
30 abstract class gmapsCtg extends propertyObject {
31 
32  protected $_data_www, $_data_dir;
33 
37  protected $_prefix_img = 'img_';
38 
42  protected $_prefix_thumb = 'thumb_';
43 
47  protected $_extension_media = array('jpg', 'jpeg', 'png');
48 
52  protected $_img_width = 200;
53 
57  protected $_thumb_width = 100;
58 
67  function __construct($id, $tbl) {
68 
69  $this->_tbl_data = $tbl;
70  parent::__construct($id);
71 
72  }
73 
81  public function setInstance($value) {
82 
83  if($this->_p['instance']!=$value && !in_array('instance', $this->_chgP)) $this->_chgP[] = 'instance';
84  $this->_p['instance'] = $value;
85  return true;
86 
87  }
88 
97  public static function deleteInstance($instance) {
98 
99  $db = db::instance();
100  $query = "DELETE FROM ".static::$_tbl." WHERE instance='$instance'";
101  $res = $db->actionquery($query);
102 
103  return $res;
104 
105  }
106 
119  public static function get($instance, $opts=null) {
120 
121  $where = "instance='".$instance."'".(isset($opts['where']) ? " AND ".$opts['where'] : '');
122  $order = isset($opts['order']) ? $opts['order'] : 'name';
123  $limit = isset($opts['limit']) ? "LIMIT ".$opts['limit'] : '';
124 
125  $res = array();
126 
127  $db = db::instance();
128  $query = "SELECT id FROM ".static::$_tbl." WHERE $where ORDER BY $order $limit";
129  $a = $db->selectquery($query);
130  foreach($a as $b) {
131  $res[] = $b['id'];
132  }
133 
134  return $res;
135 
136  }
137 
149  public static function getForSelect($instance, $opts=null) {
150 
151  $where = "instance='".$instance."'".(isset($opts['where']) ? " AND ".$opts['where'] : '');
152  $order = isset($opts['order']) ? $opts['order'] : 'name';
153 
154  $res = array();
155 
156  $db = db::instance();
157  $query = "SELECT id, name FROM ".static::$_tbl." WHERE $where ORDER BY $order";
158  $a = $db->selectquery($query);
159  foreach($a as $b) {
160  $res[$b['id']] = htmlChars($b['name']);
161  }
162 
163  return $res;
164 
165  }
166 
174  public function form($redirect) {
175 
176  if(isset($_POST['submit'])) {
177  $gform = new Form('form_ctg', 'post', false, array('verifyToken'=>true));
178  $gform->save('dataform');
179  $req_error = $gform->arequired();
180  if(!$req_error) {
181  $this->name = cleanVar($_POST, 'name', 'string', '');
182  $this->description = cleanVar($_POST, 'description', 'string', '');
183  $this->updateDbData();
184 
185  $old_icon = cleanVar($_POST, 'old_icon', 'string', '');
186 
187  $res = $gform->manageFile('icon', $old_icon, true, $this->_extension_media, $this->_data_dir.OS, preg_replace("#action=insert#", 'action=modify&id='.$this->id, $_SERVER['QUERY_STRING']), $this->_tbl_data, 'icon', 'id', $this->id, array('prefix_file'=>$this->_prefix_img, 'prefix_thumb'=>$this->_prefix_thumb, 'width'=>$this->_img_width, 'thumb_width'=>$this->_thumb_width));
188 
189  header("Location: ".$redirect);
190  exit();
191  }
192  else {
193  error::errorMessage(array('error'=>1), $_SERVER['QUERY_STRING']);
194  exit();
195  }
196  }
197 
198  if($this->id) {
199  $title = _("Modifica categoria");
200  $submit = _("modifica");
201  }
202  else {
203  $title = _("Nuova categoria");
204  $submit= _("inserisci");
205  }
206  $htmlsection = new htmlSection(array('class'=>'admin', 'headerTag'=>'header', 'headerLabel'=>$title));
207 
208  $gform = new Form('form_ctg', 'post', true, array('trnsl_table'=>$this->_tbl_data, 'trnsl_id'=>$this->id));
209  $gform->load('dataform');
210  $buffer = $gform->form('', true, 'name', array('generateToken'=>true));
211  $buffer .= $gform->hidden('id', $this->id);
212 
213  $buffer .= $gform->cinput('name', 'text', $gform->retvar('name', htmlInput($this->name)), _("Nome"), array('required'=>true, 'maxlength'=>200, 'size'=>40, 'trnsl'=>true, 'field'=>'name'));
214  $buffer .= $gform->ctextarea('description', $gform->retvar('description', htmlInput($this->description)), _("Descrizione"), array('cols'=>40, 'rows'=>4, 'trnsl'=>true, 'field'=>'description'));
215  $buffer .= $gform->cfile('icon', $this->icon, _("Icona"), array("extensions"=>$this->_extension_media, "del_check"=>true, "preview"=>true, "previewSrc"=>$this->_data_www.'/'.$this->_prefix_img.$this->icon));
216  $buffer .= $gform->cinput('submit', 'submit', $submit, '', array('classField'=>'submit'));
217 
218  $buffer .= $gform->cform();
219 
220  $htmlsection->content = $buffer;
221 
222  return $htmlsection->render();
223  }
224 
225 }
226 
227 ?>