coupons_id = tep_db_input( $coupons_id ); } else { return false; } //check that the table definition for the type exists if( defined( 'TABLE_DISCOUNT_COUPONS_TO_'.strtoupper( $type ) ) ) { $this->type = $type; $this->table_name = constant( 'TABLE_DISCOUNT_COUPONS_TO_'.strtoupper( $type ) ); } else { return false; } $this->selected_options = array(); $this->all_options = array(); } function save( $selected_options = array() ) { tep_db_query( $sql = 'DELETE FROM '.$this->table_name.' WHERE coupons_id="'.$this->coupons_id.'"' ); if( is_array( $selected_options ) && count( $selected_options ) > 0 ) { foreach( $selected_options as $ids ) { tep_db_query( $sql = 'INSERT INTO '.$this->table_name.' VALUES ( "'.$this->coupons_id.'", '.(int)$ids.' )' ); } } else return false; } function get_selected_options( $sql, $separator = ' :: '/*category exclusions*/, $category_separator = '->', $category_path = true/*end category exclusions*/ ) { if( !tep_not_null( $sql ) ) return false; $result = tep_db_query( $sql ); $selected_ids = array(); if( tep_db_num_rows( $result ) > 0 ) { while( $row = tep_db_fetch_array( $result ) ) { $id = $row['id']; unset( $row['id'] ); //don't display in the list //category exclusions if( $category_path ) { $path = ''; //get the category path $categories = array(); tep_get_parent_categories( $categories, $id ); $categories = array_reverse( $categories ); foreach( $categories as $cat ) { $path .= tep_get_categories_name( $cat, (int)$languages_id ).$category_separator; } $row['categories_name'] = $path.$row['categories_name']; } //end category exclusions $selected_ids[] = $id; $this->selected_options[] = array( 'text' => implode( $row, $separator ), 'id' => $id ); } sort( $this->selected_options ); } return $selected_ids; } function get_all_options( $sql, $separator = ' :: '/*category exclusions*/, $category_separator = '->', $category_path = true/*end category exclusions*/, $selected_ids = array() ) { if( !tep_not_null( $sql ) ) return false; $result = tep_db_query( $sql ); if( tep_db_num_rows( $result ) > 0 ) { while( $row = tep_db_fetch_array( $result ) ) { $id = $row['id']; //category exclusions if( $category_path ) { $path = ''; //get the category path $categories = array(); tep_get_parent_categories( $categories, $id ); $categories = array_reverse( $categories ); foreach( $categories as $cat ) { $path .= tep_get_categories_name( $cat, (int)$languages_id ).$category_separator; } $row['categories_name'] = $path.$row['categories_name']; } //end category exclusions unset( $row['id'] ); //don't display in the list $this->all_options[] = array( 'text' => implode( $row, $separator ), 'id' => $id ); } sort( $this->all_options ); } return true; } function display() { $return = ' '.tep_draw_form( 'choose'.$this->type, FILENAME_DISCOUNT_COUPONS_EXCLUSIONS, 'cID='.$this->coupons_id.'&type='.$this->type, 'post', 'onsubmit="form_submission( document.getElementById(\'selected_'.$this->type.'\') )"' ).'
'.HEADING_AVAILABLE.'   '.HEADING_SELECTED.'
'.tep_draw_pull_down_menu('available_'.$this->type.'[]', $this->all_options, '', 'size="20" multiple style="width: 300px" id="available_'.$this->type.'"').' '.tep_draw_pull_down_menu('selected_'.$this->type.'[]', $this->selected_options, '', 'size="20" multiple style="width: 300px" id="selected_'.$this->type.'"').'
'; return $return; } } ?>