require_once('../include/orm.php');
require_once('../include/globals.php');
require_once('../include/util.php');
require_once("../include/phpexcel/Classes/PHPExcel/IOFactory.php");
$_import_importerhorizontal_db_connected = $Link == '';
if($_import_importerhorizontal_db_connected) $Link = connectDb();
define('DBCONNECTED', 1);
debugstartpage();
if( isset($_x) ) {
//if( $_x != '' ) {
$_x = $_x == '' ? array() : StringTokenize($_x, ",");
$_result = array();
$_result['version'] = array('actual' => 2202);
$_result['visibility'] = array();
$_initialvars = arrayExclude(get_defined_vars(), array("_*", "form_*", "s_*", "GLOBALS", "Link", "thisname"));
}
// isbasewindow:
// On Open
while( ($__action == "" or $__action == "executedonopen") and (empty($_x) or in('onopen', $_x)) ) {
$__action = "executedonopen";
if( $_importer == '' ) $_importer="x";
$ddform = DDFORM;
$ddfield = DDFIELD;
$datos = array(array(""));
if( $t == '' and $f == '' and $form == '' ) {
redirect("../import/dbimporter.php?return=../import/importer.php");
break;
}
if( $tit == "" ) {
$tit = $_mode == 'export' ? "Exportacion" : "Importacion";
}
if( $tfolder == "" ) $tfolder = "../files/$_filesfolder/import/templates/";
//print("RET: $ret
");
$denominacion[] = "";
$denominacion[] = "";
$denominacion[] = "";
$denominacion[] = "";
$denominacion[] = "";
$fieldstooltips = array();
$fieldsprops = array();
$fieldstypes = array();
$fieldstitles = array();
$fieldsname = array();
$fieldsmultiple = array();
//print("Ret: $ret
");
//"celular", "celular2", "oficina",
//$fields = array("consorcio", "denominacion", "torre", "piso", "departamento", "apellido" , "nombre", "tipodoc", "numdoc", "telefono", "celular", "oficina", "email","email2", "porcentaje_a", "porcentaje_b", "porcentaje_c", "porcentaje_d", "cochera", "notas");
$limit1 = 4;
if( $_mode == 'export' ) $limit1 = 1000;
if( $form != '' ) {
$f2array = array();
$f2types = array();
$relarray = array();
$propsarray = array();
$transformsarray = array();
$combos = array();
$subforms = array();
$subformscant = array();
$onlists = array();
$searchables = array();
if( $window != '' ) {
$__tempresult = sqlexec($Link, "select concat('../', module, '/', window, '.php'), name, title, dbtable,dbwhere, orderby from " . mysql_escape($ddform) . " where concat(module, '.', name) = '" . mysql_escape($form) . "' and window = '" . mysql_escape($window) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$formurl = $__temprow[0];
$formname = $__temprow[1];
$formtitle = $__temprow[2];
$formdbtable = $__temprow[3];
$formdbwhere = $__temprow[4];
$formorderby = $__temprow[5];
}
$__tempresult = sqlexec($Link, "select group_concat(if(locate('.', f.form)=0,f.name,concat(substr(f.form, locate('.', f.form) + 1), '_', f.name )) order by f.numero) from " . mysql_escape($ddfield) . " as f where (concat(f.module, '.', f.form) = '" . mysql_escape($form) . "' or concat(f.module, '.', f.form) like '" . mysql_escape($form) . ".%') and f.name != 'id' and f.type != 'table' and f.window = '" . mysql_escape($window) . "' and (f.props is null or f.props not like '%invisible%')");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$f = $__temprow[0];
}
// , if( (select f2.type from $ddfield as f2 where f2.module = f.module and f2.window = f.window and concat(f2.form, '.', f2.name) = f.form )='table' , '(1)', '')
$__tempresult = sqlexec($Link, "select concat(substr(form, locate('.', form) + 1), '_', name), info, props, '', type, title from " . mysql_escape($ddfield) . " where (concat(module, '.', form) = '" . mysql_escape($form) . "' or concat(module, '.', form) like '" . mysql_escape($form) . ".%') and name != 'id' and type != 'table' and window = '" . mysql_escape($window) . "' and (props is null or props not like '%invisible%') order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($fieldsname, $__temprow[0]);
array_push($fieldstooltips, $__temprow[1]);
array_push($fieldsprops, $__temprow[2]);
array_push($fieldsmultiple, $__temprow[3]);
array_push($fieldstypes, $__temprow[4]);
array_push($fieldstitles, $__temprow[5]);
}
$__tempresult = sqlexec($Link, "select if(locate('.', form)=0,name,concat(substr(form, locate('.', form) + 1), '_', name)) from " . mysql_escape($ddfield) . " where (concat(module, '.', form) = '" . mysql_escape($form) . "' or concat(module, '.', form) like '" . mysql_escape($form) . ".%') and window = '" . mysql_escape($window) . "' and type = 'combo' order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($combos, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select name, size from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "' and window = '" . mysql_escape($window) . "' and type = 'table' order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($subforms, $__temprow[0]);
array_push($subformscant, $__temprow[1]);
}
$__tempresult = sqlexec($Link, "select name, relation, props, sqltransform from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "' and window = '" . mysql_escape($window) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($f2array, $__temprow[0]);
array_push($relarray, $__temprow[1]);
array_push($propsarray, $__temprow[2]);
array_push($transformsarray, $__temprow[3]);
}
$__tempresult = sqlexec($Link, "select name from " . mysql_escape($ddfield) . " as f where (concat(f.module, '.', f.form) = '" . mysql_escape($form) . "' or concat(f.module, '.', f.form) like '" . mysql_escape($form) . ".%') and (f.props is null or f.props not like '%invisible%') and list like '%onfilter%'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($onlists, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select name from " . mysql_escape($ddfield) . " as f where (concat(f.module, '.', f.form) = '" . mysql_escape($form) . "' or concat(f.module, '.', f.form) like '" . mysql_escape($form) . ".%') and (f.props is null or f.props not like '%invisible%') and list like '%searchable%'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($searchables, $__temprow[0]);
}
} else {
$__tempresult = sqlexec($Link, "select concat('../', module, '/', window, '.php'), name, title, dbtable, dbwhere, orderby from " . mysql_escape($ddform) . " where concat(module, '.', name) = '" . mysql_escape($form) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$formurl = $__temprow[0];
$formname = $__temprow[1];
$formtitle = $__temprow[2];
$formdbtable = $__temprow[3];
$formdbwhere = $__temprow[4];
$formorderby = $__temprow[5];
}
$__tempresult = sqlexec($Link, "select group_concat(if(locate('.', form)=0,name,concat(substr(form, locate('.', form) + 1), '_', name)) order by numero) from " . mysql_escape($ddfield) . " where (concat(module, '.', form) = '" . mysql_escape($form) . "' or concat(module, '.', form) like '" . mysql_escape($form) . ".%') and name != 'id' and type != 'table' and (props is null or props not like '%invisible%')");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$f = $__temprow[0];
}
$__tempresult = sqlexec($Link, "select concat(substr(form, locate('.', form) + 1), '_', name), info, props, '', type, title from ddfield where (concat(module, '.', form) = '" . mysql_escape($form) . "' or concat(module, '.', form) like '" . mysql_escape($form) . ".%') and name != 'id' and type != 'table' and (props is null or props not like '%invisible%') order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($fieldsname, $__temprow[0]);
array_push($fieldstooltips, $__temprow[1]);
array_push($fieldsprops, $__temprow[2]);
array_push($fieldsmultiple, $__temprow[3]);
array_push($fieldstypes, $__temprow[4]);
array_push($fieldstitles, $__temprow[5]);
}
$__tempresult = sqlexec($Link, "select if(locate('.', form)=0,name,concat(substr(form, locate('.', form) + 1), '_', name )) from " . mysql_escape($ddfield) . " where (concat(module, '.', form) = '" . mysql_escape($form) . "' or concat(module, '.', form) like '" . mysql_escape($form) . ".%') and type = 'combo' and (props is null or props not like '%invisible%') order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($combos, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select name, size from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "' and type = 'table' and (props is null or props not like '%invisible%') order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($subforms, $__temprow[0]);
array_push($subformscant, $__temprow[1]);
}
$__tempresult = sqlexec($Link, "select distinct name from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($f2array, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select relation from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($relarray, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select props, sqltransform from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($propsarray, $__temprow[0]);
array_push($transformsarray, $__temprow[1]);
}
$__tempresult = sqlexec($Link, "select name from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "' and (props is null or props not like '%invisible%') and list like '%onfilter%' order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($onlists, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select name from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "' and (props is null or props not like '%invisible%') and list like '%searchable%' order by numero");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($searchables, $__temprow[0]);
}
}
if( $_importer == "x" ) {
// subforms fields x 4
foreach($subforms as $ii => $subform) {
// busca primer y ultimo campo de subform
$tstart = strpos($f, $subform . '_');
$tend = strrpos($f, $subform . '_');
$scant = $subformscant[$ii];
if( $scant == '-1' ) {
//print("FIELDSNAME:");
//print_r($fieldsname);
foreach($fieldsname as $ii0 => $field) {
if( startsWith($field, $subform . '_') ) {
$fieldsmultiple[$ii0] = 'yes';
}
}
continue;
}
if( $scant == '' or $scant == '0' ) $scant = 4;
if( $tstart !== false ) {
$tend = strpos($f, ',', $tend);
if( $tend === false )
$tend = strlen($f);
debug("F before $subform: $f");
$fend = substr($f, $tend);
$fmid = substr($f, $tstart, $tend - $tstart);
debug("fmid: $fmid");
$f = substr($f, 0, $tstart) .
str_replace(",", "(1),", $fmid) . "(1)";
for($i0 = 2; $i0 <= $scant; $i0++) {
$f .= "," . str_replace(",", "($i0),", $fmid) . "($i0)";
}
$f .= $fend;
debug("F after $subform: $f");
}
}
}
if( $tit == "Importacion" or $tit == "Exportacion" ) {
$tit .= " " . plural(trim($formtitle));
}
if( $_mode == 'update' or $_mode == 'export' ) {
// Arma sql main
debug("Fields to load", $f2array);
$t = $formdbtable;
$f2 = "";
// Arma sql select
foreach($f2array as $ii => $col) {
if( $f2 != '' ) $f2 .= ", ";
$rel = $relarray[$ii];
$sqltransform = $transformsarray[$ii];
// Relations
if( $rel != '' )
{
$__tempresult = sqlexec($Link, "select dbtable from ddform where concat(module, '.', name) = '" . mysql_escape($rel) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$tablerel = $__temprow[0];
}
$prop = $propsarray[$ii];
debug("Relation $col rel $rel tablerel $tablerel props $props ");
if( strpos($prop, ' tostring ') !== false ) {
$prop0 = trim(str_replace(",", "','", substr($prop, strpos($prop, ' tostring ') + 10)));
if( strpos($prop0, ' ') !== false ) $prop0 = substr($prop0, 0, strpos($prop0, ' '));
$colrel = array();
debug("rel tostring $rel prop $prop0");
$colrel = sqltovector($Link, "select distinct dbcol from ddfield where concat(module, '.', form) = '$rel' and name in ('$prop0') order by field(name, '$prop0')");
debug("colrel (tostring) ", $colrel);
$f2 .= "(select concat(" . arrayToString(arrayconcat($colrel, "ifnull(", ", '')"), ", ' ', ") . ") from $tablerel where id = $t.$col) as $col";
} else {
$colrel = "";
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' and list like '%tostring%' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
if( $colrel == '' ) {
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' and list like '%onlist%' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
}
if( $colrel == '' ) {
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
}
debug("colrel ", $colrel);
if( $colrel == '' )
$f2 .= $t . "." . $col;
else
$f2 .= "(select temp.$colrel from $tablerel as temp where temp.id = $t.$col) as $col";
}
} else {
$f2 .= $sqltransform . $col . ' as ' . $col;
}
}
// Arma where
$where = $formdbwhere == '' ? '1 = 1' : $formdbwhere;
if( strpos($where, '$') !== false ) {
$where = replacewithvariables($where);
}
// Filtros
foreach($onlists as $onlist) {
$val = "";
if( isset($GLOBALS[$onlist]) ) {
$val = $GLOBALS[$onlist];
} else if( isset($_SESSION[$onlist]) ) {
$val = $_SESSION[$onlist];
} else if( isset($_REQUEST[$onlist]) ) {
$val = $_REQUEST[$onlist];
} else if( isset($_REQUEST[$onlist . '_filter']) ) {
$val = $_REQUEST[$onlist . '_filter'];
}
if( $val != "" ) {
if( substr($val, 11, 1) == '-' ) {
$dates = StringTokenize($val, '-');
$val1 = trim($dates[0]);
$val2 = trim($dates[1]);
if( is_date($val1) and is_date($val2) ) {
$val1 = textdatetosql($val1);
$val2 = textdatetosql($val2);
$where .= " and $onlist between '$val1' and '$val2'";
debug("ONLIST $onlist vals $val1 $val2");
} else {
$where .= " and $onlist = '$val'";
debug("ONLIST $onlist val $val");
}
} else {
$where .= " and $onlist = '$val'";
debug("ONLIST $onlist val $val");
}
}
}
// Search text
$wheresearch = "";
foreach($searchables as $searchable) {
$val = "";
if( isset($_REQUEST['search_filter']) ) {
$val = $_REQUEST['search_filter'];
}
if( $val != "" ) {
if( $wheresearch != "" ) $wheresearch .= " or ";
$iindex = searchInArray($searchable, $f2array);
$rel = $relarray[$iindex];
if( $rel != '' )
{
$__tempresult = sqlexec($Link, "select dbtable from ddform where concat(module, '.', name) = '" . mysql_escape($rel) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$tablerel = $__temprow[0];
}
$prop = $propsarray[$iindex];
debug("Relation $col rel $rel tablerel $tablerel props $props ");
if( strpos($prop, ' tostring ') !== false ) {
$prop0 = trim(str_replace(",", "','", substr($prop, strpos($prop, ' tostring ') + 10)));
if( strpos($prop0, ' ') !== false ) $prop0 = substr($prop0, 0, strpos($prop0, ' '));
$colrel = array();
debug("rel tostring $rel prop $prop0");
$colrel = sqltovector($Link, "select distinct dbcol from ddfield where concat(module, '.', form) = '$rel' and name in ('$prop0') order by field(name, '$prop0')");
debug("colrel (tostring) ", $colrel);
$wheresearch .= "(select concat(" . arrayToString(arrayconcat($colrel, "ifnull(", ", '')"), ", ' ', ") . ") from $tablerel where id = $t.$col) like '%$val%'";
} else {
$colrel = "";
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' and list like '%tostring%' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
if( $colrel == '' ) {
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' and list like '%onlist%' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
}
if( $colrel == '' ) {
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
}
debug("colrel ", $colrel);
if( $colrel == '' )
$wheresearch .= $t . "." . $col . " like '%$val%'";
else
$wheresearch .= "(select temp.$colrel from $tablerel as temp where temp.id = $t.$col) like '%$val%'";
}
} else {
$wheresearch .= " $searchable like '%$val%'";
}
debug("SEARCHABLE $searchable val $val");
}
}
if( $wheresearch != "" ) {
$where .= " and ($wheresearch)";
}
// Order by
if( $formorderby == "" ) {
$formorderby = "id";
}
// Ejecuta sql
$datos = sqltoarray($Link, "select id, $f2 from $t where $where order by $formorderby"); // limit 500");
// Subforms
if( $_mode == 'export' ) {
$andwindow = "";
// Carga datos de subforms
$datossubforms = array();
foreach($subforms as $indexsubform => $subform) {
$scant = $subformscant[$indexsubform];
// Carga campos y rels
debug("PROCESSING SUBFORM $subform scant $scant");
$f2array = array();
$relarray = array();
$propsarray = array();
$transformarray = array();
$dbcol = "";
// Carga dd de subform
if( $window != '' ) {
$__tempresult = sqlexec($Link, "select distinct name from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "' and window = '" . mysql_escape($window) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($f2array, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select relation from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "' and window = '" . mysql_escape($window) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($relarray, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select props, sqltransform from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "' and window = '" . mysql_escape($window) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($propsarray, $__temprow[0]);
array_push($transformarray, $__temprow[1]);
}
$__tempresult = sqlexec($Link, "select dbtable, dbwhere from ddform where concat(module, '.', name) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "' and window = '" . mysql_escape($window) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$ts = $__temprow[0];
$dbwhere = $__temprow[1];
}
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "' and name = '" . mysql_escape($subform) . "' and window = '" . mysql_escape($window) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$dbcol = $__temprow[0];
}
} else {
$__tempresult = sqlexec($Link, "select distinct name from " . mysql_escape($ddfield) . " where concat(module, '.', form) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($f2array, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select relation from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($relarray, $__temprow[0]);
}
$__tempresult = sqlexec($Link, "select props, sqltransform from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "' and type not in ('table') order by numero limit " . mysql_escape($limit1) . "");
while( $__temprow = mysql_fetch_array($__tempresult)) {
array_push($propsarray, $__temprow[0]);
array_push($transformarray, $__temprow[1]);
}
$__tempresult = sqlexec($Link, "select dbtable, dbwhere from ddform where concat(module, '.', name) = '" . mysql_escape($form) . "." . mysql_escape($subform) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$ts = $__temprow[0];
$dbwhere = $__temprow[1];
}
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($form) . "' and name = '" . mysql_escape($subform) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$dbcol = $__temprow[0];
}
}
if( $dbcol == "" ) $dbcol = $formname;
debug("Fields to load", $f2array);
debug("subform $subform (form $form) dbcol $dbcol");
// Arma sql para cargar subform
$f2 = "";
foreach($f2array as $ii => $col) {
if( $f2 != '' ) $f2 .= ", ";
$rel = $relarray[$ii];
$sqltransform = $transformarray[$ii];
$sqltransform = str_replace('$' . $dbcol, $ts . '.' . $dbcol, $sqltransform);
if( $rel != '' ) {
$__tempresult = sqlexec($Link, "select dbtable from ddform where concat(module, '.', name) = '" . mysql_escape($rel) . "'");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$tablerel = $__temprow[0];
}
$prop = $propsarray[$ii];
if( strpos($prop, ' tostring ') !== false ) {
$prop0 = trim(str_replace(",", "','", substr($prop, strpos($prop, ' tostring ') + 10)));
if( strpos($prop0, ' ') !== false ) $prop0 = substr($prop0, 0, strpos($prop0, ' '));
$colrel = array();
debug("rel tostring $rel prop $prop0");
$colrel = sqltovector($Link, "select distinct dbcol from ddfield where concat(module, '.', form) = '$rel' and name in ('$prop0') order by field(name, '$prop0')");
debug("colrel ", $colrel);
if( empty($colrel) )
$f2 .= $ts . "." . $col;
else
$f2 .= "(select concat(" . arrayToString(arrayconcat($colrel, "ifnull(", ", '')"), ", ' ', ") . ") from $tablerel where id = $ts.$col) as $col";
} else {
$colrel = "";
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' and list like '%tostring%' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
if( $colrel == '' ) {
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' and list like '%onlist%' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
}
if( $colrel == '' ) {
$__tempresult = sqlexec($Link, "select dbcol from ddfield where concat(module, '.', form) = '" . mysql_escape($rel) . "' order by numero limit 1");
while( $__temprow = mysql_fetch_array($__tempresult)) {
$colrel = $__temprow[0];
}
}
if( $colrel == '' )
$f2 .= $ts . "." . $col;
else
$f2 .= "(select temp.$colrel from $tablerel as temp where temp.id = $ts.$col) as $col";
}
} else {
$f2 .= $sqltransform . $col . ' as ' . $col;
}
}
$where2 = " $dbcol in (select id from $t where $where)";
// Carga subform
if( $dbwhere != "" ) $where2 = "(" . $dbwhere . ") and " . $where2;
$datos3 = sqltoarray($Link, "select id, $dbcol, $f2 from $ts where $where2 order by $dbcol, id"); // limit 500");
$datossubforms[$indexsubform] = $datos3;
}
// Calcula cantidad de filas por registro
$sizerows = array();
//print("DATOS SUBFORMS:
"); //print_r($datossubforms); //print(""); foreach($datossubforms as $indexsubform => $datossubform) { $scant = $subformscant[$indexsubform]; if( $scant >= 0 ) continue; $sizerowssubform = array(); foreach($datossubform as $i0 => $irow3) { $relval = $irow3[$dbcol]; // valor columna relacionada con form principal if( empty($sizerowssubform[$relval]) ) { $sizerowssubform[$relval] = 1; } else { $sizerowssubform[$relval] = $sizerowssubform[$relval] + 1; } } foreach($sizerowssubform as $irel => $rval ) { if( empty($sizerows[$irel]) or $sizerows[$irel] < $rval ) $sizerows[$irel] = $rval; } } //print_r($sizerows); // Arma planilla final con cantidad de filas por cada registro $datos4 = array(); $filavacia = array(); foreach($datos[0] as $ti => $tv) { $filavacia[$ti] = ""; } foreach($datos as $fila) { $datos4[] = $fila; $tid = $fila['id']; if( $sizerows[$tid] > 1 ) { for($i0 = 1; $i0 < $sizerows[$tid]; $i0++ ) { $filavacia['id'] = $tid; $datos4[] = $filavacia; } } } // Carga datos de los subforms en planilla final $totdatos = sizeof($datos4); foreach($datossubforms as $indexsubform => $datossubform) { $subform = $subforms[$indexsubform]; $scant = $subformscant[$indexsubform]; $posdatos4 = 0; $index = 0; foreach($datossubform as $i0 => $irow3) { $relval = $irow3[$dbcol]; // valor columna relacionada con form principal $index++; if( $datos4[$posdatos4]['id'] != $relval ) { // buscar siguientes filas while($datos4[$posdatos4]['id'] != $relval) { $posdatos4++; if( $posdatos4 >= $totdatos ) { print("
"); //print_r($datos); //print(""); //finanzas.movimiento_importe(1) } } // Si viene parametro f son los fields if($f != "") { debug("f: $f"); $fields = StringTokenize($f, ","); //print("Columnas: $f