Gino Gmaps  1.0.1
Modulo di gestione di mappe interattive per Gino CMS
 Tutto Strutture dati File Funzioni Variabili Gruppi Pagine
class.gmapsAttachment.php
Vai alla documentazione di questo file.
1 <?php
33 class gmapsAttachment extends propertyObject {
34 
35  private static $_tbl_event = 'gmaps_point_attachment';
36 
38 
47  function __construct($id, $instance) {
48 
49  $this->_controller = $instance;
50  $this->_tbl_data = self::$_tbl_event;
51  parent::__construct($id);
52 
53  $this->_extension_attachment = array('doc', 'docx', 'pdf', 'ppt', 'pptx', 'xlsx', 'xls', 'odt', 'ods', 'odp', 'zip');
54  $this->_data_www = CONTENT_WWW.'/gmaps/'.$this->_controller->instanceName().'/point/attachments';
55  $this->_data_dir = CONTENT_DIR.OS.'gmaps'.OS.$this->_controller->instanceName().OS.'point'.OS.'attachments';
56  }
57 
65  public function setPoint_id($value) {
66 
67  if($this->_p['point_id']!=$value && !in_array('point_id', $this->_chgP)) $this->_chgP[] = 'point_id';
68  $this->_p['point_id'] = $value;
69  return true;
70 
71  }
72 
80  public function setSize($value) {
81 
82  if($this->_p['size']!=$value && !in_array('size', $this->_chgP)) $this->_chgP[] = 'size';
83  $this->_p['size'] = $value;
84  return true;
85 
86  }
87 
95  public function form($redirect) {
96 
97  if(isset($_POST['submit'])) {
98  $gform = new Form('form_attachment', 'post', false, array('verifyToken'=>true));
99  $gform->save('dataform');
100  $req_error = $gform->arequired();
101  if(!$req_error) {
102  if(!$this->id) {
103  $this->insert_date = date("Y-m-d H:i:s");
104  }
105  $this->name = cleanVar($_POST, 'name', 'string', '');
106  $this->description = cleanVar($_POST, 'description', 'string', '');
107 
108  $this->updateDbData();
109 
110  $old_filename = cleanVar($_POST, 'old_filename', 'string', '');
111 
112  $res = $gform->manageFile('filename', $old_filename, false, $this->_extension_attachment, $this->_data_dir.OS, preg_replace("#action=insert#", 'action=modify&id='.$this->id, $_SERVER['QUERY_STRING']), $this->_tbl_data, 'filename', 'id', $this->id, array('check_type'=>false));
113 
114  $this->size = $_FILES['filename']['size'];
115  $this->updateDbData();
116 
117  header("Location: ".$redirect);
118  exit();
119  }
120  else {
121  error::errorMessage(array('error'=>1), $_SERVER['QUERY_STRING']);
122  exit();
123  }
124  }
125 
126  if($this->id) {
127  $title = _("Modifica allegato");
128  $submit = _("modifica");
129  }
130  else {
131  $title = _("Nuovo allegato");
132  $submit= _("inserisci");
133  }
134  $htmlsection = new htmlSection(array('class'=>'admin', 'headerTag'=>'header', 'headerLabel'=>$title));
135 
136  $gform = new Form('form_attachment', 'post', true, array('trnsl_table'=>$this->_tbl_data, 'trnsl_id'=>$this->id));
137  $gform->load('dataform');
138  $buffer = $gform->form('', true, 'name', array('generateToken'=>true));
139  $buffer .= $gform->hidden('id', $this->id);
140 
141  $buffer .= $gform->cinput('name', 'text', $gform->retvar('name', htmlInput($this->name)), _("Nome"), array('required'=>true, 'maxlength'=>200, 'size'=>40, 'trnsl'=>true, 'field'=>'name'));
142  $buffer .= $gform->ctextarea('description', $gform->retvar('description', htmlInput($this->description)), _("Descrizione"), array('cols'=>40, 'rows'=>4, 'trnsl'=>true, 'field'=>'description'));
143  $buffer .= $gform->cfile('filename', $this->filename, _("File"), array("required"=>true, "extensions"=>$this->_extension_attachment, "del_check"=>true, "preview"=>false));
144 
145  $buffer .= $gform->cinput('submit', 'submit', $submit, '', array('classField'=>'submit'));
146 
147  $buffer .= $gform->cform();
148 
149  $htmlsection->content = $buffer;
150 
151  return $htmlsection->render();
152  }
153 
161  public function delete() {
162 
163  @unlink($this->_data_dir.OS.$this->filename);
164 
165  return $this->deleteDbData();
166 
167  }
168 
175  public function filePath() {
176 
177  return $this->_data_www."/".$this->filename;
178 
179  }
180 
181 }
182 
183 ?>