Example #1
0
 function hWikiFromTable($table_id, $pagename, $flag_title = true)
 {
     $tid = SQL_ESCAPE_STRING($table_id);
     $pn = SQLFC($pagename);
     $row = SQL_OneRow("SELECT pagewiki FROM {$tid} where pagename={$pn}");
     $title = $flag_title ? $pagename : '';
     return $this->hWiki($table_id, $pagename, $row['pagewiki'], $title);
 }
Example #2
0
 function main()
 {
     if (gpExists('gp_xajax')) {
         $sq = "UPDATE variables\n                    SET variable_value = " . SQLFC(gp('varval')) . "\n                  WHERE variable = " . SQLFC(gp('variable'));
         SQL($sq);
     }
     if (gpExists('gp_cache')) {
         //unlink($GLOBALS['AG']['dirs']['dynamic'].'table_variables.php');
         OptionGet('X');
     }
     if (gpExists('gp_xajax')) {
         return;
     }
     parent::main();
 }
 function checkDBFilesForChanges()
 {
     global $parm;
     $this->LogStage("Checking spec files for changes");
     $changed = false;
     $checksums = array();
     $specboot = $parm["SPEC_BOOT"] . ".add";
     $checksums[] = array('file' => $specboot, 'md5' => md5_file($parm['DIR_PUB'] . "lib/" . $specboot), 'fullpath' => $parm['DIR_PUB'] . "lib/" . $specboot);
     if (isset($parm['INST'])) {
         $app = str_replace('_' . $parm['INST'], '', $parm['APP']);
     } else {
         $app = $parm['APP'];
     }
     if ($parm["SPEC_LIST"] != "") {
         $speclist = explode(",", $parm["SPEC_LIST"]);
         foreach ($speclist as $spec) {
             if (substr($spec, -5) != '.yaml') {
                 $file = $spec . ".add";
             } else {
                 $file = $spec;
             }
             $checksums[] = array('file' => $file, 'md5' => md5_file($parm["DIR_PUB"] . "application/" . $file), 'fullpath' => $parm["DIR_PUB"] . "application/" . $file);
         }
     }
     $checkqry = "SELECT relname FROM pg_class WHERE relname='instance_spec_checksums'";
     $checkrslts = SQL_AllRows($checkqry);
     if (count($checkrslts) == 0) {
         $this->LogEntry("Instance tracking table doesnt exist yet...ignoring until next build");
         return true;
     }
     foreach ($checksums as $checksum) {
         $query = "SELECT checksum,skey FROM " . ddTable_idResolve('instance_spec_checksums') . " WHERE \n            application=" . SQLFC($app) . " AND spec_name=" . SQLFC($checksum['file']) . (isset($parm['INST']) ? " AND instance=" . SQLFC($parm['INST']) : '');
         $row = SQL_OneRow($query);
         if ($row) {
             $this->LogEntry('Entry for ' . $checksum['file'] . ' file found');
             if ($row['checksum'] != $checksum['md5']) {
                 $this->LogEntry("Spec File Changed: " . $checksum['file']);
                 $changed = true;
                 $checksum_update = array('skey' => $row['skey'], 'checksum' => md5_file($checksum['fullpath']));
                 SQLX_Update('instance_spec_checksums', $checksum_update);
                 $this->LogEntry("Updating Entry");
             }
         } else {
             $this->LogEntry('Entry for ' . $checksum['file'] . ' not found');
             $checksum_entry = array('application' => $app, 'instance' => isset($parm['INST']) ? $parm['INST'] : '', 'spec_name' => $checksum['file'], 'checksum' => md5_file($checksum['fullpath']));
             SQLX_Insert('instance_spec_checksums', $checksum_entry);
             $this->LogEntry("Spec File Changed: " . $checksum['file']);
             $changed = true;
         }
     }
     if ($changed) {
         $this->LogEntry('One or more spec files have changed: Proceeding with full build');
     } else {
         $this->LogEntry('Spec files have not changed: Proceeding with mini build');
     }
     return $changed;
 }
Example #4
0
 function fbProcInner($fi, $t)
 {
     x_EchoFlush("BEGIN FILE PROCESSING");
     $FILE = fopen($fi['uname'], 'r');
     if (!$FILE) {
         x_EchoFlush("Trouble opening local uploaded file.");
         x_EchoFlush("ABORT WITH ERROR");
         return 0;
     }
     // Make sure first line is ok
     $line1 = fsGets($FILE);
     if (strlen($line1) == 0) {
         x_EchoFlush("Failed reading first line, file is empty?");
         x_EchoFlush("ABORT WITH ERROR");
         return 0;
     }
     if (strlen($line1) > 4998) {
         x_EchoFlush("First line is > 4998 bytes, this cannot be right.");
         x_EchoFlush("ABORT WITH ERROR");
         return 0;
     }
     // Now convert the first line into the list of columns
     $acols = explode('|', $line1);
     x_echoFlush("COLUMNS IN FILE:");
     foreach ($acols as $acol) {
         x_EchoFlush($acol);
     }
     // Retrieve maps
     $mapcols = SQL_AllRows("SELECT column_id,COALESCE(column_id_src,'') as src\n            FROM importmapcolumns\n           WHERE table_id=" . SQLFC($t['table_id']) . "\n             AND importmap=" . SQLFC(gp('gp_map')), 'column_id');
     echo "<hr>";
     echo "<h2>Map is as follows: " . gp('gp_map') . "</h2>";
     hprint_r($mapcols);
     echo "<hr>";
     // Now convert each line as we go
     $linenum = 0;
     $linesok = 0;
     while (($oneline = fsGets($FILE)) !== false) {
         $linenum++;
         // Give the user something to believe in
         if ($linenum % 100 == 0) {
             x_EchoFlush("Line: {$linenum} processing");
         }
         // Pull the line
         $data = explode('|', $oneline);
         // Maybe a problem?
         if (count($data) != count($acols)) {
             x_EchoFlush("ERROR LINE {$linenum}");
             x_EchoFlush("Too many or too few values");
             hprint_r($data);
             continue;
         }
         // No problem yet, attempt the insert
         ErrorsClear();
         // Assign first-row column names to incoming data
         $row = array_combine($acols, $data);
         // Match the values from the map
         $rowi = array();
         foreach ($mapcols as $mapcol => $info) {
             if ($info['src'] != '') {
                 if (isset($row[$info['src']])) {
                     $rowi[$mapcol] = $row[$info['src']];
                 }
             }
         }
         $mixed = array($t['table_id'] => array($rowi));
         SQLX_Cleanup($mixed);
         SQLX_insert($t, $mixed[$t['table_id']][0]);
         // Complaints?  Problems? Report them!
         if (Errors() && strpos(hErrors(), 'Duplicate Value') === false) {
             x_EchoFlush('------------------------------------------------');
             x_EchoFlush("ERROR LINE {$linenum} when attempting to insert");
             x_EchoFlush(hErrors());
             x_EchoFlush('------------------------------------------------');
             continue;
         }
         $linesok++;
     }
     return array($linenum, $linesok);
 }
