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("

datos

"); matrixtohtml($datos); print("

datos4

"); matrixtohtml($datos4); die("ERROR NO ENCONTRADO ID $ts.$dbcol: $relval FILA $posdatos4"); break; } } $index = 1; } if( $scant > 0 ) { foreach($irow3 as $n => $v) { // seteo el campo if( $n != 'id' and $n != $dbcol ) { $datos4[$posdatos4][$subform . '_' . $n . '(' . $index . ')'] = $v; } } } else { foreach($irow3 as $n => $v) { // seteo el campo if( $n != 'id' and $n != $dbcol ) { $datos4[$posdatos4][$subform . '_' . $n] = $v; } } $posdatos4++; } } } $datos = $datos4; } //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
"); } logToFile("F: $f sizeof fields: " . sizeof($fields) . " t: " . $t); // Si viene parametro t y no hay fields tomar los fields de la tabla if( $t != "" and ($fields == "" or sizeof($fields) == 0) ) { $dbcolumns = getdbcolumns($Link, $t); $fields = array(); $fields = $dbcolumns; debug("No f. Fields : " . print_r($dbcolumns, true)); //foreach($dbcolumns as $dbrow) { // $fields[] = $dbrow[0]; //} } $fieldsvalues = $fields; // Carga plantilla if( is_file($tfolder . "/" . $tit . ".cfg") ) { $fieldsvalues = explode(",", readFromFile($tfolder . "/" . $tit . ".cfg")); logToFile("Fieldsvalues from template: " . print_r($fieldsvalues, true)); foreach($fieldsvalues as $i => $fv) { if( !in($fv, $fields) ) $fieldsvalues[$i] = ""; } } // Reordena datos si en modo _export if( $_mode == 'export' ) { //print("EXPORT fields before:"); //print_r($fields); $totrows = sizeof($datos); //$fieldsvalues = array(); //$fields = array(); foreach($datos as $irow => $row) { foreach($row as $n => $v) { $tpos = searchInArray($n, $fields); if( $tpos == -1 and $n != 'id' ) { $fields[] = $n; $fieldsvalues[] = $n; } } } //print("EXPORT fields after:"); //print_r($fields); $datos2 = array(); for($irow = 0; $irow < $totrows; $irow++) { $datos2[$irow] = array(); $datos2[$irow][0] = $datos[$irow]['id']; foreach($fieldsvalues as $ii => $fval) { $tdato = $datos[$irow][$fval]; if( is_sqldate($tdato) ) $tdato = formatdate($tdato); $datos2[$irow][$ii + 1] = $tdato; } } $datos = $datos2; } if( startsWith($t, "temp")) { if( isset($delete) ) { sqlexec($Link, "delete from " . mysql_escape($t) . ""); } $datos = sqltoarray($Link, "select * from $t"); } else if( $form == '' ) { if( $t != '' and sqlget($Link, "select count(*) from importer where atable = '$t'") == 0 ) die("Tabla no autorizada para importar"); $f2 = $f; debug("f: $f"); if( $f2 == '' ) $f2 = '*'; $f2 = str_replace('%', 'porcentaje', str_replace(' ', '_', $f2)); debug("f2: $f2"); if( $dv != '' and $where == '' ) { $dvs = StringTokenize($dv, ","); foreach($dvs as $dv1) { if( $where != '' ) $where .= " and "; $where .= $dv1; } } if($where != "" ) { $datos = sqltoarray($Link, "select $f2 from $t where $where"); // limit 500"); } else if( $t != "" ) { $datos = sqltoarray($Link, "select $f2 from $t"); // limit 500"); } else if( $f != "" ) { $datos = array(array_fill(0, sizeof($fields), null)); } } $help = "$stit"; $traducciones = array(); $traducciones = array("mail" => "email", "mail2" => "email2", "pora" => "porcentaje_a", "porb" => "porcentaje_b", "porc" => "porcentaje_c", "pord" => "porcentaje_d"); //$traducciones = array("nombre" => "givenName", "apellido" => "familyName", "empresa" => "orgName", "telefono" => "phoneNumber", "domicilio" => "street", "cp" => "postcode", "ciudad" => "city", "provincia" => "region", "pais" => "country", "email 2" => "email2", "notas" => "notes"); $importando = false; $paso = 1; $empids = array(); $empnombres = array(); //select id, nombre into $empids[], $empnombres[] from Emprendimientos where administradora = '$administradora' and estado = 'EN FUNCIONAMIENTO'; //$emprendimientos = assocarray($empids, $empnombres); if( isset($pl) ) { foreach($fields as $ii => $tfield) { $datos[0][$ii] = $tfield; } } // Si puso header location para ir a otra pagina cierra el script if( !isset($_x) and $__exiting ) { disconnectDb($Link); exit(0); } break; } // On Refresh do { //print("
ASSOCS:
"); //print_r($associations); //print("sizeof datos: " . sizeof($datos)); //print("Importando: $importando
"); $ddform = DDFORM; $ddfield = DDFIELD; if( $importando ) { $erroresimportacion = array(); //print_r($emprendimientos); // Ver asociaciones , si existe la de consorcio chequear toda la tabla en busqueda de filas con consorcio y sin consorcio //print_r($emprendimientos); foreach($cols as $i => $col) { $assoc = $associations[$i]; if( $assoc == "consorcio" ) { //print(" COnsorcios: "); $lastvalue = ""; foreach($datos as $i0 => $row) { if( trim($row[$i]) != "" and trim($row[$i]) != $lastvalue ) { $found = searchlike($row[$i], $emprendimientos); if( $found == "" ) { $erroresimportacion[$i0] = "Consorcio no encontrado"; //print($row[$i] . " NO ENCONTRADO
"); } else { $erroresimportacion[$i0] = ""; //print($row[$i] . " ENCONTRADO $found
"); } $lastvalue = trim($row[$i]); } else if( trim($row[$i]) != "" and $found == "" ) { $erroresimportacion[$i0] = "Consorcio no encontrado"; } } } } //print_r($erroresimportacion); } if( has($_x, 'datacol') ) { if( $form != '' ) { $f2array = array(); $onlists = array(); if( $window != '' ) { $__tempresult = sqlexec($Link, "select concat('../', module, '/', window, '.php'), name, title, dbtable,dbwhere 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]; } $__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]); } } else { $__tempresult = sqlexec($Link, "select concat('../', module, '/', window, '.php'), name, title, dbtable, dbwhere 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]; } $__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]); } } if( $_mode == 'update' ) { debug("Fields to load", $f2array); $f2 = arrayToString($f2array); $t = $formdbtable; $where = $formdbwhere == '' ? '1 = 1' : $formdbwhere; if( strpos($where, '$') !== false ) { $where = replacewithvariables($where); } 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]; } if( $val != "" ) $where .= " and $onlist = '$val'"; } $datos0 = sqltoarray($Link, "select id, $_col from $t where $where"); // limit 500"); $_result['datacol'] = $datos0; } } } // Guarda plantilla de columnas if( has($_x, 'savetemplate') ) { if( $tit == "" ) { $tit = "Importacion"; } if( $window != '' ) { $__tempresult = sqlexec($Link, "select concat('../', module, '/', window, '.php'), name, title, dbtable,dbwhere 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]; } } else { $__tempresult = sqlexec($Link, "select concat('../', module, '/', window, '.php'), name, title, dbtable, dbwhere 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]; } } if( $tit == "Importacion" ) { $tit .= " " . plural(trim($formtitle)); } if( $tfolder == "" ) { $tfolder = "../files/$_filesfolder/import/templates/"; } if( !is_dir($tfolder) ) mkdir($tfolder, 0777, true); debug("Saving plantillas to " . $tfolder . "/" . $tit . ".cfg"); writeToFile($tfolder . "/" . $tit . ".cfg", $cols); debug($cols); } // Si puso header location para ir a otra pagina cierra el script if( !isset($_x) and $__exiting ) { disconnectDb($Link); exit(0); } } while(false); // PHP Vars while( ($__action == "" or $__action == "executedonopen") and isset($_GET['_x']) and empty($_x) ) { $__row0 = array(); $__row0['__unnamed6__1'] = $formname ; $__row0['__unnamed6__2'] = $formurl ; $__row0['__unnamed6__3'] = $formurl ; $__row0['__unnamed6__4'] = $formname ; $__row0['__unnamed7__1'] = $formurl ; $__row0['__unnamed7__2'] = $formurl ; $__row0['__unnamed7__3'] = $formurl ; $__row0['__unnamed7__4'] = $formname ; $__row0['__unnamed7__5'] = $formurl ; $__row0['__unnamed7__6'] = $formname ; $__row0['__unnamed7__7'] = $formname ; $__row0['__unnamed7__8'] = $formurl ; $__row0['__formimporter__1'] = $_id ; $__row0['__formimporter__2'] = $id == '0' ? 'Nuevo ' : '' ; $__row0['__formimporter__3'] = "$tit $help " ; $__row0['__sinnombre_1000__1'] = ($_mode != 'menu') ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__creaciondeplanilla__1'] = arrayToJavascriptCode($fields) ; $__row0['__creaciondeplanilla__2'] = arrayToJavascriptCode($fieldsvalues) ; $__row0['__creaciondeplanilla__3'] = arrayToJavascriptCode($fieldstooltips) ; $__row0['__creaciondeplanilla__4'] = arrayToJavascriptCode($fieldsprops) ; $__row0['__creaciondeplanilla__5'] = arrayToJavascriptCode($fieldstypes) ; $__row0['__creaciondeplanilla__6'] = arrayToJavascriptCode($fieldstitles) ; $__row0['__creaciondeplanilla__7'] = arrayToJavascriptCode($fieldsmultiple) ; $__row0['__creaciondeplanilla__8'] = arrayToJavascriptCode($datos) ; $__row0['__creaciondeplanilla__9'] = arrayToJavascriptCode($ids) ; $__row0['__creaciondeplanilla__10'] = arrayToJavascriptCode($warray) ; $__row0['__creaciondeplanilla__11'] = arrayToJavascriptCode(searchInArray(array_map('strtolower', StringTokenize($rf, ",")), array_map('strtolower',StringTokenize($f, ",")))) ; $__row0['__creaciondeplanilla__12'] = $fc ; $__row0['__creaciondeplanilla__13'] = isset($_popup) ? 10 : 50 ; $__row0['__creaciondeplanilla__14'] = isset($_popup) ? 80 : 160 ; $__row0['__seccionimportar__1'] = ($_mode != 'menu') ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__botonimportarportapapeles__1'] = (1 == 0) ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__botonimportar__1'] = $_SERVER['QUERY_STRING'] ; $__row0['__botonimportar__2'] = $ret ; $__row0['__botonimportar__3'] = $t ; $__row0['__botonimportar__4'] = strpos($tit, 'archivo 2') === false ? '' : '&nodelete' ; $__row0['__botonimportar__5'] = $ret ; $__row0['__botonimportar__6'] = $_SERVER['QUERY_STRING'] ; $__row0['__botonimportar__7'] = strpos($tit, 'archivo 2') === false ? '' : '&nodelete' ; $__row0['__botonimportar__8'] = $prefijoimportar ; $__row0['__otroscampos__1'] = (1 == 0) ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__fixed__1'] = $fixed ; $__row0['__sinnombre4__1'] = $sinnombre4 ; $__row0['__starttext__1'] = $starttext ; $__row0['__sinnombre3__1'] = $sinnombre3 ; $__row0['__nombreplantilla__1'] = $nombreplantilla ; $__row0['__sinnombre__1'] = $sinnombre ; $__row0['__asociar__1'] = ($importando == true and 1 == 0) ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__sinnombre_1004__1'] = $i ; $__row0['__sinnombre_1005__1'] = (1 == 0) ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__botonseparar__1'] = ($paso == 2) ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__archivo__1'] = "../temp/" ; $__row0['__archivo__2'] = date('Y_m') ; $__row0['__archivo__3'] = randomname() ; $__row0['__archivo__4'] = str_replace(enters(), '|', $archivo) ; $__row0['__botonpegar__1'] = (1 == 0) ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__importardesdearchivo__1'] = (1 == 0) ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__descargar__1'] = $_SERVER['QUERY_STRING'] ; $__row0['__botoncontinuar__1'] = ($_mode != 'menu' and $_mode != 'export') ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__botoncontinuar__2'] = $_SERVER['QUERY_STRING'] ; $__row0['__botoncontinuar__3'] = arrayToJavascriptCode($combos) ; $__row0['__botoncontinuar__4'] = arrayToJavascriptCode($subforms) ; $__row0['__botoncontinuar__5'] = $_SERVER['QUERY_STRING'] ; $__row0['__botoncontinuar__6'] = $_SERVER['QUERY_STRING'] ; $__row0['__botoncontinuar__7'] = $ret ; $__row0['__botoncontinuar__8'] = $prefijoimportar ; $__row0['__seleccioneunaopcinparacontinuar__1'] = ($_mode == 'menu') ? 'display: inline !important;' : 'display: none !important;' ; $__row0['__unnamed3__1'] = str_replace('_mode=menu', '_mode=insert', $_SERVER['QUERY_STRING']) ; $__row0['__unnamed4__1'] = str_replace('_mode=menu', '_mode=update', $_SERVER['QUERY_STRING']) ; $_result['morevars'] = $__row0; break; } if( has($_x, 'pdf') or has($_x, 'pdfprint') or has($_x, 'pdfprint2') ) { require_once('../include/fpdfreport.php'); $_pdf = new PDF((isset($_orientation) ? $_orientation : 'P'),'pt', (isset($_size) ? $_size : 'A4' )); $_pdf->initialPage = ($_page != '' ? $_page : 1); //$_pdf->SetAutoPageBreak(true); $_pdf->title = ""; $_pdf->SetTopMargin(50); $_pdf->AliasNbPages(); $_pdf->AddPage(); } function procesaarchivo($file, $params = array()) { global $paso; global $cols; global $datos; global $fields; global $associations; global $texto; debug("[procesaarchivo] $file"); $dir = "../temp/"; $temp_imagen = $file; $extension = strtoupper(pathinfo($temp_imagen, PATHINFO_EXTENSION)); // Controla que exista el archivo a importar if( !file_exists($dir . $temp_imagen) ) die("FILE " . $dir . $temp_imagen . " does not exist" ); logToFile("File $dir$file exists. Extension $extension"); // Si es pdf lo convierte a TXT if( $extension == 'PDF' ) { exec("/usr/bin/pdftotext -layout " . chr(34) . $dir . $temp_imagen . chr(34)); $temp_imagen = substr($temp_imagen, 0, strlen($temp_imagen) - 3) . "txt"; // Parsea $cols = array(); // Titulos de columnas $datos = array(); // Valores $texto = readFromFile($dir . $temp_imagen); $rows = StringTokenize($texto, chr(10)); $isindata = true; $isinrows = false; $irow = 0; $colspos = array(); $colspos2 = array(); // Busca linea para empezar foreach($rows as $line) { if( strtoupper(trim($line)) == "ESTADO DE CUENTA Y PRORRATEO" ) $isindata = false; } foreach($rows as $line) { if( strtoupper(trim($line)) == "ESTADO DE CUENTA Y PRORRATEO" ) { $isindata = true; continue; } if( $isindata ) { $row = array(); if( !$isinrows ) { $line = str_replace('NOMBRE DEL', 'NOMBRE_DEL', $line); $line = str_replace('SU PAGO', 'SU_PAGO', $line); $line = str_replace('SALDO A', 'SALDO_A', $line); $line = str_replace('DEL MES', 'DEL_MES', $line); } $cells = explode(" ", trim($line)); //StringTokenize($line, chr(32)); $colpos = strlen($line) - strlen(trim($line)); $emptycellcount = 0; $colindex = 0; $firstisnumber = true; $lastcell = ""; // Cuenta cantidad de palabras $cantpalabras = 0; $cantnumeros = 0; $primerpalabra = ""; foreach($cells as $cell) { if( $cell == "" ) continue; if( $cantpalabras == 0 ) $primerpalabra = $cell; $cantpalabras++; if( ismoney($cell) or is_number($cell) ) $cantnumeros++; } // Solo toma filas con 3 o mas numeros if( $cantnumeros < 3 ) continue; $cells2 = explode(" ", trim($line)); //StringTokenize($line, chr(32)); $cells3 = array(); $row2 = array(); $tcolspos = array(); $tcolspos2 = array(); foreach($cells2 as $cell2) { $cell3 = trim($cell2); if( $cell3 == "" ) { $colpos += 2; continue; } if( strpos($cell3, " ") !== false ) { $cells4 = explode(" ", $cell3); $allnumber = true; foreach($cells4 as $cell4) { if( !is_number($cell4) and !ismoney($cell4) ) { $allnumber = false; break; } } if( $allnumber ) { $colpos += strlen($cell2) - strlen(ltrim($cell2)); foreach($cells4 as $cell4) { $cells3[] = $cell4; $from = $colpos; $to = ($colpos + strlen($cell4) - 1); $colpos += strlen($cell4) + 1; $tcolspos[] = $from; $tcolspos2[] = $to; } } else { $cells3[] = $cell3; $from = ($colpos + (strlen($cell2) - strlen(ltrim($cell2)))); $to = ($colpos + strlen($cell2) - 1); $colpos += strlen($cell2) + 2; $tcolspos[] = $from; $tcolspos2[] = $to; } } else { $cells3[] = $cell3; $from = ($colpos + (strlen($cell2) - strlen(ltrim($cell2)))); $to = ($colpos + strlen($cell2) - 1); $colpos += strlen($cell2) + 2; $tcolspos[] = $from; $tcolspos2[] = $to; } } $row = $cells3; // SI es primer fila if( sizeof($colspos) == 0 ) { $colspos = $tcolspos; $colspos2 = $tcolspos2; } else { // Siguientes filas, chequea posicion for($ii = 0; $ii < sizeof($row); $ii++) { $val = $row[$ii]; //$row2[$ii] = $row2[$ii] . " tcolspos " . $tcolspos[$ii] . "," . $tcolspos2[$ii] . " colspos " . $colspos[$ii]; if( $tcolspos[$ii] < $colspos[$ii] and $tcolspos2[$ii] < $colspos[$ii] ) { /** print("

