/** * query if editable for current user */ static function getEditableById($id) { if ($pp = ProjectPerson::getById($id)) { if ($p = Project::getById($pp->project)) { if ($p->validateEditItem($pp)) { return $pp; } } } return NULL; }
/** * Submit changes to a person @ingroup pages */ function personEditSubmit() { global $PH; global $auth; global $g_user_profile_names; global $g_user_profiles; ### cancel ? ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('home', array()); } exit; } ### Validate form integrity if (!validateFormCrc()) { $PH->abortWarning(__('Invalid checksum for hidden form elements')); } ### get person #### $id = getOnePassedId('person'); ### temporary obj, not in db if ($id == 0) { $person = new Person(array('id' => 0)); } else { if (!($person = Person::getEditableById($id))) { $PH->abortWarning(__("Could not get person")); return; } } ### person category ### $pcategory = get('pcategory'); if ($pcategory != NULL) { if ($pcategory == -1) { $person->category = PCATEGORY_STAFF; } else { if ($pcategory == -2) { $person->category = PCATEGORY_CONTACT; } else { $person->category = $pcategory; } } } ### validate rights ### if ($auth->cur_user->id == $person->id && $auth->cur_user->user_rights & RIGHT_PERSON_EDIT_SELF || $auth->cur_user->user_rights & RIGHT_PERSON_EDIT || $auth->cur_user->user_rights & RIGHT_PERSON_CREATE && $person->id == 0) { $pass = true; } else { $PH->abortWarning(__("not allowed to edit"), ERROR_RIGHTS); } $flag_ok = true; # update valid? # retrieve all possible values from post-data # NOTE: # - this could be an security-issue. # - TODO: as some kind of form-edit-behaviour to field-definition foreach ($person->fields as $f) { $name = $f->name; $f->parseForm($person); } ### rights & theme & profile ### if ($auth->cur_user->user_rights & RIGHT_PERSON_EDIT_RIGHTS) { /** * if profile != -1, it will OVERWRITE (or reinit) user_rights * * therefore persEdit set profil to 0 if rights don't fit profile. It will * then be skipped here */ $profile_num = get('person_profile'); if (!is_null($profile_num)) { if ($profile_num != -1) { $person->profile = $profile_num; if (isset($g_user_profiles[$profile_num]['default_user_rights'])) { $rights = $g_user_profiles[$profile_num]['default_user_rights']; /** * add warning on changed profile */ if ($person->user_rights != $rights && $person->id) { new FeedbackHint(__('The changed profile <b>does not affect existing project roles</b>! Those has to be adjusted inside the projects.')); } $person->user_rights = $rights; } else { trigger_error("Undefined profile requested ({$profile_num})", E_USER_ERROR); } } } } ### can login ### if ($auth->cur_user->user_rights & RIGHT_PERSON_EDIT_RIGHTS || $auth->cur_user->user_rights & RIGHT_PERSON_CREATE && $auth->cur_user->user_rights & RIGHT_PROJECT_ASSIGN && $person->id == 0) { /** * NOTE, if checkbox is not rendered in editForm, user-account will be disabled! * there seems no way the be sure the checkbox has been rendered, if it is not checked in form */ if ($can_login = get('person_can_login')) { $person->can_login = 1; } else { $person->can_login = 0; } } $period = get('person_notification_period'); ### turn off ### if ($period === 0 || $period === "0") { $person->settings &= USER_SETTING_NOTIFICATIONS ^ RIGHT_ALL; $person->notification_period = 0; } else { $person->settings |= USER_SETTING_NOTIFICATIONS; $person->notification_period = $period; if ($person->can_login && !$person->personal_email && !$person->office_email) { $flag_ok = false; $person->fields['office_email']->required = true; $person->fields['personal_email']->required = true; new FeedbackWarning(__("Sending notifactions requires an email-address.")); } } if (get('person_html_mail')) { $person->settings |= USER_SETTING_HTML_MAIL; } else { $person->settings &= USER_SETTING_HTML_MAIL ^ RIGHT_ALL; } ### effort style ### if ($effort_style = get('person_effort_style')) { if ($effort_style == EFFORT_STYLE_TIMES) { $person->settings &= USER_SETTING_EFFORTS_AS_DURATION ^ RIGHT_ALL; } else { if ($effort_style == EFFORT_STYLE_DURATION) { $person->settings |= USER_SETTING_EFFORTS_AS_DURATION; } else { trigger_error("undefined person effort style", E_USER_WARNING); } } } ### filter own changes ### if (get('person_filter_own_changes')) { $person->settings |= USER_SETTING_FILTER_OWN_CHANGES; } else { $person->settings &= USER_SETTING_FILTER_OWN_CHANGES ^ RIGHT_ALL; } ### enable bookmarks ### if (get('person_enable_bookmarks')) { $person->settings |= USER_SETTING_ENABLE_BOOKMARKS; } else { $person->settings &= USER_SETTING_ENABLE_BOOKMARKS ^ RIGHT_ALL; } if (get('person_enable_efforts')) { $person->settings |= USER_SETTING_ENABLE_EFFORTS; } else { $person->settings &= USER_SETTING_ENABLE_EFFORTS ^ RIGHT_ALL; } $zone = get('person_time_zone'); if ($zone != NULL && $person->time_zone != 1.0 * $zone) { $person->time_zone = 1.0 * $zone; if ($zone == TIME_OFFSET_AUTO) { new FeedbackMessage(__("Using auto detection of time zone requires this user to relogin.")); } else { $person->time_offset = $zone * 60.0 * 60.0; if ($person->id == $auth->cur_user->id) { $auth->cur_user->time_offset = $zone * 60.0 * 60.0; } } } $theme = get('person_theme'); if ($theme != NULL) { $person->theme = $theme; ### update immediately / without page-reload #### if ($person->id == $auth->cur_user->id) { $auth->cur_user->theme = $theme; } } $language = get('person_language'); global $g_languages; if (isset($g_languages[$language])) { $person->language = $language; ### update immediately / without page-reload #### if ($person->id == $auth->cur_user->id) { $auth->cur_user->language = $language; setLang($language); } } $t_nickname = get('person_nickname'); ### check if changed nickname is unique if ($person->can_login || $person->nickname != "") { /** * actually this should be mb_strtolower, but this is not installed by default */ if ($person->nickname != strtolower($person->nickname)) { new FeedbackMessage(__("Nickname has been converted to lowercase")); $person->nickname = strtolower($person->nickname); } ### authentication ### $p_auth = get('person_auth'); if ($p_auth) { $person->ldap = 1; } else { $person->ldap = 0; } if ($p2 = Person::getByNickname($t_nickname)) { # another person with this nick? if ($p2->id != $person->id) { new FeedbackWarning(__("Nickname has to be unique")); $person->fields['nickname']->required = true; $flag_ok = false; } } } ### password entered? ### $t_password1 = get('person_password1'); $t_password2 = get('person_password2'); $flag_password_ok = true; if (($t_password1 || $t_password2) && $t_password1 != "__dont_change__") { ### check if password match ### if ($t_password1 !== $t_password2) { new FeedbackWarning(__("Passwords do not match")); $person->fields['password']->required = true; $flag_ok = false; $flag_password_ok = false; } ### check if password is good enough ### if ($person->can_login) { $password_length = strlen($t_password1); $password_count_numbers = strlen(preg_replace('/[\\d]/', '', $t_password1)); $password_count_special = strlen(preg_replace('/[\\w]/', '', $t_password1)); $password_value = -7 + $password_length + $password_count_numbers * 2 + $password_count_special * 8; if ($password_value < confGet('CHECK_PASSWORD_LEVEL')) { new FeedbackWarning(__("Password is too weak (please add numbers, special chars or length)")); $flag_ok = false; $flag_password_ok = false; } } if ($flag_password_ok) { $person->password = md5($t_password1); } } if ($flag_ok && $person->can_login) { if (!$person->nickname) { new FeedbackWarning(__("Login-accounts require a unique nickname")); $person->fields['nickname']->required = true; $person->fields['nickname']->invalid = true; $flag_ok = false; } } ### repeat form if invalid data ### if (!$flag_ok) { $PH->show('personEdit', NULL, $person); exit; } /** * store indentifier-string for login from notification & reminder - mails */ $person->identifier = $person->calcIdentifierString(); ### insert new object ### if ($person->id == 0) { if ($person->settings & USER_SETTING_NOTIFICATIONS && $person->can_login) { $person->settings |= USER_SETTING_SEND_ACTIVATION; new FeedbackHint(sprintf(__("A notification / activation will be mailed to <b>%s</b> when you log out."), $person->name) . " " . sprintf(__("Read more about %s."), $PH->getWikiLink('notifications'))); } $person->notification_last = getGMTString(time() - $person->notification_period * 60 * 60 * 24 - 1); $person->cookie_string = $person->calcCookieString(); if ($person->insert()) { ### link to a company ### if ($c_id = get('company')) { require_once confGet('DIR_STREBER') . 'db/class_company.inc.php'; if ($c = Company::getVisibleById($c_id)) { require_once confGet('DIR_STREBER') . 'db/class_employment.inc.php'; $e = new Employment(array('id' => 0, 'person' => $person->id, 'company' => $c->id)); $e->insert(); } } ## assigne to project ## require_once confGet('DIR_STREBER') . 'db/class_projectperson.inc.php'; $prj_num = get('assigned_prj'); if (isset($prj_num)) { if ($prj_num != -1) { if ($p = Project::getVisibleById($prj_num)) { $prj_person = new ProjectPerson(array('person' => $person->id, 'project' => $p->id, 'name' => $g_user_profile_names[$person->profile])); $prj_person->insert(); } } } new FeedbackMessage(sprintf(__('Person %s created'), $person->getLink())); } else { new FeedbackError(__("Could not insert object")); } } else { new FeedbackMessage(sprintf(__('Updated settings for %s.'), $person->getLink())); $person->update(); } if ($auth->cur_user->id == $person->id) { $auth->cur_user = $person; } ### notify on change ### $person->nowChangedByUser(); ### store cookie, if accountActivation ### if (get('tuid')) { $auth->removeUserCookie(); $auth->storeUserCookie(); } ### create another person ### if (get('create_another')) { if ($c_id = get('company')) { $PH->show('personNew', array('company' => $c_id)); } else { $PH->show('personNew'); } } else { ### display fromPage #### if (!$PH->showFromPage()) { $PH->show('home', array()); } } }
/** * Submit data of a newly registered person @ingroup pages */ function personRegisterSubmit() { global $PH; global $auth; ### cancel ? ### if (get('form_do_cancel')) { if (!$PH->showFromPage()) { $PH->show('home', array()); } exit; } if (!validateFormCrc()) { $PH->abortWarning(__('Invalid checksum for hidden form elements')); } $person = new Person(array('id' => 0)); $person->user_rights = RIGHT_PERSON_EDIT_SELF; ### person category ### $pcategory = get('pcategory'); if ($pcategory != NULL) { if ($pcategory == -1) { $person->category = PCATEGORY_STAFF; } else { if ($pcategory == -2) { $person->category = PCATEGORY_CONTACT; } else { $person->category = $pcategory; } } } $flag_ok = true; # update valid? # retrieve all possible values from post-data # NOTE: # - this could be an security-issue. # - TODO: as some kind of form-edit-behaviour to field-definition foreach ($person->fields as $f) { $name = $f->name; $f->parseForm($person); } $person->can_login = 1; $period = get('person_notification_period'); ### turn off ### if ($period === 0 || $period === "0") { $person->settings &= USER_SETTING_NOTIFICATIONS ^ RIGHT_ALL; $person->notification_period = 0; } else { $person->settings |= USER_SETTING_NOTIFICATIONS; $person->notification_period = $period; if ($person->can_login && !$person->personal_email && !$person->office_email) { $flag_ok = false; $person->fields['office_email']->required = true; $person->fields['personal_email']->required = true; new FeedbackWarning(__("Sending notifactions requires an email-address.")); } } if (get('person_html_mail')) { $person->settings |= USER_SETTING_HTML_MAIL; } else { $person->settings &= USER_SETTING_HTML_MAIL ^ RIGHT_ALL; } $zone = get('person_time_zone'); if ($zone != NULL && $person->time_zone != 1.0 * $zone) { $person->time_zone = 1.0 * $zone; if ($zone == TIME_OFFSET_AUTO) { new FeedbackMessage(__("Using auto detection of time zone requires this user to relogin.")); } else { $person->time_offset = $zone * 60.0 * 60.0; if ($person->id == $auth->cur_user->id) { $auth->cur_user->time_offset = $zone * 60.0 * 60.0; } } } $theme = get('person_theme'); if ($theme != NULL) { $person->theme = $theme; ### update immediately / without page-reload #### if ($person->id == $auth->cur_user->id) { $auth->cur_user->theme = $theme; } } $language = get('person_language'); global $g_languages; if (isset($g_languages[$language])) { $person->language = $language; ### update immediately / without page-reload #### if ($person->id == $auth->cur_user->id) { $auth->cur_user->language = $language; setLang($language); } } if (!$person->name) { new FeedbackWarning(__("Login-accounts require a full name.")); $person->fields['name']->required = true; $person->fields['name']->invalid = true; $flag_ok = false; } if (!$person->office_email) { new FeedbackWarning(__("Please enter an e-mail address.")); $person->fields['office_email']->required = true; $person->fields['office_email']->invalid = true; $flag_ok = false; } $t_nickname = get('person_nickname'); if (!$person->nickname) { new FeedbackWarning(__("Login-accounts require a unique nickname")); $person->fields['nickname']->required = true; $person->fields['nickname']->invalid = true; $flag_ok = false; } ### check if changed nickname is unique if ($person->can_login || $person->nickname != "") { /** * \todo actually this should be mb_strtolower, but this is not installed by default */ if ($person->nickname != strtolower($person->nickname)) { new FeedbackMessage(__("Nickname has been converted to lowercase")); $person->nickname = strtolower($person->nickname); } if ($p2 = Person::getByNickname($t_nickname)) { # another person with this nick? if ($p2->id != $person->id) { new FeedbackWarning(__("Nickname has to be unique")); $person->fields['nickname']->required = true; $flag_ok = false; } } } ### password entered? ### $t_password1 = get('person_password1'); $t_password2 = get('person_password2'); $flag_password_ok = true; if (($t_password1 || $t_password2) && $t_password1 != "__dont_change__") { ### check if password match ### if ($t_password1 !== $t_password2) { new FeedbackWarning(__("Passwords do not match")); $person->fields['password']->required = true; $flag_ok = false; $flag_password_ok = false; $person->cookie_string = $auth->cur_user->calcCookieString(); } } ### check if password is good enough ### $password_length = strlen($t_password1); $password_count_numbers = strlen(preg_replace('/[\\d]/', '', $t_password1)); $password_count_special = strlen(preg_replace('/[\\w]/', '', $t_password1)); $password_value = -7 + $password_length + $password_count_numbers * 2 + $password_count_special * 4; if ($password_value < confGet('CHECK_PASSWORD_LEVEL')) { new FeedbackWarning(__("Password is too weak (please add numbers, special chars or length)")); $flag_ok = false; $flag_password_ok = false; } if ($flag_password_ok) { $person->password = md5($t_password1); } if (!validateFormCaptcha()) { new FeedbackWarning(__("Please copy the text from the image.")); $flag_ok = false; } ### repeat form if invalid data ### if (!$flag_ok) { $PH->show('personRegister', NULL, $person); exit; } /** * store indentifier-string for login from notification & reminder - mails */ $person->identifier = $person->calcIdentifierString(); ### insert new object ### if ($person->settings & USER_SETTING_NOTIFICATIONS && $person->can_login) { $person->settings |= USER_SETTING_SEND_ACTIVATION; new FeedbackHint(sprintf(__("A notification / activation will be mailed to <b>%s</b> when you log out."), $person->name) . " " . sprintf(__("Read more about %s."), $PH->getWikiLink('notifications'))); } $person->notification_last = getGMTString(time() - $person->notification_period * 60 * 60 * 24 - 1); $person->cookie_string = $person->calcCookieString(); if ($person->insert()) { new FeedbackHint(__("Thank you for registration! After your request has been approved by a moderator, you will can an email.")); ### link to a company ### if ($c_id = get('company')) { require_once confGet('DIR_STREBER') . 'db/class_company.inc.php'; if ($c = Company::getVisibleById($c_id)) { require_once confGet('DIR_STREBER') . 'db/class_employment.inc.php'; $e = new Employment(array('id' => 0, 'person' => $person->id, 'company' => $c->id)); $e->insert(); } } ## assigne to project ## require_once confGet('DIR_STREBER') . 'db/class_projectperson.inc.php'; $prj_num = confGet('REGISTER_NEW_USERS_TO_PROJECT'); global $g_user_profile_names; if (isset($prj_num)) { if ($prj_num != -1) { if ($p = Project::getVisibleById($prj_num)) { $prj_person = new ProjectPerson(array('person' => $person->id, 'project' => $p->id, 'name' => $g_user_profile_names[$person->profile])); $prj_person->insert(); } } } new FeedbackMessage(sprintf(__('Person %s created'), $person->getLink())); ### automatically login ### $foo = array('login_name' => $person->nickname, 'login_password_md5' => $person->password); addRequestVars($foo); $PH->show('loginFormSubmit', array()); exit; } else { new FeedbackError(__("Could not insert object")); } ### display fromPage #### if (!$PH->showFromPage()) { $PH->show('home', array()); } }
/** * duplicate a project including all belonging items (tasks, efforts, etc.) @ingroup pages * * - This function is a massive database-process and should be protected * from parallel database accesses. Failure of this procedure can lead to * inconsistent db-structures. Maybe we should add a db-structure validation * somewhere * - all items (even the already deleted) are duplicated because there might * be some relationships (like effort on an deleted task, is still an effort) * - does NOT change the name of the project. The caller has to change this to "copy of ..." * * returns... * - On Success: new project-object (which has already been added to db) for fine * tuning of fields. * - On Failure: NULL (error's have been triggered) */ function projDuplicate($org_project_id = NULL) { require_once confGet('DIR_STREBER') . "db/class_effort.inc.php"; require_once confGet('DIR_STREBER') . "db/class_file.inc.php"; require_once confGet('DIR_STREBER') . "db/class_issue.inc.php"; global $PH; global $auth; $count_items = 0; if (!$org_project_id) { trigger_error("projDuplicate() called without project-id", E_USER_WARNING); return; } /** * normally the project-id is already been checked by caller, but just to be sure... */ if (!($org_project = Project::getEditableById($org_project_id))) { trigger_error("could not get Project", E_USER_NOTICE); return; } /** * @Warning: getting the project a second time might give a reference to * the first one. Since caching of project-requests has not yet be activated * this works for now. Later be sure to use array_clone(). */ if (!($new_project = Project::getEditableById($org_project_id))) { trigger_error("could not get Project", E_USER_NOTICE); return; } ### duplicate project ### $new_project->id = 0; $new_project->created_by = $auth->cur_user->id; $new_project->modified_by = $auth->cur_user->id; $new_project->date_start = getGMTString(); $new_project->status = 3; #@@@ avoid majic numbers $new_project->state = 1; # be sure project is no deleted if (!$new_project->insert()) { trigger_error("Failed to insert new project. Datastructure might have been corrupted", E_USER_WARNING); return; } $flag_cur_user_in_project = false; ### copy projectpeople ### if ($org_ppeople = $org_project->getProjectPeople(array('alive_only' => false, 'visible_only' => false))) { foreach ($org_ppeople as $pp) { $pp->id = 0; $pp->project = $new_project->id; ### make current user project admin ### if ($pp->person == $auth->cur_user->id) { $pp->initWithUserProfile(PROFILE_ADMIN); $flag_cur_user_in_project = true; } if (!$pp->insert()) { trigger_error(__("Failed to insert new project person. Data structure might have been corrupted"), E_USER_WARNING); return; } $count_items++; } } ### be sure, current user is admin ### if (!$flag_cur_user_in_project) { $pp_new = new ProjectPerson(array('id' => 0, 'person' => $auth->cur_user->id, 'project' => $new_project->id)); $pp_new->initWithUserProfile(PROFILE_ADMIN); if (!$pp_new->insert()) { trigger_error(__("Failed to insert new project person. Data structure might have been corrupted"), E_USER_WARNING); return; } } ### copy issues ### $dict_issues = array(0 => 0); $org_issues = $org_project->getIssues(NULL, false, false); foreach ($org_issues as $i) { $org_issue_id = $i->id; $i->project = $new_project->id; $i->id = 0; if (!$i->insert()) { trigger_error(__("Failed to insert new issue. DB structure might have been corrupted."), E_USER_WARNING); return; } $count_items++; $dict_issues[$org_issue_id] = $i->id; } ### pass1 ### $dict_tasks = array(0 => 0); # assoc array of old / new task-ids $new_tasks = array(); if ($org_tasks = $org_project->getTasks(array('show_folders' => true, 'status_min' => 0, 'status_max' => 10, 'visible_only' => false, 'alive_only' => false))) { foreach ($org_tasks as $t) { $org_task_id = $t->id; $t->id = 0; $t->project = $new_project->id; if (!isset($dict_issues[$t->issue_report])) { trigger_error("undefined issue-id {$t->issue_report}. DB structure might have been corrupted.", E_USER_NOTICE); } else { $t->issue_report = $dict_issues[$t->issue_report]; } if (!$t->insert()) { trigger_error("Failed to insert new task. DB structure might have been corrupted.", E_USER_WARNING); return; } $count_items++; $dict_tasks[$org_task_id] = $t->id; $new_tasks[] = $t; } } ### pass2: tasks / parent_task ### foreach ($new_tasks as $nt) { if (isset($dict_tasks[$nt->parent_task])) { $nt->parent_task = $dict_tasks[$nt->parent_task]; $nt->for_milestone = $dict_tasks[$nt->for_milestone]; } else { trigger_error("undefined task-id {$nt->parent_task}", E_USER_WARNING); } if (!$nt->update()) { trigger_error(__("Failed to update new task. DB structure might have been corrupted."), E_USER_WARNING); return; } } ### copy efforts ### $dict_efforts = array(0 => 0); if ($org_efforts = Effort::getAll(array('project' => $org_project->id, 'visible_only' => false, 'alive_only' => false))) { foreach ($org_efforts as $e) { $org_effort_id = $e->id; if (isset($dict_tasks[$e->task])) { $e->task = $dict_tasks[$e->task]; } else { trigger_error("undefined task-id {$e->task}", E_USER_NOTICE); } $e->id = 0; $e->project = $new_project->id; if (!$e->insert()) { trigger_error("Failed to insert new effort. DB structure might have been corrupted.", E_USER_WARNING); return; } $count_items++; $dict_efforts[$org_effort_id] = $e->id; } } ### copy task_assigments ### $dict_taskpeople = array(0 => 0); # this hash is not required if ($org_taskpeople = $org_project->getTaskPeople("", false, false)) { foreach ($org_taskpeople as $tp) { $org_taskperson_id = $tp->id; if (isset($dict_tasks[$tp->task])) { $tp->task = $dict_tasks[$tp->task]; } else { trigger_error("undefined task-id {$e->task}", E_USER_WARNING); } $tp->id = 0; $tp->project = $new_project->id; if (!$tp->insert()) { trigger_error("Failed to insert new taskperson. DB structure might have been corrupted.", E_USER_WARNING); return; } $count_items++; $dict_taskpeople[$org_taskperson_id] = $tp->id; } } $dict_comments = array(0 => 0); $new_comments = array(); if ($org_comments = $org_project->getComments("", false, false)) { foreach ($org_comments as $c) { $org_comment_id = $c->id; if (isset($dict_tasks[$c->task])) { $c->task = $dict_tasks[$c->task]; } if (isset($dict_efforts[$c->effort])) { $c->effort = $dict_efforts[$c->effort]; } if (isset($dict_effort[$c->effort])) { $c->effort = $dict_efforts[$c->effort]; } $c->id = 0; $c->project = $new_project->id; if (!$c->insert()) { trigger_error(__("Failed to insert new comment. DB structure might have been corrupted."), E_USER_WARNING); return; } $count_items++; $dict_comments[$org_comment_id] = $c->id; $new_comments[] = $c; } } ### pass2: comment / on comment ### foreach ($new_comments as $nc) { $nc->comment = $dict_comments[$nc->comment]; if (!$nc->update()) { trigger_error("Failed to update new comment. DB structure might have been corrupted.", E_USER_WARNING); return; } } #new FeedbackMessage(sprintf(__("Project duplicated (including %s items)"), $count_items)); #if(!$new_project->insert()) { # trigger_error("Inserting new project failed. DB structure might have been corrupted.", E_USER_WARNING); # return; #} return $new_project; #$PH->show('projEdit',array('prj'=>$new_project->id),$new_project); }
/** * Remove a teammember from a project @ingroup pages */ function projectPersonDelete() { global $PH; ### get project person #### $ids = getPassedIds('projectperson', 'projectpeople_*'); if (!$ids) { $PH->abortWarning("No team-member(s) selected?", ERROR_NOTE); return; } $counter = 0; $errors = 0; foreach ($ids as $id) { $pp = ProjectPerson::getEditableById($id); if (!$pp) { $PH->abortWarning("Invalid project person-id!"); } if ($pp->delete()) { $counter++; } else { $errors++; } } if ($errors) { new FeedbackWarning(sprintf(__("Failed to remove %s members from team"), $errors)); } elseif ($counter) { new FeedbackMessage(sprintf(__("Unassigned %s team member(s) from project"), $counter)); } else { trigger_error('this should never happen'); } if (!$PH->showFromPage()) { $PH->show('projView', array('prj' => $pp->project)); } }
function render_tr(&$obj, $style = "") { global $PH; $str_url = ""; $str_name = ""; $str_addon = ""; switch ($obj->type) { case ITEM_PROJECT: if ($project = Project::getVisibleById($obj->id)) { $str_name = asHtml($project->name); $str_url = $PH->getUrl('projView', array('prj' => $project->id)); } break; case ITEM_TASK: if ($task = Task::getVisibleById($obj->id)) { $str_name = asHtml($task->name); $str_url = $PH->getUrl('taskView', array('tsk' => $task->id)); if ($project = Project::GetVisibleById($task->project)) { $str_addon = "(" . $project->getLink(false) . ")"; } } break; case ITEM_COMMENT: if ($comment = Comment::getVisibleById($obj->id)) { if ($comment->name == '') { $str_name = "-"; } else { $str_name = asHtml($comment->name); } $str_url = $PH->getUrl('taskView', array('tsk' => $comment->task)); $str_addon .= "("; if ($task = Task::getVisibleById($comment->task)) { if ($project = Project::getVisibleById($task->project)) { $str_addon .= $project->getLink(false) . " > "; } $str_addon .= $task->getLink(false); if ($comment->comment) { if ($comm = Comment::getVisibleById($comment->comment)) { $str_addon .= " > " . $comm->name; } } } $str_addon .= ")"; } break; case ITEM_COMPANY: if ($c = Company::getVisibleById($obj->id)) { $str_name = asHtml($c->name); $str_url = $PH->getUrl('companyView', array('company' => $c->id)); } break; case ITEM_PERSON: if ($person = Person::getVisibleById($obj->id)) { $str_name = asHtml($person->name); $str_url = $PH->getUrl('personView', array('person' => $person->id)); } break; case ITEM_PROJECTPERSON: if ($pp = ProjectPerson::getVisibleById($obj->id)) { if (!($person = new Person($pp->person))) { $PH->abortWarning("ProjectPerson has invalid person-pointer!", ERROR_BUG); } $str_name = asHtml($person->name); $str_url = $PH->getUrl('personView', array('person' => $person->id)); if ($project = Project::getVisibleById($pp->project)) { $str_addon = "(" . $project->getLink(false) . ")"; } } break; case ITEM_EMPLOYMENT: if ($emp = Employment::getById($obj->id)) { if ($person = Person::getVisibleById($emp->person)) { $str_name = asHtml($person->name); $str_url = $PH->getUrl('personView', array('person' => $person->id)); } if ($company = Company::getVisibleById($emp->company)) { $str_addon = "(" . $company->getLink(false) . ")"; } } break; case ITEM_EFFORT: if ($e = Effort::getVisibleById($obj->id)) { $str_name = asHtml($e->name); $str_url = $PH->getUrl('effortEdit', array('effort' => $e->id)); if ($task = Task::getVisibleById($e->task)) { if ($project = Project::getVisibleById($task->project)) { $str_addon .= "(" . $project->getLink(false); $str_addon .= " > " . $task->getLink(false) . ")"; } } } break; case ITEM_FILE: if ($f = File::getVisibleById($obj->id)) { $str_name = asHtml($f->org_filename); $str_url = $PH->getUrl('fileView', array('file' => $f->id)); $str_addon .= "("; if ($p = Project::getVisibleById($f->project)) { $str_addon .= $p->getLink(false); } if ($t = Task::getVisibleById($f->parent_item)) { $str_addon .= " > " . $t->getLink(false); } $str_addon .= ")"; } break; case ITEM_ISSUE: if ($i = Issue::getVisibleById($obj->id)) { if ($t = Task::getVisibleById($i->task)) { $str_name = asHtml($t->name); $str_url = $PH->getUrl('taskView', array('tsk' => $t->id)); if ($p = Project::getVisibleById($t->project)) { $str_addon .= "(" . $p->getLink(false) . ")"; } } } break; case ITEM_TASKPERSON: if ($tp = TaskPerson::getVisibleById($obj->id)) { if ($person = Person::getVisibleById($tp->person)) { $str_name = asHtml($person->name); $str_url = $PH->getUrl('personView', array('person' => $person->id)); } if ($task = Task::getVisibleById($tp->task)) { if ($project = Project::getVisibleById($task->project)) { $str_addon .= "(" . $project->getLink(false); $str_addon .= " > " . $task->getLink(false) . ")"; } } } break; default: break; } print "<td><a href='{$str_url}'>{$str_name}</a><span class='sub who'> {$str_addon}</span></td>"; }