Example #5
0
/**
name:rowsForSelect
parm:string Table_id
parm:string First_Letters
return:array rows

Returns an array of rows that can be put into a drop-down select box.
The first column is always "_value" and the second is always "_display".

The second parameter, if provided, filters to the results so that
only values of _display that start with "First_Letters" are returned.

For a multiple-column primary key, this routine will filter for any pk
column that exists in the session array "ajaxvars".  This feature is
controlled by an (as-yet undocumented) feature in [[ahInputsComprehensive]]
that can make inputs use Ajax when their value changes to store their
value in the session on the server.

This was created 1/15/07 to work with Ajax-dynamic-list from
dhtmlgoodies.com.
*/
function RowsForSelect($table_id, $firstletters = '', $matches = array(), $distinct = '', $allcols = false)
{
    $table = DD_TableRef($table_id);
    // Determine which columns to pull and get them
    // KFD 10/8/07, a DISTINCT means we are pulling a single column of
    //              a multiple column key, pull only that column
    if ($distinct != '') {
        $proj = $distinct;
    } else {
        if (ArraySafe($table['projections'], 'dropdown') == '') {
            if (!vgfGet('x6')) {
                $proj = $table['pks'];
            } else {
                $proj = $table['projections']['_uisearch'];
            }
        } else {
            $proj = $table['projections']['dropdown'];
        }
    }
    $aproj = explode(',', $proj);
    $acollist = array();
    foreach ($aproj as $aproj1) {
        $acollist[] = "COALESCE({$aproj1},'')";
    }
    $collist = str_replace(',', " || ' - ' || ", $proj);
    //$collist = implode(" || ' - ' || ",$acollist);
    //syslog($collist);
    // Get the primary key, and resolve which view we have perms for
    // KFD 10/8/07, do only one column if passed
    if ($distinct != '') {
        $pk = $distinct;
    } else {
        $pk = $table['pks'];
    }
    $view_id = ddtable_idResolve($table_id);
    // Initialize the filters
    $aWhere = array();
    // Generate a filter for each pk that exists in session ajaxvars.
    // There is a BIG unchecked for issue here, which is that a multi-column
    //  PK must have *all but one* column supplied, and it then returns
    //  the unsupplied column.
    $pkeys = explode(',', $table['pks']);
    $ajaxvars = afromGP('adl_');
    foreach ($pkeys as $index => $pkey) {
        if (isset($ajaxvars[$pkey])) {
            $aWhere[] = "{$pkey}=" . SQLFC($ajaxvars[$pkey]);
            // This is important!  Unset the pk column, we'll pick the leftover
            unset($pkeys[$index]);
        }
    }
    // If we did the multi-pk route, provide the missing column
    //  as the key value
    if (count($ajaxvars) > 0) {
        $pk = implode(',', $pkeys);
    }
    // Determine if this is a filtered table
    if (isset($table['flat']['flag_noselect'])) {
        $aWhere[] = "COALESCE(flag_noselect,'N')<>'Y'";
    }
    // Add more matches on
    foreach ($matches as $matchcol => $matchval) {
        $aWhere[] = $matchcol . ' = ' . SQLFC($matchval);
    }
    // See if there is a hardcoded filter in the program class
    $obj = dispatchObject($table_id);
    if (method_exists($obj, 'aSelect_where')) {
        $aWhere[] = $obj->aSelect_where();
        if (ConfigGet('LOG_SQL', 'Y') == 'Y') {
            sysLog(LOG_NOTICE, $obj->aSelect_Where());
        }
    }
    // If "firstletters" have been passed, we will filter each
    // select column on it
    //
    // KFD 8/8/07, a comma in first letters now means look in
    //             1st column only + second column only
    $SLimit = '';
    $xWhere = array();
    if ($firstletters == '*') {
        // do nothing, no where clauses
    } elseif ($firstletters != '') {
        $SLimit = "Limit 40 ";
        if (strpos($firstletters, ',') === false) {
            // original code, search all columns
            $implode = ' OR ';
            foreach ($aproj as $aproj1) {
                $type_id = $table['flat'][$aproj1]['type_id'];
                $subs = '';
                if (!in_array($type_id, array('char', 'vchar', 'text'))) {
                    $subs = '::varchar';
                }
                $sl = strlen($firstletters);
                $xWhere[] = "SUBSTRING(LOWER({$aproj1}{$subs}) FROM 1 FOR {$sl})" . "=" . strtolower(SQLFC($firstletters));
            }
        } else {
            // New code 8/8/07, search first column, 2nd, third only,
            // based on existence of commas
            $implode = ' AND ';
            $afl = explode(',', $firstletters);
            foreach ($afl as $x => $fl) {
                $type_id = $table['flat'][$aproj1]['type_id'];
                $subs = '';
                if (!in_array($type_id, array('char', 'vchar', 'text'))) {
                    $subs = '::varchar';
                }
                $sl = strlen($fl);
                $xWhere[] = "SUBSTRING(LOWER({$aproj[$x + 1]}{$subs}) FROM 1 FOR {$sl})" . "=" . strtolower(SQLFC($fl));
            }
        }
    }
    if (count($xWhere) > 0) {
        $aWhere[] = "(" . implode($implode, $xWhere) . ")";
    }
    // Finish off the where clause
    if (count($aWhere) > 0) {
        $SWhere = "WHERE " . implode(' AND ', $aWhere);
    } else {
        $SWhere = '';
    }
    // Execute and return
    $sDistinct = $distinct != '' ? ' DISTINCT ' : '';
    $SOB = $aproj[0];
    if ($allcols) {
        # KFD 6/9/08, added in automatic ordering on queuopos column
        $OB = isset($table['flat']['queuepos']) ? 'queuepos' : '2';
        $sq = "SELECT skey,{$proj}\n              FROM {$view_id}\n           {$SWhere}\n            ORDER BY {$OB} {$SLimit}";
    } else {
        $sq = "SELECT {$sDistinct} {$pk} as _value,{$collist} as _display\n              FROM {$view_id}\n           {$SWhere}\n             ORDER BY {$SOB} {$SLimit} ";
    }
    /*
    openlog(false,LOG_NDELAY,LOG_USER);
    if ( ConfigGet( 'flag_syslog', 'Y' ) == 'Y' ) {
    	   syslog(LOG_INFO,$table['projections']['dropdown']);
    	   syslogbodyRows
    	   (LOG_INFO,$sq);
    }
    closelog();
    */
    if (ConfigGet('flag_syslog', 'Y') == 'Y') {
        syslog(LOG_INFO, $sq);
    }
    $rows = SQL_Allrows($sq);
    return $rows;
}
Example #6
0
 function hMover()
 {
     // Get the parent table, and the "left" side, which is us
     $dd = ContextGet('drilldown', array());
     $tpar = $dd[0]['page'];
     $tleft = $this->table_id;
     // The right side we *assume* is the other parent table
     // of us that is not the drilldown source.  Get it?  It breaks
     // of course if this table has more than one parent
     $tables = array_keys($this->table['fk_parents']);
     unset($tables[$tpar]);
     $tright = array_pop($tables);
     // if > 1 parent, this won't work
     $dd_right = dd_tableref($tright);
     // Get match expression for left-hand side
     $matches = $dd[0]['parent'];
     $pmatch = '';
     foreach ($matches as $key => $value) {
         $ileft = $key;
         $imatch = SQLFC($value);
         $pmatch .= $key . "='" . $value . "'";
     }
     // Do an insert if coming through as ajax
     $sqins = '';
     if (gpExists('moveradd')) {
         if (gp('moveradd') != '0') {
             $row1 = array($dd_right['pks'] => gp('moveradd'));
             $row2 = $dd[0]['parent'];
             $rowi = array_merge($row1, $row2);
             SQLX_Insert($this->table_id, $rowi);
         } else {
             $tab = $this->table_id;
             $cols = $this->table['pks'];
             $colr = $dd_right['pks'];
             $sqins = "insert into {$tab}\n                   ( {$cols} ) \n                  SELECT {$imatch}, {$colr} \n                    FROM {$tright}\n                  WHERE NOT EXISTS (\n                    SELECT * FROM {$tleft}\n                     WHERE {$tleft}.{$key} = {$imatch}\n                       AND {$tleft}.{$colr} = {$tright}.{$colr})";
             SQL($sqins);
         }
     }
     // Do a delete if coming through as ajax
     $sqldel = 'hi';
     if (gpExists('moverdel')) {
         $sqldel = 'moverdel exists';
         if (gp('moverdel') != '0') {
             $sqldel = "delete from " . ddTable_idResolve($this->table_id) . " where skey=" . SQLFN(gp('moverdel'));
             //echo "echo|$sq";
         } else {
             $sqldel = "delete from " . ddTable_idResolve($this->table_id) . " WHERE " . $pmatch;
         }
         SQL($sqldel);
     }
     # Pull the source table, the right-hand side
     # KFD 6/9/08, make left hand side sort by description
     #             if present.
     $vright = ddTable_idResolve($tright);
     $vleft = ddTable_idResolve($tleft);
     $ob = $dd_right['pks'];
     $ljoin = '';
     $lob = '';
     if (isset($dd_right['flat']['description'])) {
         $ob = 'description';
         $ljoin = " JOIN {$vright} r ON {$vleft}." . $dd_right['pks'] . '=r.' . $dd_right['pks'];
         $lob = ' ORDER BY r.description';
     }
     $sq = "SELECT " . $dd_right['pks'] . " as pk\n                 ,description\n             FROM " . ddTable_idResolve($tright) . "\n            WHERE description <> ''\n            ORDER BY {$ob}";
     $rows_right = sql_allrows($sq, 'pk');
     # Left side table.
     $sq = "SELECT {$vleft}." . $dd_right['pks'] . " as pk,{$vleft}.skey\n             FROM " . ddTable_IDResolve($this->table_id) . $ljoin . ' ' . " WHERE {$pmatch} {$lob}";
     $rows_left = sql_allrows($sq, 'pk');
     // Convert the left hand side into options
     $ahl = array();
     foreach ($rows_left as $row) {
         if (isset($rows_right[trim($row['pk'])])) {
             $ahl[] = "<OPTION " . ' VALUE="' . $row['skey'] . '"' . '>' . $rows_right[trim($row['pk'])]['description'] . '</option>';
         }
     }
     // Convert the right hand side into options
     $ahr = array();
     foreach ($rows_right as $row) {
         if (!isset($rows_left[trim($row['pk'])])) {
             $ahr[] = "<OPTION " . ' VALUE="' . $row['pk'] . '"' . '>' . $row['description'] . '</option>';
         }
     }
     ob_start();
     ?>
   <table class="table table-bordered table-striped table-condensed">
     <tr>
     <td>
        <b>Selected Values</b><br/><br/> 
        <select size=20 style="width: 250px"
           onclick="formPostAjax('&gp_xajax=1&moverdel='+this.value)"
           >
        <?php 
     echo implode("\n", $ahl);
     ?>
        </select>
     <td style="padding:10px; vertical-align: top">
        <br/>
        <br/>
        <button onclick="formPostAjax('&gp_xajax=1&moveradd=0')"
              >&lt;&lt; All</button>
        <br/>
        <br/>
        <button onclick="formPostAjax('&gp_xajax=1&moverdel=0')"
              >All &gt;&gt;</button>
     <td>
        <b>Available Values</b><br/><br/> 
        <select size=20 style="width: 250px"
           onclick="formPostAjax('&gp_xajax=1&moveradd='+this.value)"
           >
        <?php 
     echo implode("\n", $ahr);
     ?>
        </select>
   </table>
   <?php 
     $this->h['Content'] = ob_get_clean();
     if (gpexists('gp_xajax')) {
         echo 'mover|' . $this->h['Content'];
         if (errors()) {
             echo "|-|echo|" . asErrors();
         }
         exit;
     } else {
         $this->h['Content'] = '<div id="mover">' . $this->h['Content'] . '</div>';
     }
 }
