00001 <?php
00002 require_once
TM_PATH . 'constants.php';
00003 require_once
TM_PATH . 'juelich/JuelichGlobals.php';
00004
00017 class JuelichDataProduct {
00018 var
$db;
00019 var
$pData = array('product' => array(),
00020 'detail' => array(),
00021 'access' => array(),
00022 'depend' => array()
00023 ); #
00024 var
$accessCache = array();
00026 function
JuelichDataProduct() {
00027 $this->db =&
getDbReaderInstance();
00028 }
00029
00037 function
getModel($modellId, &$modelData) {
00038 $sqlPrep =
"SELECT m_name, m_besch, m_sort, m_forumSearch "
00039 .
"FROM modell "
00040 .
"LEFT JOIN modell_l10n USING(modell_id)"
00041 .
"WHERE modell.modell_id = %d "
00042 .
"AND l10n_id=%d ";
00043
$sql = sprintf($sqlPrep,
00044 $modellId,
00045
getDataInstance()->getAppData('l10n')
00046 );
00047 $this->db->getOneRow($sql, $modelData);
00048
if (empty($modelData)) {
00049 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00050 $error =
new JuelichError;
00051 $error->printError(4,
00052 'Keine Daten zum Modell: '
00053 . $modellId);
00054
exit();
00055 }
00056
return;
00057 }
00058
00067 function
getProducts($modellId, &$pData) {
00068 $data =&
getDataInstance();
00069 $sqlPrep =
"SELECT p_preis, p_bild, p_name, "
00070 .
"p_besch2, produkt.produkt_id%s "
00071 .
"FROM produkt "
00072 .
"LEFT JOIN produkt_l10n USING(produkt_id) "
00073 .
"LEFT JOIN %s USING(produkt_id) "
00074 .
"WHERE modell_id = %d "
00075 .
"AND p_online = '%s' "
00076 .
"AND l10n_id = %d "
00077 .
"ORDER BY %s";
00078 $short = implode(', ', $data->getModuleDbData('
short'));
00079
if ($short !=
"") {
00080 $short = ', ' . $short;
00081 }
00082
$sql = sprintf($sqlPrep,
00083 $
short,
00084 $data->getModuleDbData('table'),
00085 $modellId,
00086
SQL_ONLINE,
00087 $data->getAppData('l10n'),
00088 $data->getAppData('modelSort')
00089 );
00090 $products = array();
00091 $rows = $this->db->getAllRows($sql, $products);
00092
if ($rows == 0) {
00093 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00094 $error =
new JuelichError;
00095 $error->printError(4,
00096 'Keine Produkte zum Modell: '
00097 . $modell_id);
00098
exit();
00099 }
00100 foreach ($products as $p) {
00101 $pTmp = $this->pData;
00102
00103 $dp = $data->getAppData('module')->depend;
00104
if ($dp && in_array(
M_MODEL, $dp['mode'])) {
00105 $gId = $data->getAppData('module')->gruppe_id;
00106
$sql = $this->
getDependSql($gId, $p['produkt_id']);
00107 $dpTmp = array();
00108 $this->db->getAllRows($sql, $dpTmp);
00109 array_unshift($dpTmp, $p['produkt_id']);
00110 $pTmp['depend'] = $dpTmp;
00111 }
00112
00113
if ($data->getAppData('module')->showAccessory) {
00114 $zTmp = array();
00115 $aIds = array();
00116 $aDbIds = array();
00117 $this->
getAccessIds($p['produkt_id'], $aIds);
00118
00119
if (!empty($aIds)) {
00120 foreach ($aIds as $
id) {
00121
00122
if (!empty($this->accessCache[$
id])) {
00123 array_push($zTmp, $this->accessCache[$
id]);
00124 }
00125
00126
else {
00127 array_push($aDbIds, $
id);
00128 }
00129 }
00130
00131
if (!empty($aDbIds)) {
00132 $sqlPrep =
"SELECT z_preis, z_name, zubehoer.zubehoer_id, z_intern "
00133 .
"FROM zubehoer "
00134 .
"LEFT JOIN zubehoer_l10n USING(zubehoer_id) "
00135 .
"WHERE z_online = '%s' "
00136 .
"AND zubehoer.zubehoer_id IN(%s)"
00137 .
"AND l10n_id = %d "
00138 .
"ORDER BY z_sort, z_name";
00139
$sql = sprintf($sqlPrep,
00140
SQL_ONLINE,
00141 implode(', ', $aDbIds),
00142 $data->getAppData('l10n')
00143 );
00144 $this->db->getAllRows($sql, $zTmp);
00145 $pTmp['access'] = $zTmp;
00146 foreach ($zTmp as $z) {
00147 $id = $z['zubehoer_id'];
00148 $this->accessCache[$id] = $z;
00149 }
00150 }
00151 }
00152 }
00153
$s = count($p);
00154 $pTmp['product'] = array_slice($p, 0, 5);
00155 $pTmp['detail'] = array_slice($p, 5, $s - 5);
00156
if (!empty($p['access'])) {
00157 $pTmp['access'] = $p['access'];
00158 }
00159
if (!empty($p['depend'])) {
00160 $pTmp['depend'] = $p['depend'];
00161 }
00162 array_push($pData, $pTmp);
00163 }
00164
return $rows;
00165 }
00166
00174 function
getDetailProduct($
id, &$pData) {
00175 $data =&
getDataInstance();
00176 $dTmp = array('depend' => array(),
00177 'data' => array()
00178 );
00179
00180
if ($data->getAppData('dependDetail')) {
00181 $sqlPrep =
"SELECT %s "
00182 .
"FROM produkt "
00183 .
"LEFT JOIN produkt_l10n USING(produkt_id) "
00184 .
"LEFT JOIN %s USING(produkt_id) "
00185 .
"WHERE produkt.produkt_id = %d "
00186 .
"AND produkt_l10n.l10n_id = %d ";
00187
$sql = sprintf($sqlPrep,
00188 implode(', ', $data->getModuleDbData('dpExtra')),
00189 $data->getModuleDbData('dpTable'),
00190 $data->getAppData('dependId'),
00191 $data->getAppData('l10n')
00192 );
00193 $this->db->getOneRow($sql, $dTmp['depend']);
00194 }
00195
00196 $sqlPrep =
"SELECT p_preis, p_bild, p_name, "
00197 .
"p_besch1, p_besch2, produkt.produkt_id, m_name%s "
00198 .
"FROM produkt "
00199 .
"LEFT JOIN produkt_l10n USING(produkt_id) "
00200 .
"LEFT JOIN %s USING(produkt_id) "
00201 .
"%s "
00202 .
"LEFT JOIN modell_l10n "
00203 .
"ON produkt.modell_id=modell_l10n.modell_id "
00204 .
"WHERE produkt.produkt_id = %d "
00205 .
"AND produkt_l10n.l10n_id = %d "
00206 .
"AND modell_l10n.l10n_id = %d "
00207 .
"%s";
00208 $long = implode(', ', $data->getModuleDbData('
long'));
00209
if ($long !=
"") {
00210 $long = ', ' . $long;
00211 }
00212 $table = $data->getModuleDbData('table');
00213 $l10nData = '';
00214 $l10nDataLang = '';
00215 $l10n = $data->getAppData('l10n');
00216
if ($data->getModuleDbData('l10n')) {
00217 $t = $table . '_l10n';
00218 $l10nData =
"LEFT JOIN $t USING(produkt_id) ";
00219 $l10nDataLang =
"AND $t.l10n_id = $l10n";
00220 }
00221
$sql = sprintf($sqlPrep,
00222 $
long,
00223 $table,
00224 $l10nData,
00225 $
id,
00226 $l10n,
00227 $l10n,
00228 $l10nDataLang
00229 );
00230
00231 $success = $this->db->getOneRow($sql, $dTmp['data']);
00232
if (!$success) {
00233 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00234 $error =
new JuelichError;
00235 $error->printError(4,
00236 'Keine Detail-Daten zum Produkt: ' . $
id);
00237
exit();
00238 }
00239
$pData = $this->pData;
00240
$pData['product'] = array_slice($dTmp['data'], 0, 7);
00241
$pData['detail'] = array_slice($dTmp['data'], 7);
00242
if (!empty($dTmp['depend'])) {
00243
$pData['detail'] = array_merge($pData['detail'], $dTmp['depend']);
00244 }
00245 $t =
$pData['product']['m_name']
00246 .
' '
00247 . $pData['product']['p_name'];
00248
getDataInstance()->setModelName($pData['product']['m_name']);
00249
getDataInstance()->setTitle($t);
00250
return;
00251 }
00252
00260 function
getDetailAccess($
id, &$zData) {
00261 $data =&
getDataInstance();
00262 $sqlPrep =
"SELECT zubehoer.zubehoer_id, z_preis, z_bild, "
00263 .
"z_name, z_besch1, z_besch2, h_name "
00264 .
"FROM zubehoer "
00265 .
"LEFT JOIN zubehoer_l10n USING(zubehoer_id) "
00266 .
"LEFT JOIN hersteller "
00267 .
"ON zubehoer.hersteller_id=hersteller.hersteller_id "
00268 .
"WHERE zubehoer.zubehoer_id = %d "
00269 .
"AND l10n_id = %d";
00270
$sql = sprintf($sqlPrep,
00271 $
id,
00272 $data->getAppData('l10n')
00273 );
00274 $success = $this->db->getOneRow($sql, $zData);
00275
if (!$success) {
00276 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00277 $error =
new JuelichError;
00278 $error->printError(4,
00279 'Keine Detail-Daten zum Zubehör: ' . $
id);
00280
exit();
00281 }
00282 $t = $zData['h_name']
00283 .
' '
00284 . $zData['z_name'];
00285
getDataInstance()->setModelName($zData['h_name']);
00286
getDataInstance()->setTitle($t);
00287
return;
00288 }
00289
00297 function
getAccessIds($pId, &$ids) {
00298
$sql =
"SELECT zubehoer_id "
00299 .
"FROM r_PZ "
00300 .
"WHERE produkt_id = " . $pId;
00301 $this->db->getAllCols($sql, $ids);
00302
return;
00303 }
00304
00315 function
getDependSql($gId, $pId) {
00316
switch ($gId) {
00317
case G_SPEKTIV:
00318
$sql =
"SELECT hersteller_id "
00319 .
"FROM produkt WHERE produkt_id=" . $pId;
00320 $hId = $this->db->getOneValue($sql);
00321 $sqlPrep =
"SELECT p_preis, p_name, produkt.produkt_id "
00322 .
"FROM produkt "
00323 .
"LEFT JOIN produkt_l10n USING(produkt_id) "
00324 .
"WHERE l10n_id = %d "
00325 .
"AND p_online = '%s' "
00326 .
"AND gruppe_id = %d "
00327 .
"AND hersteller_id = %d "
00328 .
"ORDER BY p_preis, p_sort";
00329
return sprintf($sqlPrep,
00330
getDataInstance()->getAppData('l10n'),
00331
SQL_ONLINE,
00332
G_SPEKTIV_OKULAR,
00333 $hId
00334 );
00335
default:
00336
break;
00337 }
00338 }
00339
00340 }
00341
00342 ?>