Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

optionedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: optionedit.php 8119 2001-10-31 11:19:09Z ce $
5 //
6 // Created on: <20-Sep-2000 10:18:33 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlocale.php" );
30 // include_once( "classes/ezcurrency.php" );
31 // include_once( "classes/ezcachefile.php" );
32 // include_once( "classes/ezhttptool.php" );
33
34 $ini =& eZINI::instance( 'site.ini' );
35 $Language = $ini->variable( "eZTradeMain", "Language" );
36 $StdHeaders = $ini->variable( "eZTradeMain", "StandardOptionHeaders" );
37 $MinHeaders = $ini->variable( "eZTradeMain", "MinimumOptionHeaders" );
38 $MinValues = $ini->variable( "eZTradeMain", "MinimumOptionValues" );
39 $SimpleOptionHeaders = $ini->variable( "eZTradeMain", "SimpleOptionHeaders" ) == "true" ? true : false;
40 $ShowQuantity = $ini->variable( "eZTradeMain", "ShowQuantity" ) == "true";
41
42 // include_once( "eztrade/classes/ezproductcategory.php" );
43 // include_once( "eztrade/classes/ezproduct.php" );
44 // include_once( "eztrade/classes/ezoption.php" );
45 // include_once( "eztrade/classes/ezoptionvalue.php" );
46 // include_once( "eztrade/classes/ezpricegroup.php" );
47
48 if ( !isset( $OptionPrice ) or !is_array( $OptionPrice ) )
49 $OptionPrice = array();
50 if ( !isset( $OptionValueDescription ) or !is_array( $OptionValueDescription ) )
51 $OptionValueDescription = array();
52 if ( isset( $DeleteOption ) )
53 {
54 foreach( $DeleteOptionID as $option_id )
55 {
56 $option = new eZOption( $option_id );
57 $option->delete();
58 }
59
60 $files = eZCacheFile::files( "kernel/eztrade/cache/", array( array( "productview", "productprint" ),
61 $ProductID, NULL ),
62 "cache", "," );
63 foreach( $files as $file )
64 {
65 $file->delete();
66 }
67
68 eZHTTPTool::header( "Location: /trade/productedit/optionlist/$ProductID/" );
69 exit();
70 }
71
72 $product = new eZProduct( $ProductID );
73
74 if ( isset( $Delete ) )
75 {
76 if ( isset( $OptionDelete ) )
77 {
78 foreach( $OptionDelete as $del )
79 {
80 unset( $OptionValue[$del] );
81 unset( $OptionValueID[$del] );
82 $OptionValueID = array_values( $OptionValueID );
83 $ValueID = $OptionValueID;
84 unset( $OptionPrice[$del] );
85 unset( $OptionMainPrice[$del] );
86 unset( $OptionQuantity[$del] );
87 }
88 }
89 if ( isset( $OptionDescriptionDelete ) )
90 {
91 foreach( $OptionDescriptionDelete as $del )
92 {
93 unset( $OptionValueDescription[$del] );
94 $count = count( $OptionValue );
95 for ( $i = 0; $i < $count; $i++ )
96 {
97 unset( $OptionValue[$i][$del] );
98 }
99 $ValueCount = max( $MinHeaders, $ValueCount - 1 );
100 }
101 }
102 }
103
104
105 if ( isset( $Abort ) )
106 {
107 eZHTTPTool::header( "Location: /trade/productedit/optionlist/$ProductID/" );
108 exit();
109 }
110
111 if ( isset( $OK ) )
112 {
113 $option = new eZOption( $OptionID );
114 $option->setName( $OptionName );
115 $option->setDescription( $Description );
116
117 $option->store();
118
119 if ( !is_numeric( $OptionID ) )
120 $product->addOption( $option );
121
122 $option->removeHeaders();
123 $option->addHeader( $OptionValueDescription );
124
125 //$option->removeValues();
126 $i = 0;
127 $option_ids = array();
128
129 foreach ( $OptionValue as $name )
130 {
131 if ( $name != "" )
132 {
133 if ( is_numeric( $OptionValueID[$i] ) and $OptionValueID[$i] > 0 )
134 $option_ids[] = $OptionValueID[$i];
135 }
136 $i++;
137 }
138
139 $optionObject = new eZOptionValue();
140 $orig_option_ids = $optionObject->getByOption( $option, false );
141 $old_option_ids = array_diff( $orig_option_ids, $option_ids );
142 foreach( $old_option_ids as $id )
143 {
144 $optionValueObject = new eZOptionValue();
145 $optionValueObject->delete( $id );
146 }
147
148 $i = 0;
149 foreach ( $OptionValue as $name )
150 {
151 if ( $name != "" )
152 {
153 if ( !is_null( $OptionValueID[$i] ) and $OptionValueID[$i] > 0 )
154 $value = new eZOptionValue( $OptionValueID[$i] );
155 else
156 $value = new eZOptionValue();
157 $value->setPrice( $OptionMainPrice[$i] );
158 $value->setOptionID( $option->id() );
159 $value->store();
160
161 if ( $ShowQuantity )
162 {
163 $value->setTotalQuantity( !is_null( $OptionQuantity[$i] ) ? $OptionQuantity[$i] : false );
164 }
165
166 $value->removeDescriptions();
167 $value->addDescription( $name );
168 //var_dump( $OptionPrice ); die();
169 $option_price = $OptionPrice[$i];
170
171 eZPriceGroup::removePrices( $ProductID, $option->id(), $value->id() );
172
173 if ( count( $option_price ) > 0 )
174 {
175 reset( $option_price );
176 foreach( $option_price as $group => $price )
177 {
178 if ( is_numeric( $price ) )
179 {
180 $priceGroupObject = new eZPriceGroup();
181 $priceGroupObject->addPrice( $ProductID, $group, $price, $option->id(), $value->id() );
182 }
183 }
184 }
185 }
186 $i++;
187 }
188
189 $files = eZCacheFile::files( "kernel/eztrade/cache/", array( array( "productview", "productprint" ),
190 $ProductID, NULL ),
191 "cache", "," );
192 foreach( $files as $file )
193 {
194 $file->delete();
195 }
196
197 eZHTTPTool::header( "Location: /trade/productedit/optionlist/$ProductID/" );
198 exit();
199 }
200
201 $t = new eZTemplate( "kernel/eztrade/admin/" . $ini->variable( "eZTradeMain", "AdminTemplateDir" ),
202 "kernel/eztrade/admin/intl/", $Language, "optionedit.php" );
203
204 $t->setAllStrings();
205
206 $t->set_file( "option_edit_page", "optionedit.tpl" );
207
208 $t->set_block( "option_edit_page", "value_header_item_tpl", "value_header_item" );
209 $t->set_block( "option_edit_page", "group_item_tpl", "group_item" );
210 $t->set_block( "option_edit_page", "option_quantity_header_tpl", "option_quantity_header" );
211
212 $t->set_block( "option_edit_page", "value_headers_tpl", "value_headers" );
213
214 $t->set_block( "value_headers_tpl", "value_description_item_tpl", "value_description_item" );
215 $t->set_block( "value_description_item_tpl", "value_description_item_checkbox_tpl", "value_description_item_checkbox" );
216
217 $t->set_block( "option_edit_page", "option_item_tpl", "option_item" );
218 $t->set_block( "option_item_tpl", "value_item_tpl", "value_item" );
219 $t->set_block( "option_item_tpl", "option_price_item_tpl", "option_price_item" );
220 $t->set_block( "option_item_tpl", "option_quantity_item_tpl", "option_quantity_item" );
221
222 $t->set_block( "option_edit_page", "new_description_tpl", "new_description" );
223
224 //default values
225 $t->set_var( "name_value", "" );
226 $t->set_var( "description_value", "" );
227 $t->set_var( "option_values", "" );
228 $t->set_var( "hidden_fields", "" );
229 $t->set_var( "action_value", "Insert" );
230 $t->set_var( "option_id", "" );
231
232 $t->set_var( "product_name", $product->name() );
233
234 $groups = eZPriceGroup::getAll( false );
235 $t->set_var( "group_item", "" );
236 foreach( $groups as $group )
237 {
238 $price_group = new eZPriceGroup( $group );
239 $t->set_var( "price_group_name", $price_group->name() );
240 $t->parse( "group_item", "group_item_tpl", true );
241 }
242 $count = count ( $groups );
243
244 $main_price = array();
245
246 if ( isset( $Action ) && $Action == "New" )
247 {
248 $OptionValueDescription = $StdHeaders;
249 $OptionValue = array();
250 $OptionMainPrice = array();
251 $OptionPrice = array();
252 $NewValue = true;
253 }
254
255 if ( isset( $Action ) && $Action == "Edit" )
256 {
257 $option = new eZOption( $OptionID );
258 $values = $option->values();
259 $ValueID = array();
260 $OptionValueDescription = $option->descriptionHeaders();
261 $i = 0;
262 foreach( $StdHeaders as $header )
263 {
264 if ( !isset( $OptionValueDescription[$i] ) )
265 $OptionValueDescription[$i] = $header;
266 $i++;
267 }
268 $hiddenArray = "";
269 $valueText = "";
270 $OptionValue = array();
271 $OptionMainPrice = array();
272 $OptionPrice = array();
273 $OptionQuantity = array();
274 $i = 0;
275 foreach ( $values as $value )
276 {
277 $OptionValue[$i] = $value->descriptions();
278 $OptionValue[$i][] = "";
279 $OptionMainPrice[] = $value->price();
280 $OptionValueID[$i] = $value->id();
281 $OptionQuantity[$i] = $value->totalQuantity();
282 $valueid = $value->id();
283 $ValueID[] = $valueid;
284 $prices = eZPriceGroup::prices( $ProductID, $OptionID, $value->id() );
285 foreach( $groups as $group )
286 {
287 foreach( $prices as $price )
288 {
289 if ( $price["PriceID"] == $group )
290 $OptionPrice[$valueid][$group] = $price["Price"];
291 }
292 }
293 $i++;
294 }
295 $ValueCount = max( $MinHeaders, count( $OptionValueDescription ) );
296 if ( $SimpleOptionHeaders )
297 $ValueCount = $MinHeaders;
298
299 $OptionName = $option->name();
300 $Description = $option->description();
301 }
302
303 if ( isset( $NewValue ) )
304 {
305 $OptionValue[] = array();
306 $OptionValueID[] = "";
307 $ValueID[] = "";
308 $option_price = array();
309 for( $i = 0; $i < $count; ++$i )
310 {
311 $option_price[$groups[$i]] = "";
312 }
313 $OptionPrice[] = $option_price;
314 }
315
316 while( max( count( $OptionValue ), count( $ValueID ), count( $OptionPrice ) ) < $MinValues )
317 {
318 $OptionValue[] = array();
319 $OptionValueID[] = "";
320 $ValueID[] = "";
321 $option_price = array();
322 for( $i = 0; $i < $count; ++$i )
323 {
324 $option_price[$groups[$i]] = "";
325 }
326 $OptionPrice[] = $option_price;
327 }
328
329 if ( isset( $NewDescription ) )
330 {
331 for( $i = 0; $i < count( $OptionValue ); $i++ )
332 {
333 $OptionValue[$i][] = "";
334 }
335 $OptionValueDescription[] = "";
336 $ValueCount = max( $MinHeaders, $ValueCount + 1 );
337 }
338 else
339 {
340 $ValueCount = 0;
341 }
342
343 $value_count = max( $MinHeaders, $ValueCount );
344
345 $t->set_var( "option_quantity_header", "" );
346 if ( $ShowQuantity )
347 $t->parse( "option_quantity_header", "option_quantity_header_tpl" );
348
349 $t->set_var( "value_count", $value_count );
350
351 $t->set_var( "value_headers", "" );
352 if ( !$SimpleOptionHeaders )
353 {
354 reset( $OptionValueDescription );
355 foreach( $OptionValueDescription as $header )
356 {
357 $value_header_item = $header;
358 }
359 // $value_header_item = each( $OptionValueDescription );
360 $t->parse( "value_description_item_checkbox", "value_description_item_checkbox_tpl" );
361 for ( $i = 0; $i < max( $MinHeaders, $value_count ); $i++ )
362 {
363 if ( isset( $value_header_item[1] ) )
364 {
365 $t->set_var( "option_description_value", $value_header_item[1] );
366 }
367 else
368 {
369 $t->set_var( "option_description_value", "" );
370 }
371 //$t->set_var( "option_description_value", $value_header_item[1] );
372 $t->set_var( "value_description_index", $i );
373 $t->parse( "value_description_item", "value_description_item_tpl", true );
374 foreach( $OptionValueDescription as $header )
375 {
376 $value_header_item = $header;
377 }
378 }
379
380 $t->parse( "value_headers", "value_headers_tpl" );
381 }
382
383 reset( $OptionPrice );
384 $index = 0;
385 $j = 0;
386 $t->set_var( "option_item", "" );
387 $t->set_var( "group_count", $count );
388 foreach( $OptionMainPrice as $header )
389 {
390 if( $header != "" )
391 $main_price[] = $header;
392 }
393 //$main_price = each( $OptionMainPrice );
394
395 foreach ( $OptionValue as $value )
396 {
397 $t->set_var( "value_pos", $index + 1 );
398 $t->set_var( "value_index", $index );
399 $t->set_var( "number_run", $j );
400 $t->set_var( "option_value_id", $OptionValueID[$index] );
401 $t->set_var( "value_item", "" );
402 reset( $value );
403 $value_item = array();
404 // $OptionQuantity = array();
405
406 foreach( $value as $header )
407 {
408 if( $header != "" )
409 $value_item = $header;
410 }
411
412 // $value_item = each( $value );
413 for( $i = 0; $i < max( $MinHeaders, $value_count ); $i++ )
414 {
415 // $value_item = each( $value );
416 if ( isset( $value_item ) && $value_item != array() )
417 {
418 $t->set_var( "option_value", $value_item );
419 }
420 else
421 {
422 $t->set_var( "option_value", "" );
423 }
424
425 $t->parse( "value_item", "value_item_tpl", true );
426 foreach( $value as $header )
427 {
428 $value_item = $header;
429 }
430 //$value_item = each( $value );
431 }
432
433 $t->set_var( "main_price_value", isset( $main_price[$index] ) ? $main_price[$index] : false );
434
435 $t->set_var( "option_price_item", "" );
436 foreach( $OptionPrice as $header )
437 {
438 if( $header != "" )
439 $option_price[] = $header;
440 }
441
442 // $option_price = each( $OptionPrice );
443 $i = 0;
444 foreach( $groups as $group )
445 {
446 $t->set_var( "price_value", isset( $option_price[$index][$group] ) ? $option_price[$index][$group] : false ); //$option_price[1][$group] );
447 $t->set_var( "price_group", $group );
448 $t->set_var( "value_index", $i );
449 $t->parse( "option_price_item", "option_price_item_tpl", true );
450 $i++;
451 }
452
453 $t->set_var( "option_quantity_item", "" );
454 if ( $ShowQuantity )
455 {
456 $t->set_var( "quantity_value", isset( $OptionQuantity[$index] ) ? $OptionQuantity[$index] : false ); // $OptionQuantity[$index] );
457 $t->parse( "option_quantity_item", "option_quantity_item_tpl" );
458 }
459
460 $t->parse( "option_item", "option_item_tpl", true );
461 foreach( $OptionMainPrice as $header )
462 {
463 $main_price[] = $header;
464 }
465 // $main_price = each( $OptionMainPrice );
466 $index++;
467 $j++;
468 }
469
470 $t->set_var( "option_id", isset( $OptionID ) ? $OptionID : false );
471 $t->set_var( "name_value", isset( $OptionName ) ? $OptionName : false );
472 $t->set_var( "description_value", isset( $Description ) ? $Description : false);
473
474 $t->set_var( "new_description", "" );
475 if ( !$SimpleOptionHeaders )
476 $t->parse( "new_description", "new_description_tpl" );
477
478 $t->set_var( "product_id", $ProductID );
479
480 $t->pparse( "output", "option_edit_page" );
481
482 ?>
$i
$i
Definition: admin/adlist.php:91
$group
$group
Definition: admin/articleedit.php:799
$Description
$Description
Definition: articlelistrss.php:38
$files
$files
Definition: articlepreview.php:91
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZOptionValue
Definition: ezoptionvalue.php:54
eZOption
Definition: ezoption.php:82
eZPriceGroup
Definition: ezpricegroup.php:38
eZPriceGroup\getAll
static & getAll( $as_object=true)
Definition: ezpricegroup.php:127
eZPriceGroup\removePrices
static removePrices( $productid, $optionid=0, $valueid=0, $priceid='')
Definition: ezpricegroup.php:499
eZPriceGroup\prices
static prices( $productid, $optionid=0, $valueid=0)
Definition: ezpricegroup.php:461
eZProduct
Definition: ezproduct.php:71
eZTemplate
Definition: eztemplate.php:107
$Action
$Action
Definition: companysearch.php:80
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$values
$values
Definition: fixedvalues.php:103
exit
exit
Definition: folder.php:81
$groups
$groups
Definition: optionedit.php:234
$index
$index
Definition: optionedit.php:384
$main_price
$main_price
Definition: optionedit.php:244
$StdHeaders
$StdHeaders
Definition: optionedit.php:36
$t
if(isset( $Delete)) if(isset( $Abort)) if(isset( $OK)) $t
Definition: optionedit.php:201
$j
$j
Definition: optionedit.php:385
$count
foreach( $groups as $group) $count
Definition: optionedit.php:242
$MinHeaders
$MinHeaders
Definition: optionedit.php:37
$Language
$Language
Definition: optionedit.php:35
$ini
$ini
Definition: optionedit.php:34
$product
if(isset( $DeleteOption)) $product
Definition: optionedit.php:72
$SimpleOptionHeaders
$SimpleOptionHeaders
Definition: optionedit.php:39
$ShowQuantity
$ShowQuantity
Definition: optionedit.php:40
$value_count
$value_count
Definition: optionedit.php:343
$MinValues
$MinValues
Definition: optionedit.php:38
$header
$header
Definition: paypalnotify.php:141
$price
$price
Definition: pricegroupedit.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.