示例#1
0
 function FMDBClose()
 {
     $queryResult = $this->ExecuteQuery("-dbclose");
     if (FX::isError($queryResult)) {
         return $queryResult;
     }
 }
 function doQuery($action)
 {
     if (strlen(trim($this->FX->dataServer)) < 1) {
         return new FX_Error('No MySQL server specified.');
     }
     if (strlen(trim($this->FX->dataPort)) > 0) {
         $tempServer = $this->FX->dataServer . ':' . $this->FX->dataPort;
     } else {
         $tempServer = $this->FX->dataServer;
     }
     $mysql_res = @mysql_connect($tempServer, $this->FX->DBUser, $this->FX->DBPassword);
     // although username and password are optional for this function, FX.php expects them to be set
     if ($mysql_res == false) {
         return new FX_Error('Unable to connect to MySQL server.');
     }
     if ($action != '-dbopen') {
         if (!mysql_select_db($this->FX->database, $mysql_res)) {
             return new FX_Error('Unable to connect to specified MySQL database.');
         }
     }
     if (substr_count($action, '-db') == 0 && substr_count($action, 'names') == 0 && strlen(trim($this->FX->layout)) > 0) {
         $theResult = mysql_query('SHOW COLUMNS FROM ' . $this->FX->layout);
         if (!$theResult) {
             return new FX_Error('Unable to access MySQL column data: ' . mysql_error());
         }
         $counter = 0;
         $keyPrecedence = 0;
         while ($tempRow = mysql_fetch_assoc($theResult)) {
             $this->FX->fieldInfo[$counter]['name'] = $tempRow['Field'];
             $this->FX->fieldInfo[$counter]['type'] = $tempRow['Type'];
             $this->FX->fieldInfo[$counter]['emptyok'] = $tempRow['Null'];
             $this->FX->fieldInfo[$counter]['maxrepeat'] = 1;
             $this->FX->fieldInfo[$counter]['extra'] = $tempRow['Key'] . ' ' . $tempRow['Extra'];
             if ($this->FX->fuzzyKeyLogic) {
                 if (strlen(trim($this->FX->primaryKeyField)) < 1 || $keyPrecedence < 3) {
                     if (substr_count($this->FX->fieldInfo[$counter]['extra'], 'UNI ') > 0 && $keyPrecedence < 3) {
                         $this->FX->primaryKeyField = $this->FX->fieldInfo[$counter]['name'];
                         $keyPrecedence = 3;
                     } elseif (substr_count($this->FX->fieldInfo[$counter]['extra'], 'auto_increment') > 0 && $keyPrecedence < 2) {
                         $this->FX->primaryKeyField = $this->FX->fieldInfo[$counter]['name'];
                         $keyPrecedence = 2;
                     } elseif (substr_count($this->FX->fieldInfo[$counter]['extra'], 'PRI ') > 0 && $keyPrecedence < 1) {
                         $this->FX->primaryKeyField = $this->FX->fieldInfo[$counter]['name'];
                         $keyPrecedence = 1;
                     }
                 }
             }
             ++$counter;
         }
     }
     switch ($action) {
         case '-dbopen':
         case '-dbclose':
             return new FX_Error('Opening and closing MySQL databases not available.');
             break;
         case '-delete':
         case '-edit':
         case '-find':
         case '-findall':
         case '-findany':
         case '-new':
             if ($action == '-findany') {
                 $this->FX->dataQuery = 'SELECT ' . ($this->FX->selectColsSet ? $this->FX->selectColumns : '*') . " FROM {$this->FX->layout} ORDER BY RAND() LIMIT 1;";
             } else {
                 $this->FX->dataQuery = $this->BuildSQLQuery($action);
                 if (FX::isError($this->FX->dataQuery)) {
                     return $this->FX->dataQuery;
                 }
             }
         case '-sqlquery':
             // note that there is no preceding break, as we don't want to build a query
             $theResult = mysql_query($this->FX->dataQuery);
             if ($theResult === false) {
                 return new FX_Error('Invalid query: ' . mysql_error());
             } elseif ($theResult !== true) {
                 if (substr_count($action, '-find') > 0 || substr_count($this->FX->dataQuery, 'SELECT ') > 0) {
                     $this->FX->foundCount = mysql_num_rows($theResult);
                 } else {
                     $this->FX->foundCount = mysql_affected_rows($theResult);
                 }
                 if ($action == '-dup' || $action == '-edit') {
                     // pull in data on relevant record
                 }
                 $currentKey = '';
                 while ($tempRow = mysql_fetch_assoc($theResult)) {
                     foreach ($tempRow as $key => $value) {
                         if ($this->FX->useInnerArray) {
                             $tempRow[$key] = array($value);
                         }
                         if ($key == $this->FX->primaryKeyField) {
                             $currentKey = $value;
                         }
                     }
                     if ($this->FX->genericKeys || $this->FX->primaryKeyField == '') {
                         $this->FX->currentData[] = $tempRow;
                     } else {
                         $this->FX->currentData[$currentKey] = $tempRow;
                     }
                 }
             } else {
                 $this->FX->currentData = array();
             }
             break;
         case '-dup':
             break;
     }
     $this->FX->fxError = 0;
     return true;
 }