Example #7
0
    function ehTab_Filters($ajax = true)
    {
        if ($ajax) {
            echo "x2_content|";
        }
        $skey = SQLFN(gp('gp_skey'));
        $report = SQL_OneValue('report', "Select report from reports where skey={$skey}");
        // Do any processing that may have come through
        if (gp('gp_ajax') == 'filtrep') {
            $repfilters = SQLFC(gp('gp_val'));
            //echo "we are setting $repfilters";
            SQL("UPDATE reports SET repfilters={$repfilters} WHERE skey={$skey}");
        }
        if (gp('gp_ajax') == 'filtlev') {
            $repfilters = SQLFC(gp('gp_val'));
            $skeylev = SQLFN(gp('gp_skeylev'));
            SQL("UPDATE reportlevels \n                 SET repfilters={$repfilters} WHERE skey={$skeylev}");
        }
        // Retrieve and display
        $repfilter = SQL_OneValue('repfilters', "Select skey,repfilters from reports where skey={$skey}");
        $levs = SQL_AllRows("Select rl.skey,rl.reportlevel,rl.repfilters \n           from reportlevels    rl\n          WHERE exists ( SELECT * from reportcollevels\n                          WHERE report = '{$report}'\n                            AND reportlevel = rl.reportlevel)\n            AND report='{$report}'");
        //echo hErrors();
        // Now for each level list some filters
        ?>
      <table>
        <tr>
          <td class="dhead" style="width: 10em">Level</td>
          <td class="dhead">SQL Filters</td>
          <td class="dhead">Save</td>
        </tr>
        <tr>
          <td valign=top>Base</td>
          <td><textarea id='lev0' name="lev0"
                   cols=60
                   rows=5 
                  style="border:1px solid gray"
                ><?php 
        echo $repfilter;
        ?>
</textarea></td>
           <td><a href="javascript:sndReq('&gp_ajax=filtrep&gp_val='+encodeURIComponent(ob('lev0').value))">Save</a>

        </tr>
      <?php 
        foreach ($levs as $lev) {
            $js = '&gp_ajax=filtlev&gp_skeylev=' . $lev['skey'];
            ?>
         <tr>
           <td valign=top><?php 
            echo $lev['reportlevel'];
            ?>
</td>
           <td><textarea 
                    cols=60 
                    rows=5 
                   style="border:1px solid gray"
               onchange="sndReq('<?php 
            echo $js;
            ?>
&gp_val='+this.value)"
                 ><?php 
            echo $lev['repfilters'];
            ?>
</textarea></td>
         </tr>
         <?php 
        }
        ?>
      </table>
      <br/>
      <h3>Columns in this report</h3>
      <table style="width:50%">
        <tr>
          <td class="dhead">Description</td>
          <td class="dhead">Table</td>
          <td class="dhead">Column</td>
        </tr>
        <?php 
        // Columns in this report
        $sql = "SELECT description,table_id,column_id from reportcolumns\n                WHERE report = '{$report}'\n                ORDER BY description";
        $cols = SQL_Allrows($sql);
        foreach ($cols as $col) {
            ?>
            <tr><td><?php 
            echo $col['description'];
            ?>
                <td><?php 
            echo $col['table_id'];
            ?>
                <td><?php 
            echo $col['column_id'];
            ?>
            <?php 
        }
        ?>
      </table>
      <?php 
    }
