0) $part = new Part($database, $current_user, $log, $selected_part_id); else $part = NULL; } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); $fatal_error = true; } /******************************************************************************** * * Execute actions * *********************************************************************************/ if ( ! $fatal_error) { switch ($action) { case 'decrement': // remove one part try { if ( ! is_object($part)) throw new Exception('Es wurde keine gültige Bauteil-ID übermittelt!'); $part->set_instock($part->get_instock() - 1); $reload_site = true; } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); } break; case 'increment': // add one part try { if ( ! is_object($part)) throw new Exception('Es wurde keine gültige Bauteil-ID übermittelt!'); $part->set_instock($part->get_instock() + 1); $reload_site = true; } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); } break; case 'export': try { $parts = Part::search_parts($database, $current_user, $log, $keyword, '', $search_name, $search_description, $search_comment, $search_footprint, $search_category, $search_storelocation, $search_supplier, $search_supplierpartnr, $search_manufacturer, $search_last_modified); $export_string = export_parts($parts, 'searchparts', $export_format_id, true, 'search_parts'); } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); } break; } } if (isset($reload_site) && $reload_site) { // reload the site to avoid multiple actions by manual refreshing $header = 'Location: show_search_parts.php?keyword='.$keyword; if ($search_name) {$header.= '&search_name=1';} if ($search_category) {$header.= '&search_category=1';} if ($search_description) {$header.= '&search_description=1';} if ($search_comment) {$header.= '&search_comment=1';} if ($search_supplier) {$header.= '&search_supplier=1';} if ($search_supplierpartnr) {$header.= '&search_supplierpartnr=1';} if ($search_storelocation) {$header.= '&search_storelocation=1';} if ($search_footprint) {$header.= '&search_footprint=1';} if ($search_manufacturer) {$header.= '&search_manufacturer=1';} if ($search_last_modified) {$header.= '&search_last_modified=1';} header($header); } /******************************************************************************** * * Generate Table * *********************************************************************************/ if ( ! $fatal_error) { try { $category_parts = Part::search_parts($database, $current_user, $log, $keyword, 'categories', $search_name, $search_description, $search_comment, $search_footprint, $search_category, $search_storelocation, $search_supplier, $search_supplierpartnr, $search_manufacturer, $search_last_modified); $hits_count = count($category_parts, COUNT_RECURSIVE) - count($category_parts); $parts_table_loops = array(); foreach($category_parts as $category_full_path => $parts) { $parts_table_loops[$category_full_path] = Part::build_template_table_array($parts, 'search_parts'); } } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); $fatal_error = true; } } /******************************************************************************** * * Set the rest of the HTML variables * *********************************************************************************/ $html->use_javascript(array('popup')); $html->set_variable('keyword', $keyword, 'string'); $html->set_variable('hits_count', (isset($hits_count) ? $hits_count : 0), 'integer'); $html->set_variable('search_name', $search_name, 'boolean'); $html->set_variable('search_category', $search_category, 'boolean'); $html->set_variable('search_description', $search_description, 'boolean'); $html->set_variable('search_comment', $search_comment, 'boolean'); $html->set_variable('search_supplier', $search_supplier, 'boolean'); $html->set_variable('search_supplierpartnr', $search_supplierpartnr, 'boolean'); $html->set_variable('search_storelocation', $search_storelocation, 'boolean'); $html->set_variable('search_footprint', $search_footprint, 'boolean'); $html->set_variable('search_manufacturer', $search_manufacturer, 'boolean'); $html->set_variable('search_last_modified', $search_last_modified, 'boolean'); if ( ! $fatal_error) { // export formats $html->set_loop('export_formats', build_export_formats_loop('searchparts')); // global stuff $html->set_variable('disable_footprints', $config['footprints']['disable'], 'boolean'); $html->set_variable('disable_manufacturers', $config['manufacturers']['disable'], 'boolean'); $html->set_variable('disable_auto_datasheets', $config['auto_datasheets']['disable'], 'boolean'); $html->set_variable('use_modal_popup', $config['popup']['modal'], 'boolean'); $html->set_variable('popup_width', $config['popup']['width'], 'integer'); $html->set_variable('popup_height', $config['popup']['height'], 'integer'); } /******************************************************************************** * * Generate HTML Output * *********************************************************************************/ $html->print_header($messages); if ( ! $fatal_error) { $html->print_template('search_header'); foreach($parts_table_loops as $category_full_path => $loop) { $html->set_variable('category_full_path', $category_full_path, 'string'); $html->set_variable('table_rowcount', count($loop), 'integer'); $html->set_loop('table', $loop); $html->print_template('searched_parts_table'); } } $html->print_footer(); ?>