public function create($project_id, $name, $description, $itemname, $tv3_id) { $id_sharing = new TrackerIdSharingDao(); if ($tv5_id = $id_sharing->generateTrackerId()) { $tv3_id = $this->da->escapeInt($tv3_id); $tracker_id = $this->createTracker($tv5_id, $project_id, $name, $description, $itemname, $tv3_id); $this->duplicateTrackerPerms($tv3_id, $tracker_id); return $tracker_id; } return false; }
public function create($tracker_id, $submitted_by, $submitted_on, $use_artifact_permissions) { $tracker_id = $this->da->escapeInt($tracker_id); $use_artifact_permissions = $this->da->escapeInt($use_artifact_permissions); $submitted_on = $this->da->escapeInt($submitted_on); $submitted_by = $this->da->escapeInt($submitted_by); $this->startTransaction(); $sql = "SELECT IFNULL(MAX(per_tracker_artifact_id), 0) + 1 as per_tracker_artifact_id\n FROM tracker_artifact\n WHERE tracker_id = {$tracker_id}"; $row = $this->retrieveFirstRow($sql); $per_tracker_id = $row['per_tracker_artifact_id']; $id_sharing = new TrackerIdSharingDao(); if ($id = $id_sharing->generateArtifactId()) { if ($this->getPriorityManager()->putArtifactAtTheEnd($id)) { // We do not keep trace of the history change here because it doesn't have any sense to say // the newly created artifact has less priority than the one at the bottom of the priority chain. $sql = "INSERT INTO {$this->table_name}\n (id, tracker_id, per_tracker_artifact_id, submitted_by, submitted_on, use_artifact_permissions)\n VALUES ({$id}, {$tracker_id}, {$per_tracker_id}, {$submitted_by}, {$submitted_on}, {$use_artifact_permissions})"; if ($this->update($sql)) { $this->commit(); return $id; } } } $this->rollBack(); return false; }
/** * Create a new artifact (and its values) in the db * * @param array $vfl the value-field-list. Array association pair of field_name => field_value. * If the function is called by the web-site submission form, the $vfl is set to false, and will be filled by the function extractFieldList function retrieving the HTTP parameters. * If $vfl is not false, the fields expected in this array are *all* the fields of this tracker that are allowed to be submited by the user. * @return boolean */ function create($vfl = false, $import = false, $row = 0) { global $ath, $art_field_fact, $Language; $group = $ath->getGroup(); $group_artifact_id = $ath->getID(); $error_message = $import ? $Language->getText('tracker_common_artifact', 'row', $row) : ""; // Retrieve HTTP GET variables and store them in $vfl array if (!$vfl) { $vfl = $art_field_fact->extractFieldList(); } // We check the submitted fields to see if the user has the permissions to submit it if (!$import) { while (list($key, $val) = each($vfl)) { $field = $art_field_fact->getFieldFromName($key); if ($field && !$field->getName() == 'comment_type_id') { // SR #684 we don't check the perms for the field comment type if (!$field->userCanSubmit($group->getID(), $group_artifact_id, user_getid())) { // The user does not have the permissions to update the current field, // we exit the function with an error message $this->setError($Language->getText('tracker_common_artifact', 'bad_field_permission_submission', $field->getLabel())); return false; } // we check if the given value is authorized for this field (for select box fields only) // we don't check here the none value, we check after it with the function checkEmptyFields, to get a better error message if the field required (instead of value 100 is not a valid valid value for the field) if ($field->isSelectBox() && $val != 100 && !$field->checkValueInPredefinedValues($this->ArtifactType->getID(), $val)) { $this->setError($Language->getText('tracker_common_artifact', 'bad_field_value', array($field->getLabel(), $val))); return false; } if ($field->isMultiSelectBox()) { foreach ($val as $a_value) { if ($a_value != 100 && !$field->checkValueInPredefinedValues($this->ArtifactType->getID(), $a_value)) { $this->setError($Language->getText('tracker_common_artifact', 'bad_field_value', array($field->getLabel(), $val))); return false; } } } } } //When user is not autorised to submit some fields //we should block those artifact with mandatory fields and default value set to "None" $fieldsNotShown = $art_field_fact->getAllFieldsNotShownOnAdd(); if ($art_field_fact->checkEmptyFields($fieldsNotShown, false) == false) { $this->setError($Language->getText('tracker_common_artifact', 'mandatory_not_set')); return false; } } if (!$import) { // make sure required fields are not empty if ($art_field_fact->checkEmptyFields($vfl) == false) { $this->setError($art_field_fact->getErrorMessage()); exit_missing_param(); } } // we don't force them to be logged in to submit a bug if (!user_isloggedin()) { $user = 100; } else { $user = user_getid(); } // add default values for fields that have not been shown $add_fields = $art_field_fact->getAllFieldsNotShownOnAdd(); while (list($key, $def_val) = each($add_fields)) { if (!array_key_exists($key, $vfl)) { $vfl[$key] = $def_val; } } if ($import && $vfl['submitted_by'] && $vfl['submitted_by'] != "") { $user = $vfl['submitted_by']; } // first make sure this wasn't double-submitted $field = $art_field_fact->getFieldFromName('summary'); if ($field && $field->isUsed()) { $res = db_query("SELECT * \n FROM artifact \n WHERE group_artifact_id = " . db_ei($ath->getID()) . " \n AND submitted_by=" . db_ei($user) . " \n AND summary='" . db_es(htmlspecialchars($vfl['summary'])) . "'"); if ($res && db_numrows($res) > 0) { $this->setError($Language->getText('tracker_common_artifact', 'double_subm', db_result($res, 0, 'artifact_id'))); return false; } } // // Create the insert statement for standard field // //Reference manager for cross reference $reference_manager =& ReferenceManager::instance(); reset($vfl); $vfl_cols = ''; $vfl_values = ''; $text_value_list = array(); while (list($field_name, $value) = each($vfl)) { //echo "<br>field_name=$field_name, value=$value"; $field = $art_field_fact->getFieldFromName($field_name); if ($field && $field->isStandardField()) { // skip over special fields if ($field->isSpecial()) { continue; } $vfl_cols .= ',' . $field->getName(); $is_text = $field->isTextField() || $field->isTextArea(); if ($is_text) { $value = htmlspecialchars($value); //Log for Cross references $text_value_list[] = $value; } else { if ($field->isDateField()) { // if it's a date we must convert the format to unix time list($value, $ok) = util_date_to_unixtime($value); } } $vfl_values .= ',\'' . db_es($value) . '\''; } } // while // Add all special fields that were not handled in the previous block $fixed_cols = 'open_date,last_update_date,group_artifact_id,submitted_by'; if ($import) { if (!isset($vfl['open_date']) || !$vfl['open_date'] || $vfl['open_date'] == "") { $open_date = time(); } else { list($open_date, $ok) = util_date_to_unixtime($vfl['open_date']); } $fixed_values = "'" . db_ei($open_date) . "','" . time() . "','" . db_ei($group_artifact_id) . "','" . db_ei($user) . "'"; } else { $fixed_values = "'" . time() . "','" . time() . "','" . db_ei($group_artifact_id) . "','" . db_ei($user) . "'"; } // // Finally, build the full SQL query and insert the artifact itself // $id_sharing = new TrackerIdSharingDao(); if ($artifact_id = $id_sharing->generateArtifactId()) { $sql = "INSERT INTO artifact (artifact_id, {$fixed_cols} {$vfl_cols}) VALUES ({$artifact_id}, {$fixed_values} {$vfl_values})"; //echo "<br>DBG - SQL insert artifact: $sql"; $result = db_query($sql); $was_error = false; if (!$result || db_affected_rows($result) == 0) { $this->setError($Language->getText('tracker_common_artifact', 'insert_err', $sql)); $was_error = true; } else { // // Insert the field values for no standard field // $fields = $art_field_fact->getAllUsedFields(); while (list($field_name, $field) = each($fields)) { // skip over special fields if ($field->isSpecial() || $field->isStandardField()) { continue; } if (array_key_exists($field_name, $vfl) && isset($vfl[$field_name]) && $vfl[$field_name]) { // The field has a value from the user input $value = $vfl[$field_name]; $is_text = $field->isTextField() || $field->isTextArea(); if ($is_text) { $value = htmlspecialchars($value); //Log for Cross references $text_value_list[] = $value; } else { if ($field->isDateField()) { // if it's a date we must convert the format to unix time list($value, $ok) = util_date_to_unixtime($value); } } // Insert the field value if (!$field->insertValue($artifact_id, $value)) { $error_message .= $Language->getText('tracker_common_artifact', 'field_err', array($field->getLabel(), $value)); $was_error = true; $this->setError($error_message); } } else { // The field hasn't a value from the user input // We need to insert default value for this field // because all SQL queries (from Report or Artifact read/update) don't allow // empty record (we must use join and not left join for performance reasons). if (!$field->insertValue($artifact_id, $field->getDefaultValue())) { $error_message .= $Language->getText('tracker_common_artifact', 'def_err', array($field->getLabel(), $field->getDefaultValue())); $was_error = true; $this->setError($error_message); } } } // while } //Add Cross Reference for ($i = 0; $i < sizeof($text_value_list); $i++) { $reference_manager->extractCrossRef($text_value_list[$i], $artifact_id, ReferenceManager::REFERENCE_NATURE_ARTIFACT, $ath->getGroupID()); } // artifact permissions $request = HTTPRequest::instance(); $this->data_array['artifact_id'] = $artifact_id; // cheat $this->setPermissions($request->get('use_artifact_permissions_name'), $request->get('ugroups')); // All ok then reload the artifact data to make sure it is cached // correctly in memory $this->fetchData($artifact_id); } else { $this->setError($Language->getText('tracker_common_artifact', 'insert_err', $sql)); $was_error = true; } return !$was_error; }
public function create($tracker_id, $submitted_by, $use_artifact_permissions) { $tracker_id = $this->da->escapeInt($tracker_id); $use_artifact_permissions = $this->da->escapeInt($use_artifact_permissions); $submitted_on = $this->da->escapeInt($_SERVER['REQUEST_TIME']); $submitted_by = $this->da->escapeInt($submitted_by); $id_sharing = new TrackerIdSharingDao(); if ($id = $id_sharing->generateArtifactId()) { $priority_dao = new Tracker_Artifact_PriorityDao(); if ($priority_dao->putArtifactAtTheEnd($id)) { $sql = "INSERT INTO {$this->table_name}\n (id, tracker_id, submitted_by, submitted_on, use_artifact_permissions)\n VALUES ({$id}, {$tracker_id}, {$submitted_by}, {$submitted_on}, {$use_artifact_permissions})"; if ($this->update($sql)) { return $id; } } } return false; }
function create($group_id, $name, $description, $item_name, $allow_copy, $submit_instructions, $browse_instructions, $status, $deletion_date, $instantiate_for_new_projects, $stop_notification) { $group_id = $this->da->escapeInt($group_id); $name = $this->da->quoteSmart($name); $description = $this->da->quoteSmart($description); $item_name = $this->da->quoteSmart($item_name); $allow_copy = $this->da->escapeInt($allow_copy); $submit_instructions = $this->da->quoteSmart($submit_instructions); $browse_instructions = $this->da->quoteSmart($browse_instructions); $status = $this->da->quoteSmart($status); $deletion_date = $deletion_date ? $this->da->escapeInt($deletion_date) : 'NULL'; $instantiate_for_new_projects = $this->da->quoteSmart($instantiate_for_new_projects); $stop_notification = $this->da->escapeInt($stop_notification); $id_sharing = new TrackerIdSharingDao(); if ($id = $id_sharing->generateTrackerId()) { $sql = "INSERT INTO {$this->table_name} \n (id,\n group_id, \n name, \n description, \n item_name, \n allow_copy, \n submit_instructions, \n browse_instructions, \n status, \n deletion_date, \n instantiate_for_new_projects, \n stop_notification)\n VALUES ({$id},\n {$group_id}, \n {$name}, \n {$description}, \n {$item_name}, \n {$allow_copy}, \n {$submit_instructions}, \n {$browse_instructions}, \n {$status}, \n {$deletion_date}, \n {$instantiate_for_new_projects}, \n {$stop_notification})"; if ($this->update($sql)) { return $id; } } return false; }
/** * create - use this to create a new ArtifactType in the database. * * @param group_id: the group id of the new tracker * @param group_id_template: the template group id (used for the copy) * @param atid_template: the template artfact type id * @param name: the name of the new tracker * @param description: the description of the new tracker * @param itemname: the itemname of the new tracker * @return id on success, false on failure. */ function create($group_id, $group_id_template, $atid_template, $name, $description, $itemname, $ugroup_mapping = false, &$report_mapping = array()) { global $Language; if (!$name || !$description || !$itemname || trim($name) == "" || trim($description) == "" || trim($itemname) == "") { $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'name_requ')); return false; } // Necessary test to avoid issues when exporting the tracker to a DB (e.g. '-' not supported as table name) if (!eregi("^[a-zA-Z0-9_]+\$", $itemname)) { $this->setError($Language->getText('tracker_common_type', 'invalid_shortname', $itemname)); return false; } $reference_manager = ReferenceManager::instance(); if ($reference_manager->_isKeywordExists($itemname, $group_id)) { $this->setError($Language->getText('tracker_common_type', 'shortname_already_exists', $itemname)); return false; } if ($this->isNameExists($name, $group_id)) { $this->setError($Language->getText('tracker_common_type', 'name_already_exists', $name)); return false; } // get the template Group object $pm = ProjectManager::instance(); $template_group = $pm->getProject($group_id_template); if (!$template_group || !is_object($template_group) || $template_group->isError()) { $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'invalid_templ')); } // get the Group object of the new tracker $pm = ProjectManager::instance(); $group = $pm->getProject($group_id); if (!$group || !is_object($group) || $group->isError()) { $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'invalid_templ')); } // We retrieve allow_copy from template $at_template = new ArtifactType($template_group, $atid_template); $id_sharing = new TrackerIdSharingDao(); if ($id = $id_sharing->generateTrackerId()) { // First, we create a new ArtifactType into artifact_group_list // By default, set 'instantiate_for_new_projects' to '1', so that a project that is not yet a // template will be able to have its trackers cloned by default when it becomes a template. $sql = "INSERT INTO \n artifact_group_list \n (group_artifact_id, group_id, name, description, item_name, allow_copy,\n submit_instructions,browse_instructions,instantiate_for_new_projects,stop_notification\n ) \n VALUES \n ({$id},\n '" . db_ei($group_id) . "',\n '" . db_es($name) . "',\n '" . db_es($description) . "',\n '" . db_es($itemname) . "',\n '" . db_ei($at_template->allowsCopy()) . "',\n '" . db_es($at_template->getSubmitInstructions()) . "',\n '" . db_es($at_template->getBrowseInstructions()) . "',1,0)"; //echo $sql; $res = db_query($sql); if (!$res || db_affected_rows($res) <= 0) { $this->setError('ArtifactTypeFactory: ' . db_error()); return false; } else { //No need to get the last insert id since we already know the id : $id //$id = db_insertid($res,'artifact_group_list','group_artifact_id'); $at_new = new ArtifactType($group, $id); if (!$at_new->fetchData($id)) { $this->setError('ArtifactTypeFactory: ' . $Language->getText('tracker_common_type', 'load_fail')); return false; } else { //create global notifications $sql = "INSERT INTO artifact_global_notification (tracker_id, addresses, all_updates, check_permissions)\n SELECT " . db_ei($id) . ", addresses, all_updates, check_permissions\n FROM artifact_global_notification\n WHERE tracker_id = " . db_ei($atid_template); $res = db_query($sql); if (!$res || db_affected_rows($res) <= 0) { $this->setError('ArtifactTypeFactory: ' . db_error()); } // Create fieldset factory $art_fieldset_fact = new ArtifactFieldSetFactory($at_template); // Then copy all the field sets. $mapping_field_set_array = $art_fieldset_fact->copyFieldSets($atid_template, $id); if (!$mapping_field_set_array) { $this->setError('ArtifactTypeFactory: ' . $art_fieldset_fact->getErrorMessage()); return false; } // Create field factory $art_field_fact = new ArtifactFieldFactory($at_template); // Then copy all the fields informations if (!$art_field_fact->copyFields($id, $mapping_field_set_array, $ugroup_mapping)) { $this->setError('ArtifactTypeFactory: ' . $art_field_fact->getErrorMessage()); return false; } // Then copy all the reports informations // Create field factory $art_report_fact = new ArtifactReportFactory(); if (!($report_mapping = $art_report_fact->copyReports($atid_template, $id))) { $this->setError('ArtifactTypeFactory: ' . $art_report_fact->getErrorMessage()); return false; } $em =& EventManager::instance(); $pref_params = array('atid_source' => $atid_template, 'atid_dest' => $id); $em->processEvent('artifactType_created', $pref_params); // Copy artifact_notification_event and artifact_notification_role if (!$at_new->copyNotificationEvent($id)) { return false; } if (!$at_new->copyNotificationRole($id)) { return false; } // Create user permissions: None for group members and Admin for group admin if (!$at_new->createUserPerms($id)) { return false; } // Create canned responses $canned_new = new ArtifactCanned($at_new); $canned_template = $at_template->getCannedResponses(); if ($canned_template && db_numrows($canned_template) > 0) { while ($row = db_fetch_array($canned_template)) { $canned_new->create($row['title'], $row['body']); } } //Copy template permission permission_copy_tracker_and_field_permissions($atid_template, $id, $group_id_template, $group_id, $ugroup_mapping); //Copy Rules require_once 'ArtifactRulesManager.class.php'; $arm = new ArtifactRulesManager(); $arm->copyRules($atid_template, $id); } } } return $id; }
function copyArtifact($from_atid, $from_aid) { $aid = 0; $res = true; // copy common artifact fields $id_sharing = new TrackerIdSharingDao(); if ($aid = $id_sharing->generateArtifactId()) { $result = db_query("INSERT INTO artifact (artifact_id, group_artifact_id,status_id,submitted_by,open_date,close_date,summary,details,severity) " . "SELECT {$aid}, " . db_ei($this->getID()) . ",status_id,submitted_by," . time() . ",close_date,summary,details,severity " . "FROM artifact " . "WHERE artifact_id='" . db_ei($from_aid) . "' " . "AND group_artifact_id='" . db_ei($from_atid) . "'"); if (!$result || db_affected_rows($result) == 0) { $this->setError(db_error()); return false; } // copy specific artifact fields $result = db_query("INSERT INTO artifact_field_value (field_id,artifact_id,valueInt,valueText,valueFloat,valueDate) " . "SELECT field_id," . db_ei($aid) . ",valueInt,valueText,valueFloat,valueDate " . "FROM artifact_field_value " . "WHERE artifact_id = '" . db_ei($from_aid) . "'"); if (!$result || db_affected_rows($result) <= 0) { $this->setError(db_error()); $res = false; } //copy cc addresses $result = db_query("INSERT INTO artifact_cc (artifact_id,email,added_by,comment,date) " . "SELECT " . db_ei($aid) . ",email,added_by,comment,date " . "FROM artifact_cc " . "WHERE artifact_id='" . db_ei($from_aid) . "'"); if (!$result || db_affected_rows($result) <= 0) { $this->setError(db_error()); $res = false; } //copy artifact files db_query("INSERT INTO artifact_file (artifact_id,description,bin_data,filename,filesize,filetype,adddate,submitted_by) " . "SELECT " . $aid . ",description,bin_data,filename,filesize,filetype,adddate,submitted_by " . "FROM artifact_file " . "WHERE artifact_id='" . db_ei($from_aid) . "'"); if (!$result || db_affected_rows($result) <= 0) { $this->setError(db_error()); $res = false; } return $res; } return false; }