private function buildComboBox($sql) { $sql = $this->replacePlaceholder($sql); $combo = new ComboBox($this->id); $combo->setDboHandler($this->db); $combo->setModel($this->getModel()); $this->add($combo)->att('label', $this->label)->par('datasource-sql', $sql); //Setto la risorsa per popolare la combo e la connessione al DB necessaria ad effettuare le query. }
public function ajaxResponse($controller, &$response) { if (!empty($_REQUEST['ajax-param'])) { $param = unserialize(base64_decode($_REQUEST['ajax-param'])); $_REQUEST[$this->id . '_set'] = $param['p_value']; $sql = $param['component_datasource']; } switch ($param['component_type']) { case 'CMB': $sql = $this->replacePlaceholder($sql); $cmp = new ComboBox($this->id . '_set'); $cmp->att('label', $this->label)->par('datasource-sql', $sql)->setDboHandler($this->db); break; case 'TAR': $cmp = new TextArea($this->id . '_set'); $cmp->att('style', 'width: 95%;')->att('rows', '20'); break; default: $cmp = new TextBox($this->id . '_set'); $cmp->att('style', 'width: 95%'); break; } $response->message('result', '<div class="osy-grip-property-popup">' . $cmp . ' <span class="fa fa-save"></span> <span class="fa fa-save"></span></div>'); }
protected function build() { $sql = $this->get_par('datasource-sql'); if (empty($sql)) { die('[ERROR] - Multibox ' . $this->id . ' - query builder assente'); } $sql = $this->replacePlaceholder($sql); $res = $this->db->exec_query($sql, null, 'ASSOC'); //die($sql); if (empty($res)) { return; } $mlt_tbl = $this->add(tag::create('table')); $val_from_db = array_key_exists($this->id, $_REQUEST) && is_array($_REQUEST[$this->id]) ? false : true; foreach ($res as $k => $cmp_raw) { if ($val_from_db) { $_REQUEST[$this->id][$cmp_raw['id']] = $cmp_raw['val']; } $mlt_row = $mlt_tbl->add(tag::create('tr')); $cmp = $lbl = null; if (strlen($this->readonly) > 4) { $this->readonly = HelperOsy::exec_string(null, 'return ' . $this->readonly . ';'); } if ($this->readonly) { $cmp = tag::create('span'); if ($cmp_raw['typ'] == 'CMB') { $cmp_raw['val'] = label::getFromDatasource($cmp_raw['val'], $cmp_raw['sql_qry'], $this->db); } $cmp->add($cmp_raw['val']); } else { $is_req = $cmp_raw['is_req']; $cmp_nam = "{$this->id}[{$cmp_raw['id']}]"; switch ($cmp_raw['typ']) { case 'DAT': $cmp = new DateBox($cmp_nam); $cmp->par('date-format', 'dd/mm/yyyy'); break; case 'TXT': case 'NUM': $cmp = new TextBox($cmp_nam); if ($cmp_raw['typ'] == 'NUM') { $cmp->att('class', 'numeric', true); } else { $cmp->att('class', 'text', true); } break; case 'CMB': $cmp = new ComboBox($cmp_nam); //echo $cmp_raw['sql_qry']; $cmp->par('datasource-sql', HelperOsy::replaceVariable($cmp_raw['sql_qry'])); break; } $cmp->att('label', $cmp_raw['nam']); if (!empty($is_req)) { $lbl = '(*) '; $cmp->att('class', 'is-request', true); } } if (!is_null($cmp)) { $lbl = "<label class=\"multibox\">{$lbl}{$cmp_raw['nam']}</label>"; $mlt_row->add(new Tag('td'))->add($lbl); $mlt_row->add(new Tag('td'))->add($cmp); } } }