public static function create()
 {
     if ($_GET['nextpage'] == 1) {
         $page_1_passed = true;
     } else {
         $page_1_passed = false;
         $error = "";
     }
     if ($page_1_passed == false) {
         $template = new HTMLTemplate("sample/admin/sample_template/add.html");
         $paramquery = $_GET;
         $paramquery['nextpage'] = "1";
         $params = http_build_query($paramquery, '', '&');
         $template->set_var("params", $params);
         if ($error) {
             $template->set_var("error", $error);
         } else {
             $template->set_var("error", "");
         }
         $folder = Folder::get_instance(constant("OLDL_FOLDER_ID"));
         $data_entity_array = $folder->get_children();
         if (is_array($data_entity_array)) {
             $result = array();
             $counter = 0;
             foreach ($data_entity_array as $key => $value) {
                 if (($file_id = File::get_file_id_by_data_entity_id($value)) != null) {
                     $file = File::get_instance($file_id);
                     $result[$counter]['value'] = $value;
                     $result[$counter]['content'] = $file->get_name();
                     $counter++;
                 }
             }
             $template->set_var("file", $result);
         }
         $category_array = SampleTemplateCat::list_entries();
         if (is_array($category_array)) {
             $result = array();
             $counter = 0;
             foreach ($category_array as $key => $value) {
                 $sample_template_cat = new SampleTemplateCat($value);
                 $result[$counter]['value'] = $value;
                 $result[$counter]['content'] = $sample_template_cat->get_name();
                 $counter++;
             }
             $template->set_var("category", $result);
         }
         $template->output();
     } else {
         $sample_template = new SampleTemplate(null);
         $paramquery = $_GET;
         unset($paramquery['action']);
         unset($paramquery['nextpage']);
         $params = http_build_query($paramquery, '', '&');
         if ($sample_template->create($_POST['data_entity_id'], $_POST['category_id'])) {
             Common_IO::step_proceed($params, "Add Sample Template", "Operation Successful", null);
         } else {
             Common_IO::step_proceed($params, "Add Sample Template", "Operation Failed", null);
         }
     }
 }