Example #8
0
    function main()
    {
        switch (gp('gp_action')) {
            case 'pull':
                $this->mainPull();
                break;
            case 'over':
                $this->mainOver();
                break;
            case 'diff':
                $this->mainDiff();
                break;
        }
        if (gp('gp_action') != '') {
            return;
        }
        if (gpExists('gp_clearremote')) {
            SessionSet('remoteUID', '');
            SessionSet('remotePWD', '');
            SessionSet('remoteNODE', '');
        }
        // Need this basic stuff for everything
        $skey = gp('gp_skey');
        hidden('gp_skey', $skey);
        hidden('gp_page', 'a_scontrol');
        $row = SQL_OneRow("Select * from applications WHERE skey={$skey}");
        $App = trim($row['application']);
        $sApp = SQLFC($App);
        $node = SQL_OneRow("Select * from nodes WHERE node=" . SQLFC($row['node']));
        $this->row = $row;
        $this->node = $node;
        // Some file functions execute before showing the screen, because
        // they affect what is displayed on the screen
        switch (gp('gpfa')) {
            case 'patch':
                $this->Patch();
                break;
            case 'overlocal':
                $this->OverLocal();
                break;
            case 'servsend':
                $this->ServerSend();
                break;
            case 'servdel':
                $this->ServerDel();
                break;
        }
        $h1 = "?gp_page=a_scontrol" . "&gp_action=pull&gp_url=" . $node['node_url'] . "&gp_app=" . $App;
        $h2 = "?gp_page=a_scontrol&gp_action=over";
        $h3 = "?gp_page=a_scontrol&gp_skey={$skey}";
        ?>
      <h1>Source Code Operations</h1>
      <p>For application 
         <a href="?gp_page=applications&gp_skey=<?php 
        echo $skey;
        ?>
"><?php 
        echo $App;
        ?>
</a>.
      </p>
      <?php 
        echo sourceDeprecated();
        ?>
      <?php 
        if (!$this->CheckRemoteUID($node['node'])) {
            return;
        }
        ?>

      <p><a href="javascript:formPostString('x=y')">Refresh This Page</a></p>
      <p>The Authoritative Node for this application is 
         <?php 
        echo $node['node'];
        ?>
 at <?php 
        echo $node['node_url'];
        ?>
.
         You are using username <b><?php 
        echo SessionGet('remoteUID');
        ?>
</b> on
         the remote node.
         <a href="javascript:formPostString('gp_clearremote=1')">Connect as New User</a>.
      </p>
      <br>
      
      <style>table.sc td { padding: 3px; }</style>
      <table cellpadding=0 cellspacing=0 class="sc">
        <tr><td class="dhead" width=100>Function</td>
            <td class="dhead">Details</td>
        <tr><td>
            <a href="javascript:Popup('<?php 
        echo $h1;
        ?>
')">
               Update Reference</a>
            <td>Pulls the latest code from the Authoritative Node and puts
                it into the "ref" directory of the application.  Does not
                modify programs in 'application' or 'appclib' (or 'lib',
                'clib', 'root' and 'templates' for the node manager).
        <!--
        <tr><td>
            <a href="javascript:Popup('< ?=$h2? >')">
               Overwrite From Reference</a>
            <td><font color=red>Unconditionally destroys any code you have
                for this application</font> and replaces it with the
                reference code. Before being destroyed, the code is backed up into
                a directory named "ref-"+current timestamp, so that it can
                be recovered if necessary.  It is the programmer's
                responsibility to delete these backup directories as desired.
           -->
      </table>
      <?php 
        $hbase = "?gp_page=a_scontrol&gp_app={$App}&gp_skey={$skey}";
        $dir = AppDir($App);
        $dirs = AppDirs($App);
        $filesL = array();
        $filesR = array();
        clearstatcache();
        // need this before scanning dirs
        foreach ($dirs as $onedir) {
            $this->WalkDir($filesL, $dir, trim($onedir));
            $this->WalkDir($filesR, $dir . "ref/", trim($onedir));
        }
        // Files they have and we don't. Pretty easy
        ?>
      <br><br>
      <h2>Server Files Not on Local Machine</h2>
      <table>
        <tr><td class="dhead">Filename
            <td class="dhead">&nbsp;
            <td class="dhead">&nbsp;
      <?php 
        $count = 0;
        foreach ($filesR as $name => $fileR) {
            if (!isset($filesL[$name])) {
                $hlinkC = $hbase . '&gpfa=overlocal' . '&gpfile=' . urlencode($name);
                $hlinkD = $hbase . '&gpfa=servdel' . '&gpfile=' . urlencode($name);
                $count++;
                $row = array($name, "&nbsp&nbsp;<a href='{$hlinkC}'>Overwrite Local</a>&nbsp&nbsp;", "&nbsp&nbsp;<a href='{$hlinkD}'>Delete From Server</a>&nbsp&nbsp;");
                echo hTRFromArray('', $row);
            }
        }
        if ($count == 0) {
            echo hTrFromArray('', array('none', ''));
        }
        echo "</table>";
        // Files we have and they dont
        ?>
      <br><br>
      <h2>Local Files Not on Server</h2>
      <table>
        <tr><td class="dhead">Name
            <td class="dhead">&nbsp;
      <?php 
        $count = 0;
        foreach ($filesL as $name => $fileL) {
            if (!isset($filesR[$name])) {
                $count++;
                $hlink = $hbase . '&gpfa=servsend' . '&gpfile=' . urlencode($name);
                $row = array($name, "&nbsp&nbsp;<a href='{$hlink}'>Send To Server</a>&nbsp&nbsp;");
                echo hTRFromArray('', $row);
            }
        }
        if ($count == 0) {
            echo hTrFromArray('', array('none', ''));
        }
        echo "</table>";
        ?>
      <br><br>
      <h2>Files That Are Different</h2>
      <table>
        <tr><td class="dhead">Name
            <td class="dhead">Differences
            <td class="dhead">&nbsp;
            <td class="dhead">&nbsp;
            <td class="dhead">&nbsp;
      <?php 
        foreach ($filesR as $name => $fileR) {
            if (!isset($filesL[$name])) {
                continue;
            }
            $fileL = $filesL[$name];
            $diffs = array();
            if ($fileL['fsize'] != $fileR['fsize']) {
                $diffs[] = 'fsize';
            }
            if ($fileL['md5'] != $fileR['md5']) {
                $diffs[] = 'md5';
            }
            if (count($diffs) != 0) {
                $hlinkP = $hbase . '&gpfa=patch' . '&gpfile=' . urlencode($name);
                $hlinkC = $hbase . '&gpfa=overlocal' . '&gpfile=' . urlencode($name);
                $hlinkD = "javascript:Popup('{$hbase}" . '&gp_action=diff' . '&gpfile=' . urlencode($name) . "')";
                $row = array($name . "&nbsp;&nbsp;", "&nbsp;&nbsp;" . implode(' ', $diffs) . "&nbsp;&nbsp;", "&nbsp;&nbsp;<a href='{$hlinkP}'>Patch To Server</a>&nbsp;&nbsp;", "&nbsp;&nbsp;<a href='{$hlinkC}'>Overwrite Local</a>&nbsp;&nbsp;", "&nbsp;&nbsp;<a href=\"{$hlinkD}\">View Diff</a>&nbsp;&nbsp;");
                echo hTRFromArray('', $row);
            }
        }
        echo "</table>";
        //hprint_r($filesL);
        //hprint_r($filesR);
        /*
        <table cellpadding=0 cellspacing=0 class="sc">
          <tr><td class="dhead">File</td>
              <td class="dhead">Local</td>
              <td class="dhead">Reference</td>
              <td class="dhead">Patch to Server</td>
              <td class="dhead">New To Server</td>
              <td class="dhead">Ovewrite Local</td>
        */
    }
