Example #1
0
        $update_log = $database->update();
        $html->set_variable('database_update_log', nl2br($update_log));
    }
}
/********************************************************************************
 *
 *   Show a warning if there are empty tables
 *       (categories, storelocations, footprints, suppliers)
 *
 *********************************************************************************/
if (!$fatal_error && !$database->is_update_required()) {
    $good = "✔ ";
    $bad = "✘ ";
    try {
        $missing_category = Category::get_count($database) == 0 ? $bad : $good;
        $missing_storelocation = Storelocation::get_count($database) == 0 ? $bad : $good;
        $missing_footprint = Footprint::get_count($database) == 0 ? $bad : $good;
        $missing_supplier = Supplier::get_count($database) == 0 ? $bad : $good;
        $display_warning = $missing_category == $bad || $missing_storelocation == $bad || $missing_footprint == $bad || $missing_supplier == $bad;
        $html->set_variable('missing_category', $missing_category);
        $html->set_variable('missing_storeloc', $missing_storelocation);
        $html->set_variable('missing_footprint', $missing_footprint);
        $html->set_variable('missing_supplier', $missing_supplier);
        $html->set_variable('display_warning', $display_warning, 'boolean');
    } catch (Exception $e) {
        $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
    }
}
/********************************************************************************
 *
 *   Show a warning if there are footprints with broken filenames
Example #2
0
 *
 *   Initialize Objects
 *
 *********************************************************************************/