示例#3
0
 /**
  * handleFXResult
  * 
  * logs queries, logs errors, and returns false on error
  * 
  * @param FX result object or FX error object
  * @param string : model name
  * @param string : action name
  * 
  * @return false if result is an FX error object
  */
 function handleFXResult($result, $modelName = 'N/A', $actionName = 'N/A')
 {
     $this->_queriesCnt++;
     // if a connection error
     if (FX::isError($result)) {
         // log error
         $this->_queriesLog[] = array('model' => $modelName, 'action' => $actionName, 'query' => '', 'error' => $result->toString(), 'numRows' => '', 'took' => round((getMicrotime() - $this->timeFlag) * 1000, 0));
         if (count($this->_queriesLog) > $this->_queriesLogMax) {
             array_pop($this->_queriesLog);
         }
         CakeLog::write('error', $this->formatErrorMessage('FX Error', $result->toString(), $modelName, $actionName));
         $this->timeFlag = getMicrotime();
         return FALSE;
         // if a filemaker error other than no records found
     } elseif ($result['errorCode'] != 0 && $result['errorCode'] != 401) {
         // log error
         $this->_queriesLog[] = array('model' => $modelName, 'action' => $actionName, 'query' => substr($result['URL'], strrpos($result['URL'], '?')), 'error' => $result['errorCode'], 'numRows' => '', 'took' => round((getMicrotime() - $this->timeFlag) * 1000, 0));
         if (count($this->_queriesLog) > $this->_queriesLogMax) {
             array_pop($this->_queriesLog);
         }
         CakeLog::write('error', $this->formatErrorMessage('FileMaker Error', $result['errorCode'], $modelName, $actionName, substr($result['URL'], strrpos($result['URL'], '?'))));
         $this->timeFlag = getMicrotime();
         return FALSE;
     } else {
         // log query
         $this->_queriesLog[] = array('model' => $modelName, 'action' => $actionName, 'query' => substr($result['URL'], strrpos($result['URL'], '?')), 'error' => $result['errorCode'], 'numRows' => isset($result['data']) ? count($result['data']) : $result['foundCount'], 'took' => round((getMicrotime() - $this->timeFlag) * 1000, 0));
         $this->timeFlag = getMicrotime();
         return TRUE;
     }
 }
 function doQuery($action)
 {
     $availableActions = array('-delete', '-edit', '-find', '-findall', '-new', '-sqlquery');
     if (!in_array(strtolower($action), $availableActions)) {
         // first off, toss out any requests for actions NOT supported under ODBC
         return new FX_Error("The action requested ({$action}) is not supported under ODBC via FX.php.");
     }
     $odbc_res = odbc_connect($this->FX->database, $this->FX->DBUser, $this->FX->DBPassword);
     // although username and password are optional for this function, FX.php expects them to be set
     if ($odbc_res == false) {
         return new FX_Error('Unable to connect to ODBC data source.');
     }
     switch ($action) {
         case '-delete':
         case '-edit':
         case '-find':
         case '-findall':
         case '-new':
             $this->FX->dataQuery = $this->BuildSQLQuery($action);
             if (FX::isError($this->FX->dataQuery)) {
                 return $this->FX->dataQuery;
             }
         case '-sqlquery':
             // note that there is no preceding break, as we don't want to build a query
             $odbc_result = odbc_exec($odbc_res, $this->FX->dataQuery);
             if (!$odbc_result) {
                 $tempErrorText = odbc_errormsg($odbc_res);
                 odbc_close($odbc_res);
                 return new FX_Error("Unsuccessful query: {$this->FX}->dataQuery ({$tempErrorText})");
             }
             $this->FX->foundCount = odbc_num_rows($odbc_result);
             $fieldCount = odbc_num_fields($odbc_result);
             if ($theResult < 0) {
                 $tempErrorText = odbc_errormsg($odbc_res);
                 odbc_close($odbc_res);
                 return new FX_Error("Unable to access field count for current ODBC query.  ({$tempErrorText})");
             }
             $odbc_columns = odbc_columns($odbc_res);
             if (!$odbc_columns) {
                 $tempErrorText = odbc_errormsg($odbc_res);
                 odbc_close($odbc_res);
                 return new FX_Error("Unable to retrieve column data via ODBC.  ({$tempErrorText})");
             }
             while (odbc_fetch_row($odbc_columns)) {
                 $fieldNumber = odbc_result($odbc_columns, 'ORDINAL_POSITION');
                 $this->FX->fieldInfo[$fieldNumber]['name'] = odbc_result($odbc_columns, 'COLUMN_NAME');
                 $this->FX->fieldInfo[$fieldNumber]['type'] = odbc_result($odbc_columns, 'TYPE_NAME');
                 $this->FX->fieldInfo[$fieldNumber]['emptyok'] = odbc_result($odbc_columns, 'IS_NULLABLE');
                 $this->FX->fieldInfo[$fieldNumber]['maxrepeat'] = 1;
                 $this->FX->fieldInfo[$fieldNumber]['extra'] = 'COLUMN_SIZE:' . odbc_result($odbc_columns, 'COLUMN_SIZE') . '|BUFFER_LENGTH:' . odbc_result($odbc_columns, 'BUFFER_LENGTH') . '|NUM_PREC_RADIX:' . odbc_result($odbc_columns, 'NUM_PREC_RADIX');
             }
             while (odbc_fetch_row($odbc_result)) {
                 $tempRow = array();
                 for ($i = 1; $i <= $fieldCount; ++$i) {
                     $theResult = odbc_result($odbc_result, $i);
                     if (!$this->FX->useInnerArray) {
                         $tempRow[$this->FX->fieldInfo[$i]['name']] = $theResult;
                     } else {
                         $tempRow[$this->FX->fieldInfo[$i]['name']] = array($theResult);
                     }
                     if ($this->FX->fieldInfo[$i]['name'] == $this->FX->primaryKeyField) {
                         $currentKey = $theResult;
                     }
                 }
                 if ($this->FX->genericKeys || $this->FX->primaryKeyField == '') {
                     $this->FX->currentData[] = $tempRow;
                 } else {
                     $this->FX->currentData[$currentKey] = $tempRow;
                 }
             }
             break;
         default:
             return new FX_Error("The action requested ({$action}) is not supported by FileMaker under ODBC via FX.php.");
             break;
     }
     $this->FX->fxError = 0;
     return true;
 }
