Exemple #1
0
 function main()
 {
     // First pull the report
     $row_rep = SQL_OneRow("SELECT * from reports where skey=" . gp('gp_skey'));
     $sreport = SQL_Format('char', $row_rep['report']);
     // 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 ");
     // Go get the joins
     $SQL_FROMJOINS = $this->ehProcessFromJoins(array_keys($rows_tab));
     // Build a list of columns, and order-by columns, and filters
     $SQL_COLSA = array();
     $SQL_COLSOBA = array();
     $SQL_COLSWHA = array();
     foreach ($rows_col as $row_col) {
         $SQL_COLSA[] = $row_col['table_id'] . '.' . $row_col['column_id'];
         if ($row_col['uisort'] != 0) {
             $SQL_COLSOBA[$row_col['uisort']] = $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 (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;
     // Display
     $this->ehProcessDisplay($SQ, $rows_col, $row_rep);
 }
Exemple #2
0
 /**
  * Generate search results for an x4browse/search
  *
  * @author: Kenneth Downs
  */
 function browseFetch()
 {
     #  This is the list of columns to return
     $acols = explode(',', $this->dd['projections']['_uisearch']);
     #  By default the search criteria come from the
     #  variables, unless it is a child table search
     $vals = aFromGP('x4w_');
     $awhere = array();
     $tabPar = gp('tableIdPar');
     if ($tabPar != '') {
         $ddpar = ddTable(gp('tableIdPar'));
         $pks = $ddpar['pks'];
         $stab = ddView(gp('tableIdPar'));
         $skey = SQLFN(gp('skeyPar'));
         $vals2 = SQL_OneRow("SELECT {$pks} FROM {$stab} WHERE skey = {$skey}");
         if (!$vals2) {
             $vals2 = array();
         }
         $vals = array_merge($vals, $vals2);
     }
     # Build the where clause
     #
     foreach ($vals as $column_id => $colvalue) {
         if (!isset($this->flat[$column_id])) {
             continue;
         }
         $colinfo = $this->flat[$column_id];
         $exact = isset($vals2[$column_id]);
         //$tcv  = trim($colvalue);
         $tcv = $colvalue;
         $type = $colinfo['type_id'];
         if ($tcv != "") {
             // trap for a % sign in non-string
             $xwhere = sqlFilter($this->flat[$column_id], $tcv);
             if ($xwhere != '') {
                 $awhere[] = "({$xwhere})";
             }
         }
     }
     # <----- RETURN
     if (count($awhere) == 0) {
         x4Debug("returning");
         return;
     }
     # Generate the limit
     # KFD 11/12/08, modified to respect sql_limit, with default of 100
     $SLimit = ' LIMIT ' . configGet('sql_limit', 100);
     if ($tabPar != '') {
         if (a($this->dd['fk_parents'][$tabPar], 'uiallrows', 'N') == 'Y') {
             $SLimit = '';
         }
     }
     #  Build the Order by
     #
     $ascDesc = gp('sortAD') == 'ASC' ? ' ASC' : ' DESC';
     $aorder = array();
     $searchsort = trim(a($this->dd, 'uisearchsort', ''));
     if (gpExists('sortAD')) {
         $aorder[] = gp('sortCol') . ' ' . gp('sortAD');
     }
     if ($searchsort != '') {
         $aocols = explode(",", $searchsort);
         foreach ($aocols as $pmcol) {
             $char1 = substr($pmcol, 0, 1);
             $column_id = substr($pmcol, 1);
             if ($char1 == '+') {
                 $aorder[] = $column_id . ' ASC';
             } else {
                 $aorder[] = $column_id . ' DESC';
             }
         }
         $SQLOrder = " ORDER BY " . implode(',', $aorder);
     } else {
         # KFD 6/18/08, new routine that works out sort
         $aorder = sqlOrderBy($vals);
         if (count($aorder) == 0) {
             $SQLOrder = '';
         } else {
             $SQLOrder = " ORDER BY " . implode(',', $aorder);
         }
     }
     # just before building the query, drop out
     # any columns that have a table_id_fko to the parent
     foreach ($acols as $idx => $column_id) {
         if ($this->flat[$column_id]['table_id_fko'] == $tabPar && $tabPar != '') {
             unset($acols[$idx]);
         }
     }
     // Build the where and limit
     $SWhere = ' WHERE ' . implode(' AND ', $awhere);
     // Retrieve data
     $SQL = "SELECT skey," . implode(',', $acols) . "  FROM " . $this->view_id . $SWhere . $SQLOrder . $SLimit;
     $answer = SQL_AllRows($SQL);
     $this->browseFetchModify($answer);
     x4Data('browseFetch', $answer);
     return;
 }
Exemple #3
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 &gt; 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);
 }
Exemple #4
0
 function processSubmit()
 {
     // Get the submitted data
     $table = gp('gp_table_upd', '');
     // Get the flat table def
     $table_dd = dd_TableRef($table);
     $tabflat = ArraySafe($table_dd, 'flat');
     //hprint_r($table);
     $row = aFromGP('gp_upd_');
     //hprint_r($row);
     //hprint_r($row);
     // Build a WHERE clause
     $where = array();
     foreach ($row as $col => $val) {
         if (ArraySafe($tabflat[$col], 'primary_key', 'N') != 'Y') {
             continue;
         }
         $where[] = $col . " = '" . $val . "'";
     }
     //hprint_r($where);
     $where = implode(' AND ', $where);
     // Build a SELECT
     $sql = "SELECT skey\n                 FROM " . ddTable_IDResolve($table) . "\n                WHERE " . $where;
     //hprint_r($sql);
     $records = SQL_AllRows($sql);
     if (count($records) != 1) {
         echo "Invalid or non-unique key supplied\n<br>";
         return;
     }
     // Well, we haven't failed yet, let's add the skey before the update, just to be safe.
     $row['skey'] = $records[0]['skey'];
     $skey = $records[0]['skey'];
     //hprint_r($row);
     SQLX_Update($table_dd, $row);
     if (Errors()) {
         echo hErrors();
     } else {
         echo "Update Successful.  <a href=\"?gp_page={$table}&gp_skey={$skey}\">View Record</a> <br>\n";
     }
 }
Exemple #5
0
    function ehTab_Filters_OLD()
    {
        $skey = SQL_Format('numb', gp('gp_skey'));
        $sq = "SELECT  rc.table_id,rc.column_id\n                 ,rc.compoper,rc.compval\n                 ,t.description as tdesc\n                 ,f.description as cdesc\n                 ,rc.skey\n            FROM reportcolumns rc \n            JOIN reports       r  ON r.report = rc.report\n            JOIN tables  t  ON rc.table_id = t.table_id\n            JOIN tabflat f  ON rc.table_id = f.table_id\n                                 AND rc.column_id= f.column_id\n           WHERE r.skey={$skey}\n           ORDER BY rc.uicolseq";
        $rows = SQL_AllRows($sq);
        $opts = array('', '=', '!=', '>', '<', '>=', '<=');
        ob_start();
        foreach ($rows as $row) {
            $row['compoper'] = trim($row['compoper']);
            $hSelBase = "'&gp_ajax=colsave&gp_colsk=" . $row['skey'] . "&gp_val='+this.value+'&gp_col=";
            $hSel1 = $hSelBase . "compoper'";
            $hSel2 = $hSelBase . "compval'";
            $hOpts = '';
            foreach ($opts as $opt) {
                $sel = $row['compoper'] == $opt ? ' SELECTED ' : '';
                $hOpts .= "\n<option {$sel} value=\"{$opt}\">" . htmlentities($opt) . "</option>";
            }
            ?>
         <tr>
         <td><?php 
            echo '(' . $row['tdesc'] . ') ' . $row['cdesc'];
            ?>
         <td><select onchange="sndReq(<?php 
            echo $hSel1;
            ?>
)" 
                     value="<?php 
            echo $row['compoper'];
            ?>
">
             <?php 
            echo $hOpts;
            ?>
             </select>
         <td><input onblur="sndReq(<?php 
            echo $hSel2;
            ?>
)"
                value="<?php 
            echo $row['compval'];
            ?>
"
                size=70 maxlength=100>
         </tr>   
         <?php 
        }
        $hHTML = ob_get_clean();
        ?>
      <table width=100%>
         <tr>
           <td class="dhead" style="width:25%">Column
           <td class="dhead" style="width:10%">Operator
           <td class="dhead" style="width:65%">Value
         </tr>
         <?php 
        echo $hHTML;
        ?>
      </table>
      <?php 
    }