Example #9
0
    function main()
    {
        $app = gp('gp_app');
        // Today's date will become version.  Confirm that it is ok
        $v = date("Y.m.d", time());
        $mv = SQL_AllRows("Select version from appversions \n           where version = '{$v}'\n             AND application=" . SQLFC($app));
        if (count($mv) > 0) {
            ?>
         <div class="errorbox">There is already a version of the application
           stamped for today.  Cannot have two versions in the same day.
         </div>
         <?php 
            return;
        }
        // Will need list of directories.
        if ($app == 'andro') {
            $dirs = SQL_AllRows("Select * from appdirs where flag_copy='Y'");
        } else {
            $dirs = SQL_AllRows("Select * from appdirs where flag_copy='Y'\n                AND flag_lib='N'");
        }
        // Determine the app and root directory
        // Get the app
        $this->app = $app;
        $root = SQL_OneValue('dir_pub', "select wp.dir_pub \n           from webpaths     wp\n           JOIN applications ap ON wp.webpath=ap.webpath\n          WHERE ap.application = " . SQLFC($app));
        $root = AddSlash($root) . AddSlash($app);
        $this->root = $root;
        //x_echoFlush("Root directory will be: ".$root);
        // Either run the process....
        if (gp('gp_process') == 1) {
            ob_start();
            $this->mainProcess($v, $dirs);
            echo ob_end_clean();
            return;
        }
        $link = '?gp_page=appversions_p&gp_process=1&gp_app=' . gp('gp_app');
        // ...or ask them to click the button
        ?>
      <h1>Freeze Current Version</h1>
      <p>This program will create a new version of all application files
         for application <?php 
        echo hSanitize(gp('gp_app'));
        ?>
.
         It will copy all disk files into the database.
         The version will be numbered as <?php 
        echo $v;
        ?>
.
      </p>
         
      <p>The top level directory to be scanned is: <?php 
        echo $root;
        ?>
.
      </p>
      
      <p>The subdirectories to be scanned are:
      </p>
      <ul>
      <?php 
        foreach ($dirs as $dir) {
            echo "<li>" . $dir['dirname'];
        }
        ?>
      </ul>
         
      <p><a href="javascript:Popup('<?php 
        echo $link;
        ?>
')">Process Now</a>
      </p>
      
      <?php 
    }
Example #10
0
    function main()
    {
        $app = gp('gp_app');
        $sApp = SQLFC(gp('gp_app'));
        $sInst = SQLFC(gp('gp_inst'));
        $hApp = hSanitize(gp('gp_app'));
        $hInst = hSanitize(gp('gp_inst'));
        $rows = SQL_AllRows("SELECT * from instances \n           where application={$sApp} AND instance={$sInst}");
        if (count($rows) != 1) {
            ?>
         <div class="errorbox">Incorrect call to instance processing.</div>
         <?php 
            return;
        }
        $row = $rows[0];
        $hVer = hSanitize(trim($row['version']));
        // Maybe we are on processing branch
        if (gp('gp_posted') == 1) {
            $this->Process($rows[0]);
            return;
        }
        // KFD 2/4/08, Modify this to look for versions on disk
        //     for an svn-enabled server node
        $hWarn = '';
        $av = '';
        if (OptionGet('DEV_STATION', '') == 'N') {
            $sq = "Select * from applications where application={$sApp}";
            $rapp = SQL_OneRow($sq);
            if (trim($rapp['svn_url']) == '') {
                $hWarn = '<br/><br/><b>Subversion url needed.</b> ' . 'You can begin by providing a URL to the subversions ' . 'repository for this application on ' . '<a href="?gp_page=applications&gp_skey=' . $rapp['skey'] . '">the editing screen</a>.';
            }
            $versions = svnVersions();
            $verx = trim($versions[$app]['local']);
            $av = "<p>Latest Andromeda Version: " . trim($versions['andro']['local']);
        } else {
            // Get the current version, and get the latest version available
            $verx = SQL_OneValue("mv", "Select max(version) as mv from appversions\n               WHERE application={$sApp}");
            if (is_null($verx)) {
                $verx = '';
            }
        }
        ?>
        <h1>Instance Upgrade</h1>
        <p>Application: <?php 
        echo $hApp;
        ?>
   </p>
        <p>Instance: <?php 
        echo $hInst;
        ?>
     </p>
        <p>Current Version: <?php 
        echo $hVer == '' ? '-none-' : $hVer;
        ?>
 </p>
        <p>Latest Version Available: <?php 
        echo $verx == '' ? '-none-' : $verx;
        ?>
 </p>
        <?php 
        echo $av;
        ?>
 
        <p>&nbsp;</p>
        <p>
        <?php 
        if ($verx == '') {
            ?>
            <b>No official versions are available.</b>  An instance can only
            be upgraded when an official version is available.  You may
            download release code for this application, or you may
            generate files out of your development code.
            </p>
            <?php 
            echo $hWarn;
            ?>
            <?php 
            return;
        } else {
            $caption = $hVer == '' ? 'Build as ' : 'Upgrade To';
            echo hLinkPopup('', $caption . ' version ' . $verx, array('gp_app' => gp('gp_app'), 'gp_inst' => gp('gp_inst'), 'gp_posted' => 1, 'gp_page' => 'instances_p2', 'gp_out' => 'none', 'gp_ver' => $verx));
        }
    }
Example #11
0
 function PW_ForgotPage3()
 {
     $retval = false;
     $UID = gp('uid');
     $eml = gp('eml');
     $hash = gp('hash');
     $pw1 = gp('pw1');
     $pw2 = gp('pw2');
     if ($pw1 != $pw2) {
         ErrorAdd("Password values did not match");
     }
     if (strlen($pw1) < 5) {
         ErrorAdd("Password must be at least 5 characters");
     }
     if (Errors()) {
         echo hErrors();
         gpSet('gpp', '2');
         ErrorsClear();
         return;
     }
     // confirm that user/hash is ok
     //
     scDBConn_Push('usermaint');
     $sql = "\nSelect count(*) as cnt \n  FROM users \n where LOWER(email) =" . SQLFC($eml) . "\n   and user_pwkey   =" . SQLFC($hash) . "\n   and user_disabled<>'Y'";
     $cnt = SQL_OneValue('cnt', $sql);
     if ($cnt == 0) {
         ErrorAdd("Bad Link, cannot reset password.");
     }
     scDBConn_Pop();
     if (Errors()) {
         echo hErrors();
         gpSet('gpp', '2');
         ErrorsClear();
         return;
     }
     // All is clear, update the password
     scDBConn_Push('usermaint');
     $sql = "\nUPDATE users SET member_password="******"\n WHERE email = " . SQLFC($eml);
     SQL($sql);
     scDBConn_Pop();
     if (Errors()) {
         echo hErrors();
         gpSet('gpp', '2');
         ErrorsClear();
     } else {
         echo "Password has been reset!";
     }
 }
Example #12
0
 function viewClob()
 {
     $table_id = gp('x6page');
     $skey = SQLFC(gp('skey'));
     $column = gp('column');
     $sql = 'SELECT "' . $column . '" from "' . $table_id . '" where skey= ' . $skey;
     echo "<pre>";
     $text = SQL_OneValue($column, $sql);
     echo $text;
     file_put_contents(fsDirTop() . 'tmp/viewClob.txt', $text);
     echo "</pre>";
     exit;
 }
