function install_sql() { global $base_name; /* Verificar se existe tabela */ $sql = "SELECT table_name FROM information_schema.tables \n\t\t\t\t\t\tWHERE table_name = 'apoio_titulacao'\n\t\t\t\t\t\t\t\tand table_schema = '{$base_name}' "; $rlt = db_query($sql); /* Consulta */ if ($line = db_read($rlt)) { /* Tabelas já instaladas */ echo 'Database already exist.'; } else { $file_sql = "../proethos.sql"; /* Le arquivo com estrutura do banco */ $flt = fopen($file_sql, "r"); $sql = ""; while (!feof($flt)) { $sql .= fread($flt, 1024); } fclose($flt); $ln = splitx(';', $sql . ';'); /* Executa criacao das tabelas */ for ($r = 0; $r < count($ln); $r++) { echo '<BR>' . substr($ln[$r], 0, strpos('(', $ln[$r])); $sql = trim($ln[$r]); if (strlen($sql) > 10) { $rlt = db_query($sql); } } echo '<BR>Database install!!'; } }
function search_by_word($field, $words) { $wd = UpperCaseSql($words); $wd = troca($wd, ' ', ';') . ';'; $wd = splitx(';', $wd); $wh = ''; for ($r = 0; $r < count($wd); $r++) { /* recupera word do termo */ $term = $wd[$r]; if ($r > 0) { $wh .= ' and '; } $wh .= " ({$field} like '%{$term}%') "; } return $wh; }
/** * Campo de Rich Text * TinyMCE: http://www.tinymce.com * @return string html/js de um campo com controles de texto rico */ function type_R() { $ops = splitx('&', $this->par); for ($r = 0; $r < count($ops); $r++) { $so = $ops[$r]; $check = ''; $vl = substr($so, 0, strpos($so, ':')); if (trim($this->value) == trim($vl)) { $check = 'checked'; } $sx .= '<input type="radio" value="' . $vl . '" ' . $check . ' '; $sx .= ' id="' . $this->name . '" name="' . $this->name . '" '; if (strlen(trim($this->class_select_option)) > 0) { $sx .= ' class="' . $this->class_select_option . '"'; } $sx .= '>'; //$sx .= $ops[$r]; $txt = trim(substr($so, strpos($so, ':') + 1, strlen($so))); if (substr($txt, 0, 1) == '#') { $txt = msg($txt) . ' '; } $sx .= $txt; } return $sx; }
function form_field($cp, $vlr) { global $dd, $ddi; /* Zera tela */ $tela = ''; $table = 1; if (!isset($dd)) { $dd = array(); $ddi = 0; } $type = $cp[0]; $label = $cp[2]; $required = $cp[3]; $placeholder = $label; $readonly = $cp[4]; $tt = substr($type, 1, 1); /* exessoes */ if (substr($type, 0, 4) == '$MES') { $tt = 'MES'; } if (substr($type, 0, 3) == '$SW') { $tt = 'SW'; } if (substr($type, 0, 3) == '$HV') { $tt = 'HV'; } if (substr($type, 0, 5) == '$LINK') { $tt = 'LINK'; } if (substr($type, 0, 3) == '$AA') { $tt = 'AA'; } /* form */ $max = 100; $size = 100; $dados = array(); $dn = 'dd' . $ddi; if ($table == 1) { $td = '<td>'; $tdl = '<td align="right">'; $tdn = '</td>'; $tr = '<tr valign="top">'; $trn = '</tr>'; } else { $td = ''; $tdl = ''; $tdn = ''; $tr = ''; $trn = ''; } //$dados = array('name'=>'dd'.$ddi, 'id'=>'dd'.$ddi,'value='.$dd[$ddi],'maxlenght'=>$max,'size'=>$size,$class=>''); switch ($tt) { case '{': $tela .= $tr; $tela .= '<td colspan=2>'; $tela .= '<fieldset class="border1"><legend class="lt3 bold">' . $label . '</legend>'; $tela .= '<table width="100%" class="tabela00">'; break; case '}': $tela .= '</table>'; $tela .= '</fieldset>'; $tela .= '</td></tr>'; $tela .= '<table width="100%" id="row">'; $tela .= '</td></tr>'; break; /* Select Box */ /* Select Box */ case '[': $ntype = trim(substr($type, 2, strlen($type))); $n1 = substr($ntype, 0, strpos($ntype, '-')); $n2 = sonumero(substr($ntype, strpos($ntype, '-'), strlen($ntype))); $n3 = substr($ntype, strlen($ntype) - 1, 1); $options = array('' => '::select an option::'); if ($n3 != 'D') { /* Crescente */ for ($r = $n1; $r <= $n2; $r++) { $options[$r] = $r; } } else { /* Descrecente */ for ($r = $n2; $r >= $n1; $r--) { $options[$r] = $r; } } /* recupera dados */ $dados = array('name' => $dn, 'id' => $dn, 'size' => 1, 'class' => 'form_select'); $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $tela .= '<TD>'; $tela .= form_dropdown($dados, $options, $vlr); break; /* Select Box - Autocomplete*/ /* Select Box - Autocomplete*/ case 'AA': $ntype = trim(substr($type, 2, strlen($type))); $ntype = troca($ntype, ':', ';') . ';'; $param = splitx(';', $ntype); /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } /* **/ $dados = array('name' => $dn . 'a', 'id' => $dn . 'a', 'value' => $vlr, 'maxlenght' => $max, 'size' => $size, 'placeholder' => $label, 'class' => 'form_string', 'autocomplete' => 'on'); $tela .= $td . form_input($dados); $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => $max, 'size' => 10, 'placeholder' => $label, 'class' => 'form_string', 'autocomplete' => 'on'); if ($readonly == false) { $dados['readonly'] = 'readonly'; } $tela .= form_input($dados); $tela .= $tdn . $trn; $tela .= ' <script> $(function(){ var $sfield = $("#' . $dn . 'a").autocomplete({ source: function(request, response){ var url = "' . base_url("index.php/instituicao/autocomplete?term=") . '" + $("#' . $dn . 'a").val(); $.get(url, {}, function(data) { response($.map(data, function(rlt) { return { label: rlt.nome, value: rlt.id }; })); }, "json"); }, select: function( event, ui ) { $( "#' . $dn . 'a" ).val( ui.item.label ); $( "#' . $dn . '" ).val( ui.item.value ); return false; } , minLength: 4, autofocus: true }); }); </script> '; break; /* Button */ /* Button */ case 'B': $tela .= $tr . $tdl . $td; $dados = array('name' => 'acao', 'id' => 'acao', 'value' => $label, 'class' => 'form_submit'); $tela .= form_submit($dados); $tela .= $tdn . $trn; break; case 'C': /* TR da tabela */ $tela .= $tr; $dados = array('name' => $dn, 'id' => $dn, 'value' => '1', 'class' => 'onoffswitch-checkbox'); if ($readonly == false) { $dados['readonly'] = 'readonly'; } $tela .= '<td align="right">' . form_checkbox($dados, 'accept', $vlr); /* label */ if (strlen($label) > 0) { $tela .= '<td>' . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $tela .= $tdn . $trn; break; /* Oculto */ /* Oculto */ case 'H': $dados = array($dn => $vlr); $tela .= form_hidden($dados); break; case 'HV': $vlr = $cp[2]; $dados = array($dn => $vlr); $tela .= '<input type="hidden" name="' . $dn . '" id="' . $dn . '" value="' . $vlr . '">' . cr(); break; /* Select Box - Mes */ /* Select Box - Mes */ case 'MES': $options = array('' => '::select an option::'); /* recupera dados */ for ($r = date("Y") + 4; $r > 1990; $r--) { $vlra = $r; $options[$vlra] = '===' . $r . '==='; //array_push($options,array('2019')); $ar = array(); for ($y = 12; $y > 0; $y--) { $vlrs = $r . strzero($y, 2) . '01'; $cpt = $r . '/' . msg('mes_' . strzero($y, 2)); $op = array($vlr => $cpt); $ar[$vlrs] = $cpt; //array_push($options,$op); } $options[$vlra] = $ar; } $dados = array('name' => $dn, 'id' => $dn, 'size' => 1, 'class' => 'form_select'); $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } if (strlen($vlr) == 0) { $vlr = date("Ym") . '01'; } else { $vlr = sonumero($vlr); } $tela .= '<TD>'; $tela .= form_dropdown($dados, $options, $vlr); break; /* Select Box */ /* Select Box */ case 'O': $ntype = trim(substr($type, 2, strlen($type))); $ntype = troca($ntype, '&', ';') . ';'; $param = splitx(';', $ntype); $options = array('' => '::select an option::'); for ($r = 0; $r < count($param); $r++) { if (count(trim($param[$r])) > 0) { $nterm = splitx(':', $param[$r] . ':'); $key = $nterm[0]; $valor = $nterm[1]; $options[$key] = $valor; } } /* recupera dados */ $dados = array('name' => $dn, 'id' => $dn, 'size' => 1, 'class' => 'form_select'); $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $tela .= '<TD>'; $tela .= form_dropdown($dados, $options, $vlr); break; /* Select Box */ /* Select Box */ case 'Q': $ntype = trim(substr($type, 2, strlen($type))); $ntype = troca($ntype, ':', ';') . ';'; $param = splitx(';', $ntype); $options = array('' => '::select an option::'); /* recupera dados */ $sql = "select * from (" . $param[2] . ") as tabela order by " . $param[1]; $CI =& get_instance(); $query = $CI->db->query($sql); foreach ($query->result_array() as $row) { /* recupera ID */ $flds = trim($param[0]); $vlrs = trim($param[1]); $flds = $row[$flds]; $vlrs = $row[$vlrs]; $options[$flds] = $vlrs; } $dados = array('name' => $dn, 'id' => $dn, 'size' => 1, 'class' => 'form_select'); $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $tela .= '<TD>'; $tela .= form_dropdown($dados, $options, $vlr); break; /* String */ /* String */ case 'R': $ntype = trim(substr($type, 2, strlen($type))); $ntype = troca($ntype, '&', ';') . ';'; $param = splitx(';', $ntype); $form = '<table width="100%" border=0>'; for ($r = 0; $r < count($param); $r++) { if (count(trim($param[$r])) > 0) { $nterm = splitx(':', $param[$r] . ':'); $key = $nterm[0]; $valor = $nterm[1]; $options[$key] = $valor; $checked = false; if ($key == $vlr) { $checked = true; } $dados = array('name' => $dn, 'id' => $dn, 'value' => $key, 'class' => 'form_select', 'checked' => $checked); $form .= '<tr valign="top"><td>' . form_radio($dados) . '</td>'; $form .= '<td class="form_radio">' . $valor . '</td>'; $form .= '</tr>'; } } $form .= '</table>'; /* recupera dados */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $tela .= '<TD>'; //$tela .= form_radio($dados, $options, $vlr); $tela .= $form; break; /* String */ /* String */ case 'D': /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => 12, 'size' => 12, 'placeholder' => $label, 'class' => 'form_string date'); if ($readonly == false) { $dados['readonly'] = 'readonly'; } $tela .= $td . form_input($dados) . ' (dd/mm/yyyy)'; $tela .= $tdn . $trn; $tela .= ' <script> $(function() { $( "#' . $dn . '" ).datepicker(); }); </script> '; break; /* String */ /* String */ case 'LINK': /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => $max, 'size' => $size, 'placeholder' => $label, 'class' => 'form_string'); if ($readonly == false) { $dados['readonly'] = 'readonly'; } $tela .= $td . form_input($dados); $tela .= $tdn . $trn; break; case 'M': /* TR da tabela */ $tela .= $tr; /* label */ $tela .= '<td colspan=2>' . '<span class="lt1">' . $label . '</span>'; $tela .= $tdn . $trn; break; /* form_number */ /* form_number */ case 'N': /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => 15, 'size' => 15, 'placeholder' => $label, 'class' => 'form_string money'); if ($readonly == false) { $dados['readonly'] = 'readonly'; } $tela .= $td . form_input($dados); $tela .= $tdn . $trn; break; /* String */ /* String */ case 'S': /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $size = sonumero($type); $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => $max, 'size' => $size, 'placeholder' => $label, 'class' => 'form_string'); if ($readonly == false) { $dados['readonly'] = 'readonly'; } $tela .= $td . form_input($dados); $tela .= $tdn . $trn; break; case 'SW': /* TR da tabela */ $tela .= $tr; $checked = False; /* label */ $tela .= ' <td class="lt4" colspan=2> <table> <tr> <td> <div class="onoffswitch"> '; /* cehcked */ if (trim($vlr) == '1') { $checked = True; } /* Monta lista */ $data = array('name' => $dn, 'checked' => $checked, 'class' => 'onoffswitch-checkbox', 'id' => $dn, 'value' => '1'); $tela .= form_checkbox($data); $tela .= ' <label class="onoffswitch-label" for="' . $dn . '"> <span class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span> </label> </div></td><td class="lt2"> ' . $label . ' </td> </tr> </table></td></tr>'; break; /* Update */ /* Update */ case 'U': if (round($vlr) == 0) { $vlr = date("Y-m-d"); } $dados = array($dn => $vlr); $tela .= form_hidden($dados); break; /* Textarea */ /* Textarea */ case 'T': $ntype = trim(substr($type, 2, strlen($type))); $ntype = troca($ntype, ':', ';') . ';'; $param = splitx(';', $ntype); /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $data = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'rows' => $param[1], 'cols' => $param[0], 'class' => 'form_textarea'); $tela .= $td . form_textarea($data); $tela .= $tdn . $trn; break; /* Password */ /* Password */ case 'P': if (strlen($label) > 0) { $tela .= $label . ' '; } $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => $max, 'size' => $size); $tela .= form_password($dados); break; } $ddi++; return $tela; }
function form_field($cp, $vlr) { global $dd, $ddi; /* Zera tela */ $tela = ''; $table = 1; if (!isset($dd)) { $dd = array(); $ddi = 0; } $type = $cp[0]; $label = $cp[2]; $required = $cp[3]; $placeholder = $label; $readonly = $cp[4]; $tt = substr($type, 1, 1); /* exessoes */ if (substr($type, 0, 4) == '$MES') { $tt = 'MES'; } /* form */ $max = 100; $size = 100; $dados = array(); $dn = 'dd' . $ddi; if ($table == 1) { $td = '<td>'; $tdl = '<td align="right">'; $tdn = '</td>'; $tr = '<tr valign="top">'; $trn = '</tr>'; } else { $td = ''; $tdl = ''; $tdn = ''; $tr = ''; $trn = ''; } //$dados = array('name'=>'dd'.$ddi, 'id'=>'dd'.$ddi,'value='.$dd[$ddi],'maxlenght'=>$max,'size'=>$size,$class=>''); switch ($tt) { /* Button */ case 'B': $tela .= $tr . $tdl . $td; $dados = array('name' => 'acao', 'id' => 'acao', 'value' => $label); $tela .= form_submit($dados); $tela .= $tdn . $trn; break; /* Oculto */ /* Oculto */ case 'H': $dados = array($dn => $vlr); $tela .= form_hidden($dados); break; /* Select Box - Mes */ /* Select Box - Mes */ case 'MES': $options = array('' => '::select an option::'); /* recupera dados */ for ($r = date("Y") + 4; $r > 1990; $r--) { $vlra = $r; $options[$vlra] = '===' . $r . '==='; //array_push($options,array('2019')); $ar = array(); for ($y = 12; $y > 0; $y--) { $vlrs = $r . strzero($y, 2) . '01'; $cpt = $r . '/' . msg('mes_' . strzero($y, 2)); $op = array($vlr => $cpt); $ar[$vlrs] = $cpt; //array_push($options,$op); } $options[$vlra] = $ar; } $dados = array('name' => $dn, 'id' => $dn, 'size' => 1, 'class' => 'form_select'); $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } if (strlen($vlr) == 0) { $vlr = date("Ym") . '01'; } $tela .= '<TD>'; $tela .= form_dropdown($dados, $options, $vlr); break; /* Select Box */ /* Select Box */ case 'Q': $ntype = trim(substr($type, 2, strlen($type))); $ntype = troca($ntype, ':', ';') . ';'; $param = splitx(';', $ntype); $options = array('' => '::select an option::'); /* recupera dados */ $sql = "select * from (" . $param[2] . ") as tabela "; $CI =& get_instance(); $query = $CI->db->query($sql); foreach ($query->result_array() as $row) { /* recupera ID */ $flds = trim($param[0]); $vlrs = trim($param[1]); $flds = $row[$flds]; $vlrs = $row[$vlrs]; $options[$flds] = $vlrs; } $dados = array('name' => $dn, 'id' => $dn, 'size' => 1, 'class' => 'form_select'); $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $tela .= '<TD>'; $tela .= form_dropdown($dados, $options, $vlr); break; /* String */ /* String */ case 'S': /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => $max, 'size' => $size, 'placeholder' => $label, 'class' => 'form_string'); if ($readonly == false) { $dados['readonly'] = 'readonly'; } $tela .= $td . form_input($dados); $tela .= $tdn . $trn; break; /* Update */ /* Update */ case 'U': if (round($vlr) == 0) { $vlr = date("Ymd"); } $dados = array($dn => $vlr); $tela .= form_hidden($dados); break; /* Textarea */ /* Textarea */ case 'T': $ntype = trim(substr($type, 2, strlen($type))); $ntype = troca($ntype, ':', ';') . ';'; $param = splitx(';', $ntype); /* TR da tabela */ $tela .= $tr; /* label */ if (strlen($label) > 0) { $tela .= $tdl . $label . ' '; } if ($required == 1) { $tela .= ' <font color="red">*</font> '; } $data = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'rows' => $param[1], 'cols' => $param[0], 'class' => 'form_textarea'); $tela .= $td . form_textarea($data); $tela .= $tdn . $trn; break; /* Password */ /* Password */ case 'P': if (strlen($label) > 0) { $tela .= $label . ' '; } $dados = array('name' => $dn, 'id' => $dn, 'value' => $vlr, 'maxlenght' => $max, 'size' => $size); $tela .= form_password($dados); break; } $ddi++; return $tela; }