$html = new HTML($config['html']['theme'], $config['html']['custom_css'], 'Bauteil bearbeiten');
try {
    $database = new Database();
    $log = new Log($database);
    $current_user = new User($database, $current_user, $log, 1);
    // admin
    if (!$is_new_part) {
        $part = new Part($database, $current_user, $log, $part_id);
        ///@todo: remove this line:
        $new_visible = $part->get_visible();
    }
    $root_storelocation = new Storelocation($database, $current_user, $log, 0);
    $root_category = new Category($database, $current_user, $log, 0);
    $root_manufacturer = new Manufacturer($database, $current_user, $log, 0);
    $root_footprint = new Footprint($database, $current_user, $log, 0);
    $root_supplier = new Supplier($database, $current_user, $log, 0);
    $root_attachement_type = new AttachementType($database, $current_user, $log, 0);
    if ($orderdetails_id > 0) {
        $orderdetails = new Orderdetails($database, $current_user, $log, $orderdetails_id);
    } else {
        $orderdetails = NULL;
    }
    if ($pricedetails_id > 0) {
        $pricedetails = new Pricedetails($database, $current_user, $log, $pricedetails_id);
    } else {
        $pricedetails = NULL;
    }
Example #3
0
/**
 * @brief Import Parts (create Parts, and if neccessary, Categories, Footprints and so on)
 *
 * @note    This function uses database transactions. If an error occurs, all changes will be rolled back.
 *
 * @param Database  &$database          reference to the database object
 * @param User      &$current_user      reference to the user which is logged in
 * @param Log       &$log               reference to the Log-object
 * @param array     $data               The import data array from "extract_import_data_from_request()"
 * @param boolean   $only_check_data    If true, this function will only check if all values in "$data" are valid.
 *                                      In this case, no parts will be imported!
 *
 * @retval array    All new Part objects (only if "$only_check_data == false")
 *
 * @throws Exception    if there was an error (maybe the passed data is not valid)
 */
function import_parts(&$database, &$current_user, &$log, $data, $only_check_data = false)
{
    $parts = array();
    try {
        $transaction_id = $database->begin_transaction();
        // start transaction
        // Get the category, footprint, storelocation, ... which are named "Import", or create them.
        // We need this elements as parent for new elements, which will be created while import parts.
        $import_categories = Category::search($database, $current_user, $log, 'Import', true);
        if (count($import_categories) > 0) {
            $import_category = $import_categories[0];
            $import_category_created = false;
        } else {
            $import_category = Category::add($database, $current_user, $log, 'Import', NULL);
            $import_category_created = true;
            // we can delete it later if we didn't need it
        }
        $import_storelocations = Storelocation::search($database, $current_user, $log, 'Import', true);
        if (count($import_storelocations) > 0) {
            $import_storelocation = $import_storelocations[0];
            $import_storelocation_created = false;
        } else {
            $import_storelocation = Storelocation::add($database, $current_user, $log, 'Import', NULL);
            $import_storelocation_created = true;
            // we can delete it later if we didn't need it
        }
        $import_footprints = Footprint::search($database, $current_user, $log, 'Import', true);
        if (count($import_footprints) > 0) {
            $import_footprint = $import_footprints[0];
            $import_footprint_created = false;
        } else {
            $import_footprint = Footprint::add($database, $current_user, $log, 'Import', NULL);
            $import_footprint_created = true;
            // we can delete it later if we didn't need it
        }
        $import_suppliers = Supplier::search($database, $current_user, $log, 'Import', true);
        if (count($import_suppliers) > 0) {
            $import_supplier = $import_suppliers[0];
            $import_supplier_created = false;
        } else {
            $import_supplier = Supplier::add($database, $current_user, $log, 'Import', NULL);
            $import_supplier_created = true;
            // we can delete it later if we didn't need it
        }
        $import_manufacturers = Manufacturer::search($database, $current_user, $log, 'Import', true);
        if (count($import_manufacturers) > 0) {
            $import_manufacturer = $import_manufacturers[0];
            $import_manufacturer_created = false;
        } else {
            $import_manufacturer = Manufacturer::add($database, $current_user, $log, 'Import', NULL);
            $import_manufacturer_created = true;
            // we can delete it later if we didn't need it
        }
        $import_category_used = false;
        $import_storelocation_used = false;
        $import_footprint_used = false;
        $import_supplier_used = false;
        $import_manufacturer_used = false;
        // start import
        $row_index = 0;
        foreach ($data as $row) {
            $name = $row['part_name'];
            $description = $row['part_description'];
            $instock = $row['part_instock'];
            $mininstock = $row['part_mininstock'];
            $comment = $row['part_comment'];
            $category_name = $row['part_category_name'];
            $footprint_name = $row['part_footprint_name'];
            $storelocation_name = $row['part_storelocation_name'];
            $manufacturer_name = $row['part_manufacturer_name'];
            $supplier_name = $row['part_supplier_name'];
            $supplierpartnr = $row['part_supplierpartnr'];
            $price = $row['part_price'];
            // search elements / create them if they don't exist already
            if (strlen($category_name) > 0) {
                $categories = Category::search($database, $current_user, $log, $category_name, true);
                if (count($categories) > 0) {
                    $category = $categories[0];
                } else {
                    $category = Category::add($database, $current_user, $log, $category_name, $import_category->get_id());
                    $import_category_used = true;
                }
            } else {
                throw new Exception('Jedes Bauteil muss eine Kategorie haben!');
            }
            if (strlen($storelocation_name) > 0) {
                $storelocations = Storelocation::search($database, $current_user, $log, $storelocation_name, true);
                if (count($storelocations) > 0) {
                    $storelocation = $storelocations[0];
                } else {
                    $storelocation = Storelocation::add($database, $current_user, $log, $storelocation_name, $import_storelocation->get_id());
                    $import_storelocation_used = true;
                }
            }
            if (strlen($manufacturer_name) > 0) {
                $manufacturers = Manufacturer::search($database, $current_user, $log, $manufacturer_name, true);
                if (count($manufacturers) > 0) {
                    $manufacturer = $manufacturers[0];
                } else {
                    $manufacturer = Manufacturer::add($database, $current_user, $log, $manufacturer_name, $import_manufacturer->get_id());
                    $import_manufacturer_used = true;
                }
            }
            if (strlen($footprint_name) > 0) {
                $footprints = Footprint::search($database, $current_user, $log, $footprint_name, true);
                if (count($footprints) > 0) {
                    $footprint = $footprints[0];
                } else {
                    $footprint = Footprint::add($database, $current_user, $log, $footprint_name, $import_footprint->get_id());
                    $import_footprint_used = true;
                }
            }
            if (strlen($supplier_name) > 0) {
                $suppliers = Supplier::search($database, $current_user, $log, $supplier_name, true);
                if (count($suppliers) > 0) {
                    $supplier = $suppliers[0];
                } else {
                    $supplier = Supplier::add($database, $current_user, $log, $supplier_name, $import_supplier->get_id());
                    $import_supplier_used = true;
                }
            } else {
                if (strlen($supplierpartnr) > 0 || $price > 0) {
                    throw new Exception('Ist eine Bestellnummer oder ein Preis angegeben, so muss auch ein Lieferant angegeben werden!');
                }
            }
            $new_part = Part::add($database, $current_user, $log, $name, $category->get_id(), $description, $instock, $mininstock, isset($storelocation) ? $storelocation->get_id() : NULL, isset($manufacturer) ? $manufacturer->get_id() : NULL, isset($footprint) ? $footprint->get_id() : NULL, $comment);
            if (isset($supplier)) {
                $new_orderdetails = Orderdetails::add($database, $current_user, $log, $new_part->get_id(), $supplier->get_id(), $supplierpartnr);
                if ($price > 0) {
                    $new_pricedetails = Pricedetails::add($database, $current_user, $log, $new_orderdetails->get_id(), $price);
                }
            }
            if (!$only_check_data) {
                $parts[] = $new_part;
            }
            $row_index++;
        }
        // delete all elements which were created in this function, but were not used
        if ($import_category_created && !$import_category_used) {
            $import_category->delete();
        }
        if ($import_storelocation_created && !$import_storelocation_used) {
            $import_storelocation->delete();
        }
        if ($import_footprint_created && !$import_footprint_used) {
            $import_footprint->delete();
        }
        if ($import_supplier_created && !$import_supplier_used) {
            $import_supplier->delete();
        }
        if ($import_manufacturer_created && !$import_manufacturer_used) {
            $import_manufacturer->delete();
        }
        if ($only_check_data) {
            $database->rollback();
        } else {
            $database->commit($transaction_id);
        }
        // commit transaction
    } catch (Exception $e) {
        $database->rollback();
        // rollback transaction
        throw new Exception((isset($row_index) ? 'Nr. ' . ($row_index + 1) . ': ' : '') . $e->getMessage());
    }
    return $parts;
}
}
if (isset($_REQUEST["apply"])) {
    $action = 'apply';
}
/********************************************************************************
 *
 *   Initialize Objects
 *
 *********************************************************************************/