Example #13
0
function index_hidden_x6FETCH()
{
    $returns = array();
    # This is everything that *might* go back, make a place
    # for all of it
    $GLOBALS['AG']['x4'] = array('error' => array(), 'debug' => array(), 'notice' => array(), 'html' => array(), 'script' => array());
    // First fetch the values
    $table_id = gp('x6fetch');
    $dd = ddTable($table_id);
    $column = gp('x6col');
    $colvalue = gp('x6val');
    # Look for fetch columns that pull from this column's
    # table_id_fko
    $tfko = $dd['flat'][$column]['table_id_fko'];
    $cfko = $dd['flat'][$column]['column_id_fko'];
    $cols = array();
    foreach ($dd['flat'] as $fcol => $cdetails) {
        $arr = array('FETCH', 'FETCHDEF', 'DISTRIBUTE');
        if (in_array($cdetails['automation_id'], $arr)) {
            if ($cdetails['auto_table_id'] == $tfko) {
                $cols[$fcol] = $cdetails['auto_column_id'];
            }
        }
    }
    # We now have a list of source and destination
    # columns, build the query
    $sql = "Select " . implode(',', $cols) . " FROM {$tfko} WHERE {$cfko} = " . SQLFC($colvalue);
    $row = SQL_OneRow($sql);
    foreach ($cols as $fcol => $srccol) {
        $type = $dd['flat'][$fcol]['formshort'];
        if ($type == 'date') {
            x6html("x6inp_{$table_id}_{$fcol}", date("Y-m-d", dEnsureTs($row[$srccol])));
        } else {
            x6html("x6inp_{$table_id}_{$fcol}", $row[$srccol]);
        }
    }
    echo json_encode_safe($GLOBALS['AG']['x4']);
    exit;
}
Example #14
0
 function PullCodeApp($row)
 {
     $app = trim($row['application']);
     $sApp = SQLFC($app);
     $ver = $row['version'];
     $sVer = SQLFC($ver);
     x_echoFlush("");
     x_EchoFlush("*** Application: " . $row['application']);
     x_EchoFlush("  Authoritative Node is: " . $row['node']);
     x_EchoFlush("  Current Local Version: " . $ver);
     // Get version from remote node
     $remote = $this->CURL($row['node_url'], "select max(version) as version\n             FROM appversions\n            WHERE application={$sApp}");
     if (count($remote) == 0) {
         x_EchoFlush("The remote server says it's got nothing for us!");
     } else {
         $vremote = $remote[0]['version'];
         x_EchoFlush("  Remote server has version: {$vremote}");
         if ($vremote == $ver) {
             x_EchoFlush("Local version is up-to-date, nothing to do here.");
         } elseif ($vremote < $ver) {
             x_EchoFlush("Local version is more recent.");
             x_EchoFlush("  --> this should not normally happen, perhaps");
             x_EchoFlush("      somebody published code on this machine?");
         } else {
             x_EchoFlush("Local version out of date, pulling latest");
             $this->VersionPull($app, $vremote, $row);
             $table_dd = DD_TableRef('appversions');
             $row = array('application' => $app, 'version' => $vremote);
             SQLX_Insert($table_dd, $row);
             echo hERrors();
         }
     }
 }
Example #15
0
    function ProcessData_OneTable($table)
    {
        $tab = trim($table["table_id"]);
        ob_start();
        ?>
       <table class="table table-striped table-bordered table-condensed table-hover">
          <thead>
          <tr>
              <th>Module</th>
              <th>Parent Tables</th>
              <th>Child Tables</th>
          </tr>
          </thead>
          <tr>
      <?php 
        echo "<td>" . $this->PageLink('Module', $table['module']);
        $pars = SQL_AllRows("Select table_id_par from zdd.tabfky\n           WHERE table_id = '{$tab}'");
        $hpars = array();
        echo "<td>";
        foreach ($pars as $par) {
            $hpars[] = $this->pagelink('Table', $par['table_id_par']);
        }
        echo implode(',&nbsp; ', $hpars);
        echo "<td>";
        $pars = SQL_AllRows("Select table_id from zdd.tabfky\n           WHERE table_id_par = '{$tab}'");
        $hpars = array();
        foreach ($pars as $par) {
            $hpars[] = $this->pagelink('Table', $par['table_id']);
        }
        echo implode(',&nbsp; ', $hpars);
        echo "</table>";
        echo "<br><br>";
        echo "<h3>Column Definitions:</h3><br/>";
        $this->ehTableHeader();
        $titles = array('Column', 'Caption', 'PK', 'Browse', 'Stats', 'Automation', 'Parent');
        echo hTRFromArray('adocs_th dark', $titles);
        $cols = SQL_AllRows("select * from zdd.tabflat where table_id = '{$tab}'\n          ORDER BY uicolseq", 'column_id');
        $hCalcCon = array();
        foreach ($cols as $row) {
            $column_id = $row['column_id'];
            $display = array($row['column_id'], $row['description'], $row['primary_key'], $row['uisearch'], $row['formula'], $this->MakeAutomation($row), $this->pagelink('Table', $row['table_id_fko']));
            echo hTRFromArray('', $display);
        }
        echo "</table>\n";
        // Output chain: Calculations and extensions
        $colsCons = SQL_AllRows("\nSelect c.* from zdd.colchains c\n  JOIN zdd.column_seqs     seq\n    ON c.table_id = seq.table_id\n   AND c.column_id= seq.column_id\n WHERE c.table_id = '{$tab}' \n ORDER BY seq.sequence,chain");
        echo "<br>";
        echo "<div class=\"head1\">Column Calculations and Constraints</div>";
        if (count($colsCons) == 0) {
            echo "There are no constraints or calculations for this table.";
        }
        foreach ($colsCons as $colsCon) {
            $column_id = $colsCon['column_id'];
            echo "<br>";
            echo "<div class=head2>" . "Column: " . $cols[$column_id]['description'] . " ({$column_id}) " . ($colsCon['chain'] == 'calc' ? 'Calculation' : 'Constraint') . "</div>";
            ?>
		<table class="table table-striped table-bordered table-condensed table-hover">
			<thead>
				<tr>
					<th width=50% class="adocs_th">Test</th>
					<th width=50% class="adocs_th">Returns</th>
				</tr>
			</thead>
			<tbody>
				<tr>
         <?php 
            $tests = SQL_AllRows("\nselect arg.*,test.funcoper,test.compoper \n  from zdd.colchainargs  arg \n  JOIN zdd.colchaintests test \n    ON arg.uicolseq = test.uicolseq\n WHERE arg.table_id = '{$tab}'\n   AND arg.column_id = " . SQLFC($column_id) . "\n ORDER by uicolseq,argtype,sequence");
            $cat = '';
            $cui = 0;
            foreach ($tests as $test) {
                $at = $test['argtype'];
                $ui = $test['uicolseq'];
                // Change from one row to the other requires closeup
                if ($cui != $ui) {
                    if ($cui != 0) {
                        echo "</tr>";
                    }
                    // close prior row
                    $cui = $ui;
                    echo "<tr><td>";
                    // open new row and cell
                    if ($at == 0) {
                        echo $test['compoper'] . "&nbsp;";
                    }
                    $cat = 0;
                }
                // when changing from comparison to
                if ($at == 1 && $cat == 0) {
                    echo "<td>" . $test['funcoper'] . "&nbsp;";
                    $cat = $at;
                }
                if ($test['column_id_arg'] != '') {
                    echo "@" . $test['column_id_arg'] . "&nbsp;";
                } else {
                    echo $test['literal_arg'] . "&nbsp;";
                }
            }
            echo "</tr>";
            echo "</tbody>";
            echo "</table>";
        }
        echo "<br><br>";
        echo "This tables's permissions by group: ";
        $this->ehtableheader();
        $headers = array('Group', 'Select', 'Insert', 'Update', 'Delete');
        echo hTRFromArray('adocs_th', $headers);
        $bymods = SQL_AllRows("SELECT * FROM zdd.perm_tabs\n            WHERE table_id = '{$tab}'\n            ORDER BY group_id");
        foreach ($bymods as $bymod) {
            if (!$this->ProcessGroup($bymod['group_id'])) {
                continue;
            }
            $display = array($this->pageLink('Group', $bymod['group_id']), $this->PermResolve($bymod['permsel']), $this->PermResolve($bymod['permins']), $this->PermResolve($bymod['permupd']), $this->PermResolve($bymod['permdel']));
            echo hTRFromArray('', $display);
        }
        echo "</table>";
        $pagetext = ob_get_Clean();
        $this->PageUpdate('Table: ' . $table['table_id'], $pagetext, 'Tables');
    }