Exemple #6
0
    function main()
    {
        # KFD 2/17/09.  If installed with Debian package, will
        #               have username and password of "start".
        #               Must force a new id now.
        #
        if (SessionGet('UID') == 'start') {
            if (gp('user_id') != '') {
                if (gp('user_id') == '') {
                    ErrorAdd("User Id may not be empty");
                }
                if (substr(gp('user_id'), 0, 5) == 'andro') {
                    ErrorAdd("User Id may not begin with 'andro'");
                }
                if (gp('password1') != gp('password2')) {
                    ErrorAdd("Passwords do not match");
                }
                if (strlen(trim(gp('password1'))) == 0) {
                    ErrorAdd("Password may not be empty");
                }
                if (!Errors()) {
                    $row = array('user_id' => gp('user_id'), 'member_password' => gp('password1'));
                    SQLX_Insert('usersroot', $row);
                    if (!Errors()) {
                        scDBConn_Pop();
                        SessionSet('UID', gp('user_id'));
                        SessionSet('PWD', gp('password1'));
                        scDBConn_Push();
                        SQL("DELETE FROM USERSROOT WHERE user_id='start'");
                        # Get rid of the form that replaces login
                        $file = fsDirTop() . 'application/x_login_form.inc.html';
                        $fileto = $file . '.done';
                        @rename($file, $fileto);
                        ?>
                        <h1>New Root User Created</h1>
                        
                        <p>Your new user is created.</p>
                        
                        <p><a href="index.php?st2logout=1">
                           Return to Login Page</a></p>
                        <?php 
                        return;
                    }
                }
            }
            ?>
            <h1>New Install - Must Create User</h1>
            
            <p>You are logged into your Node Manager with the default
               username of "start" and password "start".  We have to change
               this right now so nobody can get into your new system.
            </p>
            
            <p>Please provide a new ROOT (superuser) user id and password
               below.  Andromeda will create the new user, log you in as
               that user, and remove the "start" user.
            </p>
            
            <table>
              <tr><td align="left">User Name
                  <td><input name = 'user_id' /> (may not begin with 'andro')
              <tr><td align="left">Password
                  <td><input type="password" name = 'password1'/>
              <tr><td align="left">Password (verify)
                  <td><input type="password" name = 'password2'/>
            </table>
            <input type="submit" value="Create User Now" />
            <?php 
            return;
        }
        /* FUTURE X6 VERSION OF NODE MANAGER
           ?>
           <h1>Node Manager Upgrade Required</h1>
           
           <p>The new version of the Node Manager uses the "x6" 
              interface to provide a richer experience.  Please click
              the link below to upgrade your Node Manager.  Once the
              upgrade is complete, log out and back in.
           </p>
           
           <p><a href="javascript:Popup('index.php?gp_page=a_builder&gp_out=none&x2=1&txt_application=andro','Build')"
               >Upgrade Node Manager Now</a>.</p>
               
           <p><a href="?st2logout=1">Logout After Upgrade</a>.</p>
           
           <?php
           return;
           */
        # <------- EARLY RETURN.
        # KFD 1/10/08, The old x_welcome screen is not used anymore,
        #              we have the new 'cpanel' now in x6.
        # ===============================================================
        ?>
        <h1>Welcome to the Andromeda Node Manager</h1>
        <?php 
        // Work out if there is a new release available
        //
        $apps = svnVersions();
        $andro = a($apps, 'andro', array('svn_url' => ''));
        if (trim($andro['svn_url']) == '') {
            $htmlVersions = '';
        } else {
            $htmlVersions = @file_get_contents($andro['svn_url']);
        }
        $matches = array();
        preg_match_all('/<li><a href=.*\\>(.*)<\\/a><\\/li>/', $htmlVersions, $matches);
        $versions = ArraySafe($matches, 1, array());
        if (count($versions) > 0) {
            $latest = array_pop($versions);
            $latest = str_replace('/', '', $latest);
            // Get current latest
            $current = $andro['local'];
            if ($latest > $current) {
                ?>
            <br/>
            <div style="border: 5px solid gray; color: blue
            font-weight: bolder; margin: 8px; padding: 0 8px 8px 8px">
            <h2>New Version of Andromeda Available</h2>
            
            <p>Version <?php 
                echo $latest;
                ?>
 is available.   <a href="?gp_page=a_pullsvn"
            >Click Here </a> to go to the Pull Code From Subversion.
            </div>
            <?php 
            }
        }
        $dirs = SQL_AllRows("select * from webpaths where webpath='DEFAULT'");
        ?>
<div style="font-size: 120%; line-height: 120%; padding: 10px">

<h2>For First Time Users</h2>
    This program is the Andromeda <b>Node Manager</b>.  You use this
    program to build your applications.
    <br/>
    <br/>
    Our main documentation is <a target="_blank" href=
    "http://www.andromeda-project.org/">here</a>.
    <br/>
    <br/>

    If you want to start programming a new application right away, 
    <a target="_blank"  href=
    "http://www.andromeda-project.org/creatinganapplication.html"
    >The instructions are here</a>, or you can just 
    <a href="?gp_page=applications&gp_mode=ins">define a new application here.</a>
    <br/>
    <br/>

After you defined an application, click on the "build this application"
link to create all of the directories and the empty database.</p>
<br/>
<br/>

<h2>Your Application Program Files</h2>

After building the application skeleton you can start working on the
   database specification.  If your application code is "test", then put
   the database specification into the file
   <br/>
   <br/>
   <b><?php 
        echo $dirs[0]['dir_pub'];
        ?>
/test/application/test.dd.yaml</b>
<br/>
<br/>

All Andromeda applications start with
a database specification.  These specifications are 
more powerful than anything else out there, 
and you will want learn the Andromeda's 
<a target="_blank" href=
"http://www.andromeda-project.org/databaseprogramming.html"
>Database Programming</a> language.

<br/>
<br/>
Once you are ready to try some custom pages, you are ready to look
at <a target="_blank" href=
"http://www.andromeda-project.org/webprogramming.html"
>Web Programming</a>.
   
    
</div>        
        <?php 
    }
