00001 <?php
00002 require_once
TM_PATH . 'credentials.php';
00003 require_once
TM_PATH . 'MDB2.php';
00004
00017 class JuelichDbReader {
00018
00019 var
$dbms;
00020 var
$tplCache = array();
00022 function
JuelichDbReader() {
00023 $dsn = getDsn();
00024
$db =& MDB2::connect($dsn);
00025
if (PEAR::isError($db)) {
00026 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00027 $error =
new JuelichError;
00028 $error->printError(1, $db->getMessage());
00029
exit();
00030 }
00031
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
00032 $this->dbms =
$db;
00033 }
00034
00042 function
getOneValue($sql) {
00043 $value = '';
00044 $this->
checkSql($sql);
00045 $value = $this->dbms->queryOne($sql);
00046 $this->
checkError($value);
00047
return $value;
00048 }
00049
00058 function
getOneRow($sql, &$row) {
00059 $this->
checkSql($sql);
00060 $row = $this->dbms->queryRow($sql);
00061 $this->
checkError($row);
00062
if (empty($row)) {
00063
return false;
00064 }
00065
return true;
00066 }
00067
00076 function
getAllRows($sql, &$rows) {
00077 $this->
checkSql($sql);
00078 $rows = $this->dbms->queryAll($sql);
00079 $this->
checkError($rows);
00080
return count($rows);
00081 }
00082
00091 function
getAllCols($sql, &$cols) {
00092 $this->
checkSql($sql);
00093 $cols = $this->dbms->queryCol($sql);
00094 $this->
checkError($cols);
00095
return count($cols);
00096 }
00097
00107 function
getTemplateContent($tName, $l10n) {
00108
if (!empty($this->tplCache[$tName])) {
00109
return $this->tplCache[$tName];
00110 }
00111 $sqlPrep =
"SELECT t_content "
00112 .
"FROM template "
00113 .
"WHERE template_id = '%s' "
00114 .
"AND l10n_id = %d";
00115
$sql = sprintf($sqlPrep,
00116 $tName,
00117 $l10n
00118 );
00119 $content = $this->
getOneValue($sql);
00120 $this->tplCache[$tName] = $content;
00121
return $content;
00122 }
00123
00131 function
getModuleString($
id) {
00132 $sqlPrep =
"SELECT g_modString "
00133 .
"FROM gruppe "
00134 .
"LEFT JOIN produkt USING(gruppe_id) "
00135 .
"WHERE produkt_id = %s ";
00136
$sql = sprintf($sqlPrep, $
id);
00137
return $this->
getOneValue($sql);
00138 }
00139
00147 function
getImage($
id, &$imgData) {
00148 $sqlPrep =
"SELECT i_name, i_size, i_time, i_data "
00149 .
"FROM image "
00150 .
"WHERE id = '%s'";
00151
$sql = sprintf($sqlPrep, $
id);
00152 $this->
getOneRow($sql, $imgData);
00153
return;
00154 }
00155
00163 function
getTelAccessCats($hId, &$catData) {
00164 $sqlPrep =
"SELECT DISTINCT "
00165 .
"telZub_kat.telZub_kat_id AS id, k_name AS name "
00166 .
"FROM telZub_kat "
00167 .
"LEFT JOIN telZub USING(telZub_kat_id) "
00168 .
"WHERE hersteller_id = %s "
00169 .
"AND tz_online = '%s'";
00170
$sql = sprintf($sqlPrep,
00171 $hId,
00172
SQL_ONLINE
00173 );
00174 $this->
getAllRows($sql, $catData);
00175
return;
00176 }
00177
00185 function
getTelAccess($catId, &$accData) {
00186 $sqlPrep =
"SELECT tz_name AS name, tz_preis AS price "
00187 .
"FROM telZub "
00188 .
"WHERE telZub_kat_id = %s "
00189 .
"AND tz_online = '%s' "
00190 .
"ORDER BY tz_sort";
00191
$sql = sprintf($sqlPrep,
00192 $catId,
00193
SQL_ONLINE
00194 );
00195 $this->
getAllRows($sql, $accData);
00196
return;
00197 }
00198
00207 function
checkError(&$value) {
00208
if (PEAR::isError($value)) {
00209 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00210 $error =
new JuelichError;
00211 $error->printError(2, $value->getDebugInfo());
00212
exit();
00213 }
00214
return false;
00215 }
00216
00224 function
checkSql($sql) {
00225
00226 $pos = strpos( $sql, '=;' );
00227
if( $pos > 0 ) {
00228 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00229 $error =
new JuelichError;
00230 $error->printError(2,
00231 'SQL-ScriptKiddies unterwegs?: ' . $sql);
00232
exit();
00233 }
00234
return;
00235 }
00236
00237 }
00238
00239 ?>