Exemplo n.º 1
0
 /**
  * @brief Search parts
  *
  * @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 string    $keyword                the search string
  * @param string    $group_by               @li if this is a non-empty string, the returned array is a
  *                                              two-dimensional array with the group names as top level.
  *                                          @li supported groups are: '' (none), 'categories',
  *                                              'footprints', 'storelocations', 'manufacturers'
  * @param boolean   $part_name              if ture, the search will include this attribute
  * @param boolean   $part_description       if ture, the search will include this attribute
  * @param boolean   $part_comment           if ture, the search will include this attribute
  * @param boolean   $footprint_name         if ture, the search will include this attribute
  * @param boolean   $category_name          if ture, the search will include this attribute
  * @param boolean   $storelocation_name     if ture, the search will include this attribute
  * @param boolean   $supplier_name          if ture, the search will include this attribute
  * @param boolean   $supplierpartnr         if ture, the search will include this attribute
  * @param boolean   $manufacturer_name      if ture, the search will include this attribute
  *
  * @retval array    all found parts as a one-dimensional array of Part objects,
  *                  sorted by their names (if "$group_by == ''")
  * @retval array    @li all parts as a two-dimensional array, grouped by $group_by,
  *                      sorted by name (if "$group_by != ''")
  *                  @li example: array('category1' => array(part1, part2, ...),
  *                      'category2' => array(part123, part124, ...), ...)
  *                  @li for the group names (in the example 'category1', 'category2', ...)
  *                      are the full paths used
  *
  * @throws Exception if there was an error
  */
 public static function search_parts(&$database, &$current_user, &$log, $keyword, $group_by = '', $part_name = true, $part_description = true, $part_comment = false, $footprint_name = false, $category_name = false, $storelocation_name = false, $supplier_name = false, $supplierpartnr = false, $manufacturer_name = false)
 {
     global $config;
     $keyword = trim($keyword);
     if (strlen($keyword) == 0) {
         return array();
     }
     $keyword = str_replace('*', '%', $keyword);
     $keyword = '%' . $keyword . '%';
     $groups = array();
     $parts = array();
     $values = array();
     $query = 'SELECT parts.id FROM parts' . ' LEFT JOIN footprints ON parts.id_footprint=footprints.id' . ' LEFT JOIN storelocations ON parts.id_storelocation=storelocations.id' . ' LEFT JOIN manufacturers  ON parts.id_manufacturer=manufacturers.id' . ' LEFT JOIN categories ON parts.id_category=categories.id' . ' LEFT JOIN orderdetails ON parts.id=orderdetails.part_id' . ' LEFT JOIN suppliers ON orderdetails.id_supplier=suppliers.id' . ' WHERE FALSE';
     if ($part_name) {
         $query .= ' OR (parts.name LIKE ?)';
         $values[] = $keyword;
     }
     if ($part_description) {
         $query .= ' OR (parts.description LIKE ?)';
         $values[] = $keyword;
     }
     if ($part_comment) {
         $query .= ' OR (parts.comment LIKE ?)';
         $values[] = $keyword;
     }
     if ($footprint_name) {
         $query .= ' OR (footprints.name LIKE ?)';
         $values[] = $keyword;
     }
     if ($category_name) {
         $query .= ' OR (categories.name LIKE ?)';
         $values[] = $keyword;
     }
     if ($storelocation_name) {
         $query .= ' OR (storelocations.name LIKE ?)';
         $values[] = $keyword;
     }
     if ($supplier_name) {
         $query .= ' OR (suppliers.name LIKE ?)';
         $values[] = $keyword;
     }
     if ($supplierpartnr) {
         $query .= ' OR (orderdetails.supplierpartnr LIKE ?)';
         $values[] = $keyword;
     }
     if ($manufacturer_name) {
         $query .= ' OR (manufacturers.name LIKE ?)';
         $values[] = $keyword;
     }
     if (!isset($config['db']['limit']['search_parts'])) {
         $config['db']['limit']['search_parts'] = 200;
     }
     switch ($group_by) {
         case '':
             $query .= ' GROUP BY parts.id ORDER BY parts.name ASC';
             if (isset($config['db']['limit']['search_parts']) && $config['db']['limit']['search_parts'] > 0) {
                 $query .= ' LIMIT ' . $config['db']['limit']['search_parts'];
             }
             break;
         case 'categories':
             $query .= ' GROUP BY parts.id ORDER BY categories.id, parts.name ASC';
             if (isset($config['db']['limit']['search_parts']) && $config['db']['limit']['search_parts'] > 0) {
                 $query .= ' LIMIT ' . $config['db']['limit']['search_parts'];
             }
             break;
         default:
             throw new Exception('$group_by="' . $group_by . '" is not supported!');
     }
     $query_data = $database->query($query, $values);
     foreach ($query_data as $row) {
         $part = new Part($database, $current_user, $log, $row['id']);
         switch ($group_by) {
             case '':
                 $parts[] = $part;
                 break;
             case 'categories':
                 $groups[$part->get_category()->get_full_path()][] = $part;
                 break;
         }
     }
     if ($group_by != '') {
         ksort($groups);
         return $groups;
     } else {
         return $parts;
     }
 }
Exemplo n.º 2
0
/********************************************************************************
 *
 *   Initialize Objects
 *
 *********************************************************************************/
$html = new HTML($config['html']['theme'], $config['html']['custom_css'], 'Detailinfo');
try {
    $database = new Database();
    $log = new Log($database);
    $current_user = new User($database, $current_user, $log, 1);
    // admin
    $part = new Part($database, $current_user, $log, $part_id);
    $footprint = $part->get_footprint();
    $storelocation = $part->get_storelocation();
    $manufacturer = $part->get_manufacturer();
    $category = $part->get_category();
    $all_orderdetails = $part->get_orderdetails();
} catch (Exception $e) {
    $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
    $fatal_error = true;
}
/********************************************************************************
 *
 *   Execute actions
 *
 *********************************************************************************/
if (!$fatal_error) {
    switch ($action) {
        case 'dec':
            // remove some parts
            try {