Exemple #7
0
 function Login_Process()
 {
     $arg2 = $this->directlogin == true ? 'direct' : '';
     // only process if user hit "post"
     if (gp('gp_posted', '', false) == '') {
         return;
     }
     vgfSet('LoginAttemptOK', false);
     // Error title
     vgfSet('ERROR_TITLE', '*');
     // If the user supplied a loginUID, this is a post and we
     // must process the request.
     $ale = vgaGet('login_errors', array());
     $app = $GLOBALS['AG']['application'];
     $em000 = isset($ale['000']) ? $ale['000'] : "That username/password combination did not work.  Please try again.";
     $em001 = isset($ale['001']) ? $ale['001'] : "That username/password combination did not work.  Please try again.";
     $em002 = isset($ale['002']) ? $ale['002'] : "That username/password combination did not work.  Please try again.";
     $em099 = isset($ale['099']) ? $ale['099'] : "That username/password combination did not work.  Please try again.";
     $terror = "";
     $uid = gp('loginUID');
     $uid = MakeUserID($uid);
     //$uid = str_replace('@','_',$uid);
     //$uid = str_replace('.','_',$uid);
     $pwd = gp("loginPWD", "", false);
     // First check, never allow the database server's superuser
     // account
     //
     if ($uid == "postgres") {
         ErrorAdd($em000);
         if (vgfGet('loglogins', false)) {
             sysLog(LOG_WARNING, "Andromeda:{$app}:Bad login attempt as postgres");
             fwLogEntry('1011', 'Attempt login as postgres', '', $arg2);
         }
         return;
     }
     $app = $GLOBALS['AG']['application'];
     if (substr($uid, 0, strlen($app)) == $app) {
         ErrorAdd($em001);
         if (vgfGet('loglogins', false)) {
             sysLog(LOG_WARNING, "Andromeda:{$app}:Bad login attempt as group role");
             fwLogEntry('1012', 'Attempt login as group role', $uid, $arg2);
         }
         return;
     }
     // Begin with a connection attempt.
     // on fail, otherwise continue
     $tcs = @SQL_CONN($uid, $pwd);
     if ($tcs === false) {
         ErrorAdd($em099);
         if (vgfGet('loglogins', false)) {
             sysLog(LOG_NOTICE, "Andromeda:{$app}:Bad login attempt server rejected");
             fwLogEntry('1013', 'Server rejected username/password', $uid, $arg2);
         }
         return;
     } else {
         SQL_CONNCLOSE($tcs);
     }
     // The rest of this routine uses an admin connection.  If we
     // have an error, we must close the connection before returning!
     //    ...yes, yes, that's bad form, all complaints to /dev/null
     //
     if (vgfGet('loglogins', false)) {
         fwLogEntry('1010', 'Login OK', $uid, $arg2);
     }
     scDBConn_Push();
     // See if they are a root user.  If not, do they have an
     //  active account?
     $root = false;
     $admin = false;
     $group_id_eff = '';
     $results = SQL("\n         Select oid\n           FROM pg_roles   \n          WHERE rolname = CAST('{$uid}' as name)\n            AND rolsuper= true");
     $cr = SQL_NUMROWS($results);
     if ($cr != 0) {
         $root = true;
     } else {
         $results = SQL("Select * from users WHERE LOWER(user_id)='{$uid}'" . "AND (user_disabled<>'Y' or user_disabled IS NULL)");
         $cr = SQL_NUMROWS($results);
         if ($cr == 0) {
             scDBConn_Pop();
             ErrorAdd($em002);
             sysLog(LOG_WARNING, "Andromeda:{$app}:Bad login attempt code 002");
             return;
         } else {
             $userinfo = SQL_Fetch_Array($results);
             $group_id_eff = $userinfo['group_id_eff'];
             SessionSet('user_name', $userinfo['user_name']);
         }
     }
     // Flag if the user is an administrator
     if ($root == true) {
         $admin = true;
     } else {
         $results = SQL("select count(*) as admin from usersxgroups " . "where user_id='{$uid}' and group_id ='{$app}" . "_admin'");
         $row = SQL_FETCH_ARRAY($results);
         $admin = intval($row["admin"]) > 0 ? true : false;
     }
     // Get the users' groups
     $groups = "";
     if ($root) {
         $results = SQL("\n            select group_id \n              from zdd.groups \n             where COALESCE(grouplist,'')=''");
     } else {
         $results = SQL("select group_id from usersxgroups WHERE LOWER(user_id)='{$uid}'");
     }
     while ($row = SQL_FETCH_ARRAY($results)) {
         $agroups[] = "'" . trim($row['group_id']) . "'";
         #$groups.=ListDelim($groups)."'".trim($row["group_id"])."'";
     }
     $groups = array();
     if (!empty($agroups)) {
         $groups = implode(",", $agroups);
     }
     //scDBConn_Pop();
     // We have a successful login.  If somebody else was already
     // logged in, we need to wipe out that person's session.  But
     // don't do this if there was an anonymous login.
     if (LoggedIn()) {
         $uid_previous = SessionGet('UID');
         if ($uid != $uid_previous) {
             //Session_Destroy();
             SessionReset();
             //Index_Hidden_Session_Start(false);
         }
     }
     // We know who they are and that they can connect,
     // see if there is any app-specific confirmation required
     //
     if (function_exists('app_login_process')) {
         //echo "Calling the process now";
         if (!app_login_process($uid, $pwd, $admin, $groups)) {
             return;
         }
     }
     // Protect the session from hijacking, generate a new ID
     Session_regenerate_id();
     // We now have a successful connection, set some
     // flags and lets go
     //
     vgfSet('LoginAttemptOK', true);
     SessionSet("UID", $uid);
     SessionSet("PWD", $pwd);
     SessionSet("ADMIN", $admin);
     SessionSet("ROOT", $root);
     SessionSet("GROUP_ID_EFF", $group_id_eff);
     SessionSet("groups", $groups);
     if (gp('gpz_page') == '') {
         # KFD 9/12/08, extra command to not change page
         if (gp('st2keep') != 1) {
             gpSet('gp_page', '');
         }
     }
     $GLOBALS['session_st'] = 'N';
     // for "N"ormal
     // -------------------------------------------------------------------
     // We are about to make the menu.  Before doing so, see if there
     // are any variables set for the menu layout.  Set defaults and then
     // load from database.
     //
     $this->pmenu = array('MENU_TYPE' => vgaGet('MENU_TYPE', 'div'), 'MENU_CLASS_MODL' => vgaGet('MENU_CLASS_MODL', 'modulename'), 'MENU_CLASS_ITEM' => vgaGet('MENU_CLASS_ITEM', 'menuentry'), 'MENU_TICK' => vgaGET('MENU_TICK', ' - '));
     //$sql = "SELECT * from variables WHERE variable like 'MENU%'";
     //$dbres = SQL($sql);
     //while ($row = SQL_FETCH_ARRAY($dbres)) {
     //   $this->pmenu[trim($row['variable'])]=trim($row['variable_value']);
     //}
     // -------------------------------------------------------------------
     // KFD 10/28/06, Modified to examine "nomenu" instead of permsel
     //   pulls all tables user has nomenu='N'.  The basic idea is
     //   to remove from $AGMENU the stuff they don't see
     //
     // GET AGMENU
     $AGMENU = array();
     // avoid compiler warning, populated next line
     include "ddmodules.php";
     // Pull distinct modules person has any menu options in.
     $sq = "SELECT DISTINCT module\n             FROM zdd.perm_tabs \n            WHERE nomenu='N'\n              AND group_id iN ({$groups})";
     $modules = SQL_AllRows($sq, 'module');
     $AGkeys = array_keys($AGMENU);
     foreach ($AGkeys as $AGkey) {
         if (!isset($modules[$AGkey])) {
             unset($AGMENU[$AGkey]);
         }
     }
     // Now recurse the remaining modules and do the same trick
     // for each one, removing the tables that don't exist
     foreach ($AGMENU as $module => $moduleinfo) {
         $sq = "SELECT DISTINCT table_id\n                FROM zdd.perm_tabs \n               WHERE nomenu='N'\n                 AND module = '{$module}'\n                 AND group_id iN ({$groups})";
         $tables = SQL_AllRows($sq, 'table_id');
         $tkeys = array_keys($moduleinfo['items']);
         foreach ($tkeys as $tkey) {
             if (!isset($tables[$tkey])) {
                 unset($AGMENU[$module]['items'][$tkey]);
             }
         }
     }
     // KFD 12/18/06.  Put all table permissions into session
     $table_perms = SQL_AllRows("Select distinct table_id FROM zdd.perm_tabs\n           WHERE group_id IN ({$groups})\n             AND nomenu='N'", 'table_id');
     SessionSet('TABLEPERMSMENU', array_keys($table_perms));
     $table_perms = SQL_AllRows("Select distinct table_id FROM zdd.perm_tabs\n           WHERE group_id IN ({$groups})\n             AND permsel='Y'", 'table_id');
     SessionSet('TABLEPERMSSEL', array_keys($table_perms));
     $table_perms = SQL_AllRows("Select distinct table_id FROM zdd.perm_tabs\n           WHERE group_id IN ({$groups})\n             AND permins='Y'", 'table_id');
     SessionSet('TABLEPERMSINS', array_keys($table_perms));
     $table_perms = SQL_AllRows("Select distinct table_id FROM zdd.perm_tabs\n           WHERE group_id IN ({$groups})\n             AND permupd='Y'", 'table_id');
     SessionSet('TABLEPERMSUPD', array_keys($table_perms));
     $table_perms = SQL_AllRows("Select distinct table_id FROM zdd.perm_tabs\n           WHERE group_id IN ({$groups})\n             AND permdel='Y'", 'table_id');
     SessionSet('TABLEPERMSDEL', array_keys($table_perms));
     //echo "<div style='background-color:white'>";
     //echo "$uid $groups $group_id_eff";
     //hprint_r(SessionGet('TABLEPERMSMENU'));
     //hprint_r(SessionGet('TABLEPERMSSEL'));
     //echo "</div>";
     // KFD 7/9/07, we always use joomla templates now, don't need
     // options to turn them off
     //if(defined('_ANDROMEDA_JOOMLA')) {
     // In a hybrid situation, put the menu into the session
     SessionSet('AGMENU', $AGMENU);
     //}
     $HTML_Menu = "";
     $WML_Menu = "";
     /*
     foreach ($AGMENU as $key=>$module) {
        //if($key=="datadict") continue;
        //if($key=="sysref")   continue;
        $HTML_Module="";
        $WML_Module="";
        foreach($module["items"] as $itemname=>$item) {
           if (!isset($item["mode"])) { $item["mode"]="normal"; }
           switch ($item["mode"]) {
              case "normal":
                 $ins=false;
                 $extra=array();
                 if($item['menu_parms']<>'') {
                    $aextras=explode('&',$item['menu_parms']);
                    foreach($aextras as $aextra) {
                       list($var,$value)=explode("=",$aextra);
                       $extra[$var]=$value;
                    }
                 }
                 $HTML_Module.=$this->_MenuItem(
                    $item['description'],$itemname,$ins,$extra
                 );
                 $WML_Module.="<div>";
                 $WML_Module.=hLink(
                    '',$item['description'],'?gp_page='.$itemname
                 );
                 $WML_Module.="</div>";
                 break;
              case "ins":
                 //if ($admin || isset($tables_ins[$item["name"]]))  {
                    $HTML_Module.=$this->_MenuItem(
                       $item['description'],$itemname,true
                    );
                 //}
                 break;
                    
                    #$HTML_Module.=
                    #   "\n<font class=\"tablename\">- <a href=\"index.php?gp_page=".$itemname."\">".
                    #   $item["description"]."</a></font><br />";
                    
              }
        }
        
        // the module is defined AFTER its contents so it can be
        // left off if it has no entries
        if ($HTML_Module!="") {
           $HTML_Menu.=$this->_MenuModule($module['description']);
           $HTML_Menu.=$HTML_Module;
        }
        if ($WML_Module!="") {
           $WML_Menu.="<div><b>".$module['description']."</b></div>";
           $WML_Menu.=$WML_Module;
        }
     }
     */
     DynamicSave("menu_" . $uid . ".php", $HTML_Menu);
     DynamicSave("menu_wml_" . $uid . ".php", $WML_Menu);
     // -------------------------------------------------------------------
     // Fetch and cache user preferences
     if (vgaGet('member_profiles')) {
         cacheMember_Profiles();
     }
     // -------------------------------------------------------------------
     // Now find the user's table permissions more precisely table by table
     $sql = "select p.table_id,\n\t\t\t\tmax(case when p.permins='Y' then 1 else 0 end) as permins,\n\t\t\t\tmax(case when p.permupd='Y' then 1 else 0 end) as permupd,\n\t\t\t\tmax(case when p.permdel='Y' then 1 else 0 end) as permdel,\n\t\t\t\tmax(case when p.permsel='Y' then 1 else 0 end) as permsel\n\t\t\t\tfrom zdd.perm_tabs  P\n\t\t\t\tWHERE group_id in ({$groups})\n\t\t\t\tGROUP BY p.table_id";
     //echo $sql;
     $results = SQL($sql);
     $HTML_Perms = "<?php\n\$table_perms = array();\n";
     while ($row = SQL_FETCH_ARRAY($results)) {
         $tn = $row["table_id"];
         $ti = $row["permins"];
         $tu = $row["permupd"];
         $td = $row["permdel"];
         $ts = $row["permsel"];
         $HTML_Perms .= "\$table_perms[\"{$tn}\"]=array(\"ins\"=>{$ti},\"upd\"=>{$tu},\"del\"=>{$td},\"sel\"=>{$ts});\n";
     }
     $HTML_Perms .= "?>\n";
     DynamicSave("perms_" . $uid . ".php", $HTML_Perms);
     /* October 28, 2006, KFD.  Rem'd this all out, column and row security
              made this irrelevant
     		// -------------------------------------------------------------------
     		// Find out if this user has any UID Columns, columns that create
     		// filters on the user's UID
     		$sql = "Select column_id FROM groupuids WHERE group_id IN ($groups)";
     		//echo $sql;
     		$results = SQL($sql);
     		$groupuids = array();
     		while ($row = SQL_FETCH_ARRAY($results)) {
     			//echo "Found this one".$row["column_id"];
     			$groupuids[$row["column_id"]] = $row["column_id"];
     		}
     		SessionSet("groupuids",$groupuids);
           */
     scDBConn_Pop();
     return;
 }
    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 
    }