function findSeminars($args = false, $webArgs = false) {
	$sixWeeksFromToday = time() + (60 * 60 * 24 * 7 * 6);
	$dateRange = date('n/j/Y').'...'.date('n/j/Y', $sixWeeksFromToday);
	
	$fm = new FX();
	$fm->SetDBData('meyerSeminar', 'xsl_calendar');
	if($args) {
		foreach($args as $arg) {
			$fm->AddDBParam('KEY', $arg);
		}
		$fm->AddDBParam('-lop', 'or');
	} else {
		$fm->AddDBParam('isOpen', 1);
		$fm->AddDBParam('seminarTopic::isWebinar', 'yes', 'neq');
	}
//	$fm->AddDBParam('startDate', $dateRange);
	
	
	$fm->AddSortParam('venue::territory', 'regions');
	$fm->AddSortParam('startDate', 'ascend');
	$queryResult = $fm->FMFind();  
	if(FX::isError($queryResult)) $cache_this->errorCatch();
	$calendar = $queryResult['data'];
	
	
	// get Webinars
	
	$fm->SetDBData('meyerSeminar', 'xsl_calendar');
	if($webArgs) {
		foreach($webArgs as $arg) {
			$webinar_keys = $_REQUEST['ids_for_'.$arg];
			foreach($webinar_keys as $key) {
				$fm->AddDBParam('KEY', $key);
			}
		}
		$fm->AddDBParam('-lop', 'or');
	} else {
		$fm->AddDBParam('isOpen', 1);
		$fm->AddDBParam('seminarTopic::isWebinar', 'yes', 'eq');
	}
//	$fm->AddDBParam('startDate', $dateRange);
	
	$fm->AddSortParam('startDate', 'ascend');
	$fm->AddSortParam('startTime', 'ascend');
	$queryResult = $fm->FMFind();  
	if(FX::isError($queryResult)) $cache_this->errorCatch();
	if($queryResult['foundCount'] > 0) $webinars = $queryResult['data'];
	
	
	$region = '';
	$lastRegion = '';
	
	if(!$args) {
		$output = '<form action="upcoming_seminars.php" method="post">
								<input type="hidden" name="_do" value="process" />';
	}
	
	
	// seminars loop
	
	foreach($calendar as $recID => $data) {
		// 2 column design.  This $col keeps track of which column we are on, so we can know when to open/close table rows
		$col = (($col == 1)?2:1);
		$region = $data['venue::territory'][0];

		//HTML Output Variables
		$regionHTML = '
					<tr>
						<td colspan="3" align="center" height="50" style="line-height:21px;">
							<div></div>
						</td>
					</tr>
					<tr>
						<td colspan="3">
							<table cellspacing="0" cellpadding="0" border="0" class="text_wrap">
								<tr>
									<td colspan="1" style="font-size:20px;line-height:28px;" class="cat_header">
										<span style="font-family:Arial,sans-serif;font-weight:bold;color:#558ac8;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing: grayscale;">'.$region.'</span>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="3" align="center" height="20" style="line-height:21px;">
							<div style="border-top:1px solid #558ac8;" id="seminars_underline"></div>
						</td>
					</tr>
					<tr>
						<td colspan="3" align="center" height="20" style="line-height:21px;">
							<div></div>
						</td>
					</tr>
					<tr>
						<td align="center" valign="top">';
		$padding = 	'<tr><td colspan="3" align="center" height="40" style="line-height:21px;" class="seminars_pad"><div></div></td></tr>';
		$leftCol = '<tr><td align="center" valign="top"><table cellpadding="0" cellspacing="0" border="0" width="210" align="left" class="stories_cont">' . '<tr><td colspan="2" align="center">';
		$rightCol = '<table cellpadding="0" cellspacing="0" border="0" width="210" align="right" class="stories_cont"><tr><td colspan="2" align="center">';
		$openSem = '<table cellpadding="0" cellspacing="0" border="0" class="seminars_text"><tr><td colspan="1" valign="top" style="font-size:18px;line-height:25px;" class="seminars_align">';

		// split things up by region
		if(!$region || $region != $lastRegion) {
			// different case for the first row
			if($lastRegion) {
				// if row was unfinished, finish it
				if($col == 2) {
					$output .= '<td>&nbsp;</td></tr>';
					$col = 1;
				}
				// close previous section, make divider
				$output .= '
					</td>
				</tr>';
			}
			
			// open new seminar block (REPLACED)
			$output .= $regionHTML;
		}
		
		
		//open a new row
		if($col == 1) {
			$output .= $leftCol;
		}
		if($col == 2) {
			$output .= $rightCol;
		}
		// the meat of the seminars
		$id = $data['KEY'][0];
		$regLink = (($data['Cvent_link'][0])?$data['Cvent_link'][0]:'http://www.meyersound.com/seminars/registration.php?id='.$id);
		$language = '('.str_replace(array('(',')'),'',$data['web_language'][0]).')';
		$output .= $openSem;
		if(!$args) {
			$output .= '<input type="checkbox" name="selectedSeminars[]" class="seminarSelect" value="'.$id.'">';
		}
		$output .= '
										<a href="'.$regLink.'" style="font-family:Arial,sans-serif;font-weight:normal;color:#5d6e83;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-decoration:none;" class="tagline">'.$data['venue::friendlyLocation'][0].'</a> 
									</td>
								</tr>
								<tr>
									<td colspan="1" valign="top" style="font-size:14px;line-height:21px;" class="seminars_align">
										<span style="font-family:Arial, sans-serif;font-weight:normal;color:#0f4dbc;text-decoration:none;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;" class="description">'.$data['friendlyDate'][0].'</span>
									</td>
								</tr>
								<tr>
									<td colspan="1" valign="top" style="font-size:14px;line-height:21px;" class="seminars_align">
										<span style="font-family:Arial, sans-serif;font-weight:normal;color:#51667c;text-decoration:none;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;" class="description">'.$data['seminarTopic::friendlyName'][0].' '.(($region != 'North America')?$language:'').'</span>
									</td>
								</tr>
						</table>
					</td>
				</tr>
			</table>';
		if($col == 2){
			$output .= '</td></tr>' .$padding;
		}			
		$lastRegion = $region;
		
	}// End Foreach Loop	
	
	// close last region:
	//$output .= '
				//		</table>
			//		</td>
			//	</tr>';
	// open new divider if there are webinars	to display
	if($webinars) {
		$output .= '
				<tr>
						<td class="w448" style="font-size: 11px; line-height: 22px; padding: 0px 35px; vertical-align: top;">
							<p class="left" style="margin: 2px 0px; float: left;"><img src="http://www.meyersound.com/mail/seminar_images/short-hr.gif" alt="" style="border: none;" /></p>
						</td>
				</tr>
				<tr>
						<td class="w448" style="font-size: 11px; line-height: 22px; padding: 0px 35px; vertical-align: top;">

							<p class="left" style="margin: 5px 0px; float: left;"><span class="mh1 blue normal" style="font-size: 14px; font-weight: normal; color: #3a4e7f;">Webinars</span></p>						</td>
					</tr>
					<tr>
						<td class="w448" style="font-size: 11px; line-height: 22px; padding: 0px 35px; vertical-align: top;">
							<table cellspacing="0" border="0" cellpadding="0" width="100%">';
	
		$col = 0;
		// webinars loop
		// first loop through and group webinars by the same date, and format so multiple webinars on one day gets one entry
		// webinars are put into an array, keyed by dateKey (seminar date and topic ID)
		foreach($webinars as $recID => $data) {
			
			// the meat of the seminars
			$id = $data['KEY'][0];
			$regLink = (($data['Cvent_link'][0])?$data['Cvent_link'][0]:'http://www.meyersound.com/seminars/registration.php?id='.$id);
			$language = '('.str_replace(array('(',')'),'',$data['web_language'][0]).')';
			
			$dateKey = str_replace(' ','_',str_replace(',','',$data['friendlyDate'][0]).'-'.$data['seminarTopic::KEY'][0]);
			
			$web[$dateKey]['courseName'] = str_replace('Webinar - ','',$data['seminarTopic::friendlyName'][0]).' '.(($region != 'North America')?$language:'');
			$web[$dateKey]['date'] = $data['friendlyDate'][0];
			//$web[$data['friendlyDate'][0]]['topicKey'] = $data['seminarTopic::KEY'][0];
			
			$web[$dateKey]['time'][$id] = '<a href="'.$regLink.'" style="font-size: 11px; color: #555656; text-decoration: none;">Register for '.formatFMTime($data['startTime'][0]).' PST</a>';
			
		}
		
		foreach($web as $dateKey => $data) {
			// 2 column design.  This $col keeps track of which column we are on, so we can know when to open/close table rows
			$col = (($col == 1)?2:1);
			
			//open a new row
			if($col == 1) {
				$output .= '<tr>';
			}
			
			// the meat of the seminars
			$id = $data['KEY'][0];
			$regLink = (($data['Cvent_link'][0])?$data['Cvent_link'][0]:'http://www.meyersound.com/seminars/registration.php?id='.$id);
			$language = '('.str_replace(array('(',')'),'',$data['web_language'][0]).')';
			
			$output .= '
								<td style="vertical-align: top;">';
			if(!$args) {
				// each webinar has 1 or more distinct course IDs for different times
				// make one checkbox for this course (by date+key, replacing commas and spaces w/ underscores
				//$dateKey = str_replace(' ','_',str_replace(',','',$data['date']).'-'.$data['topicKey']);
				$output .= '<input type="checkbox" name="selectedWebinars[]" class="seminarSelect" value="'.$dateKey.'">';
				foreach($data['time'] as $key => $time) {
					$output .= '<input type="hidden" name="ids_for_'.$dateKey.'[]" value="'.$key.'">';
				}
			}
			$output .= '
									<ul class="seminar" style="margin: 0px; list-style: none; line-height: normal; padding: 0px 0px 20px 0px; width: 224px;">
										<li class="sloc" style="font-weight: bold; font-size: 12px; color: #555656;">
											'.str_replace('(1 hour)', '', $data['courseName']).'
											
										</li>
										<li class="sdate" style="font-size: 11px; color: #3a4e7f;">'.$data['date'].'</li>';
			foreach($data['time'] as $key => $time) {
				$output .= '<li class="sinfo" style="font-size: 11px; width: 150px;">'.$time.'</li>';
			}
			$output .= '
									</ul> 
								</td>';
										
			if($col == 2) {
				$output .= '</tr>';
			}
			
			
		}	
		// close last row
		$output .= '		</table>
						</td>
					</tr>';
	} // end if webinars	
	if(!$args) {
		$output .= '
						<tr>
					<td><input type="submit" value="submit">
				</form>
			</td>
		</tr>';
	}
	
	return $output;
}
 function doQuery($action)
 {
     $availableActions = array('-delete', '-edit', '-find', '-findall', '-new', '-sqlquery');
     $columnTypes = array(1 => 'char', 2 => 'integer', 3 => 'float', 4 => 'long', 5 => 'money', 6 => 'date', 7 => 'time', 8 => 'object', 9 => 'datetime', 10 => 'longlong', 11 => 'boolean', 12 => 'binary', 13 => 'text', 14 => 'timestamp');
     if (!in_array(strtolower($action), $availableActions)) {
         // first off, toss out any requests for actions NOT supported under OpenBase
         return new FX_Error("The action requested ({$action}) is not supported by OpenBase via FX.php.");
     }
     // although username and password are optional for this function, FX.php expects them to be set
     $openBase_res = ob_connect($this->FX->database, $this->FX->dataServer, $this->FX->DBUser, $this->FX->DBPassword);
     if (substr(trim($openBase_res), 0, 13) != 'Resource id #') {
         return new FX_Error("Error {$theResult}.  Unable to connect to OpenBase database.");
     }
     switch ($action) {
         case '-delete':
         case '-edit':
         case '-find':
         case '-findall':
         case '-new':
             $this->FX->dataQuery = $this->BuildSQLQuery($action);
             if (FX::isError($this->FX->dataQuery)) {
                 return $this->FX->dataQuery;
             }
         case '-sqlquery':
             // note that there is no preceding break, as we don't want to build a query
             ob_makeCommand($openBase_res, $this->FX->dataQuery);
             $theResult = ob_executeCommand($openBase_res);
             if (!$theResult) {
                 $tempErrorText = ob_servermessage($openBase_res);
                 ob_disconnect($openBase_res);
                 // ob_disconnect() is not in the documentation
                 return new FX_Error("Unsuccessful query: {$this->FX->dataQuery} ({$tempErrorText})");
             }
             $fieldCount = ob_resultColumnCount($openBase_res);
             for ($i = 0; $i < $fieldCount; ++$i) {
                 $this->FX->fieldInfo[$i]['name'] = ob_resultColumnName($openBase_res, $i);
                 $this->FX->fieldInfo[$i]['type'] = ob_resultColumnType($openBase_res, $i);
                 $this->FX->fieldInfo[$i]['emptyok'] = 'NO DATA';
                 $this->FX->fieldInfo[$i]['maxrepeat'] = 1;
                 $this->FX->fieldInfo[$i]['extra'] = '';
             }
             $this->FX->foundCount = ob_rowsAffected($openBase_res);
             $retrieveRow = array();
             $currentKey = '';
             while (ob_resultReturned($openBase_res) && ob_nextRowWithArray($openBase_res, $retrieveRow)) {
                 $tempRow = array();
                 foreach ($retrieveRow as $key => $value) {
                     if (!$this->FX->useInnerArray) {
                         $tempRow[$this->FX->fieldInfo[$key]['name']] = $value;
                     } else {
                         $tempRow[$this->FX->fieldInfo[$key]['name']] = array($value);
                     }
                     if ($key == $this->FX->primaryKeyField) {
                         $currentKey = $value;
                     } elseif ($this->FX->primaryKeyField == '' && $this->FX->fieldInfo[$key]['name'] == '_rowid') {
                         $currentKey = $value;
                     }
                 }
                 if (($this->FX->genericKeys || $this->FX->primaryKeyField == '') && strlen(trim($currentKey)) < 1) {
                     $this->FX->currentData[] = $tempRow;
                 } else {
                     $this->FX->currentData[$currentKey] = $tempRow;
                 }
             }
             break;
         default:
             return new FX_Error("The action requested ({$action}) is not supported by OpenBase via FX.php.");
             break;
     }
     $this->FX->fxError = 0;
     return true;
 }