$html = new HTML($config['html']['theme'], $config['html']['custom_css'], 'Lagerorte');
try {
    $database = new Database();
    $log = new Log($database);
    $current_user = new User($database, $current_user, $log, 1);
    // admin
    $root_storelocation = new Storelocation($database, $current_user, $log, 0);
    if ($selected_id > 0) {
        $selected_storelocation = new Storelocation($database, $current_user, $log, $selected_id);
    } else {
        $selected_storelocation = NULL;
    }
} catch (Exception $e) {
    $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
    $fatal_error = true;
}
/********************************************************************************
 *
 *   Execute actions
 *
 *********************************************************************************/
if (!$fatal_error) {
Example #5
0
 *
 *   Set all HTML variables
 *
 *********************************************************************************/
if (!$fatal_error) {
    try {
        $noprice_parts = Part::get_noprice_parts($database, $current_user, $log);
        $count_of_parts_with_price = Part::get_count($database) - count($noprice_parts);
        // :-)
        $html->set_variable('parts_count_with_prices', $count_of_parts_with_price, 'integer');
        $html->set_variable('parts_count_sum_value', Part::get_sum_price_instock($database, $current_user, $log, true), 'string');
        $html->set_variable('parts_count', Part::get_count($database), 'integer');
        $html->set_variable('parts_count_sum_instock', Part::get_sum_count_instock($database), 'integer');
        $html->set_variable('categories_count', Category::get_count($database), 'integer');
        $html->set_variable('footprint_count', Footprint::get_count($database), 'integer');
        $html->set_variable('location_count', Storelocation::get_count($database), 'integer');
        $html->set_variable('suppliers_count', Supplier::get_count($database), 'integer');
        $html->set_variable('manufacturers_count', Manufacturer::get_count($database), 'integer');
        $html->set_variable('devices_count', Device::get_count($database), 'integer');
        $html->set_variable('attachements_count', Attachement::get_count($database), 'integer');
        $html->set_variable('footprint_picture_count', count(find_all_files(BASE . '/img/footprints/', true)), 'integer');
        $html->set_variable('iclogos_picture_count', count(find_all_files(BASE . '/img/iclogos/', true)), 'integer');
    } catch (Exception $e) {
        $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
        $fatal_error = true;
    }
}
/********************************************************************************
 *
 *   Generate HTML Output
 *