Example #2
0
 /**
  * @see SampleInterface::clone_sample()
  * @param integer $source_sample_id
  * @param string $name
  * @param integer $manufacturer_id
  * @param integer $location_id
  * @param string $desc
  * @param integer $language_id
  * @param string $date_of_expiry
  * @param integer $expiry_warning
  * @param array $value_array
  * @param array $item_array
  * @return integer
  * @throws SampleCloneIDMissingException
  * @throws SampleCloneCreateException
  * @throws SampleCloneCreateFolderException
  * @throws SampleCloneCreateSubFolderException
  * @throws SampleCloneCreateAsItemException
  * @throws SampleCloneCreateLocationException
  * @throws SampleCloneCreateFailedException
  * @throws SampleCloneUserException
  * @throws SampleCloneOrganisationUnitException
  * @throws SampleCloneLocationException
  * @throws SampleCloneValueException
  * @throws SampleCloneFileException
  * @throws SampleCloneParentException
  * @throws SampleCloneItemException
  */
 public function clone_sample($source_sample_id, $name, $manufacturer_id, $location_id, $desc, $language_id, $date_of_expiry, $expiry_warning, $value_array, $item_array)
 {
     global $user, $transaction;
     if (is_numeric($source_sample_id) and $name) {
         $source_sample = new Sample($source_sample_id);
         $source_sample_security = new SampleSecurity($source_sample_id);
         $source_sample_folder_id = SampleFolder::get_folder_by_sample_id($source_sample_id);
         $transaction_id = $transaction->begin();
         try {
             if (($sample_id = $this->sample->create($name, $user->get_user_id(), $source_sample->get_template_id(), $manufacturer_id, $desc, $language_id, $date_of_expiry, $expiry_warning)) == null) {
                 throw new SampleCloneCreateFailedException();
             }
             if ($desc) {
                 $this->sample->set_comment_text_search_vector($desc, "english");
             }
             $sub_folder_name_array = $this->create_sample_folder($sample_id, $source_sample->get_template_id());
             $this->create_sample_item($sample_id);
             $sample_security = new SampleSecurity($sample_id);
             $source_sample_user_list = $source_sample_security->list_users();
             if (is_array($source_sample_user_list) and count($source_sample_user_list) >= 1) {
                 foreach ($source_sample_user_list as $key => $value) {
                     if ($sample_security->create_user($value, true, true) == null) {
                         throw new SampleCloneUserException();
                     }
                 }
             }
             $source_sample_organisation_list = $source_sample_security->list_organisation_units();
             if (is_array($source_sample_organisation_list) and count($source_sample_organisation_list) >= 1) {
                 foreach ($source_sample_organisation_list as $key => $value) {
                     if ($sample_security->create_organisation_unit($value) == null) {
                         throw new SampleCloneOrganisationUnitException();
                     }
                 }
             }
             // Locations
             $source_sample_location_array = SampleHasLocation_Access::list_entries_by_sample_id($source_sample_id);
             $end_sample_has_location_access = new SampleHasLocation_Access(end($source_sample_location_array));
             if (is_array($source_sample_location_array) and count($source_sample_location_array) >= 1) {
                 if ($location_id != $end_sample_has_location_access->get_location_id()) {
                     $add_new_location = true;
                 } else {
                     $add_new_location = false;
                 }
                 foreach ($source_sample_location_array as $key => $value) {
                     $current_sample_has_location_access = new SampleHasLocation_Access($value);
                     $sample_has_location_access = new SampleHasLocation_Access(null);
                     if ($sample_has_location_access->create($sample_id, $current_sample_has_location_access->get_location_id(), $user->get_user_id()) == null) {
                         throw new SampleCloneLocationException();
                     }
                 }
             } else {
                 $add_new_location = true;
             }
             if (is_numeric($location_id) and $add_new_location == true and $location_id > 0) {
                 // Create First Location
                 $sample_has_location_access = new SampleHasLocation_Access(null);
                 if ($sample_has_location_access->create($sample_id, $location_id, $user->get_user_id()) == null) {
                     throw new SampleCloneCreateLocationException("Could not create location");
                 }
             }
             if (is_array($value_array) and count($item_array) >= 1) {
                 $value_item_array = array();
                 $value_data_array = array();
                 foreach ($value_array as $key => $value) {
                     $key = str_replace("value-", "", $key);
                     $key_array = explode("-", $key, 2);
                     if ($key_array[0] == "item") {
                         $value_item_array[$key_array[1]] = $value;
                     } elseif (is_numeric($key_array[0])) {
                         $value_data_array[$key_array[0]][$key_array[1]] = $value;
                     }
                 }
                 if (is_array($value_item_array) and count($value_item_array) >= 1) {
                     foreach ($value_item_array as $key => $value) {
                         $gid = SampleItem::get_gid_by_item_id_and_sample_id($value, $source_sample_id);
                         $data_entity_id = DataEntity::get_entry_by_item_id($value);
                         $value_id = Value::get_value_id_by_data_entity_id($data_entity_id);
                         if (is_numeric($value_id)) {
                             $value_obj = Value::get_instance($value_id);
                             $parent_folder_id = $value_obj->get_parent_folder_id();
                             $value_type_id = $value_obj->get_type_id();
                             if ($parent_folder_id == $source_sample_folder_id) {
                                 $new_folder_id = $this->sample_folder_id;
                             } else {
                                 $folder_name = Folder::get_name_by_id($parent_folder_id);
                                 $new_folder_id = array_search(trim(strtolower($folder_name)), $sub_folder_name_array);
                             }
                             if (is_numeric($new_folder_id) and is_numeric($value_type_id)) {
                                 $new_value_obj = Value::get_instance(null);
                                 $new_value_obj->create($new_folder_id, $user->get_user_id(), $value_type_id, $value_data_array[$key]);
                                 $new_value_item_id = $new_value_obj->get_item_id();
                                 $sample_item = new SampleItem($sample_id);
                                 $sample_item->set_gid($gid);
                                 if ($sample_item->set_item_id($new_value_item_id) == false) {
                                     throw new SampleCloneValueException();
                                 }
                                 if ($sample_item->link_item() == false) {
                                     throw new SampleCloneValueException();
                                 }
                             }
                         }
                     }
                 }
             }
             if (is_array($item_array) and count($item_array) >= 1) {
                 $item_type_array = array();
                 $item_data_array = array();
                 foreach ($item_array as $key => $value) {
                     if ($value[1] == "1") {
                         $item_explode_array = explode("-", $value[0], 2);
                         if (!in_array($item_explode_array[0], $item_type_array)) {
                             array_push($item_type_array, $item_explode_array[0]);
                         }
                         if (!is_array($item_data_array[$item_explode_array[0]])) {
                             $item_data_array[$item_explode_array[0]] = array();
                         }
                         array_push($item_data_array[$item_explode_array[0]], $item_explode_array[1]);
                     }
                 }
                 if (is_array($item_type_array) and count($item_type_array) >= 1) {
                     foreach ($item_type_array as $key => $value) {
                         if ($value == "parent") {
                             foreach ($item_data_array[$value] as $data_key => $data_value) {
                                 $parent_item_explode_array = explode("-", $data_value, 2);
                                 if ($parent_item_explode_array[0] and $parent_item_explode_array[1]) {
                                     $item_add_holder_event = new ItemAddHolderEvent($parent_item_explode_array[1], $parent_item_explode_array[0], $this->item_id);
                                     $event_handler = new EventHandler($item_add_holder_event);
                                     if ($event_handler->get_success() == false) {
                                         throw new SampleCloneParentException();
                                     }
                                 }
                             }
                         } elseif ($value == "file") {
                             if (is_array($item_data_array[$value]) and count($item_data_array[$value]) >= 1) {
                                 foreach ($item_data_array[$value] as $data_key => $data_value) {
                                     $gid = SampleItem::get_gid_by_item_id_and_sample_id($data_value, $source_sample_id);
                                     $data_entity_id = DataEntity::get_entry_by_item_id($data_value);
                                     $file_id = File::get_file_id_by_data_entity_id($data_entity_id);
                                     if ($file_id) {
                                         $file_obj = File::get_instance($file_id);
                                         $parent_folder_id = $file_obj->get_parent_folder_id();
                                         if ($parent_folder_id == $source_sample_folder_id) {
                                             $new_folder_id = $this->sample_folder_id;
                                         } else {
                                             $folder_name = Folder::get_name_by_id($parent_folder_id);
                                             $new_folder_id = array_search(trim(strtolower($folder_name)), $sub_folder_name_array);
                                         }
                                         if (is_numeric($new_folder_id)) {
                                             if ($file_obj->copy($new_folder_id) == false) {
                                                 throw new SampleCloneFileException();
                                             }
                                             $new_file_item_id = $file_obj->get_item_id();
                                             $sample_item = new SampleItem($sample_id);
                                             $sample_item->set_gid($gid);
                                             if ($sample_item->set_item_id($new_file_item_id) == false) {
                                                 throw new SampleCloneFileException();
                                             }
                                             if ($sample_item->link_item() == false) {
                                                 throw new SampleCloneFileException();
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             if (is_array($item_data_array[$value]) and count($item_data_array[$value]) >= 1) {
                                 $handling_class = Item::get_handling_class_by_type($value);
                                 if ($handling_class) {
                                     foreach ($item_data_array[$value] as $data_key => $data_value) {
                                         $gid = SampleItem::get_gid_by_item_id_and_sample_id($data_value, $source_sample_id);
                                         $new_item_id = $handling_class::clone_item($data_value);
                                         if ($new_item_id) {
                                             $sample_item = new SampleItem($sample_id);
                                             $sample_item->set_gid($gid);
                                             if ($sample_item->set_item_id($new_item_id) == false) {
                                                 throw new SampleCloneItemException();
                                             }
                                             if ($sample_item->link_item() == false) {
                                                 throw new SampleCloneItemException();
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } catch (BaseException $e) {
             if (is_object($this->sample_folder_object)) {
                 $this->sample_folder_object->delete(true, true);
             }
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             throw $e;
         }
         if ($transaction_id != null) {
             $transaction->commit($transaction_id);
         }
         self::__construct($sample_id);
         return $sample_id;
     } else {
         throw new SampleCloneIDMissingException();
     }
 }
Example #3
0
 /**
  * @see FolderInterface::is_folder_image_content()
  * @return bool
  */
 public function is_folder_image_content()
 {
     if ($this->folder and $this->folder_id) {
         $data_entity_array = $this->get_children();
         if (is_array($data_entity_array) and count($data_entity_array) >= 1) {
             foreach ($data_entity_array as $key => $value) {
                 if (($file_id = File::get_file_id_by_data_entity_id($value)) != null) {
                     $file = File::get_instance($file_id);
                     if ($file->is_image() == true) {
                         return true;
                     }
                 }
             }
         }
         return false;
     } else {
         return false;
     }
 }
Example #4
0
 /**
  * Inits a caching procedure
  * @return bool
  */
 private function init()
 {
     global $transaction;
     if ($this->data_entity_id) {
         $transaction_id = $transaction->begin();
         $file_id = File::get_file_id_by_data_entity_id($this->data_entity_id);
         $file = File::get_instance($file_id);
         $folder = Folder::get_instance($file->get_parent_folder());
         $folder_path = $folder->get_path();
         $extension_array = explode(".", $file->get_name());
         $extension_array_length = substr_count($file->get_name(), ".");
         $file_path = constant("BASE_DIR") . "/" . $folder_path . "/" . $this->data_entity_id . "-1." . $extension_array[$extension_array_length];
         $this->xml_string = $file->get_file_content();
         if (strlen($this->xml_string) > 0) {
             $xml = new Xml($this->xml_string);
             $xml->parser();
             $this->xml_array = $xml->get_array();
             if (is_array($this->xml_array) and count($this->xml_array) >= 1) {
                 $this->xml_cache = new XmlCache_Access(null);
                 $id = $this->xml_cache->create($this->data_entity_id, $file_path, md5_file($file_path));
                 foreach ($this->xml_array as $key => $value) {
                     $xml_cache_element = new XmlCacheElement_Access(null);
                     $xml_cache_element->create($id, $value[0], $value[1], $value[2], $value[3]);
                 }
                 self::__construct($this->data_entity_id);
                 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;
         }
     }
 }
Example #5
0
 /**
  * @see EventListenerInterface::listen_events()
  * @param object $event_object
  * @return bool
  */
 public static function listen_events($event_object)
 {
     if ($event_object instanceof ItemUnlinkEvent) {
         if (($data_entity_id = DataEntityIsItem_Access::get_entry_by_item_id($event_object->get_item_id())) != null) {
             if (($file_id = File::get_file_id_by_data_entity_id($data_entity_id)) != null) {
                 $file = File::get_instance($file_id);
                 if ($file->delete() == false) {
                     return false;
                 }
             }
             if (($value_id = Value::get_value_id_by_data_entity_id($data_entity_id)) != null) {
                 $value = Value::get_instance($value_id);
                 if ($value->delete() == false) {
                     return false;
                 }
             }
             if (($parameter_id = Parameter::get_parameter_id_by_data_entity_id($data_entity_id)) != null) {
                 $parameter = Parameter::get_instance($parameter_id);
                 if ($parameter->delete() == false) {
                     return false;
                 }
             }
         }
     }
     if ($event_object instanceof UserDeleteEvent) {
         if (DataEntity_Access::set_owner_id_on_null($event_object->get_user_id()) == false) {
             return true;
         }
     }
     if ($event_object instanceof GroupDeleteEvent) {
         if (DataEntity_Access::set_owner_group_id_on_null($event_object->get_group_id()) == false) {
             return true;
         }
     }
     return true;
 }