Example #1
0
    function xajax()
    {
        if (gp('gp_xajax') != '1') {
            return $this->xAjaxColSave();
        }
        // No conditionals here, this is always ajax
        echo "xajax|";
        $tid = gp('gp_table_id');
        $parms['gp_table_id'] = $tid;
        $parms['gp_page'] = 'x_import';
        $parms['gp_xajax'] = '1';
        $parms['gp_map'] = gp('gp_map', '');
        //$a1=aFromgp('gp_');
        //hprint_r($a1);
        //$a2=aFromgp('txt_');
        //hprint_r($a2);
        // Look for a map delete command
        if (gpExists('gp_del')) {
            SQL("Delete from importmaps where importmap=" . SQLFC(gp('gp_del')));
            if (gp('gp_del') == gp('gp_map')) {
                gpSet('gp_map', '');
                $parms['gp_map'] = '';
            }
        }
        // Look for a map insert command. If found and works, automatically
        // select this as the map we want.
        $row = aFromGP('txt_');
        if (count($row) > 0 && gpExists('gp_new')) {
            $dd = DD_TableRef('importmaps');
            $row['table_id'] = gp('gp_table_id');
            SQLX_Insert($dd, $row);
            if (!Errors()) {
                gpSet('gp_map', $row['importmap']);
                $parms['gp_map'] = gp('gp_map');
            }
        }
        // Display a list of maps we may use
        $maps = SQL_AllRows("Select importmap,name_prefix from importmaps\n           where table_id=" . SQLFC($tid), 'importmap');
        //hprint_r($maps);
        ?>

      <h2>Map Selection</h2>
      
      <p>Please choose a map to use.  If no map exists, please create
         a new one.  After a map is chosen you can map individual columns.
      </p>
      
      <table id="x2data1">
        <thead>
          <tr><th>Map Name
              <th>Select
              <th>Delete
        </thead>
        <tbody>
      <?php 
        foreach ($maps as $map) {
            $px = $parms;
            $px['gp_map'] = $map['importmap'];
            $hp1 = http_build_query($px);
            $px['gp_del'] = $map['importmap'];
            $hp2 = http_build_query($px);
            echo $map['importmap'] == $parms['gp_map'] ? '<tr class="hilite">' : '<tr>';
            ?>
         <td><?php 
            echo $map['importmap'];
            ?>
         <td><a href="javascript:andrax('?<?php 
            echo $hp1;
            ?>
')">Select</a>
         <td><a href="javascript:andrax('?<?php 
            echo $hp2;
            ?>
')">Delete</a>
         <?php 
        }
        // Now the row for a new entry
        $px = $parms;
        $px['gp_new'] = 1;
        $hp = "'?" . http_build_query($px);
        $hp .= "&txt_importmap='+ob('txt_importmap').value";
        ?>
         <tr><td><input name="txt_importmap"   id="txt_importmap">
             <td>&nbsp;
             <td><a href="javascript:andrax(<?php 
        echo $hp;
        ?>
)">Create</a>
      </table>
      <?php 
        // If they have not picked a map, we are done.  If we continue
        // we will let them pick individual columns.
        if ($parms['gp_map'] == '') {
            return;
        }
        // Get column listing from dictionary
        $dd = DD_TableRef(gp('gp_table_id'));
        $cols = array_keys($dd['flat']);
        // Get cols available from import
        $fi = SessionGet('importfile');
        $FILE = fopen($fi['uname'], 'r');
        $sline = fsGets($FILE);
        $aline = explode('|', $sline);
        array_unshift($aline, '');
        $aline = array_combine($aline, $aline);
        // make keys and values the same
        fclose($FILE);
        // Get current map
        $mapcols = SQL_AllRows("Select column_id,column_id_src FROM importmapcolumns\n           WHERE importmap=" . SQLFC(gp('gp_map')) . "\n             AND table_id =" . SQLFC(gp('gp_table_id')), 'column_id');
        ?>
      <hr />
      <h2>Individual Column Mappings</h2>
      <table id="x2data1">
        <thead><tr><th>Destination Column</td>
                   <th>Caption</td>
                   <th>Source Column</td>
        </thead>
        <tbody>
      <?php 
        foreach ($cols as $col) {
            $value = ArraySafe($mapcols, $col, array());
            $value = ArraySafe($value, 'column_id_src', '');
            $px = $parms;
            $px['gp_xajax'] = $col;
            $andrax = "?" . http_build_query($px);
            $extra = "onchange=\"andrax('{$andrax}&gp_xval='+this.value)\"";
            $hSelect = hSelectFromAA($aline, 'anycol', $value, $extra);
            if ($dd['flat'][$col]['uino'] != 'Y') {
                ?>
            <tr><td><?php 
                echo $col;
                ?>
                <td><?php 
                echo $dd['flat'][$col]['description'];
                ?>
                <td><?php 
                echo $hSelect;
                ?>
            <?php 
            }
        }
        ?>
        </tbody>
      </table>
      <?php 
        $href = '?gp_page=x_import&gp_table_id=' . $tid . '&gp_fbproc=1' . '&gp_map=' . $parms['gp_map'];
        ?>
      <hr />
      <h2>File Process</h2>
      
      <p>The file <?php 
        echo $fi['name'];
        ?>
 was uploaded, size 
         <?php 
        echo number_format($fi['size']);
        ?>
 bytes.
      </p>
      
      <p><a href="javascript:SetAndPost('gp_nofile',1)">
         Upload A Different File
         </a>
      </p>  
         
      <p><a href="javascript:Popup('<?php 
        echo $href;
        ?>
')">Process Now</a>
      </p>
      
      <?php 
    }
Example #2
0
/**
 */
function hSelectFiltered($table_id, $columns, $name = '', $selected = '', $extra = '', $failsafe = array())
{
    // Make an empty select to return on failure
    // Get the correct table_id
    $table_id_resolved = DDTable_IDResolve($table_id);
    // Send this if we fail;
    $failed = count($failsafe) > 0 ? hSelectFromAA($failsafe, $name, $selected, $extra) : hSelect($name, $selected, '', $extra);
    // Quit on obvious problem
    if (count($columns) == 0 || !$table_id) {
        return $failed;
    }
    // Find out what column we are missing
    // And generate the where clause for the upcoming select
    $dd_ref = dd_tableRef($table_id);
    $pkeys = explode(',', $dd_ref['pks']);
    $missing = array();
    $where = array();
    foreach ($pkeys as $index => $pkey) {
        if (isset($columns[$pkey])) {
            $where[] = $pkey . " = '" . $columns[$pkey] . "'";
        } else {
            $missing[] = $pkey;
        }
    }
    $where = implode(' AND ', $where);
    // Quit if we are not missing exactly 1 column
    if (count($missing) != 1) {
        return $failed;
    }
    $missing = implode($missing, ',');
    // Find the possible values of the missing key
    $possible_sq = "SELECT distinct {$missing}\n                       FROM {$table_id_resolved}\n                      WHERE {$where}";
    $possibles = SQL_AllRows($possible_sq, $missing);
    $retval = $failsafe;
    // Let's rearrange the array to hand it to hSelectFromAA
    foreach ($possibles as $val => $aMissing) {
        $retval[$val] = $val;
    }
    return hSelectFromAA($retval, $name, $selected, $extra);
    exit;
}