Beispiel #1
0
 /**
  * @see CronInterface::run()
  */
 public static function run()
 {
     if (self::check() == true) {
         $last_run_daily_datetime = Registry::get_value("base_cron_last_run_daily_datetime");
         $last_run_weekly_datetime = Registry::get_value("base_cron_last_run_weekly_datetime");
         $last_run_daily_datetime_handler = new DatetimeHandler($last_run_daily_datetime);
         $last_run_weekly_datetime_handler = new DatetimeHandler($last_run_weekly_datetime);
         $current_datetime_handler = new DatetimeHandler(date("Y-m-d H:i:s"));
         if ($last_run_daily_datetime_handler->distance($current_datetime_handler) >= 86400) {
             $daily = true;
         } else {
             $daily = false;
         }
         if ($last_run_weekly_datetime_handler->distance($current_datetime_handler) >= 604800) {
             $weekly = true;
         } else {
             $weekly = false;
         }
         $cron_event = new CronEvent(self::$last_run_id, $daily, $weekly);
         $event_handler = new EventHandler($cron_event);
         if ($event_handler->get_success() == true) {
             if (self::$last_run_id + 1 > 256) {
                 Registry::set_value("base_cron_last_run_id", 1);
                 self::$last_run_id = 1;
             } else {
                 Registry::set_value("base_cron_last_run_id", self::$last_run_id + 1);
                 self::$last_run_id = self::$last_run_id + 1;
             }
             Registry::set_value("base_cron_last_run_datetime", date("Y-m-d H:i:s"));
             self::$last_run_datetime = date("Y-m-d H:i:s");
             if ($daily == true) {
                 Registry::set_value("base_cron_last_run_daily_datetime", date("Y-m-d H:i:s"));
             }
             if ($weekly == true) {
                 Registry::set_value("base_cron_last_run_weekly_datetime", date("Y-m-d H:i:s"));
             }
         }
     }
 }
