<?php function prepare_options_dataset($dbconn,$cs_id,$mb_id_owner,$o_ids=null,$tunermap=array(),&$options=false) { global $DEPEND_ON_TEMPLATES; if (!$options) if (!$tunermap['selected_o_ids_only'] || $o_ids) $options=db_load_options($dbconn,$cs_id,$mb_id_owner,$o_ids,true); else $options=array(); if ($tunermap['check_options_min']) $reserve_options_min=0+db_load_course_info_value($dbconn,$cs_id,'reserve.options.min'); else $reserve_options_min=0; $localCurrencyNameMap=loadLocalCurrencyNameMap(); if (isset($tunermap['minutes'])) $minutes=$tunermap['minutes']; else if ($tunermap['lctr_since'] && $tunermap['lctr_expire']) { $sec_since=datetime_to_seconds($tunermap['lctr_since']); $sec_expire=datetime_to_seconds($tunermap['lctr_expire']); $minutes=($sec_expire-$sec_since)/60; } $count_selected=0; $dataset=array(); $dataset['OPTION']=$options; $dataset['OPTION-NONE']=$options?array():array(0); foreach ($dataset['OPTION'] as &$opt) { $opt['cs_id']=0+$cs_id; $opt['THUMBNAIL']=$opt['o_thumbnail_url']?array(0):array(); $opt['THUMBNAIL-NONE']=$opt['o_thumbnail_url']?array():array(0); $opt['LINK-DETAIL-CS-VIEW']=$tunermap['for_course_detail']?array(0):array(); $opt['LINK-DETAIL']=$tunermap['for_course_detail']?array():array(0); $opt['price']=($opt['o_price_base']+($tunermap['cs_minutes_step']?($minutes-$tunermap['cs_minutes_min'])/$tunermap['cs_minutes_step']*$opt['o_price_step']:0))*$tunermap['optc'][$opt['o_id']]; $opt['tax']=$opt['price']*$tunermap['cs_price_taxrate']; $opt['price_with_tax']=$opt['price']+$opt['tax']; $opt['o_price_base']=format_money($opt['o_price_base'],$tunermap['cs_currency']); $opt['o_price_step']=format_money($opt['o_price_step'],$tunermap['cs_currency']); $opt['DISPLAY-TAX']=$opt['tax']?array(0):array(); $opt['count']=$tunermap['optc'][$opt['o_id']]; if (!ctype_digit($opt['count']) && $opt['o_num_min'] && !$tunermap['auto_min_num_off']) $opt['count']=max($opt['o_num_min'],0); if ($opt['count']>0) $count_selected++; $opt['local_currency_unit']=mapCurrencyLocalName($localCurrencyNameMap,$tunermap['cs_currency']); if (!$tunermap['no_count_check']) if (0+$opt['count']<$opt['o_num_min'] || 0+$opt['count']>$opt['o_num_max']) { $opt['ERROR-COUNT']=array(0); $dataset['ERROR-OPTION-COUNT']=array(0); $dataset['ERROR-OPTION-SOMEERROR']=array(0); } } if ($count_selected<$reserve_options_min) { $dataset['ERROR-OPTION-MORE']=array( array( 'reserve_options_min'=>$reserve_options_min ) ); $dataset['ERROR-OPTION-SOMEERROR']=array(0); } $dataset['IS-CS-OWNER']=$tunermap['is_cs_owner']?array(0):array(); $dataset['OPTION-MANAGE']=$tunermap['is_cs_owner'] && !$tunermap['for_course_detail']?array(0):array(); $dataset['NOT-CS-OWNER']=$tunermap['is_cs_owner']?array():array(0); $dataset['HAS-OPTIONS']=$options?array(0):array(); $dataset['INPUT-OPTION-COUNT']=$tunermap['input_count']?array(0):array(); $dataset['DISPLAY-OPTION-COUNT']=$tunermap['confirm_count']?array(0):array(); $dataset['DISPLAY-COUNT-RANGE']=$tunermap['count_range_off']?array():array(0); $dataset['OPTION-PRICE-DETAIL']=$tunermap['price_detail_off']?array():array(0); $dataset['OPTION-TOTAL-PRICE']=$tunermap['total_price']?array(0):array(); $dataset['DISPLAY-THUMBNAIL']=$tunermap['thumbnail_off']?array():array(0); array_push($DEPEND_ON_TEMPLATES,'option.list.inc'); return $dataset; } function compute_reservation_options($dbconn,$course,$optc,&$optrec,$minutes=false,$lecture=false) { if (!$minutes && !$lecture) throw new Exception('Neither $minutes nor $lecture is given.'); if (!$minutes) { $since_sec=datetime_to_seconds($lecture['lctr_since']); $expire_sec=datetime_to_seconds($lecture['lctr_expire']); $minutes=($expire_sec-$since_sec)/60; } $optc=array_true_entries_only($optc); $reserve_options_min=0+db_load_course_info_value($dbconn,$course['cs_id'],'reserve.options.min'); $options=db_load_options($dbconn,$course['cs_id'],$course['mb_id_owner'],array_keys($optc),false); $optrec=array(); $no_error=true; $count_selected=0; foreach ($options as $opt) { $count=0+$optc[$opt['o_id']]; if ($count<$opt['o_num_min'] || $count>$opt['o_num_max']) $no_error=false; if ($count) { $count_selected++; $price=$opt['o_price_base']+($course['cs_minutes_step']?($minutes-$course['cs_minutes_min'])/$course['cs_minutes_step']*$opt['o_price_step']:0); array_push($optrec, array( 'o_id'=>$opt['o_id'], 'ro_count'=>$count, 'ro_unit_price'=>$price, 'ro_unit_tax'=>$price*$course['cs_price_taxrate'] ) ); } } if ($count_selected<$reserve_options_min) $no_error=false; return $no_error; } ?>