57 $this->_controller = $instance;
58 $this->_tbl_data = self::$_tbl_service;
59 parent::__construct($id);
61 $this->_extension_media = array(
'jpg',
'jpeg',
'png');
62 $this->_prefix_img =
'img_';
63 $this->_prefix_thumb =
'thumb_';
64 $this->_data_www = CONTENT_WWW.
'/gmaps/'.$this->_controller->instanceName().
'/service';
65 $this->_data_dir = CONTENT_DIR.OS.
'gmaps'.OS.$this->_controller->instanceName().OS.
'service';
67 $this->_model_label = $this->
id ? $this->name :
'';
79 if($this->_p[
'instance']!=$value && !in_array(
'instance', $this->_chgP)) $this->_chgP[] =
'instance';
80 $this->_p[
'instance'] = $value;
96 $query =
"DELETE FROM ".self::$_tbl_service.
" WHERE instance='$instance'";
97 $res = $db->actionquery($query);
115 public static function get($instance, $opts=null) {
117 $where =
"instance='".$instance.
"'".(isset($opts[
'where']) ?
" AND ".$opts[
'where'] :
'');
118 $order = isset($opts[
'order']) ? $opts[
'order'] :
'name';
119 $limit = isset($opts[
'limit']) ?
"LIMIT ".$opts[
'limit'] :
'';
123 $db = db::instance();
124 $query =
"SELECT id FROM ".self::$_tbl_service.
" WHERE $where ORDER BY $order $limit";
125 $a = $db->selectquery($query);
147 $where =
"instance='".$instance.
"'".(isset($opts[
'where']) ?
" AND ".$opts[
'where'] :
'');
148 $order = isset($opts[
'order']) ? $opts[
'order'] :
'name';
152 $db = db::instance();
153 $query =
"SELECT id, name FROM ".self::$_tbl_service.
" WHERE $where ORDER BY $order";
154 $a = $db->selectquery($query);
156 $res[$b[
'id']] = htmlChars($b[
'name']);
170 public function form($redirect) {
172 if(isset($_POST[
'submit'])) {
173 $gform =
new Form(
'form_service',
'post',
false, array(
'verifyToken'=>
true));
174 $gform->save(
'dataform');
175 $req_error = $gform->arequired();
177 $this->name = cleanVar($_POST,
'name',
'string',
'');
178 $this->description = cleanVar($_POST,
'description',
'');
179 $this->updateDbData();
181 $old_icon = cleanVar($_POST,
'old_icon',
'string',
'');
183 $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));
185 header(
"Location: ".$redirect);
189 error::errorMessage(array(
'error'=>1), $_SERVER[
'QUERY_STRING']);
195 $title = _(
"Modifica servizio");
196 $submit = _(
"modifica");
199 $title = _(
"Nuovo servizio");
200 $submit= _(
"inserisci");
202 $htmlsection =
new htmlSection(array(
'class'=>
'admin',
'headerTag'=>
'header',
'headerLabel'=>$title));
204 $gform =
new Form(
'form_service',
'post',
true, array(
'trnsl_table'=>$this->_tbl_data,
'trnsl_id'=>$this->
id));
205 $gform->load(
'dataform');
206 $buffer = $gform->form(
'',
true,
'name', array(
'generateToken'=>
true));
207 $buffer .= $gform->hidden(
'id', $this->
id);
209 $buffer .= $gform->cinput(
'name',
'text', $gform->retvar(
'name', htmlInput($this->name)), _(
"Nome"), array(
'required'=>
true,
'maxlength'=>200,
'size'=>40,
'trnsl'=>
true,
'field'=>
'name'));
210 $buffer .= $gform->ctextarea(
'description', $gform->retvar(
'description', htmlInput($this->description)), _(
"Descrizione"), array(
'cols'=>40,
'rows'=>4,
'trnsl'=>
true,
'field'=>
'description'));
212 $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));
213 $buffer .= $gform->cinput(
'submit',
'submit', $submit,
'', array(
'classField'=>
'submit'));
215 $buffer .= $gform->cform();
217 $htmlsection->content = $buffer;
219 return $htmlsection->render();
229 public function delete() {
238 @unlink($this->_data_dir.OS.$this->_prefix_img.$this->icon);
239 @unlink($this->_data_dir.OS.$this->_prefix_thumb.$this->icon);
242 return $this->deleteDbData();