Beispiel #1
0
	/**
	 * (non-PHPdoc)
	 * @see de\RaumZeitLabor\PartKeepr\Util.Serializable::serialize()
	 */
	public function serialize () {
		$aManufacturers = array();
		
		foreach ($this->getManufacturers() as $manufacturer) {
			$aManufacturers[] = $manufacturer->serialize();
		}
		
		$aDistributors = array();
		
		foreach ($this->getDistributors() as $distributor) {
			$aDistributors[] = $distributor->serialize();
		}
		
		$aParameters = array();
		foreach ($this->getParameters() as $parameter) {
			$aParameters[] = $parameter->serialize();
		}
		
		$aImages = array();
		foreach ($this->getImages() as $image) {
			$aImages[] = $image->serialize();
		}
		
		$aAttachments = array();
		foreach ($this->getAttachments() as $attachment) {
			$aAttachments[] = $attachment->serialize();
		}
		
		return array(
					"id" => $this->getId(),
					"name" => $this->getName(),
					"comment" => $this->getComment(),
					"stockLevel" => $this->getStockLevel(),
					"footprint_id" => is_object($this->footprint) ? $this->footprint->getId() : null,
					"minStockLevel" => $this->minStockLevel,
					"storageLocation_id" => is_object($this->storageLocation) ? $this->storageLocation->getId() : null,
					"storageLocationName" => is_object($this->storageLocation) ? $this->storageLocation->getName() : null,
					"category_id" => is_object($this->category) ?  $this->category->getId() : null,
					"partUnit_id" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : null,
					"partUnit_name" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : PartKeepr::i18n("Pieces"),
					"partUnit_shortName" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : "",
					"manufacturers" => $aManufacturers,
					"distributors" => $aDistributors,
					"images" => $aImages,
					"attachments" => $aAttachments,
					"parameters" => $aParameters
		
		);
	}
Beispiel #2
0
if (isset($_REQUEST['insert_footprints'])) {
    $start_time = microtime(true);
    try {
        $trans_id = $database->begin_transaction();
        for ($i = 0; $i < $_REQUEST['count']; $i++) {
            $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
            $parent = isset($_REQUEST['with_error']) && $i == $_REQUEST['count'] / 2 ? -1 : 0;
            if ($i % 3 == 0) {
                $filename = '/IC_DIP02';
            } elseif ($i % 3 == 1) {
                $filename = '/asdf';
            } elseif ($i % 3 == 2) {
                $filename = '';
            }
            // no filename
            $footprint = Footprint::add($database, $current_user, $log, $randomString, $parent, $filename);
        }
        $database->commit($trans_id);
    } catch (Exception $e) {
        $database->rollback();
        $footprint_error = $e->getMessage();
    }
    $footprint_milliseconds = (int) (1000 * (microtime(true) - $start_time));
}
print 'Anzahl Footprints in der Tabelle: ' . $database->get_count_of_records('footprints') . '<br>';
print '<input type="text" size="6" name="count" value="' . (isset($_REQUEST['count']) ? $_REQUEST['count'] : 100) . '">';
print '<input type="submit" name="insert_footprints" value="Footprints hinzufügen">';
print '<input type="checkbox" name="with_error" ' . (isset($_REQUEST['with_error']) ? 'checked' : '') . '>Mit Fehler in der Hälfte<br>';
if (isset($footprint_milliseconds)) {
    print 'Zeit: ' . $footprint_milliseconds . 'ms<br>';
}
Beispiel #3
0
            }
            break;
        case 'save_proposed_filenames':
            $errors = array();
            for ($i = 0; $i < $broken_footprints_count; $i++) {
                $spf_footprint_id = isset($_REQUEST['broken_footprint_id_' . $i]) ? $_REQUEST['broken_footprint_id_' . $i] : -1;
                // -1 will produce an error
                $spf_new_filename = isset($_REQUEST['proposed_filename_' . $i]) ? to_unix_path($_REQUEST['proposed_filename_' . $i]) : NULL;
                $spf_checked = isset($_REQUEST['filename_checkbox_' . $i]) || $save_all_proposed_filenames;
                if (strlen($spf_new_filename) > 0 && !is_path_absolute_and_unix($spf_new_filename)) {
                    $spf_new_filename = BASE . '/' . $spf_new_filename;
                }
                // switch from relative path (like "img/foo.png") to absolute path (like "/var/www/part-db/img/foo.png")
                try {
                    if ($spf_checked) {
                        $spf_broken_footprint = new Footprint($database, $current_user, $log, $spf_footprint_id);
                        $spf_broken_footprint->set_filename($spf_new_filename);
                    }
                } catch (Exception $e) {
                    $errors[] = $e->getMessage();
                }
            }
            foreach ($errors as $error) {
                $messages[] = array('text' => 'Fehlermeldung: ' . $error, 'color' => 'red');
            }
            break;
    }
}
/********************************************************************************
 *
 *   List broken filename footprints
Beispiel #4
0
        $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
 *
 *********************************************************************************/
if (!$fatal_error && !$database->is_update_required()) {
    try {
        if (count(Footprint::get_broken_filename_footprints($database, $current_user, $log)) > 0) {
            $html->set_variable('broken_filename_footprints', true);
        } else {
            $html->set_variable('broken_filename_footprints', false);
        }
    } catch (Exception $e) {
        $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
    }
}
/********************************************************************************
 *
 *   Show Update List (RSS Feed from Google Code) if enabled
 *
 *********************************************************************************/
if (!$fatal_error && !$config['startup']['disable_update_list']) {
    $feed_link = 'https://github.com/sandboxgangster/Part-DB/releases.atom';
Beispiel #5
0
 *********************************************************************************/
$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;
    }
    if ($attachement_id > 0) {
        $attachement = new Attachement($database, $current_user, $log, $attachement_id);
    } else {
Beispiel #6
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;
}
Beispiel #7
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
Beispiel #8
0
 /**
  * @brief Get all footprints with invalid filenames (file does not exist)
  *
  * @param Database  &$database      reference to the database onject
  * @param User      &$current_user  reference to the current user which is logged in
  * @param Log       &$log           reference to the Log-object
  *
  * @retval array    all footprints with broken filename as a one-dimensional
  *                  array of Footprint objects, sorted by their names
  *
  * @throws Exception if there was an error
  */
 public static function get_broken_filename_footprints(&$database, &$current_user, &$log)
 {
     $broken_filename_footprints = array();
     $root_footprint = new Footprint($database, $current_user, $log, 0);
     $all_footprints = $root_footprint->get_subelements(true);
     foreach ($all_footprints as $footprint) {
         if (!$footprint->is_filename_valid()) {
             $broken_filename_footprints[] = $footprint;
         }
     }
     return $broken_filename_footprints;
 }