"); print(arrayToHtmlTable($colspos, $colspos2)); print(arrayToHtmlTable($tcolspos, $tcolspos2)); print("ATRAS $irow , $ii " . $tcolspos[$ii] . "," . $tcolspos2[$ii] . " " . $colspos[$ii] . " "); **/ // ATRAS for($ii2 = 0; $ii2 < $irow; $ii2++) { array_splice($datos[$ii2], $ii, 0, array("")); } array_splice($colspos, $ii, 0, array($tcolspos[$ii])); array_splice($colspos2, $ii, 0, array($tcolspos2[$ii])); /** print(arrayToHtmlTable($colspos, $colspos2)); print(arrayToHtmlTable($tcolspos, $tcolspos2)); print(arrayToHtmlTable($datos, "", "background-color:#cccccc")); print("
"); **/ } else if( $tcolspos[$ii] > $colspos2[$ii] and $tcolspos2[$ii] > $colspos2[$ii] ) { /** print("

"); print(arrayToHtmlTable($colspos, $colspos2)); print(arrayToHtmlTable($tcolspos, $tcolspos2)); print(arrayToHtmlTable($row, "", "background-color:#eeeeee")); print("ADELANTE $irow , $ii " . $tcolspos[$ii] . "," . $tcolspos2[$ii] . " " . $colspos2[$ii] . " "); **/ // ADELANTE array_splice($row, $ii, 0, array("")); array_splice($tcolspos, $ii, 0, array($colspos[$ii])); array_splice($tcolspos2, $ii, 0, array($colspos2[$ii])); /** print(arrayToHtmlTable($colspos, $colspos2)); print(arrayToHtmlTable($tcolspos, $tcolspos2)); print(arrayToHtmlTable($datos, "", "background-color:#cccccc")); print(arrayToHtmlTable($row, "", "background-color:#eeeeee")); print("
"); print(" AHORA " . arrayToString($row) . "
"); **/ } else { // Ok if( $tcolspos[$ii] < $colspos[$ii] ) $colspos[$ii] = $tcolspos[$ii]; if( $tcolspos2[$ii] > $colspos2[$ii] ) $colspos2[$ii] = $tcolspos2[$ii]; } } } /** VERSION ANTERIOR if( $isinrows and $cantnumeros < 4 ) continue; if( !$isinrows and is_number($primerpalabra) and $cantpalabras > 3 ) $isinrows = true; if( !$isinrows and $cantpalabras > 3 ) { $cols = array(); $colspos = array(); } foreach($cells as $cell) { if( $cell == "" ) { $colpos += 1; continue; } if( $isinrows and $lastcell != "" and !ismoney($lastcell) and !ismoney($cell) ) { $row[$colindex - 1] = $row[$colindex - 1] . " " . $cell; } else { $tocol = $colindex; if( $isinrows ) { // Chequea si tiene que ir a una columna mas a la derecha $distancia = abs($colspos[$colindex] - $colpos); //print(" Distancia '$cell' $colindex: $colpos " . $colspos[$colindex] . ": $distancia / "); for($iii = $colindex + 1; $iii < sizeof($colspos); $iii++) { if( abs($colpos - $colspos[$iii]) < $distancia ) { $tocol = $iii; $distancia = abs($colpos - $colspos[$iii]); } } if( $tocol > $colindex ) { //print("$colindex tocol $tocol $colpos == " . $colspos[$tocol] . " , "); //$row[$colindex] = ""; } } while($tocol >= sizeof($row) ) $row[] = ""; $row[$tocol] = $cell; $colindex++; } if( !$isinrows and $cantpalabras > 3 ) { $cols[] = $cell; $colspos[] = $colpos; } $colpos += strlen($cell) + 1; $lastcell = $cell; } //print("
"); **/ $datos[] = $row; //$datos[] = $row2; $irow++; } } // Agrega celdas vacias faltantes $maxcols = 0; foreach($datos as $dato) { if( sizeof($dato) > $maxcols ) $maxcols = sizeof($dato); } foreach($datos as $i => $dato) { if( sizeof($dato) < $maxcols ) { for($ii = sizeof($dato); $ii <= $maxcols;$ii++) { $datos[$i][] = ""; } } } /** print("DATOS:
"); foreach($datos as $dato) { print("FILA: "); print_r($dato); print("
"); } //print_r($datos); print("maxcols: $maxcols
"); print("

