pages/projectperson.inc.php

Go to the documentation of this file.
00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php5 based project management system  (c) 2005-2007  / www.streber-pm.org
00003 # Distributed under the terms and conditions of the GPL as stated in lang/license.html
00004 
00005 
00011 require_once(confGet('DIR_STREBER') . "db/class_task.inc.php");
00012 require_once(confGet('DIR_STREBER') . "db/class_project.inc.php");
00013 require_once(confGet('DIR_STREBER') . "db/class_projectperson.inc.php");
00014 require_once(confGet('DIR_STREBER') . "render/render_list.inc.php");
00015 
00016 
00020 function projectPersonEdit($pp= NULL)
00021 {
00022     global $PH;
00023 
00024     if(!$pp) {
00025         $id= getOnePassedId('projectperson','projectpersons_*', true, 'No team member selected?');   # WARNS if multiple; ABORTS if no id found
00026         if(!$pp= ProjectPerson::getEditableById($id)) {
00027             $PH->abortWarning("ERROR: could not get Project Person");
00028             return;
00029         }
00030     }
00031 
00032     ### get project ###
00033     if(!$project= Project::getVisibleById($pp->project)) {
00034         $PH->abortWarning("ERROR: could not get project");
00035     }
00036 
00037     ### get person ###
00038     if(!$person= Person::getVisibleById($pp->person)) {
00039         $PH->abortWarning("ERROR: could not get person");
00040     }
00041 
00042     ### set up page and write header ####
00043     {
00044         $page= new Page(array('use_jscalendar'=>true, 'autofocus_field'=>'projectperson_name'));
00045         $page->cur_tab='projects';
00046         $page->type=__("Edit Team Member");
00047         $page->title=sprintf(__("role of %s in %s","edit team-member title"),$person->name,$project->name);
00048 
00049         $page->crumbs=build_project_crumbs($project);
00050         $page->options[]= new NaviOption(array(
00051             'target_id' => 'projectPersonEdit',
00052 
00053         ));
00054 
00055 
00056         echo(new PageHeader);
00057     }
00058     echo (new PageContentOpen);
00059 
00060     ### write form #####
00061     {
00062         require_once(confGet('DIR_STREBER') . "render/render_form.inc.php");
00063 
00064         $form=new PageForm();
00065         $form->button_cancel=true;
00066 
00067         ### create an assoc with roles and find the current role ###
00068         {
00069             global $g_theme_names;
00070             global $g_user_profile_names;
00071             global $g_user_profiles;
00072 
00073             ### display "undefined" profile if rights changed ###
00074 
00075             $profile_num= 0;                                # will be skipped when submitting
00076             $reset="";
00077             $check = array_keys($g_user_profile_names);
00078             $number = count($g_user_profile_names);
00079             $count  = 0;
00080 
00081             for($i=0; $i < $number; $i++)
00082             {
00083                 if($pp->role == $check[intval($i)])
00084                 {
00085                     $profile_num=$count;
00086                     break;
00087                 }
00088                 $count++;
00089             }
00090 
00091             /*$profile_settings= $g_user_profiles[intval($profile_num)];
00092 
00093             $count=0;
00094             echo "LevelV: " . $pp->level_view . "<br>";
00095             echo "SetV: " . $profile_settings['level_view'] . "<br>";
00096             echo "LevelC: " . $pp->level_create . "<br>";
00097             echo "SetC: " . $profile_settings['level_create'] . "<br>";
00098             echo "LevelE: " . $pp->level_edit . "<br>";
00099             echo "SetE: " . $profile_settings['level_edit'] . "<br>";
00100             echo "LevelD: " . $pp->level_delete . "<br>";
00101             echo "SetV: " . $profile_settings['level_delete'] . "<br>";
00102             foreach($g_user_profiles as $profile_id => $profile_settings) {
00103                 if($pp->level_view          == $profile_settings['level_view']
00104                     && $pp->level_create    == $profile_settings['level_create']
00105                     && $pp->level_edit      == $profile_settings['level_edit']
00106                     && $pp->level_delete    == $profile_settings['level_delete']
00107                 ){
00108                     $profile_num=$count;
00109                     break;
00110                 }
00111                 $count++;
00112             }*/
00113 
00114             $form->add(new Form_Dropdown('person_profile',
00115                                         __("Role in this project"),
00116                                         array_flip($g_user_profile_names),
00117                                         $profile_num
00118             ));
00119 
00120 
00121         }
00122 
00123         $form->add($pp->fields['name']->getFormElement(&$pp));
00124 
00125         ### public-level ###
00126         if(($pub_levels=$pp->getValidUserSetPublevel())
00127             && count($pub_levels)>1) {
00128             $form->add(new Form_Dropdown('projectperson_pub_level',  __("Publish to"),$pub_levels,$pp->pub_level));
00129         }
00130 
00131         ### effort-style ###
00132         $effort_styles=array(
00133             __("start times and end times")=> 1,
00134             __("duration")=> 2,
00135         );
00136 
00137         $form->add(new Form_Dropdown('projectperson_effort_style',  __("Log Efforts as"), $effort_styles, $pp->adjust_effort_style));
00138 
00139 
00140         echo ($form);
00141 
00142         $PH->go_submit='projectPersonEditSubmit';
00143         echo "<input type=hidden name='projectperson' value='$pp->id'>";
00144         echo "<input type=hidden name='projectperson_project' value='$pp->project'>";
00145     }
00146     echo (new PageContentClose);
00147 }
00148 
00149 
00153 function projectPersonEditSubmit()
00154 {
00155     global $PH;
00156 
00157     ### cancel ###
00158     if(get('form_do_cancel')) {
00159         if(!$PH->showFromPage()) {
00160             $PH->show('projView',array('prj'=>$pp->project));
00161         }
00162         exit();
00163     }
00164 
00165     if(!validateFormCrc()) {
00166         $PH->abortWarning(__('Invalid checksum for hidden form elements'));
00167     }
00168 
00169     ### get projectperson ####
00170     $id= getOnePassedId('projectperson',true,'invalid id');
00171 
00172     if($id == 0) {
00173         $pp= new ProjectPerson(array('id'=>0));
00174     }
00175     else {
00176         $pp= new ProjectPerson($id);
00177         if(!$pp) {
00178             $PH->abortWarning("Could not get project person");
00179             return;
00180         }
00181     }
00182 
00183     ### get project ###
00184     if(!$project= new Project($pp->project)) {
00185         $PH->abortWarning("ERROR: could not get project",ERROR_FATAL);
00186     }
00187 
00188     ### get person ###
00189     if(!$person= new Person($pp->person)) {
00190         $PH->abortWarning("ERROR: could not get project",ERROR_FATAL);
00191     }
00192 
00193     # retrieve all possible values from post-data
00194     # NOTE:
00195     # - this could be an security-issue.
00196     # - TODO: as some kind of form-edit-behaviour to field-definition
00197     foreach($pp->fields as $f) {
00198         $name=$f->name;
00199         $f->parseForm(&$pp);
00200     }
00201 
00202 
00203 
00204     ### set rights role ###
00205 
00211     if($profile=intval(get('person_profile'))) {
00212 
00213         global $g_user_profile_names;
00214         global $g_user_profiles;
00215 
00216         #if($profile_settings= $g_user_profiles[$g_user_profile_names[$profile]]) {
00217         if($profile_settings= $g_user_profiles[$profile]) {
00218             $pp->level_view = $profile_settings['level_view'];
00219             $pp->level_edit = $profile_settings['level_edit'];
00220             $pp->level_create = $profile_settings['level_create'];
00221             $pp->level_delete = $profile_settings['level_delete'];
00222             $pp->level_reduce = $profile_settings['level_reduce'];
00223 
00224             $pp->role=$profile;
00225             new FeedbackMessage(sprintf(__('Changed role of <b>%s</b> to <b>%s</b>'), $person->name,$g_user_profile_names[$profile]));
00226         }
00227         else {
00228             trigger_error("undefined profile requested.", E_USER_WARNING);
00229         }
00230     }
00231 
00232     ### pub level ###
00233     if($pub_level=get('projectperson_pub_level')) {
00234         if($pp->id) {
00235              if($pub_level > $pp->getValidUserSetPublevel() ) {
00236                  $PH->abortWarning('invalid data',ERROR_RIGHTS);
00237              }
00238         }
00239         #else {
00240         #    #@@@ check for person create rights
00241         #}
00242         $pp->pub_level = $pub_level;
00243     }
00244 
00245     ### effort-style ###
00246     if($effort_style=get('projectperson_effort_style')) {
00247         $pp->adjust_effort_style= $effort_style;
00248     }
00249 
00250 
00251     ### write to db ###
00252     if($pp->id == 0) {
00253         $pp->insert();
00254     }
00255     else {
00256         $pp->update();
00257     }
00258 
00259     ### return to from-page ###
00260     if(!$PH->showFromPage()) {
00261         $PH->show('projView',array('prj'=>$pp->project));
00262     }
00263 }
00264 
00265 
00269 function projectPersonDelete()
00270 {
00271     global $PH;
00272 
00273     ### get project person ####
00274     $ids= getPassedIds('projectperson','projectpersons_*');
00275 
00276     if(!$ids) {
00277         $PH->abortWarning("No team-member(s) selected?",ERROR_NOTE);
00278         return;
00279     }
00280 
00281     $counter=0;
00282     $errors=0;
00283     foreach($ids as $id) {
00284         $pp= ProjectPerson::getEditableById($id);
00285 
00286         if(!$pp) {
00287             $PH->abortWarning("Invalid project person-id!");
00288         }
00289         if($pp->delete()) {
00290             $counter++;
00291         }
00292         else {
00293             $errors++;
00294         }
00295     }
00296     if($errors) {
00297         new FeedbackWarning(sprintf(__("Failed to remove %s members from team"), $errors));
00298     }
00299     elseif($counter) {
00300         new FeedbackMessage(sprintf(__("Unassigned %s team member(s) from project"), $counter));
00301     }
00302     else {
00303         trigger_error('this should never happen');
00304     }
00305 
00306     if(!$PH->showFromPage()) {
00307         $PH->show('projView',array('prj'=>$pp->project));
00308     }
00309 }
00310 
00311 
00312 ?>

Generated on Sun Mar 4 17:19:31 2007 for streber by  doxygen 1.5.1-p1