Gino Gmaps  1.0.1
Modulo di gestione di mappe interattive per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.gmapsCollectionImage.php
Vai alla documentazione di questo file.
1 <?php
32 class gmapsCollectionImage extends propertyObject {
33 
34  private static $_tbl_image = 'gmaps_point_collection_image';
35 
37 
41  private $_img_width = 600;
42 
46  private $_thumb_width = 100;
47 
56  function __construct($id, $instance) {
57 
58  $this->_controller = $instance;
59  $this->_tbl_data = self::$_tbl_image;
60  parent::__construct($id);
61 
62  $this->_extension_media = array('jpg', 'jpeg', 'png');
63  $this->_prefix_img = 'img_';
64  $this->_prefix_thumb = 'thumb_';
65  $this->_data_www = CONTENT_WWW.'/gmaps/'.$this->_controller->instanceName().'/point/collections/images';
66  $this->_data_dir = CONTENT_DIR.OS.'gmaps'.OS.$this->_controller->instanceName().OS.'point'.OS.'collections'.OS.'images';
67  }
68 
76  public function setCollection_id($value) {
77 
78  if($this->_p['collection_id']!=$value && !in_array('collection_id', $this->_chgP)) $this->_chgP[] = 'collection_id';
79  $this->_p['collection_id'] = $value;
80  return true;
81 
82  }
83 
91  public function form($redirect) {
92 
93  if(isset($_POST['submit'])) {
94  $gform = new Form('form_image', 'post', false, array('verifyToken'=>true));
95  $gform->save('dataform');
96  $req_error = $gform->arequired();
97  if(!$req_error) {
98  $this->title = cleanVar($_POST, 'title', 'string', '');
99  $this->description = cleanVar($_POST, 'description', 'string', '');
100  $this->credits = cleanVar($_POST, 'credits', 'string', '');
101 
102  $this->updateDbData();
103 
104  $old_filename = cleanVar($_POST, 'old_filename', 'string', '');
105 
106  $res = $gform->manageFile('filename', $old_filename, true, $this->_extension_media, $this->_data_dir.OS, preg_replace("#action=insert#", 'action=modify&id='.$this->id, $_SERVER['QUERY_STRING']), $this->_tbl_data, 'filename', 'id', $this->id, array('prefix_file'=>$this->_prefix_img, 'prefix_thumb'=>$this->_prefix_thumb, 'width'=>$this->_img_width, 'thumb_width'=>$this->_thumb_width));
107 
108  header("Location: ".$redirect);
109  exit();
110  }
111  else {
112  error::errorMessage(array('error'=>1), $_SERVER['QUERY_STRING']);
113  exit();
114  }
115  }
116 
117  if($this->id) {
118  $title = _("Modifica immagine");
119  $submit = _("modifica");
120  }
121  else {
122  $title = _("Nuova immagine");
123  $submit= _("inserisci");
124  }
125  $htmlsection = new htmlSection(array('class'=>'admin', 'headerTag'=>'header', 'headerLabel'=>$title));
126 
127  $gform = new Form('form_image', 'post', true, array('trnsl_table'=>$this->_tbl_data, 'trnsl_id'=>$this->id));
128  $gform->load('dataform');
129  $buffer = $gform->form('', true, 'title', array('generateToken'=>true));
130  $buffer .= $gform->hidden('image_id', $this->id);
131 
132  $buffer .= $gform->cinput('title', 'text', $gform->retvar('title', htmlInput($this->title)), _("Titolo"), array('required'=>true, 'maxlength'=>200, 'size'=>40, 'trnsl'=>true, 'field'=>'title'));
133  $buffer .= $gform->ctextarea('description', $gform->retvar('description', htmlInput($this->description)), _("Descrizione"), array('cols'=>40, 'rows'=>4, 'trnsl'=>true, 'field'=>'description'));
134  $buffer .= $gform->ctextarea('credits', $gform->retvar('credits', htmlInput($this->credits)), _("Credits"), array('cols'=>40, 'rows'=>2, 'trnsl'=>true, 'field'=>'credits'));
135 
136  $buffer .= $gform->cfile('filename', $this->filename, _("File"), array("required"=>true, "extensions"=>$this->_extension_media, "del_check"=>true, "preview"=>true, "previewSrc"=>$this->_data_www.'/'.$this->_prefix_img.$this->filename));
137  $buffer .= $gform->cinput('submit', 'submit', $submit, '', array('classField'=>'submit'));
138 
139  $buffer .= $gform->cform();
140 
141  $htmlsection->content = $buffer;
142 
143  return $htmlsection->render();
144  }
145 
152  public function thumb($css_class) {
153 
154  return "<img class=\"".$css_class."\" src=\"".$this->_data_www."/".$this->_prefix_thumb.$this->filename."\" alt=\"".preg_replace("#\"#", "'", htmlChars($this->ml('title')))."\" />";
155 
156  }
157 
164  public function img($css_class = '', $title = null, $description=null) {
165 
166  return "<img class=\"".$css_class."\" src=\"".$this->_data_www."/".$this->_prefix_img.$this->filename."\" alt=\"".preg_replace("#\"#", "'", htmlChars($this->ml('title')))."\" />";
167 
168  }
169 
176  public function thumbPath() {
177 
178  return $this->_data_www."/".$this->_prefix_thumb.$this->filename;
179 
180  }
181 
188  public function path() {
189 
190  return $this->_data_www."/".$this->_prefix_img.$this->filename;
191 
192  }
193 
201  public function delete() {
202 
203  @unlink($this->_data_dir.OS.$this->_prefix_img.$this->filename);
204  @unlink($this->_data_dir.OS.$this->_prefix_thumb.$this->filename);
205 
206  return $this->deleteDbData();
207 
208  }
209 
210 
211 }
212 
213 ?>