示例#7
0
}
?>
<html>
    <head>
        <title>FX Error Tester</title>
    </head>
    <body>
        <h1>Contact List</h1>
        <table border="1">
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Phone Number</th>
            </tr>
<?php 
if (FX::isError($contactsList)) {
    echo "            <tr>\n";
    echo "                <td colspan=\"3\" align=\"center\">ERROR</td>\n";
    echo "            </tr>\n";
} elseif (count($contactsList) < 1) {
    echo "            <tr>\n";
    echo "                <td colspan=\"3\" align=\"center\">No Records Found</td>\n";
    echo "            </tr>\n";
} else {
    foreach ($contactsList as $contact) {
        echo "            <tr>\n";
        echo "                <td>{$contact['First_Name']}</td>\n";
        echo "                <td>{$contact['Last_Name']}</td>\n";
        echo "                <td>{$contact['Phone_1']}</td>\n";
        echo "            </tr>\n";
    }
示例#8
0
 if (FX::isError($DatabaseData)) {
     echo "<pre>\n";
     print_r($LayoutData);
     echo "</pre>\n";
     exit;
 }
 foreach ($DatabaseData['data'] as $key => $value) {
     $currentDatabaseList[] = $value['DATABASE_NAME'][0];
 }
 unset($DatabaseData);
 if (in_array($FXE_currentDatabaseName, $currentDatabaseList)) {
     $FXQuery->SetDBData($FXE_currentDatabaseName);
     $FXQuery->SetDBPassword($FXE_password, $FXE_username);
     // Note that password is the FIRST parameter (since user names are only relevant for the FM Web Security DB.)
     $LayoutData = $FXQuery->FMLayoutNames();
     if (FX::isError($LayoutData)) {
         echo "<pre>\n";
         print_r($LayoutData);
         echo "</pre>\n";
         exit;
     }
     foreach ($LayoutData['data'] as $key => $value) {
         $currentLayoutList[] = $value['LAYOUT_NAME'][0];
     }
     unset($LayoutData);
     if ($FXE_currentLayoutName == '' && strtolower($dataSourceType) == 'fmpro5/6' || in_array($FXE_currentLayoutName, $currentLayoutList)) {
         $errorMessage = 'None';
         if (strtolower($FXE_action) == 'update') {
             $FXQuery->SetDBData($FXE_currentDatabaseName, $FXE_currentLayoutName);
             session_name('FXE_sessionID');
             session_start();
 function doQuery($action)
 {
     $connectString = '';
     $unsupportedActions = array('-dbnames', '-layoutnames', '-scriptnames', '-dbopen', '-dbclose');
     if (in_array($action, $unsupportedActions)) {
         return new FX_Error("The requested Action ({$action}) is not supported in PostgreSQL via FX.php.");
     }
     if (strlen(trim($this->FX->dataServer)) > 0) {
         $connectString .= " host={$this->FX->dataServer}";
     }
     if (strlen(trim($this->FX->dataPort)) > 0) {
         $connectString .= " port={$this->FX->dataPort}";
     }
     if (strlen(trim($this->FX->database)) > 0) {
         $connectString .= " dbname={$this->FX->database}";
     }
     if (strlen(trim($this->FX->DBUser)) > 0) {
         $connectString .= " user={$this->FX->DBUser}";
     }
     if (strlen(trim($this->FX->DBPassword)) > 0) {
         $connectString .= " password={$this->FX->DBPassword}";
     }
     if (strlen(trim($this->FX->urlScheme)) > 0 && $this->FX->urlScheme == 'https') {
         $connectString .= " sslmode=require";
     }
     $postresql_res = @pg_connect($connectString);
     if ($postresql_res == false) {
         return new FX_Error("Unable to connect to PostgreSQL server. (" . pg_last_error($postresql_res) . ")");
     }
     $theResult = pg_query($postresql_res, "SELECT column_name, data_type, is_nullable FROM information_schema.columns WHERE table_name ='{$this->FX->layout}'");
     if (!$theResult) {
         return new FX_Error('Unable to access PostgreSQL column data: ' . pg_last_error($postresql_res));
     }
     $counter = 0;
     $keyPrecedence = 0;
     while ($tempRow = @pg_fetch_array($theResult, $counter, PGSQL_ASSOC)) {
         $this->FX->fieldInfo[$counter]['name'] = $tempRow['column_name'];
         $this->FX->fieldInfo[$counter]['type'] = $tempRow['data_type'];
         $this->FX->fieldInfo[$counter]['emptyok'] = $tempRow['is_nullable'];
         $this->FX->fieldInfo[$counter]['maxrepeat'] = 1;
         ++$counter;
     }
     switch ($action) {
         case '-delete':
         case '-edit':
         case '-find':
         case '-findall':
         case '-new':
             $this->FX->dataQuery = $this->BuildSQLQuery($action);
             if (FX::isError($this->FX->dataQuery)) {
                 return $this->FX->dataQuery;
             }
         case '-sqlquery':
             // note that there is no preceding break, as we don't want to build a query
             $theResult = pg_query($this->FX->dataQuery);
             if (!$theResult) {
                 return new FX_Error('Invalid query: ' . pg_last_error($postresql_res));
             }
             if (substr_count($action, '-find') > 0 || substr_count($this->FX->dataQuery, 'SELECT ') > 0) {
                 $this->FX->foundCount = pg_num_rows($theResult);
             } else {
                 $this->FX->foundCount = pg_affected_rows($theResult);
             }
             if ($action == '-dup' || $action == '-edit') {
                 // pull in data on relevant record
             }
             $counter = 0;
             $currentKey = '';
             while ($tempRow = @pg_fetch_array($theResult, $counter, PGSQL_ASSOC)) {
                 foreach ($tempRow as $key => $value) {
                     if ($this->FX->useInnerArray) {
                         $tempRow[$key] = array($value);
                     }
                     if ($key == $this->FX->primaryKeyField) {
                         $currentKey = $value;
                     }
                 }
                 if ($this->FX->genericKeys || $this->FX->primaryKeyField == '') {
                     $this->FX->currentData[] = $tempRow;
                 } else {
                     $this->FX->currentData[$currentKey] = $tempRow;
                 }
                 ++$counter;
             }
             break;
         case '-findany':
             break;
         case '-dup':
             break;
     }
     $this->FX->fxError = 0;
     return true;
 }
 function doQuery($action)
 {
     // Note that because of the way in which CAFEphp and FileMaker are implemented, CAFEphp must be running on the same
     // machine that is serving as the web server.  (You'll note that PHP creates a COM object which looks for a locally
     // running application.)  For this same reason, the server IP and port are irrelevant.
     $availableActions = array('-delete', '-edit', '-find', '-findall', '-new', '-sqlquery');
     if (!in_array(strtolower($action), $availableActions)) {
         // first off, toss out any requests for actions NOT supported under CAFEphp
         return new FX_Error("The action requested ({$action}) is not supported in CAFEphp.");
     }
     $CAFEphp_res = new COM('CAFEphp.Application');
     // although username and password are optional for this function, FX.php expects them to be set
     if ($CAFEphp_res == false) {
         return new FX_Error('Unable to load to CAFEphp.');
     }
     if (defined("DEBUG") and DEBUG or DEBUG_FUZZY) {
         $currentDebugString = "<p>CAFEphp version: " . $CAFEphp_res->Version() . "</p>\n";
         $this->FX->lastDebugMessage .= $currentDebugString;
         if (defined("DEBUG") and DEBUG) {
             echo $currentDebugString;
         }
     }
     $theResult = $CAFEphp_res->Connect($this->FX->database, $this->FX->DBUser, $this->FX->DBPassword);
     if ($theResult != 0) {
         $CAFEphp_res->EndConnection();
         switch ($theResult) {
             case -1:
                 return new FX_Error('Unable to connect.  Be sure the FileMaker database and CAFEphp are running.');
                 break;
             case -2:
                 return new FX_Error('Certificate not present.  You MUST have a certificate.');
                 break;
             case -3:
                 return new FX_Error('Certificate is corrupt.');
                 break;
             case -4:
                 return new FX_Error('CAFEphp is not running or the demo version has expired.');
                 break;
             case -5:
                 return new FX_Error('The current demo of CAFEphp has expired.');
                 break;
             default:
                 return new FX_Error('An unknown error has occured while attempting to create the COM object.');
                 break;
         }
     }
     switch ($action) {
         case '-delete':
         case '-edit':
         case '-find':
         case '-findall':
         case '-new':
             $this->FX->dataQuery = $this->BuildSQLQuery($action);
             if (FX::isError($this->FX->dataQuery)) {
                 return $this->FX->dataQuery;
             }
         case '-sqlquery':
             // note that there is no preceding break, as we don't want to build a query
             if (substr(trim($this->FX->dataQuery), 0, 6) == 'SELECT') {
                 $currentSelect = true;
                 $theResult = $CAFEphp_res->Query($this->FX->dataQuery, $this->FX->groupSize);
             } else {
                 $currentSelect = false;
                 $theResult = $CAFEphp_res->Execute($this->FX->dataQuery);
             }
             if ($theResult < 0) {
                 $CAFEphp_res->EndConnection();
                 switch ($theResult) {
                     case -1:
                         return new FX_Error('No CAFEphp connection for the query.');
                         break;
                     default:
                         return new FX_Error('An unknown error occured during the query.');
                         break;
                 }
             }
             $this->FX->foundCount = $theResult;
             $theResult = $CAFEphp_res->FieldCount();
             if ($theResult < 0) {
                 $CAFEphp_res->EndConnection();
                 switch ($theResult) {
                     case -1:
                         return new FX_Error('No CAFEphp connection for the field count.');
                         break;
                     case -2:
                         return new FX_Error('No query was performed for a field count.');
                         break;
                     default:
                         return new FX_Error('An unknown error occured during the query.');
                         break;
                 }
             } else {
                 $currentFieldCount = $theResult;
             }
             for ($i = 0; $i < $currentFieldCount; ++$i) {
                 $theResult = $CAFEphp_res->FieldName($i);
                 if ($theResult == '$-CAFEphpNOCONNECTION') {
                     $CAFEphp_res->EndConnection();
                     return new FX_Error("No CAFEphp connection while retieving the name of field {$i}.");
                 } elseif ($theResult == '$-CAFEphpNOQUERY') {
                     $CAFEphp_res->EndConnection();
                     return new FX_Error("CAFEphp returned a \"No Query\" error while retieving the name of field {$i}.");
                 } elseif ($theResult == '$-CAFEphpUNKNOWNERROR') {
                     $CAFEphp_res->EndConnection();
                     return new FX_Error("CAFEphp returned an unknown error while retieving the name of field {$i}.");
                 }
                 $this->FX->fieldInfo[$i]['name'] = $theResult;
                 $this->FX->fieldInfo[$i]['type'] = 'NO DATA';
                 $this->FX->fieldInfo[$i]['emptyok'] = 'NO DATA';
                 $this->FX->fieldInfo[$i]['maxrepeat'] = 'NO DATA';
                 $this->FX->fieldInfo[$i]['extra'] = '';
             }
             if ($currentSelect) {
                 $tempRow = array();
                 for ($i = 0; $i < $this->FX->foundCount; ++$i) {
                     for ($j = 0; $j < $currentFieldCount; ++$j) {
                         $theResult = $CAFEphp_res->FieldValue($j);
                         if ($theResult == '$-CAFEphpNOCONNECTION') {
                             $CAFEphp_res->EndConnection();
                             return new FX_Error("No CAFEphp connection while retieving the value of field {$i} for record {$j}.");
                         } elseif ($theResult == '$-CAFEphpNOQUERY') {
                             $CAFEphp_res->EndConnection();
                             return new FX_Error("CAFEphp returned a \"No Query\" error while retieving the value of field {$i} for record {$j}.");
                         } elseif ($theResult == '$-CAFEphpUNKNOWNERROR') {
                             $CAFEphp_res->EndConnection();
                             return new FX_Error("CAFEphp returned an unknown error while retieving the value of field {$i} for record {$j}.");
                         }
                         if (!$this->FX->useInnerArray) {
                             $tempRow[$this->FX->fieldInfo[$j]['name']] = $theResult;
                         } else {
                             $tempRow[$this->FX->fieldInfo[$j]['name']] = array($theResult);
                         }
                         if ($this->FX->fieldInfo[$j]['name'] == $this->FX->primaryKeyField) {
                             $currentKey = $value;
                         }
                     }
                     if ($this->FX->genericKeys || $this->FX->primaryKeyField == '') {
                         $this->FX->currentData[] = $tempRow;
                     } else {
                         $this->FX->currentData[$currentKey] = $tempRow;
                     }
                     $theResult = $CAFEphp_res->MoveNext();
                     if ($theResult < 0) {
                         $CAFEphp_res->EndConnection();
                         $next = $i + 1;
                         switch ($theResult) {
                             case -1:
                                 return new FX_Error('No CAFEphp connection while moving from record {$i} to {$next}.');
                                 break;
                             case -2:
                                 return new FX_Error('There was no current query while moving from record {$i} to {$next}.');
                                 break;
                             default:
                                 return new FX_Error('An unknown error occured while moving from record {$i} to {$next}.');
                                 break;
                         }
                     }
                 }
             }
             break;
         default:
             return new FX_Error("The action requested ({$action}) is not supported in CAFEphp.");
             break;
     }
     $this->FX->fxError = 0;
     return true;
 }