/** * @copydoc DBElement::check_values_validity() */ public static function check_values_validity(&$database, &$current_user, &$log, &$values, $is_new, &$element = NULL) { // first, we set the basename as the name if the name is empty $values['name'] = trim($values['name']); if (strlen($values['name']) == 0) { $values['name'] = basename($values['filename']); } // then we let all parent classes to check the values parent::check_values_validity($database, $current_user, $log, $values, $is_new, $element); // set boolean attributes settype($values['show_in_table'], 'boolean'); // check "type_id" try { // type_id == 0 or NULL means "no attachement type", and this is not allowed! if ($values['type_id'] == 0) { throw new Exception('"type_id" ist Null!'); } $attachement_type = new AttachementType($database, $current_user, $log, $values['type_id']); } catch (Exception $e) { debug('warning', 'Ungültige "type_id": "' . $values['type_id'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__); throw new Exception('Der gewählte Dateityp existiert nicht!'); } // check "class_name" $supported_classes = array('Part'); // to be continued (step by step)... if (!in_array($values['class_name'], $supported_classes)) { debug('error', 'Die Klasse "' . $values['class_name'] . '" unterstützt (noch) keine Dateianhänge!', __FILE__, __LINE__, __METHOD__); throw new Exception('Ungültiger Klassenname: "' . $values['class_name'] . '"'); } // check "element_id" try { // element_id == 0 is not allowed! if ($values['element_id'] == 0) { throw new Exception('"element_id" ist Null!'); } $element = new $values['class_name']($database, $current_user, $log, $values['element_id']); $element->set_attributes(array()); // save element attributes to update its "last_modified" } catch (Exception $e) { debug('warning', 'Ungültige "element_id"/"class_name": "' . $values['element_id'] . '"/"' . $values['class_name'] . '"' . "\n\nUrsprüngliche Fehlermeldung: " . $e->getMessage(), __FILE__, __LINE__, __METHOD__); throw new Exception('Das gewählte Element existiert nicht!'); } // trim $values['filename'] $values['filename'] = trim($values['filename']); // empty filenames are not allowed! if (strlen($values['filename']) == 0) { throw new Exception('Der Dateiname ist leer, das ist nicht erlaubt!'); } // check if "filename" is a valid (absolute and UNIX) filepath if (!is_path_absolute_and_unix($values['filename'])) { throw new Exception('Der Dateipfad "' . $values['filename'] . '" ist kein gültiger absoluter UNIX Dateipfad!'); } // we replace the path of the Part-DB installation directory (Constant "BASE") with a placeholder ("%BASE%") $values['filename'] = str_replace(BASE, '%BASE%', $values['filename']); }