Beispiel #2
0
 /**
  * @see GroupInterface::set_name()
  * @param string $name Group Name
  * @return bool
  */
 public function set_name($name)
 {
     global $transaction;
     if ($this->group and $this->group_id and $name) {
         $transaction_id = $transaction->begin();
         if ($this->group->set_name($name) == true) {
             $group_rename_event = new GroupRenameEvent($this->group_id);
             $event_handler = new EventHandler($group_rename_event);
             if ($event_handler->get_success() == true) {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #3
0
 /**
  * @param array $get_array
  * @param integer $type_id
  */
 public static function add_as_item($get_array, $type_id)
 {
     global $user, $transaction;
     if ($get_array and is_numeric($type_id)) {
         $transaction_id = $transaction->begin();
         $equipment = new Equipment(null);
         $equipment_add_successful = $equipment->create($type_id, $user->get_user_id());
         if ($equipment_add_successful) {
             $item_id = $equipment->get_item_id();
             $item_add_event = new ItemAddEvent($item_id, unserialize($get_array), null);
             $event_handler = new EventHandler($item_add_event);
             if ($event_handler->get_success() == true) {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return "1";
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 throw new EquipmentCreateException();
             }
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             throw new EquipmentCreateException();
         }
     } else {
         throw new EquipmentIDMissingException();
     }
 }
 /**
  * Creates a new Project Folder including Folder
  * @param integer $project_id
  * @return integer
  */
 public function create($project_id, $base_folder_id)
 {
     if (is_numeric($project_id)) {
         $project = new Project($project_id);
         // Folder
         if ($base_folder_id == null) {
             $project_folder_id = constant("PROJECT_FOLDER_ID");
         } else {
             $project_folder_id = $base_folder_id;
         }
         $folder = new Folder($project_folder_id);
         $path = new Path($folder->get_path());
         $path->add_element($project_id);
         if (($folder_id = parent::create($project->get_name(), $project_folder_id, $path->get_path_string(), $project->get_owner_id(), null)) != null) {
             $project_has_folder_access = new ProjectHasFolder_Access(null);
             if ($project_has_folder_access->create($project_id, $folder_id) == null) {
                 return null;
             }
             // Virtual Folder
             $project_folder_create_event = new ProjectFolderCreateEvent($folder_id);
             $event_handler = new EventHandler($project_folder_create_event);
             if ($event_handler->get_success() == false) {
                 $this->delete();
                 return false;
             } else {
                 return $folder_id;
             }
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
Beispiel #5
0
 /**
  * @see ProjectItemInterface::unlink_item()
  * @return bool
  * @throws ProjectItemUnlinkException
  */
 public function unlink_item()
 {
     if ($this->item_id and $this->project_id) {
         if (Project_Wrapper::delete_data_entity_sub_item_links($this->item_id, $this->project_id) == false) {
             throw new ProjectItemUnlinkException(true, "Data-Entity Sub-Item delete failed");
         }
         if (ProjectHasItem_Access::delete_sub_items($this->item_id, $this->project_id) == false) {
             throw new ProjectItemUnlinkException(true, "Sub-Item delete failed");
         }
         $primary_key = ProjectHasItem_Access::get_entry_by_item_id_and_project_id($this->item_id, $this->project_id);
         $project_has_item = new ProjectHasItem_Access($primary_key);
         if ($project_has_item->delete()) {
             // Event
             $item_unlink_event = new ItemUnlinkEvent($this->item_id);
             $event_handler = new EventHandler($item_unlink_event);
             if ($event_handler->get_success() == false) {
                 throw new ProjectItemUnlinkException(true, "Event failed");
             }
             return true;
         } else {
             throw new ProjectItemUnlinkException(true, "DB failed");
         }
     } else {
         throw new ProjectItemUnlinkException();
     }
 }
Beispiel #6
0
 /**
  * @param integer $user_id
  * @return bool
  */
 public function create($user_id)
 {
     if (is_numeric($user_id)) {
         $user = new User($user_id);
         // Folder
         $user_folder_id = constant("USER_FOLDER_ID");
         $folder = new Folder($user_folder_id);
         $path = new Path($folder->get_path());
         $path->add_element($user_id);
         if (($folder_id = parent::create($user->get_username(), $user_folder_id, $path->get_path_string(), $user_id, null)) != null) {
             $folder_is_user_folder_access = new FolderIsUserFolder_Access(null);
             if ($folder_is_user_folder_access->create($user_id, $folder_id) == null) {
                 return false;
             }
             // _Public
             $public_path = new Path($path->get_path_string());
             $public_path->add_element("_public");
             $public_folder = new Folder(null);
             if ($public_folder->create("_public", $folder_id, $public_path->get_path_string(), $user_id, null) == null) {
                 $this->delete();
                 return false;
             }
             // _Private
             $private_path = new Path($path->get_path_string());
             $private_path->add_element("_private");
             $private_folder = new Folder(null);
             if ($private_folder->create("_private", $folder_id, $private_path->get_path_string(), $user_id, null) == null) {
                 $this->delete();
                 return false;
             }
             // Virtual Folders (Event)
             $user_folder_create_event = new UserFolderCreateEvent($folder_id);
             $event_handler = new EventHandler($user_folder_create_event);
             if ($event_handler->get_success() == false) {
                 $this->delete();
                 return false;
             } else {
                 return true;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * Creates a new Sample Folder including Folder
  * @param integer $sample_id
  * @return integer
  */
 public function create($sample_id)
 {
     if (is_numeric($sample_id)) {
         $sample = new Sample($sample_id);
         // Folder
         $sample_folder_id = constant("SAMPLE_FOLDER_ID");
         $folder = new Folder($sample_folder_id);
         $path = new Path($folder->get_path());
         $path->add_element($sample_id);
         $name = $sample->get_name() . " (" . $sample->get_formatted_id() . ")";
         if (($folder_id = parent::create($name, $sample_folder_id, $path->get_path_string(), $sample->get_owner_id(), null)) != null) {
             $sample_has_folder_access = new SampleHasFolder_Access(null);
             if ($sample_has_folder_access->create($sample_id, $folder_id) == null) {
                 return null;
             }
             // Virtual Folders (Event)
             $sample_folder_create_event = new SampleFolderCreateEvent($folder_id);
             $event_handler = new EventHandler($sample_folder_create_event);
             if ($event_handler->get_success() == false) {
                 $this->delete();
                 return false;
             } else {
                 return $folder_id;
             }
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
Beispiel #8
0
 /**
  * @param string $get_array
  * @param integer $sample_id
  * @return string
  * @throws SampleIDMissingException
  */
 public static function associate($get_array, $sample_id)
 {
     global $session;
     if ($get_array and is_numeric($sample_id)) {
         $_GET = unserialize($get_array);
         $post_array = array();
         $post_array['keywords'] = $session->read_value("ADD_ITEM_TEMP_KEYWORDS_" . $_GET['idk_unique_id']);
         $post_array['description'] = $session->read_value("ADD_ITEM_TEMP_DESCRIPTION_" . $_GET['idk_unique_id']);
         $sample = new Sample($sample_id);
         $item_add_event = new ItemAddEvent($sample->get_item_id(), $_GET, $post_array, true, "sample");
         $event_handler = new EventHandler($item_add_event);
         if ($event_handler->get_success() == true) {
             if ($_GET['retrace']) {
                 $params = http_build_query(Retrace::resolve_retrace_string($_GET['retrace']), '', '&');
                 return "index.php?" . $params;
             } else {
                 $paramquery['username'] = $username;
                 $paramquery['session_id'] = $session_id;
                 $paramquery['nav'] = "home";
                 $params = http_build_query($paramquery, '', '&');
                 return "index.php?" . $params;
             }
         } else {
             return "0";
         }
     } else {
         throw new SampleIDMissingException();
     }
 }
 /**
  * @see OrganisationUnitInterface::set_name()
  * @param string $name
  * @return bool
  */
 public function set_name($name)
 {
     global $transaction;
     if ($this->organisation_unit and $this->organisation_unit_id and $name) {
         $transaction_id = $transaction->begin();
         if ($this->organisation_unit->set_name($name) == true) {
             $organisation_unit_rename_event = new OrganisationUnitRenameEvent($this->organisation_unit_id);
             $event_handler = new EventHandler($organisation_unit_rename_event);
             if ($event_handler->get_success() == true) {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
     } else {
         return false;
     }
 }
 /**
  * @param integer $organisation_unit_id
  * @return bool
  */
 public function create($organisation_unit_id)
 {
     if (is_numeric($organisation_unit_id)) {
         $organisation_unit = new OrganisationUnit($organisation_unit_id);
         // Folder
         $organisation_unit_folder_id = constant("ORGANISATION_UNIT_FOLDER_ID");
         $folder = new Folder($organisation_unit_folder_id);
         $path = new Path($folder->get_path());
         $path->add_element($organisation_unit_id);
         $folder = new Folder(null);
         if (($folder_id = parent::create($organisation_unit->get_name(), $organisation_unit_folder_id, $path->get_path_string(), $organisation_unit->get_master_owner_id(), null)) != null) {
             $folder_is_organisation_unit_folder_access = new FolderIsOrganisationUnitFolder_Access(null);
             if ($folder_is_organisation_unit_folder_access->create($organisation_unit_id, $folder_id) == null) {
                 return false;
             }
             // Virtual Folders (Event)
             $organisation_unit_folder_create_event = new OrganisationUnitFolderCreateEvent($folder_id);
             $event_handler = new EventHandler($organisation_unit_folder_create_event);
             if ($event_handler->get_success() == false) {
                 $this->delete();
                 return false;
             } else {
                 return true;
             }
         } else {
             $this->delete(true, true);
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #11
0
 /**
  * @see SampleItemInterface::unlink_item()
  * @return bool
  */
 public function unlink_item()
 {
     if ($this->item_id and $this->sample_id) {
         if (Sample_Wrapper::delete_data_entity_sub_item_links($this->item_id, $this->sample_id) == false) {
             return false;
         }
         if (SampleHasItem_Access::delete_sub_items($this->item_id, $this->sample_id) == false) {
             return false;
         }
         $primary_key = SampleHasItem_Access::get_entry_by_item_id_and_sample_id($this->item_id, $this->sample_id);
         $sample_has_item = new SampleHasItem_Access($primary_key);
         if ($sample_has_item->delete()) {
             // Event
             $item_unlink_event = new ItemUnlinkEvent($this->item_id);
             $event_handler = new EventHandler($item_unlink_event);
             if ($event_handler->get_success() == false) {
                 return false;
             }
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #12
0
 /**
  * @see FolderInterface::delete()
  * @param bool $recursive
  * @param bool $content
  * @return bool
  */
 public function delete($recursive, $content)
 {
     global $transaction;
     if ($this->folder_id and $this->folder) {
         $transaction_id = $transaction->begin();
         $subfolder_array = $this->get_subfolder_array();
         if (is_array($subfolder_array) and $recursive == false or $content == false and $recursive == true) {
             return false;
         } else {
             if ($recursive == true and $content == true) {
                 if (is_array($subfolder_array)) {
                     foreach ($subfolder_array as $key => $value) {
                         $folder = Folder::get_instance($value);
                         if ($folder->delete(true, true) == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         } else {
                             if ($transaction_id != null) {
                                 // Avoids Ghost-Folders
                                 $transaction->commit($transaction_id);
                                 $transaction_id = $transaction->begin();
                             }
                         }
                     }
                 }
             }
             // Folder-Content
             $data_entity_array = $this->get_children("without_linked");
             if (is_array($data_entity_array) and count($data_entity_array) >= 1) {
                 foreach ($data_entity_array as $key => $value) {
                     // Files
                     if (($file_id = File::get_file_id_by_data_entity_id($value)) != null) {
                         $file = File::get_instance($file_id);
                         $file_delete = $file->delete();
                         if ($file_delete == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         } else {
                             if ($transaction_id != null) {
                                 // Avoids Ghost-Files
                                 $transaction->commit($transaction_id);
                                 $transaction_id = $transaction->begin();
                             }
                         }
                     }
                     // Values
                     if (($value_id = Value::get_value_id_by_data_entity_id($value)) != null) {
                         $value_obj = Value::get_instance($value_id);
                         if ($value_obj->delete() == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         }
                     }
                     // Virtual Folders
                     if (($virtual_folder_id = VirtualFolder::get_virtual_folder_id_by_data_entity_id($value)) != null) {
                         $virtual_folder = new VirtualFolder($virtual_folder_id);
                         if ($virtual_folder->delete() == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         }
                     }
                 }
             }
             // Linked Folder-Content (e.g. from sub-items)
             $data_entity_array = $this->get_children("linked_only");
             if (is_array($data_entity_array) and count($data_entity_array) >= 1) {
                 foreach ($data_entity_array as $key => $value) {
                     if ($this->unset_child($value) == false) {
                         if ($transaction_id != null) {
                             $transaction->rollback($transaction_id);
                         }
                         return false;
                     }
                 }
             }
             $path = constant("BASE_DIR") . "/" . $this->folder->get_path();
             if (file_exists($path)) {
                 $garbage_file_array = scandir($path);
                 if (is_array($garbage_file_array) and count($garbage_file_array) >= 3) {
                     foreach ($garbage_file_array as $key => $value) {
                         if ($key != 0 and $key != 1) {
                             unlink($path . "/" . $value);
                         }
                     }
                 }
             }
             $linked_virtual_folder_array = $this->get_parent_virtual_folders();
             if (is_array($linked_virtual_folder_array) and count($linked_virtual_folder_array)) {
                 foreach ($linked_virtual_folder_array as $key => $value) {
                     if ($this->unset_child_of($value) == false) {
                         if ($transaction_id != null) {
                             $transaction->rollback($transaction_id);
                         }
                         return false;
                     }
                 }
             }
             if (parent::delete() == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
             $folder_delete_event = new FolderDeleteEvent($folder_id);
             $event_handler = new EventHandler($folder_delete_event);
             if ($event_handler->get_success() == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
             if (file_exists($path)) {
                 if (rmdir($path)) {
                     if ($this->folder->delete() == true) {
                         if ($transaction_id != null) {
                             $transaction->commit($transaction_id);
                         }
                         return true;
                     } else {
                         if ($transaction_id != null) {
                             $transaction->rollback($transaction_id);
                         }
                         return false;
                     }
                 } else {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             } else {
                 if ($this->folder->delete() == true) {
                     if ($transaction_id != null) {
                         $transaction->commit($transaction_id);
                     }
                     return true;
                 } else {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             }
         }
     } else {
         return false;
     }
 }
 /**
  * @see SampleItemFactoryInterface::create()
  * @param integer $sample_id
  * @param integer $item_id
  * @param integer $gid
  * @param string $keywords
  * @param string $description
  * @param bool $parent
  * @return bool
  */
 public static function create($sample_id, $item_id, $gid, $keywords = null, $description = null, $parent_item_id = null, $parent_sample = false, $parent_is_parent_sample = false)
 {
     global $transaction;
     if ($transaction->is_in_transction() == true) {
         $sample = new Sample($sample_id);
         $sample_item = new SampleItem($sample_id);
         $sample_item->set_gid($gid);
         $sample_item->set_parent($parent_sample);
         // For parent sample only
         $sample_item->set_parent_item_id($parent_item_id);
         if ($sample_item->set_item_id($item_id) == false) {
             return false;
         }
         if ($sample_item->link_item() == false) {
             return false;
         }
         if (($class_name = $sample_item->is_classified()) == true) {
             if ($sample_item->set_class($class_name) == false) {
                 return false;
             }
         }
         $description_required = $sample_item->is_description();
         $keywords_required = $sample_item->is_keywords();
         if ($description_required == true xor $keywords_required == true) {
             if ($description_required == false and $keywords_required == true) {
                 $sample_item->set_information(null, $keywords);
             } else {
                 $sample_item->set_information($description, null);
             }
         } else {
             if ($description_required == true and $keywords_required == true) {
                 $sample_item->set_information($description, $keywords);
             }
         }
         $item_holder_type_array = Item::list_holders();
         $item_holder_id_array = array();
         if (is_array($item_holder_type_array) and count($item_holder_type_array) >= 1) {
             foreach ($item_holder_type_array as $key => $value) {
                 $item_holder_id_array[$key] = $value::list_item_holders_by_item_id($sample->get_item_id());
                 if ($key == "sample" and $parent_is_parent_sample == true) {
                     $item_holder_id_array[$key] = array_merge($item_holder_id_array[$key], Sample_Wrapper::get_sample_id_and_gid_by_parent_sample_id($sample_id));
                 }
             }
         }
         $item_holder_add_event = new ItemHolderAddEvent($item_holder_id_array, $sample->get_item_id(), $item_id, $gid);
         $event_handler = new EventHandler($item_holder_add_event);
         if ($event_handler->get_success() == false) {
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
Beispiel #14
0
 /**
  * @param string $username
  * @param string $session_id
  * @return string
  */
 public static function run($username, $session_id)
 {
     global $session, $user, $transaction;
     $sample_add_role = $session->read_value("SAMPLE_ADD_ROLE");
     $sample_item_retrace = $session->read_value("SAMPLE_ITEM_RETRACE");
     $sample_item_get_array = $session->read_value("SAMPLE_ITEM_GET_ARRAY");
     $sample_item_keywords = $session->read_value("SAMPLE_ITEM_KEYWORDS");
     $sample_item_description = $session->read_value("SAMPLE_ITEM_DESCRIPTION");
     $sample_organ_unit = $session->read_value("SAMPLE_ORGANISATION_UNIT");
     $sample_template = $session->read_value("SAMPLE_TEMPLATE");
     $sample_name = $session->read_value("SAMPLE_NAME");
     $sample_manufacturer = $session->read_value("SAMPLE_MANUFACTURER_ID");
     $sample_manufacturer_name = $session->read_value("SAMPLE_MANUFACTURER_NAME");
     $sample_location = $session->read_value("SAMPLE_LOCATION");
     $sample_expiry = $session->read_value("SAMPLE_EXPIRY");
     $sample_expiry_warning = $session->read_value("SAMPLE_EXPIRY_WARNING");
     $sample_desc = $session->read_value("SAMPLE_DESCRIPTION");
     $sample_template_data_type = $session->read_value("SAMPLE_TEMPLATE_DATA_TYPE");
     $sample_template_data_type_id = $session->read_value("SAMPLE_TEMPLATE_DATA_TYPE_ID");
     $sample_template_data_array = $session->read_value("SAMPLE_TEMPLATE_DATA_ARRAY");
     $transaction_id = $transaction->begin();
     try {
         $sample = new Sample(null);
         $sample->set_template_data($sample_template_data_type, $sample_template_data_type_id, $sample_template_data_array);
         $sample_id = $sample->create($sample_organ_unit, $sample_template, $sample_name, $sample_manufacturer, $sample_location, $sample_desc, null, $sample_expiry, $sample_expiry_warning);
         if ($sample_add_role == "item" or $sample_add_role == "item_parent") {
             // Special Parent Sample Case
             if ($sample_add_role == "item_parent") {
                 $parent_sample = new Sample($sample_item_get_array['sample_id']);
                 $sample_item_get_array['sample_id'] = $sample_id;
                 $sample_item_get_array['parent_sample'] = "1";
                 $event_item_id = $parent_sample->get_item_id();
             } else {
                 $event_item_id = $sample->get_item_id();
             }
             $post_array = array();
             $post_array['keywords'] = $sample_item_keywords;
             $post_array['description'] = $sample_item_description;
             $item_add_event = new ItemAddEvent($event_item_id, $sample_item_get_array, $post_array, true, "sample");
             $event_handler = new EventHandler($item_add_event);
             if ($event_handler->get_success() == true) {
                 // Nothing
             }
         }
     } catch (BaseException $e) {
         if ($transaction_id != null) {
             $transaction->rollback($transaction_id);
         }
         throw $e;
     }
     $session->delete_value("SAMPLE_ADD_ROLE");
     $session->delete_value("SAMPLE_ADD_ITEM_HOLDER_CLASS");
     $session->delete_value("SAMPLE_ADD_ITEM_HOLDER_ID");
     $session->delete_value("SAMPLE_ITEM_RETRACE");
     $session->delete_value("SAMPLE_ITEM_GET_ARRAY");
     $session->delete_value("SAMPLE_ITEM_KEYWORDS");
     $session->delete_value("SAMPLE_ITEM_DESCRIPTION");
     $session->delete_value("SAMPLE_ITEM_TYPE_ARRAY");
     $session->delete_value("SAMPLE_ORGANISATION_UNIT");
     $session->delete_value("SAMPLE_TEMPLATE");
     $session->delete_value("SAMPLE_NAME");
     $session->delete_value("SAMPLE_MANUFACTURER_ID");
     $session->delete_value("SAMPLE_MANUFACTURER_NAME");
     $session->delete_value("SAMPLE_LOCATION");
     $session->delete_value("SAMPLE_EXPIRY");
     $session->delete_value("SAMPLE_EXPIRY_WARNING");
     $session->delete_value("SAMPLE_DESCRIPTION");
     $session->delete_value("SAMPLE_TEMPLATE_DATA_TYPE");
     $session->delete_value("SAMPLE_TEMPLATE_DATA_TYPE_ID");
     $session->delete_value("SAMPLE_TEMPLATE_DATA_ARRAY");
     if ($sample_add_role == "item" or $sample_add_role == "item_parent") {
         if ($transaction_id != null) {
             $transaction->commit($transaction_id);
         }
         if ($sample_item_retrace) {
             $params = http_build_query(Retrace::resolve_retrace_string($sample_item_retrace), '', '&');
             return "index.php?" . $params;
         } else {
             $paramquery['username'] = $username;
             $paramquery['session_id'] = $session_id;
             $paramquery['nav'] = "home";
             $params = http_build_query($paramquery, '', '&');
             return "index.php?" . $params;
         }
     } else {
         if ($transaction_id != null) {
             $transaction->commit($transaction_id);
         }
         $paramquery = array();
         $paramquery['username'] = $username;
         $paramquery['session_id'] = $session_id;
         $paramquery['nav'] = "sample";
         $paramquery['run'] = "detail";
         $paramquery['sample_id'] = $sample_id;
         $params = http_build_query($paramquery, '', '&');
         return "index.php?" . $params;
     }
 }
Beispiel #15
0
 /**
  * Deletes an item
  * @return bool
  * @throws ItemDeleteInformationException
  * @throws ItemDeleteClassException
  * @throws ItemDeleteEventFailedException
  * @throws ItemDeleteFailedException
  * @throws ItemNoInstanceException
  */
 protected function delete()
 {
     global $transaction;
     if ($this->item_id and $this->item) {
         $transaction_id = $transaction->begin();
         try {
             $item_information_array = ItemInformation::list_item_information($this->item_id);
             if (is_array($item_information_array) and count($item_information_array) >= 1) {
                 foreach ($item_information_array as $key => $value) {
                     $item_information = new ItemInformation($value);
                     if ($item_information->unlink_item($this->item_id) == false) {
                         throw new ItemDeleteInformationException();
                     }
                 }
             }
             // Item Classes
             $item_class_array = ItemClass::list_classes_by_item_id($this->item_id);
             if (is_array($item_class_array) and count($item_class_array) >= 1) {
                 foreach ($item_class_array as $key => $value) {
                     $item_class = new ItemClass($value);
                     if ($item_class->unlink_item($this->item_id) == false) {
                         throw new ItemDeleteClassException();
                     }
                 }
             }
             // Event
             $item_delete_event = new ItemDeleteEvent($this->item_id);
             $event_handler = new EventHandler($item_delete_event);
             if ($event_handler->get_success() == false) {
                 throw new ItemDeleteEventFailedException();
             }
             if ($this->item->delete() == false) {
                 throw new ItemDeleteFailedException();
             }
         } catch (BaseException $e) {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             throw $e;
         }
         if ($transaction_id != null) {
             $transaction->commit($transaction_id);
         }
         return true;
     } else {
         throw new ItemNoInstanceException();
     }
 }
Beispiel #16
0
 /**
  * @todo business logic exceptions
  * @param integer $folder_id
  * @param integer $type_id
  * @param string $value_array
  * @param string $get_array
  * @return string
  */
 public static function add_as_item($folder_id, $type_id, $value_array, $get_array)
 {
     global $user, $transaction;
     $parent_folder = Folder::get_instance($folder_id);
     if ($parent_folder->is_write_access()) {
         $transaction_id = $transaction->begin();
         $value_array = json_decode($value_array, true);
         $value = Value::get_instance(null);
         $value_add_successful = $value->create($folder_id, $user->get_user_id(), $type_id, $value_array);
         if ($value_add_successful) {
             $item_id = $value->get_item_id();
             $item_add_event = new ItemAddEvent($item_id, unserialize($get_array), null);
             $event_handler = new EventHandler($item_add_event);
             if ($event_handler->get_success() == true) {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return "1";
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 throw new BaseException();
             }
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             throw new BaseException();
         }
     } else {
         throw new DataSecurityAccessDeniedException();
     }
 }
Beispiel #17
0
 /**
  * @param integer $group_id
  * @return bool
  */
 public function create($group_id)
 {
     global $transaction;
     if (is_numeric($group_id)) {
         $group = new Group($group_id);
         // Folder
         $group_folder_id = constant("GROUP_FOLDER_ID");
         $folder = new Folder($group_folder_id);
         $path = new Path($folder->get_path());
         $path->add_element($group_id);
         $folder = new Folder(null);
         if (($folder_id = parent::create($group->get_name(), $group_folder_id, $path->get_path_string(), 1, $group_id)) != null) {
             $folder_is_group_folder_access = new FolderIsGroupFolder_Access(null);
             if ($folder_is_group_folder_access->create($group_id, $folder_id) == null) {
                 return false;
             }
             // Virtual Folders (Event)
             $group_folder_create_event = new GroupFolderCreateEvent($folder_id);
             $event_handler = new EventHandler($group_folder_create_event);
             if ($event_handler->get_success() == false) {
                 $this->delete();
                 return false;
             } else {
                 return true;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #18
0
 /**
  * @see SampleInterface::delete()
  * @return bool
  * @throws SampleDeleteLocationException
  * @throws SampleDeleteUserException
  * @throws SampleDeleteOrganisationUnitException
  * @throws SampleDeleteItemException
  * @throws SampleDeleteFolderException
  * @throws SampleDeleteEventFailedException
  * @throws SampleDeleteFailedException
  * @throws SampleDeleteItemLinkException
  * @throws SampleNoInstanceException
  */
 public function delete()
 {
     global $transaction;
     if ($this->sample_id and $this->sample) {
         $transaction_id = $transaction->begin();
         try {
             array_push(self::$sample_delete_array, $this->sample_id);
             $tmp_sample_id = $this->sample_id;
             // Location Relations
             $sample_has_location_array = SampleHasLocation_Access::list_entries_by_sample_id($tmp_sample_id);
             if (is_array($sample_has_location_array) and count($sample_has_location_array) >= 1) {
                 foreach ($sample_has_location_array as $key => $value) {
                     $sample_has_location = new SampleHasLocation_Access($value);
                     if ($sample_has_location->delete() == false) {
                         throw new SampleDeleteLocationException();
                     }
                 }
             }
             // Organisation Unit and User Relations
             $sample_security = new SampleSecurity($tmp_sample_id);
             $organisation_unit_array = $sample_security->list_organisation_unit_entries();
             if (is_array($organisation_unit_array) and count($organisation_unit_array) >= 1) {
                 foreach ($organisation_unit_array as $key => $value) {
                     if ($sample_security->delete_organisation_unit($value) == false) {
                         throw new SampleDeleteOrganisationUnitException();
                     }
                 }
             }
             $user_array = $sample_security->list_user_entries();
             if (is_array($user_array) and count($user_array) >= 1) {
                 foreach ($user_array as $key => $value) {
                     if ($sample_security->delete_user($value) == false) {
                         throw new SampleDeleteUserException();
                     }
                 }
             }
             // Items
             $sample_item = new SampleItem($tmp_sample_id);
             $item_array = $sample_item->get_sample_items();
             if (is_array($item_array) and count($item_array) >= 1) {
                 foreach ($item_array as $item_key => $item_value) {
                     $sample_item = new SampleItem($tmp_sample_id);
                     $sample_item->set_item_id($item_value);
                     if ($sample_item->unlink_item() == false) {
                         throw new SampleDeleteItemException();
                     }
                 }
             }
             // Parent-Sample-Sub-Item-Links
             if (SampleItem::delete_remaining_sample_entries($tmp_sample_id) == false) {
                 throw new SampleDeleteItemException();
             }
             parent::delete();
             $sample_delete_event = new SampleDeleteEvent($tmp_sample_id);
             $event_handler = new EventHandler($sample_delete_event);
             if ($event_handler->get_success() == false) {
                 throw new SampleDeleteEventFailedException();
             }
             $sample_is_item = new SampleIsItem_Access($tmp_sample_id);
             if ($sample_is_item->delete() == false) {
                 throw new SampleDeleteItemLinkException();
             }
             if ($this->sample->delete() == false) {
                 throw new SampleDeleteFailedException();
             } else {
                 $this->__destruct();
                 $folder_id = SampleFolder::get_folder_by_sample_id($tmp_sample_id);
                 $folder = Folder::get_instance($folder_id);
                 if ($folder->delete(true, true) == false) {
                     throw new SampleDeleteFolderException();
                 }
             }
         } catch (BaseException $e) {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             throw $e;
         }
         if ($transaction_id != null) {
             $transaction->commit($transaction_id);
         }
         return true;
     } else {
         throw new SampleNoInstanceException();
     }
 }
 /**
  * @see VirtualFolderInterface::delete()
  * @return bool
  */
 public final function delete()
 {
     global $transaction;
     if ($this->virtual_folder_id and $this->virtual_folder) {
         $transaction_id = $transaction->begin();
         if ($this->unset_children() == false) {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
         $virtual_folder_delete_event = new VirtualFolderDeleteEvent($this->virtual_folder_id);
         $event_handler = new EventHandler($virtual_folder_delete_event);
         if ($event_handler->get_success() == false) {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
         if (parent::delete() == false) {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
         if ($this->virtual_folder->delete() == true) {
             if ($transaction_id != null) {
                 $transaction->commit($transaction_id);
             }
             return true;
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #20
0
 /**
  * @see LocationInterface::delete()
  * @return bool
  */
 public function delete()
 {
     global $transaction;
     if ($this->location and $this->location_id) {
         $transaction_id = $transaction->begin();
         // Event
         $location_delete_event = new LocationDeleteEvent($this->location_id);
         $event_handler = new EventHandler($location_delete_event);
         if ($event_handler->get_success() == false) {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         } else {
             if ($this->location->delete() == true) {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
         }
     } else {
         return false;
     }
 }
 /**
  * @see SystemHandlerInterface::disable_module()
  * @param integer $module_id
  * @return bool
  */
 public static function disable_module($module_id)
 {
     global $transaction;
     if (is_numeric($module_id)) {
         $transaction_id = $transaction->begin();
         $module_access = new BaseModule_Access($module_id);
         if ($module_access->get_disabled() == true) {
             $module_enable_event = new ModuleEnableEvent($module_id);
             $event_handler = new EventHandler($module_enable_event);
             if ($event_handler->get_success() == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
             if ($module_access->set_disabled(false) == true) {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
         } else {
             $module_disable_event = new ModuleDisableEvent($module_id);
             $event_handler = new EventHandler($module_disable_event);
             if ($event_handler->get_success() == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
             if ($module_access->set_disabled(true) == true) {
                 if ($transaction_id != null) {
                     $transaction->commit($transaction_id);
                 }
                 return true;
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
         }
     } else {
         return false;
     }
 }
Beispiel #22
0
 /**
  * @todo better transaction
  * @see FileInterface::update_file()
  * @param array $file_array
  * @param integer $previous_version_id
  * @param bool $major
  * @param bool $current
  * @return integer
  */
 public function update_file($file_array, $previous_version_id, $major, $current)
 {
     global $user, $session, $transaction;
     if ($this->file and $this->file_id and $file_array) {
         $transaction_id = $transaction->begin();
         $user_data = new DataUserData($user->get_user_id());
         $folder = Folder::get_instance($this->get_parent_folder_id());
         $folder_path = $folder->get_path();
         if ($folder->is_write_access() == true) {
             $target = constant("BASE_DIR") . "/" . $folder_path . "/" . $file_array['name'];
             if (!empty($file_array['name'])) {
                 $file_name_array = explode(".", $file_array['name']);
                 $file_name_array_length = substr_count($file_array['name'], ".");
                 // Forbidden file-types
                 if ($file_name_array[$file_name_array_length] == "php" or $file_name_array[$file_name_array_length] == "php3" or $file_name_array[$file_name_array_length] == "php4" or $file_name_array[$file_name_array_length] == "php5" or $file_name_array[$file_name_array_length] == "phtml" or $file_name_array[$file_name_array_length] == "phtm" or $file_name_array[$file_name_array_length] == "html" or $file_name_array[$file_name_array_length] == "htm" or $file_name_array[$file_name_array_length] == "cgi" or $file_name_array[$file_name_array_length] == "pl" or $file_name_array[$file_name_array_length] == "asp") {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return 7;
                 } else {
                     // Upload new file
                     move_uploaded_file($file_array['tmp_name'], $target);
                     if (($file_upload_error_no = $file_array['error']) == 0) {
                         $file_size = filesize($target);
                         $checksum = md5_file($target);
                         if ($this->compare_with_current_version($checksum) == false) {
                             $file_upload_precheck_event = new FileUploadPrecheckEvent($this->get_parent_folder_id(), $file_size);
                             $event_handler = new EventHandler($file_upload_precheck_event);
                             if ($event_handler->get_success() == false) {
                                 if ($transaction_id != null) {
                                     $transaction->rollback($transaction_id);
                                 }
                                 return 6;
                             }
                             if ($folder->get_quota_access($user->get_user_id(), $file_size) == true) {
                                 $folder->increase_filesize($user->get_user_id(), $file_size);
                                 $file_upload_event = new FileUploadEvent($this->get_parent_folder_id(), $file_size);
                                 $event_handler = new EventHandler($file_upload_event);
                                 if ($event_handler->get_success() == false) {
                                     // Nothing happens
                                 }
                                 // Rename Old File
                                 $current_file_version_id = FileVersion_Access::get_current_entry_by_toid($this->file_id);
                                 $current_file_version = new FileVersion_Access($current_file_version_id);
                                 $extension_array = explode(".", $current_file_version->get_name());
                                 $extension_array_length = substr_count($current_file_version->get_name(), ".");
                                 $new_internal_revision = $current_file_version->get_internal_revision() + 1;
                                 if ($major == true) {
                                     if ($previous_version_id == null) {
                                         $new_version = $current_file_version->get_version() + 1;
                                         $previous_version_pk_id = null;
                                     } else {
                                         $major_file_version_id = FileVersion_Access::get_entry_by_toid_and_internal_revision($this->file_id, $previous_version_id);
                                         $major_file_version = new FileVersion_Access($major_file_version_id);
                                         if ($major_file_version->get_previous_version_id() == $major_file_version->get_id()) {
                                             $previous_version_pk_id = null;
                                         } else {
                                             $previous_version_pk_id = $major_file_version->get_previous_version_id();
                                         }
                                         $major_file_version_id = FileVersion_Access::get_highest_major_version_entry_by_toid_and_previous_version_id($major_file_version->get_toid(), $previous_version_pk_id);
                                         $major_file_version = new FileVersion_Access($major_file_version_id);
                                         $new_version = $major_file_version->get_version() + 1;
                                     }
                                 } else {
                                     $major_file_version_id = FileVersion_Access::get_entry_by_toid_and_internal_revision($this->file_id, $previous_version_id);
                                     $current_minor_version_id = FileVersion_Access::get_highest_minor_version_entry_by_id($major_file_version_id);
                                     if ($current_minor_version_id) {
                                         $current_minor_version = new FileVersion_Access($current_minor_version_id);
                                         $new_version = $current_minor_version->get_version() + 1;
                                     } else {
                                         $new_version = 1;
                                     }
                                     $previous_version_pk_id = $major_file_version_id;
                                 }
                                 if ($current == true) {
                                     $file_version = new FileVersion_Access(null);
                                     $file_version->create($this->file_id, $file_array['name'], $new_version, $file_size, $checksum, null, $previous_version_pk_id, $new_internal_revision, true, $user->get_user_id());
                                     $current_file_version->set_current(false);
                                 } else {
                                     $file_version = new FileVersion_Access(null);
                                     $file_version->create($this->file_id, $file_array['name'], $new_version, $file_size, $checksum, null, $previous_version_pk_id, $new_internal_revision, false, $user->get_user_id());
                                 }
                                 // Rename File
                                 $extension_array = explode(".", $target);
                                 $extension_array_length = substr_count($target, ".");
                                 if ($extension_array_length == 0) {
                                     $extension_array[0] = "";
                                 }
                                 $new_filename = constant("BASE_DIR") . "/" . $folder_path . "/" . $this->data_entity_id . "-" . $new_internal_revision . "." . $extension_array[$extension_array_length];
                                 // Rename file with the object id
                                 if (rename($target, $new_filename) == true) {
                                     if ($transaction_id != null) {
                                         $transaction->commit($transaction_id);
                                     }
                                     return 1;
                                 } else {
                                     if ($transaction_id != null) {
                                         $transaction->rollback($transaction_id);
                                     }
                                     return 2;
                                 }
                             } else {
                                 // Delete File - Overquota
                                 if (unlink($target)) {
                                     if ($transaction_id != null) {
                                         $transaction->rollback($transaction_id);
                                     }
                                     return 6;
                                 } else {
                                     if ($transaction_id != null) {
                                         $transaction->rollback($transaction_id);
                                     }
                                     // Write Log - Delete Error (nach Rollback)
                                     return 6;
                                 }
                             }
                         } else {
                             // Delete File - Equals previous version
                             if (unlink($target)) {
                                 if ($transaction_id != null) {
                                     $transaction->rollback($transaction_id);
                                 }
                                 return 5;
                             } else {
                                 if ($transaction_id != null) {
                                     $transaction->rollback($transaction_id);
                                 }
                                 // Write Log - Delete Error
                                 return 5;
                             }
                         }
                     } else {
                         if ($file_upload_error_no == 1 or $file_upload_error_no == 2) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return 4;
                         } else {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return 2;
                         }
                     }
                 }
                 // End If/Else - Forbidden File-Types
             } else {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return 3;
             }
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return 8;
         }
     } else {
         return 3;
     }
 }