COLUMNAS:
"); print_r($cols); print("

COLUMNASPOS:
"); print_r($colspos); **/ $paso = 2; } // Si es excel o CSV abre el excel if( $extension == 'CSV' or $extension == 'XLS' or $extension == "XLSX" ) { $texto = ""; logToFile("Trying to open excel reader $dir$temp_imagen"); //$dataexcel = new Spreadsheet_Excel_Reader($dir . $temp_imagen, false); $objPHPExcel = PHPExcel_IOFactory::load($dir . $temp_imagen); $dataexcel = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); //print("Dataexcel:
"); //print_r($dataexcel); // Inicializacion variables $tt = 0; $rescontrol = ""; $tunidades = 0; $total = 0; // // XLS a ARRAY datos $sheet = 0; $excelrows = sizeof($dataexcel); // $dataexcel->rowcount($sheet_index=$sheet); $excelcols = $excelrows > 0 ? sizeof($dataexcel[0]) : 0; //$dataexcel->colcount($sheet_index=$sheet); //echo $dataexcel->dump($row_numbers=true,$col_letters=true,$sheet=$sheet,$table_class='excel'); $cols = array(); // Titulos de columnas $datos = array(); // Valores $icolcount = 0; for( $irow = 1; $irow <= $excelrows; $irow++ ) { $row = array(); // Si la primer celda esta vacia descarta la fila?? //if( $irow > 1 and trim($dataexcel->val($irow, 1, $sheet)) == "" ) // continue; //for( $ii = 1; $ii <= $excelcols; $ii++ ) { foreach($dataexcel[$irow] as $icolname => $ivalue) { //$val = trim($dataexcel->val($irow, $ii, $sheet)); $val = trim($ivalue); //trim($dataexcel[$irow][$ii]); //->val($irow, $ii, $sheet)); //if( $irow < 30 ) // print("$irow $ii = $val
"); if( $irow == 1 ) { $cols[] = $icolname; //$val; } $row[] = intelligentnumberconversion($val); $icolcount++; } for(;$icolcount < sizeof($fields); $icolcount++) { if( $irow == 1 ) { $cols[] = $fields[$icolcount]; } $row[] = ""; } // Descarta filas vacias $descarta = true; foreach($row as $i5 => $value5) { if( trim($value5) != "" ) $descarta = false; } if( $descarta == false ) $datos[] = $row; } //print("DATOS:
"); //print_r($datos); /** // Trata de enganchar campos $associations = array(); foreach($cols as $i0 => $col) { $combined = ""; if( trim($col) != "" ) { foreach($fields as $i1 => $field) { if( strtolower($col) == strtolower($field) ) $combined = $field; else if( strtolower($traducciones[strtolower($col)]) == strtolower($field) or strtolower($traducciones[strtolower($field)]) == strtolower($col) ) $combined = $field; } } $associations[] = $combined; } **/ $paso = 3; } else if( $extension != "PDF" ) { // Otros tipos de archivo serian Ancho fijo $cols = array(); // Titulos de columnas $datos = array(); // Valores $texto = readFromFile($dir . $temp_imagen); $rows = StringTokenize($texto, chr(10)); foreach($rows as $line) { $row = array(); $row[] = $line; $datos[] = $row; $irow++; } $paso = 2; } $archivo = ""; $importando = true; } function procesatexto($texto, $params) { global $cols; global $datos; global $fields; global $associations; global $retcrel; global $retcontrol; global $Link; $retcrel = array(); $retcontrol = array(); $cols = array(); // Titulos de columnas $datos = array(); // Valores $rows = StringTokenize($texto, chr(10)); $irow = 1; if( $params["fixed"] != "" ) { //print("FIXED COLUMNS! " . $params["fixed"]); $fixed = StringTokenize($params["fixed"], ","); $fixeda = array(); foreach($fixed as $ftext) { $fixeda[] = array(substr($ftext, 0, strpos($ftext, "[")), substr($ftext, strpos($ftext, "[") + 1, strpos($ftext, "/") - strpos($ftext, "[") - 1), substr($ftext, strpos($ftext, "/") + 1, strpos($ftext, "]") - strpos($ftext, "/") - 1)); } } //print("TEXTO : $texto
"); //print("starttext: " . $params['starttext']); $parse = trim($params['starttext']) == ""; foreach($rows as $line) { if( !$parse and strpos($line, $params['starttext']) !== false ) $parse = true; if( !$parse ) continue; if( $params["fixed"] != "" ) { $row = array(); foreach($fixeda as $fixed) { //print("(". $fixed[0] . ") ". $fixed[1] . "/" . $fixed[2] . "
"); if( $fixed[2] == "" ) $fixed[2] = strlen($line) ; $row[] = substr($line, $fixed[1] - 1, $fixed[2] - $fixed[1] + 1); if( $irow == 1 ) { $cols[] = trim($fixed[0]); //print("COL " . trim($fixed[0]) . "
"); } } } else { $row = StringTokenize(trim($line), chr(9)); if( $irow == 1 ) { $cols = $row; } } $datos[] = $row; $irow++; } //print("FIELDS: "); //print_r($fields); // Trata de enganchar campos if( !isset($associations) or sizeof($associations) == 0 ) { $associations = array(); foreach($cols as $i0 => $col) { $combined = ""; if( trim($col) != "" ) { foreach($fields as $i1 => $field) { if( strtolower($col) == strtolower($field) ) $combined = $field; else if( strtolower($traducciones[strtolower($col)]) == strtolower($field) or strtolower($traducciones[strtolower($field)]) == strtolower($col) ) $combined = $field; } } $associations[] = $combined; } } $asocdefault = true; foreach($associations as $aa) { if( $aa != "" ) $asocdefault = false; } if( $asocdefault ) { for($ii = 0; $ii < sizeof($associations); $ii++) { if( sizeof($fields) > $ii ) $associations[$ii] = $fields[$ii]; } } // Control related $arr = array(); if( $params['crel'] != "" ) { $arr = StringTokenize($params['crel'], "|"); $index = searchInArray($arr[0], $associations); if( $index >= 0 ) { foreach($datos as $line) { $val = trim($line[$index]); $ret = ""; if( $val != "" ) { $cant = sqlget($Link, "select count(*) from " . $arr[1] . " where " . $arr[0] . " = '" . $val . "'"); $ret = $cant; } $retcrel[] = $ret; } } } //print("RETCREL: "); //print_r($retcrel); // Control SUM if( $params['control'] != "" and searchInArray($params['control'], $associations) >= 0 ) { $totalsum = (double)0; foreach($datos as $irow => $line) { $sum = (double)0; foreach($line as $ii => $val) { if( $associations[$ii] != "" and $associations[$ii] != "-" and $associations[$ii] != $params['control'] and $associations[$ii] != $arr[0] ) { $val2 = str_replace('.', '', trim($val)); $val2 = str_replace(',', '.', $val2); if( substr($val2,-1,1) == "-" ) $val2 = -substr($val2,0,-1); //print("($val2)"); if( is_numeric($val2) ) { //print($val2 . " | "); $sum = $sum + (double)$val2; } } } $valsum = str_replace('.', '', $line[searchInArray($params['control'], $associations)]); $valsum = str_replace(',', '.', trim($valsum)); if( substr($valsum,-1,1) == "-" ) $valsum = -substr($valsum,0,-1); $ret = ""; if( is_numeric($valsum) and ($params['crel'] == "" or $retcrel[$irow] != "") ) { //print("Row $irow $valsum sum $sum "); //print( ($valsum != $sum ? "ERROR
" : "Ok
") ); $valsum = (double)$valsum; $dif = round($valsum - $sum, 2); $ret = ($dif != 0 ? "ERROR $valsum != $sum [$dif]" : "Ok"); $totalsum = $totalsum + $valsum; //print(" $valsum $totalsum
"); } $retcontrol[] = $ret; } $prefijoimportar = "Total " . $params['control'] . ": " . $totalsum; print($prefijoimportar); for($ii = 0; $ii < sizeof($retcrel); $ii++) { if( $retcontrol[$ii] == "" ) $retcrel[$ii] = ""; } } } if( has($_x, 'pdf') or has($_x, 'pdfprint') or has($_x, 'pdfprint2') ) { $_pdf->title = "$tit $help "; //$_pdf->drawText("$tit $help ",'Arial','',14); } // aca iba session get, uofr y load/saveobject while( has($_x, 'formimporter_init') ) { $_result['formimporter'] = $formimporter->toarray(false); break; } while( has($_x, 'formimporter') ) { //if( $errors == "" ) // validateformimporter(); if( $errors == "" ) { if( $_redirect != "" ) redirect($_redirect); sessionset('form_importerhorizontal_formimporter' . $_id, $formimporter); if( $_result['redirect'] == '' ) redirect("?id=$id"); } break; } while( has($_x, 'formimporter__delete') ) { //if( $errors == "" ) // validateformimporter(); if( $errors == "" ) { if( $_redirect != "" ) redirect($_redirect); sessionset('form_importerhorizontal_formimporter' . $_id, null); if( $_result['redirect'] == '' ) { $_result['redirect'] = "?message=$tit $help eliminado"; } } break; } while( has($_x, 'formimporter_unload') ) { // Not used break; } if( has($_x, 'sinnombre_1000') ) { $_result['sinnombre_1000_visible'] = $_mode != 'menu'; } if( has($_x, 'seccionerrores') ) { } if( has($_x, 'seccionimportar') ) { $_result['seccionimportar_visible'] = $_mode != 'menu'; } while( has($_x,'botonimportarportapapeles') ) { /** CODIGO ORIGINAL ONCLICK $onclick **/ procesatexto($pegar, $_REQUEST); $paso = 2; $archivo = ""; $importando = true; $pegar = ""; // Si puso header location para ir a otra pagina cierra el script if( !isset($_x) and $__exiting ) { disconnectDb($Link); exit(0); } break; } if( has($_x, 'otroscampos') ) { $_result['otroscampos_visible'] = 1 == 0; } while( has($_x,'guardaplantilla') ) { /** CODIGO ORIGINAL ONCLICK $onclick **/ //parse_ini_file("") $template = "fields = " . arrayToString($fields) . chr(13) . chr(10) . "associations = " . arrayToString($associations) . chr(13) . chr(10) . "fixed = " . $fixed . chr(13) . chr(10) . "starttext = " . $starttext . chr(13) . chr(10); if (!file_exists($tfolder)) mkdir($tfolder, 0777, true); writeToFile("$tfolder/" . $nombreplantilla, $template); // Si puso header location para ir a otra pagina cierra el script if( !isset($_x) and $__exiting ) { disconnectDb($Link); exit(0); } break; } if( has($_x, 'asociar') ) { $_result['asociar_visible'] = $importando == true and 1 == 0; } if( has($_x, 'sinnombre_1005') ) { $_result['sinnombre_1005_visible'] = 1 == 0; } while( has($_x,'botonseparar') ) { /** CODIGO ORIGINAL ONCLICK $onclick **/ $paso = 3; procesatexto($texto, $_POST); // Si puso header location para ir a otra pagina cierra el script if( !isset($_x) and $__exiting ) { disconnectDb($Link); exit(0); } break; } while( has($_x, "archivo__onchange") ) { debug('[gallery] onchange procesando archivo ' . $archivo ); procesaarchivo(strstr($archivo, '|', true)); $archivo = ""; $importando = true; $pegar = ""; // Si puso header location para ir a otra pagina cierra el script if( !isset($_x) and $__exiting ) { disconnectDb($Link); exit(0); } ; break; } if( has($_x, 'plantilla_select') ) { /** * ls($tfolder == "" ? "../include/plantillas" : "$tfolder/") */ $_result['plantilla_select'] = [["ls($tfolder == \"\" ? \"../include/plantillas\" : \"$tfolder/\")","ls($tfolder == \"\" ? \"../include/plantillas\" : \"$tfolder/\")"]]; } while( has($_x, "plantilla__onchange") ) { $atts = parse_ini_file("$tfolder/" . $plantilla); //print("PARSEANDO PLANTILLA " . $plantilla); //print(readFromFile("../include/plantillas/" . $plantilla)); //print_r($atts); $fields = stringToArray($atts['fields']); $fixed = $atts['fixed']; $associations = StringTokenize($atts['associations'], ","); //stringToArray($atts['associations']); $starttext = $atts['starttext']; print_r($fields); /** if( $texto != "" ) { $params = array("fixed" => $fixed, "starttext" => $starttext, "crel" => $crel, "control" => $control); procesatexto($texto, $params); } **/ $paso = 3; // Si puso header location para ir a otra pagina cierra el script if( !isset($_x) and $__exiting ) { disconnectDb($Link); exit(0); } break; } if( has($_x, 'seleccioneunaopcinparacontinuar') ) { $_result['seleccioneunaopcinparacontinuar_visible'] = $_mode == 'menu' ; } //$formimporter -> ['changes'] if( isormObject($formimporter) ) $formimporter->makeglobals(); if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['sinnombre_1000'] = ($_mode != 'menu'); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['seccionimportar'] = ($_mode != 'menu'); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['botonimportarportapapeles'] = (1 == 0); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['otroscampos'] = (1 == 0); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['asociar'] = ($importando == true and 1 == 0); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['sinnombre_1005'] = (1 == 0); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['botonseparar'] = ($paso == 2); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['botonpegar'] = (1 == 0); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['plantilla'] = (1 == 0); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['importardesdearchivo'] = (1 == 0); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['botoncontinuar'] = ($_mode != 'menu' and $_mode != 'export'); } if( isset($_GET['_x']) and empty($_x) ) { $_result['visibility']['seleccioneunaopcinparacontinuar'] = ($_mode == 'menu'); } if( has($_x, 'pdf') or has($_x, 'pdfprint') or has($_x, 'pdfprint2') ) { $_pdf->Output(); } ?> '); //echo(''); echo(''); ?> class="popup" >