Exemple #9
0
 function PW_ForgotPage1()
 {
     // KFD 11/13/06.  Heavily modified for new system, threw out
     //   the older code entirely, now that all apps have a users
     //   table built into them.
     $eml = trim(gp('txt_email'));
     $seml = SQLFC(strtolower($eml));
     $heml = hx($eml);
     $ueml = urlencode($eml);
     //$leml= MakeUserId(strtolower($eml));
     $db2 = scDBConn_Push('usermaint');
     $sq = "Select skey,user_id,member_password,email FROM users " . " where LOWER(email)={$seml}";
     $member = SQL_AllRows($sq);
     // Nothing of any kind is a bummer, we can't do anything
     if (count($member) == 0) {
         ErrorAdd('There are no active accounts with that email address');
     } else {
         $leml = MakeUserID($eml);
         $member = $member[0];
         // If we know who they are, send a password and allow them to change it
         $user_pwkey = md5($member['member_password'] . $leml . time());
         //$ref=$_SERVER['HTTP_REFERER'];
         $http = httpWebSite() . "/";
         $row = array('skey' => $member['skey'], 'user_pwkey' => $user_pwkey);
         $UID = $member['user_id'];
         $PWD = $member['member_password'];
         // KFD 12/21/06.  Done for medinfo originally.  If UID looks like
         //  the email, send the email instead
         $emailUID = $member['email'];
         $table_dd = DD_Tableref('users');
         SQLX_Update($table_dd, $row);
         $emailuser_id = OptionGet('EMAIL_USERID', 'N') == 'Y' ? $emailUID : $leml;
         $text_email = "\nYour username and password are: {$emailuser_id} and {$PWD}.\n   \nIf you would like to change your password, click here:\n<{$http}?gp_page=x_password&gpp=2&eml={$ueml}&hash={$user_pwkey}>\n";
         scDBConn_Pop();
         //echo $text_email;
         EmailSend($eml, 'System Access Request', $text_email);
         ?>
         <b>Email Has Been Sent</b>.  An email has been sent to you with information
         needed to access the system.
         <?php 
         gpSet('gpp', 'X');
     }
 }