Example #16
0
 /**
  *  Takes a list of tables and UNIONs them together
  *  and builds the complete query for them.  Supports
  *  only very limited abilities at this time, basically
  *  assuming the queries are defined correctly and
  *  doing a UNION ALL.
  *
  *  Returns: A SQL SELECT statement
  */
 function genSQLSectionUnion($yamlP2)
 {
     $page = $this->page;
     $uifilter = $this->page['uifilter'];
     $sql = array();
     foreach ($yamlP2 as $table_id => $tabinfo) {
         $SQL_COLSWHA = array();
         $collist = array("'{$table_id}' as _source");
         $collist[] = 'skey';
         foreach ($tabinfo['column'] as $column_id => $colinfo) {
             if (a($colinfo, 'constant', '') != '') {
                 $collist[] = SQLFC($colinfo['constant']) . " as {$column_id}";
             } else {
                 $collist[] = "{$table_id}.{$column_id}";
                 # KFD 6/18/08, reroute to new SQLFilter
                 #$compare = sqlFilter($colinfo,
                 $compare = $this->SQLCompare($table_id, $column_id, $colinfo);
                 if ($compare != '') {
                     $SQL_COLSWHA[] = $compare;
                 }
             }
         }
         $sq = "SELECT " . implode("\n      ,", $collist) . " FROM {$table_id} ";
         if (count($SQL_COLSWHA) > 0) {
             $sq .= "\n WHERE " . implode("\n   AND ", $SQL_COLSWHA);
         }
         $sql[] = $sq;
     }
     # Build the sql
     $sql = implode("\nUNION ALL\n", $sql);
     if (gp('gp_post') == 'onscreen') {
         $sql .= " LIMIT " . configGet('sql_limit');
     }
     return $sql;
 }
Example #17
0
function RowsForSelect($table_id, $firstletters = '', $matches = array(), $distinct = '', $allcols = false)
{
    $table = ddTable($table_id);
    // Determine which columns to pull and get them
    // KFD 10/8/07, a DISTINCT means we are pulling a single column of
    //              a multiple column key, pull only that column
    if ($distinct != '') {
        $proj = $distinct;
    } else {
        if (ArraySafe($table['projections'], 'dropdown') != '') {
            $proj = $table['projections']['dropdown'];
        }
        if (ArraySafe($table['projections'], '_uisearch') != '') {
            $proj = $table['projections']['_uisearch'];
        } else {
            $proj = $table['pks'];
        }
    }
    $aproj = explode(',', $proj);
    $acollist = array();
    foreach ($aproj as $aproj1) {
        $acollist[] = "COALESCE({$aproj1},'')";
    }
    $collist = str_replace(',', " || ' - ' || ", $proj);
    //$collist = implode(" || ' - ' || ",$acollist);
    //syslog($collist);
    // Get the primary key, and resolve which view we have perms for
    // KFD 10/8/07, do only one column if passed
    if ($distinct != '') {
        $pk = $distinct;
    } else {
        $pk = $table['pks'];
    }
    $view_id = ddViewFromTab($table_id);
    // Initialize the filters
    $aWhere = array();
    // Generate a filter for each pk that exists in session ajaxvars.
    // There is a BIG unchecked for issue here, which is that a multi-column
    //  PK must have *all but one* column supplied, and it then returns
    //  the unsupplied column.
    $pkeys = explode(',', $table['pks']);
    //$ajaxvars=afromGP('adl_');
    //foreach($pkeys as $index=>$pkey) {
    //   if(isset($ajaxvars[$pkey])) {
    //      $aWhere[]="$pkey=".SQLFC($ajaxvars[$pkey]);
    //      // This is important!  Unset the pk column, we'll pick the leftover
    //      unset($pkeys[$index]);
    //   }
    //}
    // If we did the multi-pk route, provide the missing column
    //  as the key value
    //if(count($ajaxvars)>0) {
    //   $pk=implode(',',$pkeys);
    //}
    // Determine if this is a filtered table
    if (isset($table['flat']['flag_noselect'])) {
        $aWhere[] = "COALESCE(flag_noselect,'N')<>'Y'";
    }
    // Add more matches on
    foreach ($matches as $matchcol => $matchval) {
        $aWhere[] = $matchcol . ' = ' . SQLFC($matchval);
    }
    // If "firstletters" have been passed, we will filter each
    // select column on it
    //
    // KFD 8/8/07, a comma in first letters now means look in
    //             1st column only + second column only
    $SLimit = '';
    $xWhere = array();
    if ($firstletters != '') {
        $SLimit = "Limit 30 ";
        if (strpos($firstletters, ',') === false) {
            // original code, search all columns
            $implode = ' OR ';
            foreach ($aproj as $aproj1) {
                $sl = strlen($firstletters);
                $xWhere[] = "SUBSTRING(LOWER({$aproj1}) FROM 1 FOR {$sl})" . "=" . strtolower(SQLFC($firstletters));
            }
        } else {
            // New code 8/8/07, search first column, 2nd, third only,
            // based on existence of commas
            $implode = ' AND ';
            $afl = explode(',', $firstletters);
            foreach ($afl as $x => $fl) {
                $sl = strlen($fl);
                $xWhere[] = "SUBSTRING(LOWER({$aproj[$x + 1]}) FROM 1 FOR {$sl})" . "=" . strtolower(SQLFC($fl));
            }
        }
    }
    if (count($xWhere) > 0) {
        $aWhere[] = "(" . implode($implode, $xWhere) . ")";
    }
    // Finish off the where clause
    if (count($aWhere) > 0) {
        $SWhere = "WHERE " . implode(' AND ', $aWhere);
    } else {
        $SWhere = '';
    }
    // Execute and return
    $sDistinct = $distinct != '' ? ' DISTINCT ' : '';
    $SOB = $aproj[0];
    if ($allcols) {
        $sq = "SELECT skey,{$proj} \n              FROM {$view_id} \n           {$SWhere} \n             ORDER BY 3 {$SLimit}";
    } else {
        $sq = "SELECT {$sDistinct} {$pk} as _value,{$collist} as _display \n              FROM {$view_id} \n           {$SWhere} \n             ORDER BY {$SOB} {$SLimit} ";
    }
    $rows = x4SQLAllrows($sq);
    return $rows;
}
Example #18
0
 function RepStandardQuery()
 {
     $sreport = SQLFC($this->report_id);
     // Now the tables
     $rows_tab = SQL_AllRows("SELECT * From reporttables WHERE report={$sreport}");
     $rows_tab = KeyRowsFromRows($rows_tab, 'table_id');
     // Now all columns
     $rows_col = SQL_AllRows("SELECT * From reportcolumns WHERE report={$sreport}\n           ORDER BY uicolseq ");
     $this->rows_col = $rows_col;
     foreach ($this->rows_col as $key => $colinfo) {
         $table_dd = dd_Tableref($colinfo['table_id']);
         $column_id = $colinfo['column_id'];
         if (intval($colinfo['dispsize']) == 0) {
             $this->rows_col[$key]['dispsize'] = $table_dd['flat'][$column_id]['dispsize'];
         }
     }
     // Make two header lines out of column information
     $aTemp = array();
     foreach ($this->rows_col as $colinfo) {
         $x = substr($colinfo['description'], 0, $colinfo['dispsize']);
         $aTemp[] = str_pad($x, $colinfo['dispsize'], ' ', STR_PAD_RIGHT);
     }
     $this->hTitles = implode('  ', $aTemp);
     $aTemp = array();
     foreach ($this->rows_col as $colinfo) {
         $aTemp[] = str_repeat('=', $colinfo['dispsize']);
     }
     $this->hDashes = implode('  ', $aTemp);
     $this->hWidth = strlen($this->hDashes);
     $this->hTitle = str_repeat(' ', intval(($this->hWidth - strlen($this->hTitle)) / 2)) . $this->hTitle;
     // Go get the joins
     $SQL_FROMJOINS = $this->ehProcessFromJoins(array_keys($rows_tab));
     // Build a list of columns, and order-by columns, and filters'
     $this->Cols = array();
     $SQL_COLSA = array();
     $SQL_COLSOBA = array();
     $SQL_COLSWHA = array();
     foreach ($rows_col as $row_col) {
         $this->Cols[] = $row_col['column_id'];
         $SQL_COLSA[] = $row_col['table_id'] . '.' . $row_col['column_id'];
         if ($row_col['flag_sort'] == 'Y') {
             //$SQL_COLSOBA[$row_col['uisort']]
             //   =$row_col['table_id'].'.'.$row_col['column_id'];
             $SQL_COLSOBA[] = $row_col['table_id'] . '.' . $row_col['column_id'];
         }
         //if($row_col['compoper']<>'' && $row_col['compval']<>'') {
         //   $table_dd=DD_TableRef($row_col['table_id']);
         //   $ddcol=&$table_dd['flat'][$row_col['column_id']];
         //   $colval=SQL_Format($ddcol['type_id'],$row_col['compval']);
         //   $SQL_COLSWHA[]
         //      =$row_col['table_id'].'.'.$row_col['column_id']
         //      .$row_col['compoper']
         //      .$colval;
         //}
     }
     // Collapse the lists into strings
     $SQL_COLS = implode("\n       ,", $SQL_COLSA);
     $SQL_COLSOB = '';
     if (count($SQL_COLSOBA) > 0) {
         ksort($SQL_COLSOBA);
         $SQL_COLSOB = "\n ORDER BY " . implode(',', $SQL_COLSOBA);
     }
     $SQL_WHERE = '';
     if ($this->row_rep['repfilters'] != '') {
         $SQL_WHERE = "\n WHERE " . $this->row_rep['repfilters'];
     }
     //if(count($SQL_COLSWHA)>0) {
     //   $SQL_WHERE="\n WHERE ".implode("\n       ",$SQL_COLSWHA);
     //}
     // Now build the final SQL
     $SQ = " SELECT " . $SQL_COLS . $SQL_FROMJOINS . $SQL_WHERE . $SQL_COLSOB;
     //echo $SQ;
     return $SQ;
 }
