function getAttachments() { // Everything is all good, load it from the database. // Connect to the database. $_db = getMysqli(); // SQL query to run. $statement = $_db->prepare("SELECT AttachmentID FROM Attachments WHERE PinkieID=?"); $statement->bind_param('i', $this->i_PinkieID); $statement->execute(); // Error running the statment. if ($statement->errno != 0) { $_tmp = $statement->error; $statement->close(); $_db->close(); onError("Pinkie::getAttachments()", 'There was an error running the query [' . $_tmp . '] Could not fetch Attachments.'); } $statement->store_result(); if ($statement->num_rows <= 0) { $statement->free_result(); $statement->close(); $_db->close(); if (SQL_NO_RESULTS_BREAK) { onError("Pinkie::getAttachments()", 'Could not find any attachments associated with the PID of: ' . $this->i_PinkieID); } return; } // We have a results. $statement->bind_result($_tempAttachementID); while ($statement->fetch()) { $_f = new Attachement($this->i_PinkieID); $_f->i_FileID = (int) $_tempAttachementID; $_f->fromDatabase(); array_push($this->a_Attachments, $_f); } // Cleanup. $statement->free_result(); $statement->close(); $_db->close(); }
throw new Exception('Es ist keine Preisinformation ausgewählt!'); } $pricedetails->delete(); } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); } break; case 'attachement_add': try { if ((strlen($_FILES['attachement_file']['name']) == 0) == (strlen($new_filename) == 0)) { throw new Exception('Sie müssen entweder ein Dateiname angeben, oder eine Datei zum Hochladen wählen!'); } if (strlen($_FILES['attachement_file']['name']) > 0) { $new_filename = upload_file($_FILES['attachement_file'], BASE . '/data/media/'); } $new_attachement = Attachement::add($database, $current_user, $log, $part, $new_attachement_type_id, $new_filename, $new_name, $new_show_in_table); if ($new_is_master_picture && $new_attachement->is_picture()) { $part->set_master_picture_attachement_id($new_attachement->get_id()); } } catch (Exception $e) { $messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red'); } break; case 'attachement_apply': try { if (!is_object($attachement)) { throw new Exception('Es ist kein Dateianhang ausgewählt!'); } if (strlen($_FILES['attachement_file']['name']) > 0) { $new_filename = upload_file($_FILES['attachement_file'], BASE . '/data/media/'); }
/** * @brief Delete this attachement from database (and the associated file from harddisc if desired) * * @note This method overrides the same-named method from the parent class. * * @param boolean $delete_from_hdd if true, and the associated file isn't used in other file records, * the file will be deleted from harddisc drive too (!!) * * @throws Exception if the file exists and should be deleted, but cannot be deleted * (maybe not enought permissions) * @throws Exception if there was an error */ public function delete($delete_from_hdd = false) { $filename = $this->get_filename(); $must_file_delete = false; if ($delete_from_hdd && strlen($filename) > 0) { // we will delete the file only from HDD if there are no other "Attachement" objects with the same filename! $attachements = Attachement::get_attachements_by_filename($this->database, $this->current_user, $this->log, $filename); if (count($attachements) <= 1 && file_exists($filename)) { // check if there are enought permissions to delete the file if (!is_writable(dirname($filename))) { throw new Exception('Die Datei "' . $filename . '" kann nicht gelöscht werden, ' . 'da im übergeordneten Ordner keine Schreibrechte vorhanden sind!'); } // all OK, file must be deleted after deleting the database record successfully $must_file_delete = true; } } try { $transaction_id = $this->database->begin_transaction(); // start transaction // Set all "id_master_picture_attachement" in the table "parts" to NULL where the master picture is this attachement $query = 'SELECT id from parts WHERE id_master_picture_attachement=?'; $query_data = $this->database->query($query, array($this->get_id())); foreach ($query_data as $row) { $part = new Part($this->database, $this->current_user, $this->log, $row['id']); $part->set_master_picture_attachement_id(NULL); } $this->get_element()->set_attributes(array()); // save element attributes to update its "last_modified" // Now we can delete the database record of this attachement parent::delete(); // now delete the file (if desired) if ($must_file_delete) { if (!unlink($filename)) { throw new Exception('Die Datei "' . $filename . '" kann nicht von der Festplatte gelöscht ' . "werden! \nÜberprüfen Sie, ob die nötigen Rechte vorhanden sind."); } } $this->database->commit($transaction_id); // commit transaction } catch (Exception $e) { $this->database->rollback(); // rollback transaction // restore the settings from BEFORE the transaction $this->reset_attributes(); throw new Exception("Der Dateianhang \"" . $this->get_name() . "\" konnte nicht entfernt werden!\nGrund: " . $e->getMessage()); } }
private function dig($bodyPart) { $bodyLines = explode(PHP_EOL, trim($bodyPart)); $headerLines = $this->parseHeader($bodyLines); if (array_key_exists('content-type', $headerLines)) { $bp = new BodyPart(); $_bodies = self::parseBody($bodyLines, $headerLines['content-type']); $bp->setBody($_bodies); if (sizeof($_bodies) > 1) { foreach ($_bodies as $_body) { self::dig($_body); } } else { $bp->setHeader($headerLines); // Is it a attachement? if (array_key_exists('content-disposition', $headerLines)) { array_push($this->contentDispos, trim($headerLines['content-disposition'])); $a = new Attachement(); preg_match('!filename=(.*)$!mi', $headerLines['content-disposition'], $matches); $filename = str_replace(array("'", '"'), '', trim($matches[1])); $a->setFilename($filename); $a->setContent(self::makeBody($bp)); $a->setContentType($headerLines['content-type']); array_push($this->attachements, $a); } else { // or just a embedded object? if (array_key_exists('content-id', $headerLines)) { array_push($this->contentIds, trim($headerLines['content-id'])); $a = new Attachement(); // Create the filename from the cid: $filename = self::sanitizeFileName($headerLines['content-id']); // The content type string often holds more data than just the mime type $ct = $headerLines['content-type']; if (strpos($ct, ';')) { $_ct = explode(';', $ct); $filename .= '.' . explode('/', $_ct[0])[1]; } else { $filename .= '.' . explode('/', $ct)[1]; } if (self::DEBUG || self::TRACE) { printf("[" . date(DATE_RFC822) . "] Filename is: %s" . PHP_EOL, $filename); } $a->setFilename($filename); $a->setContent(self::makeBody($bp)); $a->setContentType($ct); array_push($this->attachements, $a); } } array_push($this->allBodyParts, $bp); } } }
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 * *********************************************************************************/ $html->print_header($messages); if (!$fatal_error) { $html->print_template('statistics');