Exemple #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));
        }
    }
Exemple #11
0
 function profile_twosides()
 {
     # Grab the data dictionary for this table
     $dd = $this->dd;
     $table_id = $this->dd['table_id'];
     # Get the standard padding, we are going to double it
     $pad0 = x6CSSDefine('pad0');
     $heightRemain = x6cssDefine('insideheight');
     # Now put in your basic title
     $div = new androHTMLTableController($table_id);
     $div->addClass('fadein');
     $div->ap['xCache'] = 'Y';
     // results will be cached
     $div->h('h1', '<center>' . $dd['description'] . '</center>');
     $heightRemain -= x6cssHeight('h1');
     $heightRemain -= $pad0 * 2;
     # Create a two-sided layout by creating two boxes
     # Left side is a grid with the entire table
     $area0 = $div->h('div');
     $area0->hp['style'] = "float: left; \n            padding-left: {$pad0}px;\n            padding-right: {$pad0}px;";
     $x6grid = $area0->addGrid($heightRemain, $table_id, false, true, false);
     $x6grid->hp['x6profile'] = 'twosides';
     $this->gridGeneric($x6grid, $this->dd);
     # Now put the data over there
     $uisearch = $this->dd['projections']['_uisearch'];
     $ob = $this->dd['pks'];
     # KFD 1/22/09, allow filtering on "pre" values
     $pre = aFromGp('pre_');
     $awhere = array();
     $where = '';
     foreach ($pre as $colname => $value) {
         $awhere[] = sqlfilter($this->dd['flat'][$colname], $value);
     }
     if (count($awhere) > 0) {
         $where = 'WHERE ' . implode(' AND ', $awhere);
     }
     $view_id = ddView($table_id);
     $sql = "Select skey,{$uisearch} from {$view_id} {$where} ORDER BY {$ob}";
     $rows = SQL_AllRows($sql);
     $aColumns = explode(',', $uisearch);
     foreach ($rows as $row) {
         $x6grid->addRow($row['skey']);
         foreach ($aColumns as $column) {
             $x6grid->addCell($row[$column]);
         }
     }
     # Calculate how much width is left
     $wInner = x6CSSDefine('insidewidth');
     $wInner -= $x6grid->width;
     $wInner -= 2;
     // assume a border on the grid
     $wInner -= 2;
     // assume a border on the right-side
     $wInner -= $pad0 * 6;
     // 3 times padding doubled
     $box2 = $div->h('div');
     $box2->hp['style'] = "float: left; width: {$wInner}px;";
     $detail = $box2->addDetail($table_id, true, $heightRemain - 2);
     $detail->ap['x6profile'] = 'twosides';
     # Generate a list of child xrefs.  The idea here is to
     # work out the dimensions first, because we must tell the
     # class how high to make itself.  Then we generate the
     # list.  If it comes back empty, we forget about it, otherwise
     # we create a div of the correct position and put it into it.
     $xrtop = $detail->hp['xInnerHeight'] - $detail->hp['xInnerEmpty'] + x6CssHeight('h1');
     $xrhgt = $detail->hp['xInnerEmpty'] - x6cssHeight('h1') - $pad0 * 10;
     // total hack, don't know why 7 works
     $xrwdth = $wInner - $detail->hp['xInnerWidthLost'];
     $xrefs = new androHTMLxrefs($table_id, $xrhgt);
     if ($xrefs->hp['xCount'] > 0) {
         $xrefParent = $detail->innerDiv->h('div');
         $xrefParent->hp['style'] = "position: absolute;\n                width: {$xrwdth}px;\n                top: {$xrtop}px;\n                left: {$pad0}px;";
         $xrefParent->addChild($xrefs);
     }
     # tell the screen to start out by
     # focusing on the browse
     jqDocReady("x6events.fireEvent('objectFocus','{$x6grid->hp['id']}')");
     # KFD 3/7/09 Sourceforge 2669466
     #            Turn on new buttons by default
     jqDocReady('x6events.fireEvent("buttonsNew_' . $table_id . '",true)');
     # Render it!  That's it!
     # KFD 3/20/09 Sourceforge 2697962
     #             index_hidden calls this now
     #$this->hldOut($top);
     $div->render();
 }