Example #19
0
    function main_pr_execute()
    {
        ob_start();
        $sApp = SQLFC(gp('gp_app'));
        $sInst = SQLFC(gp('gp_inst'));
        $hApp = hSanitize(gp('gp_app'));
        $hInst = hSanitize(gp('gp_inst'));
        $rows = SQL_AllRows("SELECT * from instances \n           where application={$sApp} AND instance={$sInst}");
        if (count($rows) != 1) {
            ?>
         <div class="errorbox">Incorrect call to instance processing.</div>
         <?php 
            return;
        }
        $row = $rows[0];
        $sVer = SQLFC(gp('gp_ver'));
        $hVer = hSanitize(gp('gp_ver'));
        // KFD 2/4/08, If this is a subversion-enabled server,
        //     get version information from there
        if (OptionGet('DEV_STATION', '') != '') {
            $aversions = svnVersions();
            $mv = '-VER-' . $aversions['andro']['local'];
        } else {
            // Get information on latest version of Node Manager and
            // link to that
            $mv = SQL_OneValue("mv", "SELECT max(version) as mv \n                 FROM appversions\n                WHERE application='andro'");
        }
        $DIR_LINK_LIB = $GLOBALS['AG']['dirs']['root'] . '/pkg-apps/andro' . $mv;
        // Source of symlinks for app directories
        $DIR_LINK_APP = $GLOBALS['AG']['dirs']['root'] . "/pkg-apps/{$hApp}-VER-{$hVer}";
        // Get application information for the DO program
        $tsql = 'SELECT * from applications ' . ' WHERE application = ' . $sApp;
        $row_a = SQL_OneRow($tsql);
        $tsql = 'SELECT * from webpaths ' . ' WHERE webpath = ' . SQLFC($row_a['webpath']);
        $row_n = SQL_OneRow($tsql);
        $dirws = AddSlash(trim($row_n["dir_pub"]));
        //if (substr($dirws,-1,1)<>"/") $dirws.="/";
        //$row["webserver_dir_pub"] = $dirws;
        $string = '<?php
// To run this program from the command line, you must
// be logged in as a user that has superuser priveleges, such
// as root or postgres.  When running from the web app,
// the current user\'s priveleges are used.

$GLOBALS["parm"] = array(
   "DBSERVER_URL"=>"localhost"
   ,"UID"=>"' . SessionGet('UID') . '"
   ,"DIR_PUBLIC"=>"' . $dirws . '"
   ,"DIR_PUBLIC_APP"=>"' . $hApp . '_' . $hInst . '"
   ,"DIR_LINK_LIB"=>"' . $DIR_LINK_LIB . '"
   ,"DIR_LINK_APP"=>"' . $DIR_LINK_APP . '"
   ,"APP"=>"' . $hApp . '_' . $hInst . '"
   ,"INST"=>"' . $hInst . '"
   ,"IVER"=>"' . $hVer . '"
   ,"XDIRS"=>"' . trim($row_a['xdirs']) . '"
   ,"FLAG_PWMD5"=>"' . ArraySafe($row_a, 'flag_pwmd5', 'N') . '"
   ,"ROLE_LOGIN"=>"' . ArraySafe($row_a, 'flag_rolelogin', 'Y') . '"
   ,"TEMPLATE"=>"' . $row['template'] . '"
   ,"APPDSC"=>"' . trim($row_a["description"]) . '"
   ,"SPEC_BOOT"=>"' . trim($row_a["appspec_boot"]) . '"
   ,"SPEC_LIB"=>"' . trim($row_a["appspec_lib"]) . '"
   ,"SPEC_LIST"=>"' . trim($row_a["appspec"]) . '"
);
   
include("androBuild.php");  
?>
   ';
        $t = pathinfo(__FILE__);
        $dircur = AddSlash($t["dirname"]) . "../tmp/";
        //$dircur = $t["dirname"];
        if (substr($dircur, -1) != "/") {
            $dircur .= "/";
        }
        $file = $dircur . "do-{$hApp}-{$hInst}.php";
        $FILE = fopen($file, "w");
        fwrite($FILE, $string);
        fclose($FILE);
        include $file;
        if (ArraySafe($GLOBALS, 'retval', 0) == 1) {
            SQL("update instances set version={$sVer}\n               WHERE application = {$sApp}\n                 AND instance    = {$sInst}");
        }
        echo ob_get_clean();
    }