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); }
function PageUpdate($pagename, $pagetext, $pagename_par = null, $seq = null) { $table_pg = DD_TableRef('docpages'); $table_hi = DD_TableRef('dochiers'); $row = array('pagename' => $pagename, 'pagename_par' => $pagename_par, 'pagetext' => $pagetext, 'flag_auto' => 'Y'); SQLX_UpdateOrInsert($table_pg, $row); /* if (!is_null($pagename_par)) { // Get sequence if necessary. if(is_null($seq)) { if(!isset($this->parseqs[$pagename_par])) { $this->parseqs[$pagename_par]=0; } $this->parseqs[$pagename_par]+=10; $seq=$this->parseqs[$pagename_par]; } // Store the hierachy link for saving later $this->parents[$pagename]=array($pagename_par,$seq); } */ }
/** ********************************************************** name:fbProc returns:echos HTML Does actual processing. */ function fbProc() { ob_start(); $tid = gp('gp_table_id'); $fi = SessionGet('importfile', array()); $t = DD_TableRef($tid); if (!isset($t['description']) || count($fi) == 0) { echo "Problem with uploads"; return; } ?> <h1>Table Import Processing</h1> <p>For Table: <?php echo $t['description']; ?> <p>Name in database: <?php echo $tid; ?> <p>File to process: <?php echo $fi['name']; ?> <p>File upload size: <?php echo number_format($fi['size']); ?> <hr> <pre> <?php list($linenum, $linesok) = $this->fbProcInner($fi, $t); echo "</pre>"; echo "<hr>"; echo "Processed {$linesok} of {$linenum} lines without errors"; echo ob_get_clean(); }
function HTML_Format_DD($table_id, $colname, $value) { $table = DD_TableRef($table_id); $type = $table['flat'][$colname]['type_id']; return HTML_Format($type, $value); }
/** 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; }
function __construct($table_id = '') { // Grab table ID if given, otherwise try to figure // one out, but only if we don't have one if ($table_id != '') { $this->table_id = $table_id; } else { if ($this->table_id == '') { $this->table_id = get_class($this); } } // Load data dictionary. This is not a tragedy if // the page has no table, just forget about it. $this->table = DD_TableRef($this->table_id); $this->view_id = ''; if (is_array($this->table)) { if (isset($this->table['projections']['_uisearch'])) { // capure this directly so it can be overridden $this->projections['_uisearch'] = $this->table['projections']['_uisearch']; } $this->view_id = DDTable_IDResolve($this->table_id); } // Look for an application-level variable for button_images /** level:class The property "button_images" can be overridden by setting an application-level property with the [[vgaSet()]] function. */ if (vgaGet('button_images', '') != '') { $this->button_images = vgaGet('button_images'); } // Set the page subtitle if we can find it if ($this->PageSubtitle == '') { $this->PageSubtitle = ArraySafe($this->table, "description", "PLEASE SET -PageSubtitle-"); } // Set the flag_buffer to false if we detect any flags // that would do that if (gpExists('gp_ajaxcol')) { $this->flag_buffer = false; } if (gpExists('gp_fbproc')) { $this->flag_buffer = false; } if (gpExists('gp_xajax')) { $this->flag_buffer = false; } if (gpExists('fwajax')) { $this->flag_buffer = false; } // This array can be used to override properties on // child objects invoked by this object $this->children = array(); // Now set all child tables to be 'drilldown', unless // overridden in datadictionary if (isset($this->table['fk_children'])) { foreach ($this->table['fk_children'] as $table_child => $tabinfo) { $display = trim(ArraySafe($tabinfo, 'uidisplay', 'drilldown')); $this->children[$table_child]['display'] = $display != '' ? $display : 'drilldown'; } } // KFD 6/30/07, allow a gp variable to specify which control to // set focus. Do it early so it can be overrridden if (gpexists('html_focus')) { vgfset('HTML_focus', 'x2t_' . hx(gp('html_focus'))); } // ((((((((((((((((((((((((((((*)))))))))))))))))))))))))))))))) // ((((((((((((((((( Run Custom-level Construct )))))))))))))))) $this->construct_custom(); $this->custom_construct(); // ((((((((((((((((( Run Custom-level Construct )))))))))))))))) // ((((((((((((((((((((((((((((*)))))))))))))))))))))))))))))))) // Now pass through child tables again, removing any setting // that is not allowed by security privs. Notice we do this // after the custom_construct, since that is where a setting might // be that conflicts with security setting. if (isset($this->table['fk_children'])) { $a = array_keys($this->table['fk_children']); foreach ($this->table['fk_children'] as $table_child => $tabinfo) { if (!DDUserPerm($table_child, 'menu')) { $this->children[$table_child]['display'] = 'none'; } } } }
function X_EMAIL_SEND($em) { $retval = false; //scDBConn_Push('admin'); if (SQLX_TrxLevel() > 0) { ErrorAdd("ERROR: Cannot send an email within a transaction"); } else { if (configGet('email_fromaddr')) { $from_addr = configGet('email_fromaddr'); $from_name = configGet('email_fromname'); } else { $from_addr = trim(OPTION_GET("EMAILFROM_ADDR")); $from_name = trim(OPTION_GET("EMAILFROM_NAME")); } $smtp_server = trim(OPTION_GET('SMTP_SERVER', 'localhost')); if ($from_addr == "") { ErrorAdd("The system's return email address, defined in system variable " . "EMAILFROM_ADDR, must be set to a valid email address. " . HTMLE_A_STD("System Variables", "variables", "")); } else { if ($from_name != "") { $from_name = '"' . $from_name . '"'; } $from = "From: " . $from_name . " <" . $from_addr . ">"; include_once 'Mail.php'; $recipients = $em["email_to"]; $headers['From'] = $from_name . "<" . $from_addr . ">"; $headers['To'] = $em["email_to"]; $headers['Subject'] = $em["email_subject"]; $headers['Date'] = date("D, j M Y H:i:s O", time()); foreach ($em['headers'] as $hname => $hval) { $headers[$hname] = $hval; } $body = $em["email_message"]; $params['sendmail_path'] = '/usr/lib/sendmail'; $params['host'] = $smtp_server; // Create the mail object using the Mail::factory method $mail_object = Mail::factory('smtp', $params); $mail_object->send($recipients, $headers, $body); if (!$mail_object) { ErrorAdd("Email was not accepted by server"); } else { $table_ref = DD_TableRef('adm_emails'); SQLX_Insert($table_ref, $em, false); $retval = false; } } } //scDBConn_Pop(); return $retval; }
function mainPRocess($v, $dirs) { // First create the version $table_dd = DD_TableRef('appversions'); $row = array('version' => $v, 'date' => time(), 'application' => $this->app); SQLX_Insert($table_dd, $row); if (Errors()) { echo hErrors(); return; } // We'll need this for every file we load $this->tlf = DD_TableRef('appfiles'); // Create the application save directory $app = $this->app; $r2 = $GLOBALS['AG']['dirs']['root']; if (!file_exists($r2 . 'pkg-apps')) { mkdir($r2 . 'pkg-apps'); } if (!file_exists($r2 . "pkg-apps/{$app}-{$v}")) { mkdir($r2 . "pkg-apps/{$app}-{$v}"); } $r2 = $r2 . "pkg-apps/{$app}-{$v}"; foreach ($dirs as $dir) { if (!file_exists($this->root . $dir['dirname'])) { mkdir($this->root . $dir['dirname']); } $this->mainPR_DirFiles($v, $r2, $this->root, $dir['dirname'], ''); } $dpa = $GLOBALS['AG']['dirs']['root'] . 'pkg-apps/'; chdir($GLOBALS['AG']['dirs']['root'] . 'pkg-apps/'); $command = "tar czvf {$app}-{$v}.tgz {$app}-{$v}"; x_EchoFlush(""); x_EchoFlush("Tarballing with this command: {$command}"); `{$command}`; x_EchoFlush(""); // Now create the install version. if ($this->app == 'andro') { x_EchoFlush("Renaming install.done.php to install.php"); rename("{$dpa}{$app}-{$v}/application/install.done.php", "{$dpa}{$app}-{$v}/application/install.php"); x_EchoFlush("Renaming directory to andro, copying index.php"); rename("{$dpa}{$app}-{$v}", $dpa . "andro"); copy($dpa . "andro/root/index.php", $dpa . "andro/index.php"); copy($dpa . "andro/root/htaccess", $dpa . "andro/.htaccess"); // KFD 8/2/07, Sourceforge bug #1755244, for the node manager // these are created by build but we need them for // the build, so make them here. mkdir($dpa . "andro/tmp"); mkdir($dpa . "andro/generated"); // KFD 8/2/07, Sourceforge bug #1755244, END $command = "tar czvf {$app}-{$v}-install.tgz andro index.php .htaccess"; x_EchoFlush(""); x_EchoFlush("Tarballing install version with this command: {$command}"); `{$command}`; x_EchoFlush("Renaming directory back to {$app}-{$v}"); unlink($dpa . "andro/index.php"); unlink($dpa . "andro/.htaccess"); rename($dpa . "andro", "{$dpa}{$app}-{$v}"); x_EchoFlush("Process is complete!"); } }
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(); } } }