function index_hidden_sql()
{
    $rows = SQL_AllRows(gp('gp_sql'), gp('gp_col'));
    echo "<html>" . serialize($rows) . "</html>";
}
Exemple #13
0
 function pullCode()
 {
     echo "<pre>";
     x_EchoFlush("Pulling a list of applications and their nodes...");
     $sq = "SELECT a.application,n.node,n.node_url\n                 ,COALESCE(av.version,'') as version\n             FROM applications     a\n             JOIN nodes            n  ON a.node = n.node\n             LEFT JOIN (SELECT application,max(version) as version\n                          FROM appversions\n                         GROUP BY application) av\n               ON a.application = av.application";
     $rows = SQL_AllRows($sq);
     if (count($rows) == 0) {
         x_EchoFlush("");
         x_EchoFlush("There are no applications listing Authoritative Nodes");
         x_EchoFlush("Nothing to do!");
     }
     foreach ($rows as $row) {
         $this->PullCodeApp($row);
     }
     x_EchoFlush("");
     x_EchoFlush(" ---------------- ");
     x_EchoFlush("All Processing Finished.");
 }
 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;
 }
Exemple #15
0
/**
 * KFD 2/23/08, Put frequently used links over on the left
 * all of the time
 *
 */
function appModuleLeft()
{
    $retVal = '';
    $hasContent = false;
    if (!LoggedIn()) {
        return false;
    }
    $retVal .= "<ul class=\"nav nav-list\">";
    $retVal .= "<li class=\"nav-header\">Updates</li>";
    $retVal .= '<li>';
    $retVal .= '<a class="small" href="?gp_page=a_pullsvn">Pull Code From Subversion</a>';
    $retVal .= '</li>';
    // Display either applications or instances, depending upon
    // which we have here
    # KFD 4/15/08, make this unconditional
    #$ds =OptionGet('DEV_STATION','Y');
    #$boa=OptionGet( 'BUILD_ALL_APPS','N');
    #if($ds=='Y' || $boa == 'Y') {
    if (True) {
        $apps = SQL_AllRows("Select * from applications order by application");
        if (!empty($apps)) {
            $hasContent = true;
            $retVal .= '<li class="nav-header">Applications</li>';
            foreach ($apps as $app) {
                $retVal .= '<li>';
                $retVal .= '<a class="pull-left" href="?gp_page=applications&gp_skey=' . $app['skey'] . '">';
                $retVal .= $app['application'];
                $retVal .= '</a>';
                $retVal .= '&nbsp;';
                $retVal .= hLinkBuild($app['application'], 'Build');
                $retVal .= '</li>';
            }
        }
    }
    $instances = SQL_ALLROWS("Select * from instances\n        order by application,instance");
    if (!empty($instances) > 0) {
        $hasContent = true;
        $retVal .= '<li class="nav-header">Instances</li>';
        foreach ($instances as $i) {
            $retVal .= '<li>';
            $retVal .= '<a class="pull-left" href="?gp_page=instances&bp_skey=' . $i['skey'] . '">';
            $retVal .= $i['application'] . ' / ' . $i['instance'];
            $retVal .= '</a>';
            $retVal .= '<a class=" pull-right small" href="?gp_page=instances_p&gp_app=' . trim($i['application']) . '&gp_inst=' . $i['instance'] . '">';
            $retVal .= 'Build/Upgrade';
            $retVal .= '</a>';
            $retVal .= '</li>';
        }
    }
    $retVal .= '</ul>';
    $retVal .= '<div style="clear:both;"></div>';
    return $hasContent !== false ? $retVal : false;
}
 function mainLayout($container)
 {
     # Erase default help message
     vgfSet('htmlHelp', '');
     $top = $container;
     # Pull the values
     # For a user, if there is no row, enter one and try again
     $dd = ddTable("configuser");
     $view = ddView('configuser');
     $row = SQL_AllRows("Select * from {$view}");
     if (count($row) == 1) {
         $row = $row[0];
     } else {
         SQL("Insert into {$view} (skey_quiet) values ('N')");
         $row = SQL_OneRow("Select * from {$view}");
     }
     # Basic information at top
     html('h1', $top, 'User Configuration');
     html('p', $top, 'Any changes made here will take immediate 
         effect.');
     # Set up titles
     $table = html('table', $top);
     $thead = html('thead', $table);
     $tr = html('tr', $thead);
     $tr->h('th', 'Setting', 'dark');
     $tr->h('th', 'Your Value', 'dark');
     $tr->h('th', 'Default Value', 'dark');
     $tr->h('th', '&nbsp', 'dark');
     # Now put out inputs for each one
     $tbody = html('tbody', $table);
     $askip = array('recnum', '_agg', 'skey_quiet', 'skey', 'uid_ins');
     foreach ($this->flat as $column_id => $colinfo) {
         if (in_array($column_id, $askip)) {
             continue;
         }
         $tr = html('tr', $tbody);
         $tr->hp['id'] = 'tr_' . $column_id;
         $tr->SetAsParent();
         $td = html('td', $tr, $colinfo['description']);
         # the input
         $input = input($colinfo);
         $input->hp['id'] = 'inp_' . $column_id;
         if ($colinfo['type_id'] == 'text') {
             $input->setHTML($row[$column_id]);
         } else {
             $input->hp['value'] = $row[$column_id];
             x4Script('$a.byId("' . $input->hp['id'] . '").value="' . $row[$column_id] . '"');
         }
         $input->hp['onchange'] = 'instaSave(this)';
         $input->ap['skey'] = $row['skey'];
         $td = html('td', $tr);
         $td->addChild($input);
         # The default value
         $td = html('td', $tr, ConfigGet($column_id, '*null*', array('user')));
         $td->hp['id'] = 'def_' . $column_id;
         # The reset
         $td = html('td', $tr);
         $button = html('a-void', $td, 'Use Default');
         $button->hp['onclick'] = "makeDefault('{$column_id}')";
     }
 }
Exemple #17
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;
 }
Exemple #18
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');
    }
Exemple #19
0
 function mainDoit()
 {
     # Take the list of group assignments and reslot
     # them into kills and changes.
     $graw = aFromgp('grp_');
     $gsame = array();
     $gchg = array();
     foreach ($graw as $from => $to) {
         if ($from == $to) {
             $gsame[] = "'{$to}'";
         } else {
             $gchg[$from] = $to;
         }
     }
     # Step 1, make sure all users exist.  Pull the ones
     #         that don't and create them
     $users = SQL_AllRows("\n            select user_id,member_password from users\n             where COALESCE(member_password,'') <> ''\n               AND not exists (\n                   select rolname from pg_roles\n                    where rolname = users.user_id::name\n                    )");
     echo "<br/>Re-creating " . count($users) . " users.";
     foreach ($users as $user) {
         $pwd = $user['member_password'];
         SQL("create role {$user['user_id']} login password '{$pwd}'");
     }
     # Step 1.5 set passwords and let them login
     $users = SQL_AllRows("select user_id,member_password from users");
     foreach ($users as $user) {
         $pwd = $user['member_password'];
         SQL("alter role {$user['user_id']} login password '{$pwd}'");
     }
     echo "<br/>Setting passwords for " . count($users) . " users.";
     # Step 2, for all assignments that do not change,
     #         explicitly grant the role
     $slist = implode(',', $gsame);
     $assigns = SQL_AllRows("Select user_id,group_id \n               from usersxgroups\n              WHERE group_id in ({$slist})");
     $count = 0;
     foreach ($assigns as $assign) {
         $count++;
         SQL("grant {$assign['group_id']} to {$assign['user_id']}");
     }
     echo "<br/>{$count} users had existing permissions re-established";
     errorsClear();
     # Step 3, for all assignments that change,
     #         copy rows in usersxgroups, which also
     #         creates the role assignment
     foreach ($gchg as $from => $to) {
         $sql = "insert into usersxgroups (user_id,group_id)\n                 select user_id,'{$to}' FROM usersxgroups x\n                 where group_id = '{$from}'\n                   AND user_id in (Select rolname::varchar from pg_roles)\n                   and not exists (\n                       select * from usersxgroups x \n                        where user_id = x.user_id\n                          AND group_id= '{$to}'\n                   )";
         SQL($sql);
     }
     echo "<br/>Migrated permissions for " . count($gchg) . " groups";
     # Step 4, Delete all defunct user-group assignments
     foreach ($gchg as $from => $to) {
         SQL("Delete from usersxgroups where group_id = '{$from}'");
     }
     echo "<br/>Deleted old user-group rows for " . count($gchg) . " groups";
     # Step 5, delete all defunct groups
     echo "<br/>Deleted " . count($gchg) . " groups from old database";
     foreach ($gchg as $from => $to) {
         SQL("Delete from permxtables where group_id = '{$from}'");
         SQL("Delete from uimenugroups where group_id = '{$from}'");
         SQL("Delete from permxmodules where group_id = '{$from}'");
         SQL("Delete from groups where group_id = '{$from}'");
     }
 }
Exemple #20
0
 /**
  *  Run the report on-screen as a smarty template
  *
  */
 private function pageSmarty()
 {
     if (ArraySafe($this->yamlP2['options'], 'noquery', 'N') == 'N') {
         // Execute SQL and return all rows for all sections
         $sections = $this->yamlP2['section'];
         foreach ($sections as $secname => $secinfo) {
             $this->yamlP2['section'][$secname]['rows'] = SQL_AllRows($secinfo['sql']);
         }
     }
     // Create the Smarty handler and call out to that
     require_once 'androPageSmarty.php';
     $smarty = new androPageSmarty();
     // Now pass the whole ball of wax to the smarty handler
     $smarty->main($this->yamlP2, $this->page);
 }
Exemple #21
0
/**
*
* name: SQLX_Select
* parm: $tableId  optional  The name or data dictionary
*
* Select selected columns and all rows from a
* given table.  Automatically uses the correct view
* if necessary.
*
* Optionally, the second parameter can be a "*" or a
* comma-separated list of columns or an array of column
* names.
* If no column list is provided, all columns are
* provided, omitting functional columns like
* skey_quiet and _agg are omitted, but including skey.
*
*/
function SQLX_Select($tableId, $columns = '', $options = array())
{
    $dd = ddTable($tableId);
    $view = $dd['viewname'];
    if (($ob = a($options, 'ob', '')) != '') {
        $ob = " ORDER BY {$ob}";
    }
    if (!is_array($columns)) {
        if ($columns == '' || $columns == '*') {
            $columns = array_keys($dd['flat']);
            $columns = array_diff($columns, array('skey_quiet', '_agg'));
            $columns = implode(',', $columns);
        }
    }
    return SQL_AllRows("Select {$columns} from {$view} {$ob}");
}
Exemple #22
0
    function main()
    {
        // Get top page
        $this->PageSubtitle = "Documentation";
        //$sq="SELECT pagename FROM docpageshier WHERE pagehier=1";
        //$pageroot=SQL_OneValue('pagename',$sq);
        $pageroot = 'Data Dictionary';
        $pn = gp('gppn');
        $pn = $pn == '' ? $pageroot : $pn;
        $sq = "SELECT * from docpages \n            WHERE pagename = " . sql_format('char', $pn);
        $row = SQL_oneRow($sq);
        if ($row === false) {
            echo "Page does not exist: " . $pn;
            return;
        }
        // Get one parent.  We used to get all of them, but now
        // we only want one
        $hmenu = '';
        $attop = false;
        $parents = array();
        $peers = array();
        $kids = array();
        $pparent = $pprev = $pnext = '';
        $plast = $pn;
        while ($plast != $pageroot) {
            $sq = "SELECT pagename_par FROM docpages \n               WHERE pagename = '{$plast}'";
            $rownew = SQL_AllRows($sq);
            $plast = $rownew[0]['pagename_par'];
            $parents[] = $plast;
            //if ($rownew[0]['pagename_par'] == $pageroot) {
            //   break;
            //}
        }
        if (count($parents) > 0) {
            $parents = array_reverse($parents);
            //$hmenu=adocs_makemenu($parents,'Parent Topics');
            // Grab this page's peers
            $pparent = $parents[count($parents) - 1];
            $sq = "SELECT pagename FROM docpages \n               WHERE pagename_par = '{$pparent}'\n               ORDER BY sequence";
            $rs = SQL($sq);
            while ($rowx = SQL_Fetch_Array($rs)) {
                $peers[] = $rowx['pagename'];
            }
            $peersr = array_flip($peers);
            $pprev = $peersr[$pn] == 0 ? '' : $peers[$peersr[$pn] - 1];
            $pnext = $peersr[$pn] == count($peers) - 1 ? '' : $peers[$peersr[$pn] + 1];
        }
        // Now pull out the kids
        $sq = "SELECT pagename FROM docpages \n            WHERE pagename_par = '{$pn}'\n            ORDER BY sequence";
        $rs = SQL($sq);
        while ($rowx = SQL_Fetch_Array($rs)) {
            $kids[] = $rowx['pagename'];
        }
        // Make and save a menu out of what we've discovered
        adocs_makemenu($pageroot, $pn, $parents, $peers);
        // Now format the page and save it.  No caching for now.
        $html = $row['pagetext'];
        $html = $this->WikiProcess($html);
        /*
        // Remove carriage returns, makes things much easier
        $html=str_replace("\r",'',$html);
        
        // Convert newlines to double br's, but first don't do doubles
        // after headings
        $html=str_replace("=\n\n","=\n",$html);
        $html=preg_replace("/\n\s*\n/","\n<br><br>\n",$html);
             
        // Convert bold & italitcs 
        $html=preg_replace(
           "/'{4,}(.*)'{4,}/xmsU"
           ,'<b><i>$1</i></b>'
           ,$html);
        $html=preg_replace(
           "/'{3}(.*)'{3}/xmsU"
           ,'<i>$1</i>'
           ,$html);
        $html=preg_replace(
           "/\'{2}(.*)\'{2}/xmsU"
           ,'<b>$1</b>'
           ,$html);
             
        
        // Convert 6 levels of title
        $html=preg_replace(
           "/={6}(.*)={6}/xsU"
           ,'<head6>$1</head6>'
           ,$html);
        $html=preg_replace(
           "/={5}(.*)={5}/xsU"
           ,'<head5>$1</head5>'
           ,$html);
        $html=preg_replace(
           "/={4}(.*)={4}/xsU"
           ,'<head4>$1</head4>'
           ,$html);
        $html=preg_replace(
           "/={3}(.*)={3}/xsU"
           ,'<head3>$1</head3>'
           ,$html);
        $html=preg_replace(
           "/={2}(.*)={2}/xsU"
           ,'<head2>$1</head2>'
           ,$html);
           
        $html=preg_replace(
           '/^=(.*)=$/U'
           ,'<head1>$1</head1>'
           ,$html);
        
        // convert hyperlinks and images
        $matches=array();
        while(preg_match('/\[{2,}(.*)\]{2,}/xmsU',$html,$matches)>0) {
           $search=$matches[1];
           $asearch=explode(':',$search);
           if(count($asearch)==2) {
              $type=$asearch[0];
              $match=$asearch[1];
           }
           else {
              $type='ilink';
              $match=$search;
           }
           
           switch(strtolower($type)) {
              case 'ilink': $this->Linkilink($html,$match); break;
              case 'image': $this->LinkImage($html,$match,$type); break;
           }
           
           $matches=array();
        }
        */
        // Prepare a list of parents
        if (count($parents) == 0) {
            $apars = array($pn);
        } else {
            $apars = $parents;
            $apars[] = $pn;
        }
        $hpars = '';
        foreach ($apars as $apar) {
            $hpars .= ($hpars == '' ? '' : ' &gt; ') . '<a href="?gp_page=x_docview&gppn=' . urlencode($apar) . '">' . $apar . '</a>';
        }
        // Prepare the prev, next stuff
        $hpn = '';
        if ($pprev . $pnext != '') {
            $hp = $pprev == '' ? '' : '<a href="?gp_page=x_docview&gppn=' . urlencode($pprev) . '">PREV: ' . $pprev . '</a>';
            $hn = $pnext == '' ? '' : '<a href="?gp_page=x_docview&gppn=' . urlencode($pnext) . '">NEXT: ' . $pnext . '</a>';
            $hpn = "\n\t\t\t<div class=\"row\">\n\t\t\t<div class=\"span9\">\n\t\t\t\t<div class=\"pull-left\">{$hp}</div>\n\t\t\t\t<div class=\"pull-right\">{$hn}</div>\n\t\t\t</div>\n\t\t\t</div>";
        }
        // Pull out and assemble the see-also groups
        $hsa = '';
        /*
        $hsa='';
        $sq='SELECT DISTINCT seealso FROM seealsoxpages '
           ." WHERE pagename='$pn'";
        $sas=SQL_AllRows($sq);
        foreach($sas as $sa) {
           $hsa.="<hr>";
           $seealso=$sa['seealso'];
           $hsa.="<hr><h2>See Also ($seealso):</h2><p>";
           $sq="SELECT pagename FROM seealsoxpages "
              ." WHERE seealso = '$seealso' "
              ."  AND  pagename <> '$pn'"
              ." ORDER By pagename ";
           $sarows=SQL_AllRows($sq);
           foreach($sarows as $index=>$sarow) {
              $hsa.=($index==0 ? '' : ', ')
                 .'<a href="?gppn='.urlencode($sarow['pagename']).'">'
                 .$sarow['pagename'].'</a>';
           }
           $sarows.='</p>';
        }
        */
        // Now the actual output and formatting
        //
        $this->PageSubtitle = $pn;
        echo "<div class=\"hero-unit\">Database Specification</div>";
        echo $hpars . "<br><br>";
        echo $hpn;
        echo "\n<hr>";
        echo "\n<h2>" . $pn . "</h2>\n";
        echo $html;
        if (count($kids) > 0 && $pn == 'Data Dictionary') {
            echo "\n<hr>";
            echo "\n<head2>Child Topics</head2>";
            foreach ($kids as $kid) {
                echo "\n<div><a href=\"?gp_page=x_docview&gppn=" . urlencode($kid) . "\">{$kid}</a></div>";
            }
        }
        echo $hsa;
        echo "<hr>";
        echo $hpn;
        ?>
      <hr>
      Page last modified <?php 
        echo date('r', dEnsureTS($row['ts_upd']));
        ?>
 by 
         <?php 
        echo $row['uid_upd'];
        ?>
<br><br>
      <?php 
    }
    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();
    }