pages/task_more.inc.php

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 
00007 require_once(confGet('DIR_STREBER') . 'db/class_issue.inc.php');
00008 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00009 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00010 require_once(confGet('DIR_STREBER') . 'render/render_list.inc.php');
00011 require_once(confGet('DIR_STREBER') . 'lists/list_taskfolders.inc.php');
00012 require_once(confGet('DIR_STREBER') . 'lists/list_comments.inc.php');
00013 require_once(confGet('DIR_STREBER') . 'lists/list_tasks.inc.php');
00014 require_once(confGet('DIR_STREBER') . 'db/class_taskperson.inc.php');
00015 require_once(confGet('DIR_STREBER') . 'db/class_effort.inc.php');
00016 require_once(confGet('DIR_STREBER') . 'db/db_itemperson.inc.php');
00017 
00018 
00024 function taskNewBug()
00025 {
00026     $foo=array(
00027         'add_issue'=>1,
00028         'task_category' =>TCATEGORY_BUG
00029         );
00030     addRequestVars($foo);
00031     TaskNew();
00032     exit();
00033 }
00034 
00040 function TaskNewMilestone()
00041 {
00042     global $PH;
00043 
00044     $prj_id=getOnePassedId('prj','',true,__('No project selected?')); # aborts with error if not found
00045     if(!$project= Project::getVisibleById($prj_id)) {
00046         $PH->abortWarning("invalid project-id",ERROR_FATAL);
00047     }
00048 
00049 
00050     ### build dummy form ###
00051     $newtask= new Task(array(
00052         'id'        =>0,
00053         'name'      =>__("New Milestone"),
00054         'project'   =>$prj_id,
00055         'category' =>TCATEGORY_MILESTONE,
00056         'is_milestone' =>1,
00057         'status'    =>STATUS_OPEN,
00058         )
00059     );
00060     $PH->show('taskEdit',array('tsk'=>$newtask->id),$newtask);
00061 
00062 }
00063 
00064 
00070 function TaskNewVersion()
00071 {
00072     global $PH;
00073 
00074     $prj_id=getOnePassedId('prj','',true,__('No project selected?')); # aborts with error if not found
00075     if(!$project= Project::getVisibleById($prj_id)) {
00076         $PH->abortWarning("invalid project-id",ERROR_FATAL);
00077     }
00078 
00079     ### build dummy form ###
00080     $newtask= new Task(array(
00081         'id'            => 0,
00082         'name'          => __("New Version"),
00083         'project'       => $prj_id,
00084         'is_milestone'  => 1,
00085         'status'        => STATUS_APPROVED,
00086         'completion'    => 100,
00087         'category' =>TCATEGORY_VERSION,
00088         'is_released'   => RELEASED_PUBLIC,
00089         'time_released' => getGMTString(),
00090         )
00091     );
00092     $PH->show('taskEdit',array('tsk'=>$newtask->id),$newtask);
00093 }
00094 
00095 
00096 
00097 
00098 
00104 function TaskNewFolder()
00105 {
00106     global $PH;
00107 
00108     $prj_id=getOnePassedId('prj','',true,__('No project selected?')); # aborts with error if not found
00109     if(!$project= Project::getVisibleById($prj_id)) {
00110         $PH->abortWarning("invalid project-id",ERROR_FATAL);
00111     }
00112 
00113     ### for milestone ###
00114     if( $milestone= Task::getVisibleById(get('for_milestone'))) {
00115         $for_milestone= $milestone->id;
00116     }
00117     else {
00118         $for_milestone= 0;
00119     }
00120 
00121 
00122     ### get id of parent_task
00123     $parent_task_id=0;
00124     {
00125         $task_ids= GetPassedIds('parent_task','folders_*'); # aborts with error if not found
00126         if(count($task_ids) >= 1) {
00127             $parent_task_id= $task_ids[0];
00128         }
00129     }
00130 
00131     ### build dummy form ###
00132     $newtask= new Task(array(
00133         'id'        =>0,
00134         'name'      =>__("New Folder"),
00135         'project'   =>$prj_id,
00136         'is_folder' =>1,                                    #@@@ depreciated!
00137         'category' =>TCATEGORY_FOLDER,
00138         'parent_task'=>$parent_task_id,
00139         'for_milestone'=>$for_milestone,
00140         )
00141     );
00142     $PH->show('taskEdit',array('tsk'=>$newtask->id),$newtask);
00143 }
00144 
00145 
00152 function TaskNew()
00153 {
00154     global $PH;
00155 
00156     $parent_task = NULL;
00157     $parent_task_id =0;
00158 
00159     ### try to figure out parent_task ###
00160     if($task_ids=getPassedIds('parent_task','tasks_*|folders_*',false)) {
00161 
00162         if(count($task_ids) != 1) {
00163             $PH->abortWarning(__("Please select only one item as parent"),ERROR_NOTE);
00164         }
00165         if($task_ids[0] != 0) {
00166             if(!$parent_task = Task::getVisibleById($task_ids[0])) {
00167                 $PH->abortWarning(__("Insufficient rights for parent item."),ERROR_NOTE);
00168             }
00169             $parent_task_id= $parent_task->id;
00170         }
00171         else {
00172             $parent_task_id= 0;
00173         }
00174     }
00175     else {
00176         $parent_task_id= 0;
00177     }
00178 
00179     ### figure out project ###
00180     $prj_id= getOnePassedId('prj','projects_*',false);          # NOT aborts with error if not found
00181     if(!$prj_id) {
00182         if(!$parent_task) {
00183             $PH->abortWarning(__("could not find project"),ERROR_NOTE);
00184         }
00185         $prj_id= $parent_task->project;
00186 
00187     }
00188     if(!$project= Project::getVisibleById($prj_id)) {
00189         $PH->abortWarning(__("could not find project"),ERROR_NOTE);
00190     }
00191 
00192     ### make sure parent_task is valid ###
00193     if($parent_task_id && !$parent_task = Task::getVisibleById($parent_task_id)) {
00194         $PH->abortWarning(__("Parent task not found."), ERROR_NOTE);
00195     }
00196 
00197 
00198     $name=stripslashes(stripslashes(get('new_name')));  # @@@ hack to get rid of slashed strings
00199     $estimated='00:00:00';
00200 
00201 
00202 
00203     ### for milestone ###
00204     $for_milestone_id= 0;
00205     if( $milestone= Task::getVisibleById(get('for_milestone'))) {
00206         $for_milestone_id= $milestone->id;
00207     }
00208 
00209 
00210     ### if parent-task is milestone for some reason, avoid parenting ###
00211     if($parent_task && $parent_task->is_milestone) {
00212         $parent_task_id=0;
00213         if(!$for_milestone_id) {
00214             $for_milestone_id= $parent_task->id;
00215 
00216         }
00217     }
00218 
00219     ### category ###
00220     $category= TCATEGORY_TASK;
00221     if(!is_null($cat= get('task_category'))) {
00222         global $g_tcategory_names;
00223         if(!isset($g_tcategory_names[$cat])) {
00224             $category= TCATEGORY_TASK;
00225         }
00226         else {
00227             $category= $cat;
00228         }
00229     }
00230 
00231     ### build dummy form ###
00232     $newtask= new Task(array(
00233         'id'        =>0,
00234         'name'      =>$name,
00235         'project'   =>$prj_id,
00236         'state'     =>1,
00237         'estimated' =>$estimated,
00238         'category'  =>$category,
00239         'parent_task'=>$parent_task_id,
00240         'for_milestone'=>$for_milestone_id,
00241     ));
00242 
00243     ### set a valid create-level ###
00244     $newtask->pub_level= $project->getCurrentLevelCreate();
00245 
00246     ### insert without editing ###
00247     if((get('noedit'))) {
00248 
00249         $newtask->insert();
00250         if(!$PH->showFromPage()) {
00251             $PH->show('projView',array('prj'=>$prj));
00252         }
00253     }
00254 
00255     ### pass newobject to edit-page ###
00256     else {
00257         $PH->show('taskEdit',array('tsk'=>$newtask->id),$newtask);
00258     }
00259 }
00260 
00261 
00267 function taskEdit($task=NULL)
00268 {
00269     global $PH;
00270 
00271 
00272 
00273     ### object or from database? ###
00274     if(!$task) {
00275 
00276         $ids= getPassedIds('tsk','tasks_*');
00277 
00278         if(!$ids) {
00279             $PH->abortWarning(__("Select some task(s) to edit"), ERROR_NOTE);
00280             return;
00281         }
00282         else if(count($ids) > 1) {
00283             $PH->show('taskEditMultiple');
00284             exit();
00285         }
00286         else if(!$task= Task::getEditableById($ids[0])) {
00287             $PH->abortWarning(__("You do not have enough rights to edit this task"), ERROR_RIGHTS);
00288 
00289         }
00290     }
00291 
00292     ### get parent project ####
00293     if(!$project= Project::getVisibleById($task->project)) {
00294         $PH->abortWarning("FATAL error! parent project not found");
00295     }
00296 
00297 
00298     ### abort, if not enough rights ###
00299     #$project->validateEditItem($task);
00300 
00301     ### set up page and write header ####
00302     {
00303         $page= new Page(array('use_jscalendar'=>true,'autofocus_field'=>'task_name'));
00304         $page->cur_tab='projects';
00305 
00306 
00307         $page->crumbs=build_task_crumbs($task,$project);
00308         $page->options[]= new naviOption(array(
00309             'target_id'     =>'taskEdit',
00310         ));
00311 
00312         $page->type= sprintf(__("Edit %s","Page title") , $task->getLabel());
00313         if($task->id) {
00314             $page->title=$task->name;
00315             $page->title_minor=$task->short;
00316         }
00317         else {
00318             if($task->is_milestone) {
00319                 $page->title=__("New milestone");
00320             }
00321             else {
00322                 $page->title=__("New task");
00323                 if($task->parent_task && $parent_task= Task::getVisibleById($task->parent_task)) {
00324                     $page->title_minor= sprintf(__('for %s','e.g. new task for something'), $parent_task->name);
00325                 }
00326             }
00327         }
00328 
00329         echo(new PageHeader);
00330     }
00331     echo (new PageContentOpen);
00332 
00333     ### write form #####
00334     {
00335         require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00336 
00337         global $REPRODUCIBILITY_VALUES;
00338 
00339         global $g_prio_names;
00340         global $g_status_names;
00341 
00342         $block=new PageBlock(array(
00343             #'title' =>__('Edit Task'),
00344             'id'    =>'functions',
00345             'reduced_header' => true,
00346         ));
00347         $block->render_blockStart();
00348 
00349 
00350         $form=new PageForm();
00351         $form->button_cancel=true;
00352 
00353         $form->add($task->fields['name']->getFormElement(&$task));
00354 
00355         ### task category ###
00356         {
00357             $list= array();
00358             if($task->is_milestone) {
00359                 $list= array(TCATEGORY_MILESTONE, TCATEGORY_VERSION);
00360 
00361                 ### make sure it's valid
00362                 if($task->category != TCATEGORY_MILESTONE || $task->category != TCATEGORY_VERSION) {
00363                     if($task->is_released > RELEASED_UPCOMMING) {
00364                         $task->category= TCATEGORY_VERSION;
00365                     }
00366                     else {
00367                         $task->category= TCATEGORY_MILESTONE;
00368                     }
00369                 }
00370             }
00371             else {
00372                 $list= array(
00373                     TCATEGORY_TASK,
00374                     TCATEGORY_BUG,
00375                     TCATEGORY_DOCU,
00376                     TCATEGORY_FOLDER,
00377                 );
00378             }
00379             global $g_tcategory_names;
00380             $cats= array();
00381             foreach($list as $c) {
00382                 $cats[$c]= $g_tcategory_names[$c];
00383             }
00384             $form->add(new Form_Dropdown('task_category',  __("Display as"),array_flip($cats),$task->category));
00385 
00386             ### warning if folder with subtasks ###
00387             if($task->id && $task->category == TCATEGORY_FOLDER && ($num_subtasks= count($task->getSubtasks()))) {
00388                 $form->add(new Form_CustomHtml('<p><label></label>'. sprintf(__("This folder has %s subtasks. Changing category will ungroup them."), $num_subtasks) . '</p>'));
00389             }
00390         }
00391 
00392         $form->add($tab_group= new Page_TabGroup());
00393 
00394         ### task attributes ###
00395         {
00396             $tab_group->add($tab= new Page_Tab('task', __("Task")));
00397 
00398 
00399             ### milestone ###
00400             if($task->is_milestone) {
00401                 $tab->add(new Form_HiddenField('task_is_milestone','',$task->is_milestone));
00402             }
00403             ### normaltasks and folders ##
00404             else {
00405 
00406                 ### get milestones for later selection
00407                 $milestones= Task::getAll(array(
00408                     'is_milestone'  =>1,
00409                     'project'       =>$project->id,
00410                     'status_min'    =>STATUS_NEW,
00411                     'status_max'    =>STATUS_CLOSED,
00412                 ));
00413 
00414 
00415                 ### milestone ###
00416                 {
00417                     if($milestones) {
00418 
00419                         $tmp_milestonelist= array(('-- '. __('undefined') . ' --') => '0');
00420 
00421                         $tmp_resolvelist= array(('-- '. __('undefined') . ' --') => '0', __('-- next released version --')=>-1);
00422                         foreach($milestones as $m) {
00423                             if($m->is_released >= RELEASED_UPCOMMING) {
00424                                 $tmp_resolvelist[$m->name]= $m->id;
00425                             }
00426                             if($m->status >= STATUS_NEW && $m->status <= STATUS_APPROVED) {
00427                                 $tmp_milestonelist[$m->name]= $m->id;
00428                             }
00429                         }
00430                         $tab->add(new Form_Dropdown('task_for_milestone', __('For Milestone'),$tmp_milestonelist,$task->for_milestone));
00431 
00432 
00433                     }
00434                 }
00435 
00436                 ### prio ###
00437                 if(!$task->is_milestone) {
00438                     $tab->add(new Form_Dropdown('task_prio',  __("Prio","Form label"),  array_flip($g_prio_names), $task->prio));
00439                 }
00440 
00441             }
00442 
00443             ### assigned to ###
00444             {
00445                 ### for existing tasks, get already assigned
00446                 if($task->id) {
00447                     $assigned_persons = $task->getAssignedPersons();
00448                     #$task_assignments = $task->getAssignments();
00449                 }
00450 
00451                 ### for new tasks get the assignments from parent task ###
00452 
00471                 else {
00472                     ### check new assigments ###
00473                     $count=0;
00474 
00475                     while($id_new= get('task_assign_to_'.$count)) {
00476                         $count++;
00477 
00478                         ### check if already assigned ###
00479                         if($p= Person::getVisibleById($id_new)) {
00480                             $assigned_persons[]= $p;
00481                         }
00482                     }
00483 
00484                     if(!$count) {
00485                         $parents= $task->getFolder();
00486 
00487                         if($parents) {
00488                             $parents= array_reverse($parents);
00489 
00490                             foreach($parents as $p) {
00491                                 if($ap= $p->getAssignedPersons()) {
00492                                     $assigned_persons= $ap;
00493                                     break;
00494 
00495                                 }
00496                             }
00497                         }
00498                     }
00499                 }
00500 
00501                 $team=array(__('- select person -')=>0);
00502 
00503                 ### create team-list ###
00504                 foreach($project->getPersons() as $p) {
00505                     $team[$p->name]= $p->id;
00506                 }
00507 
00508 
00509                 ### create drop-down-lists ###
00510                 $count_new=0;
00511                 $count_all=0;
00512                 if(isset($assigned_persons)) {
00513                     foreach($assigned_persons as $ap) {
00514                         if(!$p= Person::getVisibleById($ap->id)) {
00515                             continue;                               # skip if invalid person
00516                         }
00517 
00518                         if($task->id) {
00519                             $tab->add(new Form_Dropdown('task_assigned_to_'.$ap->id, __("Assigned to"),$team, $ap->id));
00520                         }
00521                         else {
00522                             $tab->add(new Form_Dropdown('task_assign_to_'.$count_new, __("Assign to"),$team, $ap->id));
00523                             $count_new++;
00524                         }
00525                         $count_all++;
00526                         unset($team[$ap->name]);
00527                     }
00528                 }
00529 
00530                 ### add empty drop-downlist for new assignments ###
00531 
00532                 $str_label  = ($count_all == 0)
00533                             ? __("Assign to","Form label")
00534                             : __("Also assign to","Form label");
00535                 $tab->add(new Form_Dropdown("task_assign_to_$count_new",  $str_label,$team, 0));
00536 
00537             }
00538 
00539 
00540             ### completion ###
00541             if(!$task->is_released > RELEASED_UPCOMMING) {
00542                 #$form->add($task->fields['estimated'    ]->getFormElement(&$task));
00543                 $ar= array(
00544                     __('undefined')=> -1,
00545                     '0%'    => 0,
00546                     '10%'    => 10,
00547                     '20%'    => 20,
00548                     '30%'    => 30,
00549                     '40%'    => 40,
00550                     '50%'    => 50,
00551                     '60%'    => 60,
00552                     '70%'    => 70,
00553                     '80%'    => 80,
00554                     '90%'    => 90,
00555                     '95%'    => 95,
00556                     '98%'    => 98,
00557                     '99%'    => 99,
00558                     '100%'   => 100,
00559                 );
00560                 $tab->add(new Form_Dropdown('task_completion',__("Completed"),$ar,  $task->completion));
00561             }
00562 
00563             ### status ###
00564             {
00565                 $st=array();
00566                 foreach($g_status_names as $s=>$n) {
00567                     if($s >= STATUS_NEW) {
00568                         $st[$s]=$n;
00569                     }
00570                 }
00571                 if($task->is_milestone) {
00572                     unset($st[STATUS_NEW]);
00573                 }
00574 
00575                 $tab->add(new Form_Dropdown('task_status',"Status",array_flip($st),  $task->status));
00576             }
00577 
00578             if(!$task->is_milestone) {
00579 
00580                 if($milestones) {
00581 
00582                     ### resolved version ###
00583                     $tab->add(new Form_Dropdown('task_resolved_version', __('Resolved in'),$tmp_resolvelist,$task->resolved_version));
00584                 }
00585 
00586                 ### resolved reason ###
00587                 global $g_resolve_reason_names;
00588                 $tab->add(new Form_Dropdown('task_resolve_reason', __('Resolve reason'),array_flip($g_resolve_reason_names), $task->resolve_reason));
00589             }
00590 
00591 
00592         }
00593 
00594         ### bug report ###
00595         {
00596             $tab_group->add($tab= new Page_Tab("bug",__("Bug Report")));
00597 
00598             ### use issue-report ###
00599             #if(!$task->is_milestone && $task->issue_report != 0) {
00600                 global $g_severity_names;
00601                 global $g_reproducibility_names;
00602 
00603                 ### create new one ###
00604                 if($task->issue_report <= 0) {
00605                     $issue= new Issue(array('id'=>0));
00606 
00607                     ### get recent issue-reports ###
00608                     if($recent_ir=Issue::getCreatedRecently()) {
00609                         $default_version='';
00610                         $default_plattform='';
00611                         $default_production_build='';
00612                         $default_os='';
00613 
00614                         foreach($recent_ir as $ir){
00615                             if($ir->project == $project->id) {
00616                                 if(!$issue->version && $ir->version) {
00617                                     $issue->version= $ir->version;
00618                                 }
00619                                 if(! $issue->plattform && $ir->plattform) {
00620                                     $issue->plattform= $ir->plattform;
00621                                 }
00622                                 if(! $issue->os && $ir->os) {
00623                                     $issue->os= $ir->os;
00624                                 }
00625                                 if(! $issue->production_build && $ir->production_build) {
00626                                     $issue->production_build= $ir->production_build;
00627                                 }
00628                             }
00629                         }
00630                     }
00631                 }
00632                 else {
00636                     $issue= Issue::getById($task->issue_report);
00637 
00638                 }
00639 
00640                 if($issue) {
00641 
00642                     $tab->add(new Form_Dropdown('issue_severity',       __("Severity","Form label, attribute of issue-reports"),        array_flip($g_severity_names),        $issue->severity));
00643                     $tab->add(new Form_Dropdown('issue_reproducibility',__("Reproducibility","Form label, attribute of issue-reports"), array_flip($g_reproducibility_names), $issue->reproducibility));
00644                     foreach($issue->fields as $field) {
00645                         $tab->add($field->getFormElement(&$issue));
00646                     }
00647                     $tab->add(new Form_HiddenField('task_issue_report','',$task->issue_report));
00648                 }
00649                 else {
00650                     trigger_error("could not get Issue with id ($task->issue-report)", E_USER_NOTICE);
00651                 }
00652 
00653             #}
00654 
00655         }
00656 
00657         ### timing ###
00658         {
00659             $tab_group->add($tab= new Page_Tab("timing",__("Timing")));
00660 
00661             ### estimated ###
00662             if(!$task->is_milestone){
00663                 #$tab->add($task->fields['estimated'    ]->getFormElement(&$task));
00664                 $ar= array(
00665                     __('undefined')=> 0,
00666                     __('30 min')    => 30*60,
00667                     __('1 h')  => 60*60,
00668                     __('2 h') => 2*60*60,
00669                     __('4 h') => 4*60*60,
00670                     __('1 Day')     =>   1 * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00671                     __('2 Days')    =>   2 * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00672                     __('3 Days')    =>   3 * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00673                     __('4 Days')    =>   4 * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00674                     __('1 Week')   =>   1 * confGet('WORKDAYS_PER_WEEK') * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00675                     #__('1,5 Weeks')=> 1.5 * confGet('WORKDAYS_PER_WEEK') * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00676                     __('2 Weeks')  =>   2 * confGet('WORKDAYS_PER_WEEK') * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00677                     __('3 Weeks')  =>   3 * confGet('WORKDAYS_PER_WEEK') * confGet('WORKHOURS_PER_DAY') * 60 * 60,
00678                 );
00679                 $tab->add(new Form_Dropdown('task_estimated',__("Estimated time"),$ar,  $task->estimated));
00680                 $tab->add(new Form_Dropdown('task_estimated_max',__("Estimated worst case"),$ar,  $task->estimated_max));
00681 
00682             }
00683 
00684 
00685             ### planned time ###
00686             if(!$task->is_milestone) {
00687                 $tab->add($task->fields['planned_start'     ]->getFormElement(&$task));
00688             }
00689             $tab->add($task->fields['planned_end' ]->getFormElement(&$task));
00690 
00691             if($task->is_milestone) {
00692                 global $g_released_names;
00693                 $tab->add(new Form_Dropdown('task_is_released',       __("Release as version","Form label, attribute of issue-reports"),        array_flip($g_released_names),        $task->is_released));
00694 
00695                 $tab->add($task->fields['time_released']->getFormElement(&$task));
00696             }
00697 
00698         }
00699 
00700         ### description attributes ###
00701         {
00702             $tab_group->add($tab= new Page_Tab('description', __("Description")));
00703 
00704             $e= $task->fields['description']->getFormElement(&$task);
00705             $e->rows=20;
00706             $tab->add($e);
00707         }
00708 
00709         ### display attributes ###
00710         {
00711             $tab_group->add($tab= new Page_Tab('display',__("Display")));
00712 
00713 
00714             ### short ###
00715             $tab->add($task->fields['short']->getFormElement(&$task));
00716 
00717 
00718             ### order id ###
00719             $tab->add($task->fields['order_id']->getFormElement(&$task));
00720 
00721 
00722             ### public-level ###
00723             if(($pub_levels=$task->getValidUserSetPublevel())
00724                 && count($pub_levels)>1) {
00725                 $tab->add(new Form_Dropdown('task_pub_level',  __("Publish to"),$pub_levels,$task->pub_level));
00726             }
00727 
00728 
00729             ### label ###
00730             if(!$task->is_milestone && $task->category != TCATEGORY_FOLDER) {
00731                 $labels=array(__('undefined') => 0);
00732                 $counter= 1;
00733                 foreach(split(",",$project->labels) as $l) {
00734                     $labels[$l]=$counter++;
00735                 }
00736                 $tab->add(new Form_Dropdown('task_label',  __("Label"),$labels,$task->label));
00737             }
00738         }
00739 
00740 
00741 
00742 
00746         global $auth;
00747         if($auth->cur_user->id == confGet('ANONYMOUS_USER')) {
00748             $form->addCaptcha();
00749         }
00750 
00751 
00752         $form->add($task->fields['parent_task']->getFormElement(&$task));
00753 
00754 
00755         #echo "<input type=hidden name='tsk' value='$task->id'>";
00756         $form->add(new Form_HiddenField('tsk','',$task->id));
00757 
00758         #echo "<input type=hidden name='task_project' value='$project->id'>";
00759         $form->add(new Form_HiddenField('task_project','',$project->id));
00760 
00761         ### create another person ###
00762         if($task->id == 0) {
00763             $checked= get('create_another')
00764             ? 'checked'
00765             : '';
00766 
00767             $form->form_options[]="<input id='create_another' name='create_another' type=checkbox $checked><label for='create_another'>" . __("Create another task after submit") . "</label>";     ;
00768         }
00769 
00770         echo($form);
00771 
00772         $PH->go_submit= 'taskEditSubmit';
00773         if($return=get('return')) {
00774             echo "<input type=hidden name='return' value='$return'>";
00775         }
00776 
00777         $block->render_blockEnd();
00778 
00779         #@@@ passing project-id is an security-issue, because it might allow to add tasks to unverified projects.
00780         # Double-checking project-rights in taskEditSubmit() required
00781     }
00782 
00783     echo (new PageContentClose);
00784     echo (new PageHtmlEnd);
00785 }
00786 
00787 
00793 function taskEditSubmit()
00794 {
00795     global $PH;
00796     global $auth;
00797     require_once(confGet('DIR_STREBER') . 'db/class_taskperson.inc.php');
00798 
00803     $link_items=array();
00804 
00805     if(!validateFormCrc()) {
00806         $PH->abortWarning(__('Invalid checksum for hidden form elements'));
00807     }
00808 
00809     validateFormCaptcha(true);
00810 
00811     ### temporary object or from database? ###
00812     $tsk_id=getOnePassedId('tsk','',true,'invalid id');
00813     if($tsk_id == 0) {
00814         $task= new Task(array(
00815             'id'=>0,
00816             'project'=>get('task_project'),
00817         ));
00818     }
00819     else {
00820         if(!$task= Task::getVisiblebyId($tsk_id)) {
00821             $PH->abortWarning("invalid task-id");
00822         }
00823     }
00824 
00825     ### cancel? ###
00826     if(get('form_do_cancel')) {
00827         if(!$PH->showFromPage()) {
00828             $PH->show('taskView',array('tsk'=>$task->id));
00829         }
00830         exit();
00831     }
00832 
00833 
00834     $was_a_folder= ($task->category == TCATEGORY_FOLDER)
00835                  ? true
00836                  : false;
00837     $was_released_as= $task->is_released;
00838 
00839 
00840     ### get project ###
00841     if(!$project= Project::getVisiblebyId($task->project)) {
00842         $PH->abortWarning("task without project?");
00843 
00844     }
00845 
00846 
00850     $added_comment= false;
00851     {
00852         ### only insert the comment, when comment name and description are not NULL
00853         if(get('comment_name') || get('comment_description')) {
00854 
00855             require_once(confGet('DIR_STREBER') . 'pages/comment.inc.php');
00856             $valid_comment= true;
00857 
00858             ### new object? ###
00859             $comment= new Comment(array(
00860                 'name'=> get('comment_name'),
00861                 'description' =>get('comment_description'),
00862                 'project' => $task->project,
00863                 'task' => $task->id
00864             ));
00865 
00866             if(confGet('REJECT_SPAM_CONTENT') && $auth->cur_user->id == confGet('ANONYMOUS_USER')) {
00867                 $propability= (isSpam($comment->description) + isSpam($comment->name)) * 0.5;
00868                 if($propability  > confGet('REJECT_SPAM_CONTENT')) {
00869                     log_message(sprintf("rejected spam comment from %s with %s", $_SERVER['REMOTE_ADDR'], $propability),  LOG_MESSAGE_HACKING_ALERT);
00870                     $PH->abortWarning(__("Comment has been rejected, because it looks like spam.") );
00871                 }
00872             }
00873 
00874             ### write to db ###
00875             if($valid_comment) {
00876                 if(!$comment->insert()) {
00877                     new FeedbackWarning(__("Failed to add comment"));
00878                 }
00879                 else {
00880                     ### change task update modification date ###
00881                     if(isset($task)) {
00882                         ### Check if now longer new ###
00883                         if($task->status == STATUS_NEW) {
00884                             global $auth;
00885                             if($task->created < $auth->cur_user->last_login) {
00886                                 $task->status = STATUS_OPEN;
00887                             }
00888                         }
00889                         $task->update(array('modified','status'));
00890                     }
00891 
00892                     $added_comment= true;
00893                 }
00894             }
00895         }
00896     }
00897 
00898 
00899 
00900     if($task->id != 0 && ! Task::getEditableById($task->id)) {
00901 
00902         if($added_comment) {
00903             ### display taskView ####
00904             if(!$PH->showFromPage()) {
00905                 $PH->show('home',array());
00906             }
00907             exit();
00908         }
00909         else {
00910             $PH->abortWarning(__("Not enough rights to edit task"));
00911         }
00912     }
00913 
00914 
00915     $task->validateEditRequestTime();
00916     $status_old = $task->status;
00917 
00918     # retrieve all possible values from post-data (with field->view_in_forms == true)
00919     # NOTE:
00920     # - this could be an security-issue.
00921     # @@@ TODO: as some kind of form-edit-behaviour to field-definition
00922     foreach($task->fields as $f) {
00923         $name=$f->name;
00924         $f->parseForm(&$task);
00925     }
00926 
00927     $task->fields['parent_task']->parseForm(&$task);
00928 
00929     ### category ###
00930     if(!is_null($c= get('task_category'))) {
00931         global $g_tcategory_names;
00932         if(isset($g_tcategory_names[$c])) {
00933             $task->category= $c;
00934         }
00935         else {
00936             trigger_error("ignoring unknown task category '$c'", E_USER_NOTICE);
00937         }
00938     }
00943     $task->is_folder = ($task->category == TCATEGORY_FOLDER)
00944                      ? 1
00945                      : 0;
00946 
00947 
00948 
00949     ### Check if now longer new ###
00950     if($status_old == $task->status && $task->status == STATUS_NEW) {
00951         global $auth;
00952         if($task->created < $auth->cur_user->last_login) {
00953             $task->status = STATUS_OPEN;
00954         }
00955     }
00956 
00957 
00970     {
00971 
00972         $assigned_persons = array();
00973         $task_assignments = array();
00974 
00975         if($task->id) {
00976             foreach($task->getAssignedPersons() as $p) {
00977                 $assigned_persons[$p->id] = $p;
00978             }
00979 
00980             foreach($task->getAssignments() as $ta) {
00981                 $task_assignments[$ta->person]= $ta;
00982             }
00983         }
00984 
00985         $team= array();
00986         foreach($project->getPersons() as $p) {
00987             $team[$p->id]= $p;
00988         }
00989 
00990         $new_task_assignments= array();                     # store assigments after(!) validation
00991 
00992         if(isset($task_assignments)) {
00993             foreach($task_assignments as $id=>$t_old) {
00994                 $id_new= get('task_assigned_to_'.$id);
00995                 if($id_new === NULL) {
00996                     log_message("failure. Can't change no longer existing assigment (person-id=$id item-id=$t_old->id)", LOG_MESSAGE_DEBUG);
00997                     #$PH->abortWarning("failure. Can't change no longer existing assigment",ERROR_NOTE);
00998                     continue;
00999                 }
01000 
01001                 if($id == $id_new) {
01002                     #echo " [$id] {$team[$id]->name} still assigned<br>";
01003                     continue;
01004                 }
01005 
01006                 if($id_new == 0) {
01007                     if(!$t_old) {
01008                         continue;
01009                     }
01010                     #echo " [$id] {$team[$id]->name} unassigned<br>";
01011                     $t_old->delete();
01012                     continue;
01013                 }
01014 
01015                 #$t_new= $task_assignments[$id_new];
01016                 $p_new = @$team[$id_new];
01017                 if(!isset($p_new)) {
01018                     $PH->abortWarning("failure during form-value passing",ERROR_BUG);
01019                 }
01020                 #echo " [$id] assignment changed from {$team[$id]->name} to {$team[$id_new]->name}<br>";
01021 
01022                 $t_old->comment = sprintf(__("unassigned to %s","task-assignment comment"),$team[$id_new]->name);
01023                 $t_old->update();
01024                 $t_old->delete();
01025                 $new_assignment= new TaskPerson(array(
01026                     'person'=> $team[$id_new]->id,
01027                     'task'  => $task->id,
01028                     'comment'=>sprintf(__("formerly assigned to %s","task-assigment comment"), $team[$id]->name),
01029                     'project'=>$project->id,
01030                 ));
01031 
01032                 $new_task_assignments[]=$new_assignment;
01033                 $link_items[]=$new_assignment;
01034             }
01035         }
01036 
01037         ### check new assigments ###
01038         $count=0;
01039         while($id_new= get('task_assign_to_'.$count)) {
01040             $count++;
01041 
01042             ### check if already assigned ###
01043             if(isset($task_assignments[$id_new])) {
01044 
01045 
01046                 #new FeedbackMessage(sprintf(__("task was already assigned to %s"),$team[$id_new]->name));
01047             }
01048             else {
01049                 if(!isset($team[$id_new])) {
01050                     $PH->abortWarning("unknown person id $id_new",ERROR_DATASTRUCTURE);
01051                 }
01052 
01053                 $new_assignment= new TaskPerson(array(
01054                     'person'=> $team[$id_new]->id,
01055                     'task'  => $task->id,
01056                     'comment'=>"",
01057                     'project'=>$project->id,
01058                 ));
01059 
01065                 $new_task_assignments[] = $new_assignment;
01066 
01067                 #$new_assignment->insert();
01068                 $link_items[]=$new_assignment;
01069             }
01070         }
01071     }
01072 
01073     $is_milestone=get('task_is_milestone');
01074     if(!is_null($is_milestone)) {
01075         $task->is_milestone= $is_milestone;
01076 
01077         $is_released=get('task_is_released');
01078         if(!is_null($is_released)) {
01079             $task->is_released = $is_released;
01080         }
01081     }
01082 
01083     ### pub level ###
01084     if($pub_level=get('task_pub_level')) {
01085         if($task->id) {
01086              if($pub_level > $task->getValidUserSetPublevel() ) {
01087                  $PH->abortWarning('invalid data',ERROR_RIGHTS);
01088              }
01089         }
01090         #else {
01091         #    #@@@ check for person create rights
01092         #}
01093         $task->pub_level = $pub_level;
01094     }
01095 
01096     #--- check project---
01097     if($task->id == 0) {
01098         if(!$task->project=get('task_project')) {
01099             $PH->abortWarning("task requires project to be set");
01100         }
01101     }
01102 
01103 
01104     ### get parent_task ###
01105     $is_ok= true;
01106     $parent_task= NULL;
01107     if($task->parent_task) {
01108         $parent_task= Task::getVisibleById($task->parent_task);
01109     }
01110     #else {
01111     #    new FeedbackWarning( __("Failed to retrieve parent task"));
01112     #    $is_ok= false;
01113     #}
01114 
01115 
01116     ### validate ###
01117     if(!$task->name) {
01118         new FeedbackWarning(__("Task requires name"));
01119         $task->fields['name']->required=true;
01120         $task->fields['name']->invalid=true;
01121         $is_ok= false;
01122     }
01123     ### task-name already exist ###
01124     else if($task->id == 0){
01125         $other_tasks = array();
01126 
01127         if($parent_task) {
01128             $other_tasks= Task::getAll(array(
01129                 'project' => $project->id,
01130                 'parent_task'=> $parent_task->id,
01131                 'status_min'=> STATUS_NEW,
01132                 'status_max'=> STATUS_CLOSED,
01133                 'visible_only' => false,
01134             ));
01135         }
01136         else {
01137             $other_tasks= Task::getAll(array(
01138                 'project' => $project->id,
01139                 'parent_task'=> 0,
01140                 'status_min'=> STATUS_NEW,
01141                 'status_max'=> STATUS_CLOSED,
01142                 'visible_only' => false,
01143             ));
01144         }
01145         foreach($other_tasks as $ot) {
01146             if(!strcasecmp($task->name, $ot->name)) {
01147                 $is_ok = false;
01148                 new FeedbackWarning(sprintf(__('Task called %s already exists'), $ot->getLink(false)));
01149                 break;
01150             }
01151         }
01152     }
01153 
01154     ### Check if completion should be 100% ###
01155     if ($task->status >= STATUS_COMPLETED) {
01156         $task->completion = 100;
01157     }
01158 
01159 
01160     ### repeat form if invalid data ###
01161     if(!$is_ok) {
01162         $PH->show('taskEdit',NULL,$task);
01163         exit();
01164     }
01165 
01166     #--- write to database -----------------------------------------------------------------------
01167 
01168     #--- be sure parent-task is folder ---
01169     if($parent_task) {
01170 
01171         if($parent_task->is_milestone) {
01172             if($parent_task->is_folder) {
01173                 $parent_task->is_folder= 0;
01174                 $parent_task->update(array('is_folder'),false);
01175             }
01176             $PH->abortWarning(__("Milestones may not have sub tasks"));
01177         }
01178         else if($parent_task->category != TCATEGORY_FOLDER) {
01179             $parent_task->category= TCATEGORY_FOLDER;
01180             $parent_task->is_folder= 1;
01181             if($parent_task->update()) {
01182                 new FeedbackMessage(__("Turned parent task into a folder. Note, that folders are only listed in tree"));
01183             }
01184             else {
01185                 trigger_error(__("Failed, adding to parent-task"),E_USER_WARNING);
01186                 $PH->abortWarning(__("Failed, adding to parent-task"));
01187 
01188             }
01189         }
01190     }
01191 
01192     ### ungroup child tasks? ###
01193     if($was_a_folder && $task->category != TCATEGORY_FOLDER) {
01194 
01195         $num_subtasks= $task->ungroupSubtasks();            # @@@ does this work???
01196 
01197 
01201         $parent= Task::getById($task->parent_task);
01202         $parent_str= $parent
01203             ? $parent->name
01204             : __('Project');
01205 
01206         if($num_subtasks) {
01207             new FeedbackMessage(sprintf(__("NOTICE: Ungrouped %s subtasks to <b>%s</b>"),$num_subtasks, $parent_str));
01208         }
01209     }
01210 
01211     if($task->id && !get('task_issue_report')) {
01212         $task_issue_report = $task->issue_report;
01213     }
01214     else {
01215         $task_issue_report= get('task_issue_report');
01216     }
01217     
01218     
01219     
01220     ### consider issue-report? ###
01221     #$task_issue_report= get('task_issue_report');
01222     if( $task_issue_report != 0
01223      || $task->category == TCATEGORY_BUG
01224      #&& !get('comment_name')                            # don't update issue report 
01225     ) {
01226 
01227         ### new report as / temporary ###
01228         if($task_issue_report == 0 || $task_issue_report == -1) {
01229 
01230             $issue= new Issue(array(
01231                 'id'=>0,
01232                 'project'   => $project->id,
01233                 'task'      => $task->id,
01234             ));
01235 
01236             ### querry form-information ###
01237             foreach($issue->fields as $f) {
01238                 $name=$f->name;
01239                 $f->parseForm(&$issue);
01240             }
01241 
01242             ### write to db ###
01243             if(!$issue->insert()) {
01244                 trigger_error("Failed to insert issue to db",E_USER_WARNING);
01245             }
01246             else {
01247                 $link_items[]= $issue;
01248                 $task->issue_report= $issue->id;
01249             }
01250         }
01251         ### get from database ###
01252         else if($issue= Issue::getById($task_issue_report)) {
01253             
01254 
01255             ### querry form-information ###
01256             foreach($issue->fields as $f) {
01257                 $name=$f->name;
01258                 $f->parseForm(&$issue);
01259             }
01260 
01261             global $g_reproducibility_names;
01262             if(!is_null($rep= get('issue_reproducibility'))) {
01263                 if(isset($g_reproducibility_names[$rep])) {
01264                     $issue->reproducibility= intval($rep);
01265                 }
01266                 else {
01267                     $issue->reproducibility= REPRODUCIBILITY_UNDEFINED;
01268                 }
01269             }
01270 
01271             global $g_severity_names;
01272             if(!is_null($sev= get('issue_severity'))) {
01273                 if(isset($g_severity_names[$sev])) {
01274                     $issue->severity= intval($sev);
01275                 }
01276                 else {
01277                     $issue->severity= SEVERITY_UNDEFINED;
01278                 }
01279             }
01280 
01281 
01282             ### write to db ###
01283             if(!$issue->update()) {
01284                 trigger_error("Failed to write issue to DB (id=$issue->id)", E_USER_WARNING);
01285             }
01286 
01287             if($task->issue_report != $issue->id) {         # additional check, actually not necessary
01288                 trigger_error("issue-report as invalid id ($issue->id). Should be ($task->issue_report) Please report this bug.",E_USER_WARNING);
01289             }
01290         }
01291         else {
01292             trigger_error("Could not get issue with id $task->issue_report from database",E_USER_WARNING);
01293         }
01294     }
01295 
01296     ### write to db ###
01297     if($task->id == 0) {
01298         $task->insert();
01299 
01300 
01301         ### write task-assigments ###
01302         foreach($new_task_assignments as $nta) {
01303             $nta->insert();
01304         }
01305 
01306         ### now we now the id of the new task, link the other items
01307         foreach($link_items as $i) {
01308             $i->task= $task->id;
01309             $i->update();
01310         }
01311         new FeedbackMessage(sprintf(__("Created task %s with ID %s"),  $task->getLink(false),$task-> id));
01312     }
01313     else {
01314 
01315         ### write task-assigments ###
01316         foreach($new_task_assignments as $nta) {
01317             $nta->insert();
01318         }
01319 
01320         new FeedbackMessage(sprintf(__("Changed task %s with ID %s"),  $task->getLink(false),$task-> id));
01321         $task->update();
01322     }
01323 
01324 
01325     ### if this is a just released version add any recently resolved tasks? ###
01326     if($task->is_milestone && $task->is_released >= RELEASED_INTERNAL && $was_released_as < RELEASED_INTERNAL ) {
01327         if($resolved_tasks= Task::getAll(array(
01328             'project'           => $task->project,
01329             'status_min'        => STATUS_COMPLETED,
01330             'status_max'        => STATUS_CLOSED,
01331             'resolved_version'  => RESOLVED_IN_NEXT_VERSION,
01332             'resolve_reason_min'=> RESOLVED_DONE,                          # @@@ this is not the best solution (should be IS NOT)
01333         ))) {
01334             foreach($resolved_tasks as $rt) {
01335                 $rt->resolved_version= $task->id;
01336                 $rt->update(array('resolved_version'));
01337             }
01338             new FeedbackMessage(sprintf(__('Marked %s tasks to be resolved in this version.'), count($resolved_tasks)));
01339         }
01340     }
01341 
01342     ### notify on change ###
01343     $task->nowChangedByUser();
01344 
01345     ### create another task ###
01346     if(get('create_another')) {
01347 
01348         ### build dummy form ###
01349         $newtask= new Task(array(
01350             'id'        =>0,
01351             'name'      =>__('New task'),
01352             'project'   =>$task->project,
01353             'state'     =>1,
01354             'prio'      =>$task->prio,
01355             'label'     =>$task->label,
01356             'parent_task'=>$task->parent_task,
01357             'for_milestone'=>$task->for_milestone,
01358             'category'  =>$task->category,
01359         ));
01360 
01361 
01362 
01363         $PH->show('taskEdit',array('tsk'=>$newtask->id),$newtask);
01364     }
01365     else {
01366         ### display taskView ####
01367         if(!$PH->showFromPage()) {
01368             $PH->show('home',array());
01369         }
01370     }
01371 
01372 }
01373 
01374 
01389 function TasksMoveToFolder()
01390 {
01391     global $PH;
01392 
01393     $task_ids= getPassedIds('tsk','tasks_*');
01394 
01395     if(!$task_ids) {
01396         $PH->abortWarning(__("Select some tasks to move"));
01397         exit();
01398     }
01399 
01400 
01401 
01405     $target_id=-1;
01406 
01410     $folder_ids= getPassedIds('folder','folders_*');
01411     if(count($folder_ids) == 1) {
01412         if($folder_task= Task::getVisibleById($folder_ids[0])) {
01413             $target_id= $folder_task->id;
01414         }
01415     }
01416 
01420     else if(get('from_selection')) {
01421         $target_id= 0;
01422     }
01423 
01424 
01425     if($target_id != -1) {
01426 
01427 
01428         if($target_id != 0){
01429             if(!$target_task= Task::getEditableById($target_id)) {
01430                 $PH->abortWarning(__("insufficient rights"));
01431 
01432             }
01433             ### get path of target to check for cycles ###
01434             $parent_tasks= $target_task->getFolder();
01435             $parent_tasks[]= $target_task;
01436         }
01437         else {
01438             $parent_tasks=array();
01439         }
01440 
01441 
01442         $count=0;
01443         foreach($task_ids as $id) {
01444             if($task= Task::getEditableById($id)) {
01445 
01446                 ### check if tasks target_id is own child ###
01447                 $cycle_flag= false;
01448                 foreach($parent_tasks as $pt) {
01449                     if($pt->id == $task->id) {
01450                         $cycle_flag= true;
01451                         break;
01452                     }
01453                 }
01454                 if($cycle_flag) {
01455                     new FeedbackWarning(sprintf(__("Can not move task <b>%s</b> to own child."), $task->name));
01456                 }
01457                 else {
01458                     $task->parent_task= $target_id;
01459                     $task->update();
01460                     $task->nowChangedByUser();
01461                 }
01462             }
01463             else {
01464                 new FeedbackWarning(sprintf(__("Can not edit tasks %s"), $task->name));
01465             }
01466         }
01467 
01468         ### return to from-page? ###
01469         if(!$PH->showFromPage()) {
01470             $PH->show('home');
01471         }
01472         exit();
01473     }
01474 
01479     ### get project ####
01480     if(!$task= Task::getVisibleById($task_ids[0])) {
01481         $PH->abortWarning("could not get task", ERROR_BUG);
01482     }
01483 
01484     if(!$project= Project::getVisibleById($task->project)) {
01485         $PH->abortWarning("task without project?", ERROR_BUG);
01486     }
01487 
01488 
01489     ### set up page and write header ####
01490     {
01491         $page= new Page(array('use_jscalendar'=>false, 'autofocus_field'=>'company_name'));
01492         $page->cur_tab='projects';
01493         $page->type= __("Edit tasks");
01494         $page->title="$project->name";
01495         $page->title_minor=__("Select folder to move tasks into");
01496 
01497         $page->crumbs= build_project_crumbs($project);
01498 
01499         $page->options[]= new NaviOption(array(
01500             'target_id'     =>'tasksMoveToFolder',
01501         ));
01502 
01503         echo(new PageHeader);
01504     }
01505     echo (new PageContentOpen);
01506 
01507 
01508     ### write form #####
01509     {
01510         ### write tasks as hidden entry ###
01511         foreach($task_ids as $id) {
01512             if($task= Task::getEditableById($id)) {
01513 
01514                 echo "<input type=hidden name='tasks_{$id}_chk' value='1'>";
01515             }
01516         }
01517 
01518         ### write list of folders ###
01519         {
01520             $list= new ListBlock_tasks();
01521             $list->reduced_header= true;
01522             $list->query_options['show_folders']= true;
01523             $list->query_options['folders_only']= true;
01524             $list->query_options['project']= $project->id;
01525             $list->groupings= NULL;
01526             $list->block_functions= NULL;
01527             $list->id= 'folders';
01528             unset($list->columns['status']);
01529             unset($list->columns['date_start']);
01530             unset($list->columns['days_left']);
01531             unset($list->columns['created_by']);
01532             unset($list->columns['label']);
01533             unset($list->columns['project']);
01534 
01535             $list->functions= array();
01536 
01537             $list->active_block_function = 'tree';
01538 
01539 
01540             $list->print_automatic($project,NULL);
01541         }
01542 
01543         echo __("(or select nothing to move to project root)"). "<br> ";
01544 
01545         echo "<input type=hidden name='from_selection' value='1'>";             # keep flag to ungroup tasks
01546         echo "<input type=hidden name='project' value='$project->id'>";
01547         $button_name=__("Move items");
01548         echo "<input class=button2 type=submit value='$button_name'>";
01549 
01550         $PH->go_submit='tasksMoveToFolder';
01551 
01552     }
01553     echo (new PageContentClose);
01554     echo (new PageHtmlEnd());
01555 
01556 }
01557 
01558 
01566 function TasksDelete()
01567 {
01568     global $PH;
01569     $tsk=get('tsk');
01570     $tasks_selected=get('tasks_*');
01571     $ids=getPassedIds('tsk','tasks_*');
01572 
01573     $tasks= array();
01574 
01575     if(count($ids)==1) {
01576         $tsk=$ids[0];
01577         if(!$task= Task::getEditableById($tsk)) {
01578             $PH->abortWarning(__('insuffient rights'),ERROR_RIGHTS);
01579             $PH->show('home');
01580             return;
01581         }
01582         $tasks[]= $task;
01583     }
01584     else if($ids) {
01585        #--- get tasks ----
01586 
01587         $num_tasks=count($tasks);
01588         foreach($ids as $id) {
01589             if(!$task= Task::getEditableById($id)) {
01590                 $PH->abortWarning("invalid task-id");
01591             }
01592             $tasks[]= $task;
01593         }
01594     }
01595 
01596     if($tasks) {
01597 
01598         $num_subtasks = 0;
01599         $num_tasks= 0;
01600 
01601         foreach($tasks as $task) {
01602 
01603             $num_subtasks+= $task->ungroupSubtasks();
01604 
01605             if(!$task->delete()) {
01606                 new FeedbackWarning(sprintf(__("Failed to delete task %s"), $task->name));
01607             }
01608             else {
01609                 $num_tasks++;
01610             }
01611         }
01612         new FeedbackMessage(sprintf(__("Moved %s tasks to trash"),$num_tasks));
01613 
01614         if($num_subtasks) {
01615             new FeedbackMessage(sprintf(__(" ungrouped %s subtasks to above parents."),$num_subtasks));
01616         }
01617 
01618         ### return to from-page? ###
01619         if(!$PH->showFromPage()) {
01620             $PH->show('home');
01621         }
01622     }
01623     else {
01624         new FeedbackHint(__("No task(s) selected for deletion..."));
01625         if(!$PH->showFromPage()) {
01626             $PH->show('home');
01627         }
01628     }
01629 }
01630 
01636 function TasksUndelete()
01637 {
01638     global $PH;
01639     $tsk=get('tsk');
01640     $tasks_selected=get('tasks_*');
01641     $ids=getPassedIds('tsk','tasks_*');
01642 
01643 
01644     if(count($ids)==1) {
01645         $tsk=$ids[0];
01646         $task= Task::getEditableById($tsk);
01647         if(!$task) {
01648             new FeedbackWarning(__("Could not find task"));
01649             $PH->show('home');
01650             return;
01651         }
01652 
01653         ### check user-rights ###
01654         if(!$project= Project::getVisibleById($task->project)) {
01655             $PH->abortWarning("task without project?", ERROR_BUG);
01656         }
01657 
01658         ### delete task ###
01659         if($task->state!= -1) {
01660             new FeedbackHint(sprintf(__("Task <b>%s</b> does not need to be restored"),$task->name));
01661         }
01662         else {
01663             $task->state=1;
01664             if($task->update()) {
01665                 new FeedbackMessage(sprintf(__("Task <b>%s</b> restored"),$task->name));
01666                 $task->nowChangedByUser();
01667             }
01668             else {
01669                 new FeedbackMessage(sprintf(__("Failed to restore Task <b>%s</b>"),$task->name));
01670             }
01671         }
01672 
01673         ### go to project view ###
01674         ### return to from-page? ###
01675         if(!$PH->showFromPage()) {
01676             $PH->show('projView',array('prj'=>$project->id));
01677         }
01678     }
01679     else if($ids) {
01680        #--- get tasks ----
01681         $tasks=array();
01682         $num_tasks=count($tasks);
01683         $num_subtasks=0;
01684 
01685         foreach($ids as $id) {
01686 
01687             if(!$task = Task::getEditableById($id)) {
01688                 new FeedbackWarning("Could not find task");
01689                 $PH->show('home');
01690                 return;
01691             }
01692 
01693             ### delete task ###
01694             if($task->state!= -1) {
01695                 new FeedbackHint(sprintf(__("Task <b>%s</b> do not need to be restored"), $task->name));
01696             }
01697             else {
01698                 $task->state=1;
01699                 if($task->update()) {
01700                     new FeedbackMessage(sprintf(__("Task <b>%s</b> restored"),$task->name));
01701                 }
01702                 else {
01703                     new FeedbackWarning(sprintf(__("Failed to restore Task <b>%s</b>"),$task->name));
01704                 }
01705             }
01706         }
01707 
01708         ### return to from-page? ###
01709         if(!$PH->showFromPage()) {
01710             $PH->show('home');
01711         }
01712     }
01713     else {
01714         new FeedbackHint(__("No task(s) selected for restoring..."));
01715         if(!$PH->showFromPage()) {
01716             $PH->show('home');
01717         }
01718     }
01719 }
01720 
01721 
01727 function TasksComplete()
01728 {
01729     global $PH;
01730 
01731     $ids= getPassedIds('tsk','tasks_*');
01732 
01733     if(!$ids) {
01734         $PH->abortWarning(__("Select some task(s) to mark as completed"), ERROR_NOTE);
01735         return;
01736     }
01737 
01738     $count=0;
01739     $count_subtasks=0;
01740     $num_errors=0;
01741 
01742     foreach($ids as $id) {
01743         if($task= Task::getEditableById($id)) {
01744 
01745             $count++;
01746             $task->status=5;
01747             $task->date_closed= gmdate("Y-m-d", time());
01748             $task->completion=100;
01749             $task->update();
01750             $task->nowChangedByUser();
01751 
01752             ### get all subtasks ###
01753             if($subtasks= $task->getSubtasks()) {
01754                 foreach($subtasks as $st) {
01755                     if($subtask_editable= Task::getEditableById($st->id)) {
01756                         $count_subtasks++;
01757                         $subtask_editable->status=5;
01758                         $subtask_editable->date_closed= gmdate("Y-m-d", time());
01759                         $subtask_editable->completion=100;
01760                         $subtask_editable->update();
01761                         $subtask_editable->nowChangedByUser();
01762                     }
01763                     else {
01764                         $num_errors++;
01765                     }
01766                 }
01767             }
01768         }
01769         else {
01770             $num_errors++;
01771         }
01772     }
01773     $str_subtasks= $count_subtasks
01774      ? "(including $count_subtasks subtasks)"
01775      : "";
01776 
01777     new FeedbackMessage(sprintf(__("Marked %s tasks (%s subtasks) as completed."),$count,$str_subtasks)) ;
01778     if($num_errors) {
01779         new FeedbackWarning(sprintf(__("%s error(s) occured"), $num_errors));
01780     }
01781 
01782     ### return to from-page ###
01783     if(!$PH->showFromPage()) {
01784         $PH->show('home');
01785     }
01786 }
01787 
01793 function TasksApproved()
01794 {
01795     global $PH;
01796 
01797     $ids= getPassedIds('tsk','tasks_*');
01798 
01799     if(!$ids) {
01800         $PH->abortWarning(__("Select some task(s) to mark as approved"), ERROR_NOTE);
01801         return;
01802     }
01803 
01804     $count=0;
01805     $num_errors=0;
01806     foreach($ids as $id) {
01807         if($task= Task::getEditableById($id)) {
01808 
01809             $count++;
01810             $task->status = STATUS_APPROVED;
01811             $task->date_closed = gmdate("Y-m-d", time());
01812             $task->completion = 100;
01813             $task->update();
01814             $task->nowChangedByUser();
01815         }
01816         else {
01817             $num_errors++;
01818         }
01819 
01820     }
01821     new FeedbackMessage(sprintf(__("Marked %s tasks as approved and hidden from project-view."),$count));
01822     if($num_errors) {
01823         new FeedbackWarning(sprintf(__("%s error(s) occured"), $num_errors));
01824     }
01825 
01826     ### return to from-page ###
01827     if(!$PH->showFromPage()) {
01828         $PH->show('home');
01829     }
01830 }
01831 
01832 
01838 function TasksClosed()
01839 {
01840     global $PH;
01841 
01842     $ids= getPassedIds('tsk','tasks_*');
01843 
01844     if(!$ids) {
01845         $PH->abortWarning(__("Select some task(s) to mark as closed"), ERROR_NOTE);
01846         return;
01847     }
01848 
01849     $count=0;
01850     $num_errors=0;
01851     foreach($ids as $id) {
01852         if($task= Task::getEditableById($id)) {
01853 
01854             $count++;
01855             $task->status = STATUS_CLOSED;
01856             $task->date_closed = gmdate("Y-m-d", time());
01857             $task->completion = 100;
01858             $task->update();
01859             $task->nowChangedByUser();
01860         }
01861         else {
01862             $num_errors++;
01863         }
01864 
01865     }
01866     new FeedbackMessage(sprintf(__("Marked %s tasks as closed."),$count));
01867     if($num_errors) {
01868         new FeedbackWarning(sprintf(__("Not enough rights to close %s tasks."), $num_errors));
01869     }
01870 
01871     ### return to from-page ###
01872     if(!$PH->showFromPage()) {
01873         $PH->show('home');
01874     }
01875 }
01876 
01882 function TasksReopen()
01883 {
01884     global $PH;
01885 
01886     $ids= getPassedIds('tsk','tasks_*');
01887 
01888     if(!$ids) {
01889         $PH->abortWarning(__("Select some task(s) to reopen"), ERROR_NOTE);
01890         return;
01891     }
01892 
01893     $count  =0;
01894     $num_errors =0;
01895     foreach($ids as $id) {
01896         if($task= Task::getEditableById($id)) {
01897 
01898             $count++;
01899             $task->status=STATUS_OPEN;
01900             $task->update();
01901             $task->nowChangedByUser();
01902         }
01903         else {
01904             $num_errors++;
01905         }
01906 
01907     }
01908     new FeedbackMessage(sprintf(__("Reopened %s tasks."),$count));
01909     if($num_errors) {
01910         new FeedbackWarning(sprintf(__("%s error(s) occured"), $num_errors));
01911     }
01912 
01913     ### return to from-page ###
01914     if(!$PH->showFromPage()) {
01915         $PH->show('home');
01916     }
01917 }
01918 
01919 
01920 
01921 
01927 function TaskToggleViewCollapsed()
01928 {
01929     global $PH;
01930     global $auth;
01931 
01932     $ids= getPassedIds('tsk','tasks_*');
01933 
01934     if(!$ids) {
01935         $PH->abortWarning(__("Select some task(s)"), ERROR_NOTE);
01936         return;
01937     }
01938 
01939     $count  = 0;
01940     $num_errors = 0;
01941     foreach($ids as $id) {
01942         if($task= Task::getVisibleById($id)) {
01943 
01944             if($task->view_collapsed) {
01945                 $task->view_collapsed= 0;
01946             }
01947             else {
01948                 $task->view_collapsed= 1;
01949             }
01950             if(!$task->update(array('view_collapsed'),false)) {
01951                 new FeedbackError(__("Could not update task"));
01952                 $num_errors++;
01953             }
01954             else {
01955                 $count++;
01956             }
01957         }
01958         else {
01959             $num_errors++;
01960         }
01961     }
01962     if($num_errors) {
01963         new FeedbackWarning(sprintf(__("%s error(s) occured"), $num_errors));
01964     }
01965 
01966     ### return to from-page ###
01967     if(!$PH->showFromPage()) {
01968         $PH->show('home');
01969     }
01970 }
01971 
01972 
01973 
01979 function TaskAddIssueReport()
01980 {
01981     global $PH;
01982 
01983 
01984     $id= getOnePassedId('tsk','tasks_*',true,__('No task selected to add issue-report?'));
01985 
01986     if($task= Task::getEditableById($id)) {
01987         if($task->issue_report) {
01988             $PH->abortWarning(__("Task already has an issue-report"));
01989             exit();
01990         }
01991 
01992         ### check user-rights ###
01993         if(!$project= Project::getVisibleById($task->project)) {
01994             $PH->abortWarning(__("task without project?"), ERROR_BUG);
01995         }
01996 
01997         $task->issue_report= -1;
01998         new FeedbackHint(__("Adding issue-report to task"));
01999         $PH->show('taskEdit',array('tsk'=>$task->id),$task);
02000         exit();
02001 
02002     }
02003     else {
02004         new FeedbackWarning(__("Could not find task"));
02005     }
02006 
02007     ### return to from-page ###
02008     if(!$PH->showFromPage()) {
02009         $PH->show('home');
02010     }
02011 }
02012 
02013 
02019 function taskEditDescription($task=NULL)
02020 {
02021     global $PH;
02022 
02023     ### object or from database? ###
02024     if(!$task) {
02025 
02026         $id= getOnePassedId('tsk','tasks_*');
02027 
02028         if(!$task = Task::getEditableById($id)) {
02029             $PH->abortWarning(__("Select a task to edit description"), ERROR_NOTE);
02030             return;
02031         }
02032     }
02033 
02034     ### set up page and write header ####
02035     {
02036         $page= new Page(array('use_jscalendar'=>false, 'autofocus_field'=>'task_name'));
02037         $page->cur_tab='projects';
02038 
02039         if($task) {
02040             $page->crumbs=build_task_crumbs($task);
02041         }
02042         $page->crumbs[]=new NaviCrumb(array(
02043             'target_id' => 'taskEditDescription',
02044 
02045         ));
02046 
02047         $page->type=__("Task");
02048         $page->title= $task->name;
02049 
02050         $page->title_minor= __("Edit description");
02051 
02052         echo(new PageHeader);
02053     }
02054     echo (new PageContentOpen);
02055 
02056 
02057     ### write form #####
02058     {
02059         require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
02060 
02061         $block=new PageBlock(array(
02062             'id'    =>'edit',
02063             'reduced_header' => true,
02064         ));
02065         $block->render_blockStart();
02066 
02067         $form=new PageForm();
02068         $form->button_cancel=true;
02069 
02070 
02071         $form->add(new Form_HiddenField('task_id','',$task->id));
02072         $form->add($task->fields['name']->getFormElement(&$task));
02073         $e= $task->fields['description']->getFormElement(&$task);
02074         $e->rows=22;
02075         $form->add($e);
02076 
02077         echo ($form);
02078 
02079         $block->render_blockEnd();
02080 
02081         $PH->go_submit= 'taskEditDescriptionSubmit';
02082     }
02083     echo (new PageContentClose);
02084     echo (new PageHtmlEnd);
02085 
02086 
02087 }
02088 
02094 function taskEditDescriptionSubmit()
02095 {
02096     global $PH;
02097 
02098     ### cancel? ###
02099     if(get('form_do_cancel')) {
02100         if(!$PH->showFromPage()) {
02101             $PH->show('taskView',array('tsk'=>$task->id));
02102         }
02103         exit();
02104     }
02105 
02106     if(!$task = Task::getEditableById(intval(get('task_id')))) {
02107         $PH->abortWarning("unknown task-id");
02108     }
02109 
02110     $name= get('task_name');
02111     if(!is_null($name)) {
02112         $task->name= $name;
02113     }
02114 
02115     $description= get('task_description');
02116     if(!is_null($description)) {
02117         $task->description= $description;
02118     }
02119 
02120 
02121     ### validate ###
02122     if(!$task->name) {
02123         new FeedbackWarning(__("Task requires name"));
02124     }
02125 
02126     ### repeat form if invalid data ###
02127     if(!$task->name) {
02128         $PH->show('taskEditDescription',NULL,$task);
02129 
02130         exit();
02131     }
02132 
02133 
02134     ### write to db ###
02135     $task->update(array('name','description'));
02136 
02137     ### return to from-page? ###
02138     if(!$PH->showFromPage()) {
02139         $PH->show('taskView',array('tsk'=>$task->id));
02140     }
02141 }
02142 
02143 
02144 
02145 
02151 function TaskViewEfforts()
02152 {
02153     global $PH;
02154 
02155     require_once(confGet('DIR_STREBER') . 'lists/list_efforts.inc.php');
02156 
02157     ### get current project ###
02158     $id=getOnePassedId('task','tasks_*');
02159     if(!$task=Task::getVisibleById($id)) {
02160         $PH->abortWarning("invalid task-id");
02161         return;
02162     }
02163 
02164     ### create from handle ###
02165     $PH->defineFromHandle(array('task'=>$task->id));
02166 
02167     if(!$project= Project::getVisibleById($task->project)) {
02168         $PH->abortWarning("not enough rights");
02169     }
02170 
02171     ### set up page ####
02172     {
02173         $page= new Page();
02174         $page->cur_tab='projects';
02175 
02176         $page->cur_crumb= 'projViewTasks';
02177         $page->crumbs= build_project_crumbs($project);
02178         $page->options= build_projView_options($project);
02179 
02180         $page->title=$task->name;
02181         $page->title_minor= __("Task Efforts");
02182 
02183         $page->type= $task->renderTypeAsBreadcrumbs();
02184 
02185         ### page functions ###
02186         $page->add_function(new PageFunction(array(
02187             'target'=>'effortNew',
02188             'params'=>array('task'=>$task->id),
02189             'icon'=>'new',
02190             'name'=>__('new Effort'),
02191         )));
02192 
02193 
02194         ### render title ###
02195         echo(new PageHeader);
02196     }
02197     echo (new PageContentOpen);
02198 
02199     #--- list efforts --------------------------------------------------------------------------
02200     {
02201         $order_by=get('sort_'.$PH->cur_page->id."_efforts");
02202 
02203         require_once(confGet('DIR_STREBER') . 'db/class_effort.inc.php');
02204         $efforts= Effort::getAll(array(
02205             'task'      => $task->id,
02206             'order_by'  => $order_by,
02207 
02208         ));
02209         $list= new ListBlock_efforts();
02210         $list->reduced_header= true;
02211 
02212         $list->render_list(&$efforts);
02213     }
02214 
02215     ### 'add new task'-field ###
02216     $PH->go_submit='effortNew';
02217     echo '<input type="hidden" name="task" value="'.$id.'">';
02218 
02219     echo (new PageContentClose);
02220     echo (new PageHtmlEnd());
02221 }
02222 
02223 
02224 
02230 function TaskEditMultiple()
02231 {
02232     global $PH;
02233 
02234     $task_ids= getPassedIds('tsk','tasks_*');
02235 
02236     if(!$task_ids) {
02237         $PH->abortWarning(__("Select some tasks to move"));
02238         exit();
02239     }
02240 
02241     $count  = 0;
02242     $count_subtasks = 0;
02243     $errors = 0;
02244 
02245     $last_milestone_id=NULL;
02246     $different_milestones=false;
02247 
02248     $last_status=NULL;
02249     $different_status=false;
02250 
02251     $project= NULL;
02252 
02253     $tasks= array();
02254 
02255     $task_assignments = array();
02256     $task_assignments_count = array();
02257     $different_assignments = false;
02258 
02259     $edit_fields=array(
02260         'category',
02261         'prio',
02262         'status',
02263         'for_milestone',
02264         'resolved_version',
02265         'resolve_reason',
02266         'label',
02267         'pub_level'
02268     );
02269     $different_fields=array();  # hash containing fieldnames which are different in tasks
02270 
02271     $count=0;
02272 
02273     foreach($task_ids as $id) {
02274         if($task= Task::getEditableById($id)) {
02275 
02276             $tasks[]= $task;
02277 
02278             ## get assigned persons ##
02279             if($task_persons = $task->getAssignedPersons(false))
02280             {
02281                 $counter = 0;
02282                 foreach($task_persons as $tp){
02283                     $task_assignments[$task->id][$counter++] = $tp->id;
02284                 }
02285                 $task_assignments_count[$task->id] = count($task_persons);
02286             }
02287             ## if nobody is assigned
02288             else{
02289                 $task_assignments[$task->id][0] = '__none__';
02290                 $task_assignments_count[$task->id] = 0;
02291             }
02292 
02293             ### check project for first task
02294             if(count($tasks) == 1) {
02295 
02296                 ### make sure all are of same project ###
02297                 if(!$project = Project::getVisibleById($task->project)) {
02298                     $PH->abortWarning('could not get project');
02299                 }
02300             }
02301             else {
02302                 if($task->project != $tasks[0]->project) {
02303                     $PH->abortWarning(__("For editing all tasks must be of same project."));
02304                 }
02305 
02306                 foreach($edit_fields as $field_name) {
02307                     if($task->$field_name !== $tasks[0]->$field_name) {
02308                         $different_fields[$field_name]= true;
02309                     }
02310                 }
02311 
02312                 ## check if tasks have different persons assigned ##
02313                 if($task_assignments_count[$tasks[0]->id] != $task_assignments_count[$task->id]){
02314                     $different_assignments = true;
02315                 }
02316                 else{
02317                     for($i = 0; $i < $task_assignments_count[$tasks[0]->id]; $i++){
02318                         if($task_assignments[$tasks[0]->id][$i] != $task_assignments[$task->id][$i]){
02319                             $different_assignments = true;
02320                         }
02321                     }
02322                 }
02323             }
02324         }
02325     }
02326 
02327 
02328     ### set up page and write header ####
02329     {
02330         $page= new Page(array('use_jscalendar'=>true,'autofocus_field'=>'task_name'));
02331         $page->cur_tab='projects';
02332 
02333 
02334         #$page->crumbs=build_task_crumbs($task,$project);
02335         $page->options[]= new naviOption(array(
02336             'target_id'     =>'taskEdit',
02337         ));
02338 
02339         $page->type= __("Edit multiple tasks","Page title");
02340 
02341         $page->title= sprintf(__("Edit %s tasks","Page title"), count($tasks));
02342 
02343         echo(new PageHeader);
02344     }
02345     echo (new PageContentOpen);
02346 
02347 
02348     ### write form #####
02349     {
02350         require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
02351 
02352         global $g_status_names;
02353 
02354         echo "<ol>";
02355         foreach($tasks as $t) {
02356             echo "<li>" . $t->getLink(false). "</li>";
02357         }
02358         echo "</ol>";
02359 
02360         $form=new PageForm();
02361         $form->button_cancel=true;
02362 
02363         #$form->add($tasks[0]->fields['name']->getFormElement(&$tasks[0]));
02364         #$form->add($tasks[0]->fields['short']->getFormElement(&$tasks[0]));
02365 
02366 
02367 
02368 
02369         ### category ###
02370         {
02371             $a= array();
02372             global $g_tcategory_names;
02373             foreach($g_tcategory_names as $s=>$n) {
02374                 $a[$s]=$n;
02375             }
02376             if(isset($different_fields['category'])) {
02377                 $a['__dont_change__']= ('-- ' . __('keep different'). ' --');
02378                 $form->add(new Form_Dropdown('task_category',__("Category"),array_flip($a),  '__dont_change__'));
02379             }
02380             else {
02381                 $form->add(new Form_Dropdown('task_category',__("Category"),array_flip($a),  $tasks[0]->category));
02382             }
02383         }
02384 
02385 
02386         ### status ###
02387         {
02388             $st=array();
02389             foreach($g_status_names as $s => $n) {
02390                 if($s >= STATUS_NEW) {
02391                     $st[$s]=$n;
02392                 }
02393             }
02394             if(isset($different_fields['status'])) {
02395                 $st['__dont_change__']= ('-- ' . __('keep different'). ' --');
02396                 #$st[('-- ' . __('keep different'). ' --')]=  '__dont_change__';
02397                 $form->add(new Form_Dropdown('task_status',__("Status"),array_flip($st),  '__dont_change__'));
02398             }
02399             else {
02400                 $form->add(new Form_Dropdown('task_status',__("Status"),array_flip($st),  $tasks[0]->status));
02401             }
02402         }
02403 
02404 
02405         ### public-level ###
02406         if(($pub_levels=$task->getValidUserSetPublevel())
02407             && count($pub_levels)>1) {
02408             if(isset($different_fields['pub_level'])) {
02409                 $pub_levels[('-- ' . __('keep different'). ' --')]= '__dont_change__';
02410                 $form->add(new Form_Dropdown('task_pub_level',  __("Publish to"),$pub_levels, '__dont_change__'));
02411             }
02412             else {
02413                 $form->add(new Form_Dropdown('task_pub_level',  __("Publish to"),$pub_levels,$tasks[0]->pub_level));
02414             }
02415 
02416         }
02417 
02418         ### labels ###
02419         $labels=array(__('undefined') => 0);
02420         $counter= 1;
02421         foreach(split(",",$project->labels) as $l) {
02422             $labels[$l]=$counter++;
02423         }
02424         if(isset($different_fields['label'])) {
02425             $labels[('-- ' . __('keep different'). ' --')]= '__dont_change__';
02426             $form->add(new Form_Dropdown('task_label',  __("Label"),$labels, '__dont_change__'));
02427         }
02428         else {
02429             $form->add(new Form_Dropdown('task_label',  __("Label"),$labels,$tasks[0]->label));
02430         }
02431 
02432 
02433 
02434         ### prio ###
02435         {
02436             global $g_prio_names;
02437             $pr= array();
02438             foreach($g_prio_names as $key => $value) {
02439                 $pr[$key]= $value;
02440             }
02441             if(isset($different_fields['prio'])) {
02442                 $pr['__dont_change__']= ('-- ' . __('keep different'). ' --');
02443                 $form->add(new Form_Dropdown('task_prio',__("Prio"),array_flip($pr),  '__dont_change__'));
02444             }
02445             else {
02446                 $form->add(new Form_Dropdown('task_prio',__("Prio"),array_flip($pr),  $tasks[0]->prio));
02447             }
02448         }
02449 
02450 
02451         ### milestone ###
02452         {
02453             if($milestones= Task::getAll(array(
02454                 'is_milestone'  =>1,
02455                 'project'       => $tasks[0]->project,
02456                 'status_min'    => 0,
02457                 'status_max'    => 100,
02458             ))) {
02459                 $tmp_milestonelist= array('0' => ('-- ' . __('none') . ' --'));
02460 
02461                 foreach($milestones as $m) {
02462                     $tmp_milestonelist[$m->id]= $m->name;
02463                 }
02464                 if(isset($different_fields['for_milestone'])) {
02465                     $tmp_milestonelist['__dont_change__']= ('-- ' . __('keep different'). ' --');
02466                     $form->add(new Form_Dropdown('task_for_milestone', __('For Milestone'),array_flip($tmp_milestonelist),'__dont_change__'));
02467                 }
02468                 else {
02469                     $form->add(new Form_Dropdown('task_for_milestone', __('For Milestone'),array_flip($tmp_milestonelist),$tasks[0]->for_milestone));
02470                 }
02471             }
02472         }
02473 
02474         ### resolved_version ###
02475         {
02476             if($milestones= Task::getAll(array(
02477                 'is_milestone'  =>1,
02478                 'project'       => $tasks[0]->project,
02479                 'is_released_min'   => RELEASED_UPCOMMING,
02480             ))) {
02481                 $tmp_milestonelist= array(
02482                     '0' => ('-- ' . __('none') . ' --'),
02483                     '-1' => ('-- ' . __('next released version')));
02484 
02485                 foreach($milestones as $m) {
02486                     $tmp_milestonelist[$m->id]= $m->name;
02487                 }
02488                 if(isset($different_fields['resolved_version'])) {
02489                     $tmp_milestonelist['__dont_change__']= ('-- '. __('keep different') . ' --');
02490                     $form->add(new Form_Dropdown('task_resolved_version', __('resolved in Version'),array_flip($tmp_milestonelist),'__dont_change__'));
02491                 }
02492                 else {
02493                     $form->add(new Form_Dropdown('task_resolved_version', __('resolved in Version'),array_flip($tmp_milestonelist),$tasks[0]->resolved_version));
02494                 }
02495             }
02496         }
02497 
02498 
02499 
02500         ### resolve reason ###
02501         {
02502             global $g_resolve_reason_names;
02503             $rr= array();
02504             foreach($g_resolve_reason_names as $key => $value) {
02505                 $rr[$key]= $value;
02506             }
02507             if(isset($different_fields['resolve_reason'])) {
02508                 $rr['__dont_change__']= ('-- ' . __('keep different') . ' --');
02509                 $form->add(new Form_Dropdown('task_resolve_reason',__("Resolve Reason"),array_flip($rr),  '__dont_change__'));
02510             }
02511             else {
02512                 $form->add(new Form_Dropdown('task_resolve_reason',__("Resolve Reason"),array_flip($rr),  $tasks[0]->resolve_reason));
02513             }
02514         }
02515 
02516         ## assignement ##
02517         {
02518             $ass = array();
02519             $ass_also = array();
02520 
02521             ## get project team ##
02522             if($proj_persons = $project->getPersons()){
02523                 foreach($proj_persons as $pp){
02524                     $ass[$pp->id] = $pp->name;
02525                     $ass_also[$pp->id] = $pp->name;
02526                 }
02527             }
02528 
02529             ## different persons assigend? ##
02530             if($different_assignments){
02531                 $ass['__dont_change__'] = ('-- ' . __('keep different') . ' --');
02532                 $form->add(new Form_Dropdown('task_assignement_diff', __('Assigned to'), array_flip($ass), '__dont_change__'));
02533 
02534                 $ass_also['__select_person__'] = ('-- ' . __('select person') . ' --');
02535                 $form->add(new Form_Dropdown('task_assignement_also_diff', __('Also assigned to'), array_flip($ass_also), '__select_person__'));
02536             }
02537             else{
02538                 $ass['__none__'] = ('-- ' . __('none') . ' --');
02539                 foreach($task_assignments[$tasks[0]->id] as $key=>$value)
02540                 {
02541                     $form->add(new Form_Dropdown('task_assign_to_'.$task_assignments[$tasks[0]->id][$key], __('Assigned to'), array_flip($ass), $task_assignments[$tasks[0]->id][$key]));
02542                 }
02543 
02544                 $ass_also['__select_person__'] = ('-- ' . __('select person') . ' --');
02545                 $form->add(new Form_Dropdown('task_assign_to_0', __('Also assigned to'), array_flip($ass_also), '__select_person__'));
02546             }
02547         }
02548 
02549         foreach($tasks as $t) {
02550             $form->add(new Form_HiddenField("tasks_{$t->id}_chk",'',1));
02551         }
02552         $form->add(new Form_HiddenField('different_ass','',$different_assignments));
02553         #$form->add(new Form_HiddenField('task_project','',$project->id));
02554 
02555         echo($form);
02556 
02557         $PH->go_submit= 'taskEditMultipleSubmit';
02558         if($return=get('return')) {
02559             echo "<input type=hidden name='return' value='$return'>";
02560         }
02561     }
02562 
02563     echo (new PageContentClose);
02564     echo (new PageHtmlEnd);
02565 
02566     exit();
02567 }
02568 
02569 
02570 
02576 function taskEditMultipleSubmit()
02577 {
02578     global $PH;
02579 
02580     $ids= getPassedIds('tsk','tasks_*');
02581 
02582     if(!$ids) {
02583         $PH->abortWarning(__("Select some task(s) to mark as approved"), ERROR_NOTE);
02584         return;
02585     }
02586 
02587     $count=0;
02588     $errors=0;
02589     $number = get('number');
02590 
02591     ### cancel? ###
02592     if(get('form_do_cancel')) {
02593         if(!$PH->showFromPage()) {
02594             $PH->show('home');
02595         }
02596         exit();
02597     }
02598 
02599     foreach($ids as $id) {
02600         if($task= Task::getEditableById($id)) {
02601             $count++;
02602             $change= false;;
02603 
02604             $status_old= $task->status;
02605 
02606 
02607             ### status ###
02608             if($count == 1){
02609                 if(!$project = Project::getVisibleById($task->project)) {
02610                     $PH->abortWarning('could not get project');
02611                 }
02612 
02613                 $team= array();
02614                 foreach($project->getPersons() as $p) {
02615                     $team[$p->id]= $p;
02616                 }
02617             }
02618 
02619             ### assignment ###
02620             {
02621                 $task_assigned_persons = array();
02622                 $task_assignments = array();
02623                 $task_persons_overwrite = array();
02624                 $task_persons_new = array();
02625                 $task_persons_delete = array();
02626 
02627                 ## previous assigend persons ##
02628                 if($task_persons = $task->getAssignedPersons(false))
02629                 {
02630                     foreach($task_persons as $tp){
02631                         $task_assigned_persons[$tp->id] = $tp;
02632                     }
02633                 }
02634 
02635                 ## previous assignements ##
02636                 if($task_assign = $task->getAssignments())
02637                 {
02638                     foreach($task_assign as $ta){
02639                         $task_assignments[$ta->person] = $ta;
02640                     }
02641                 }
02642 
02643                 ## different assigned persons ##
02644                 ## overwrite ?? ##
02645                 $ass1 = get('task_assignement_diff');
02646                 if($ass1 && $ass1 != '__dont_change__'){
02647                     $task_persons_overwrite[] = $ass1;
02648                     foreach($task_assignments as $key=>$value){
02649                         $task_persons_delete[] = $value;
02650                     }
02651                     $change = true;
02652                 }
02653 
02654                 ## new ?? ##
02655                 $ass2 = get('task_assignement_also_diff');
02656                 if($ass2 && $ass2 != '__select_person__'){
02657                     $task_persons_new[] = $ass2;
02658                     $change = true;
02659                 }
02660 
02661                 $different = get('different_ass');
02662                 if(isset($different) && !$different){
02663                     if(isset($task_assignments) && count($task_assignments) != 0){
02664                         foreach($task_assignments as $tid=>$t_old){
02665                             $id_new = get('task_assign_to_'.$tid);
02666                             ## no changes ##
02667                             if($tid == $id_new){
02668                                 continue;
02669                             }
02670 
02671                             if($id_new == '__none__'){
02672                                 if(!$t_old){
02673                                     continue;
02674                                 }
02675                                 $task_persons_delete[] = $t_old;
02676                                 continue;
02677                             }
02678 
02679                             $task_persons_delete[] = $t_old;
02680                             $task_persons_overwrite[] = $id_new;
02681                         }
02682                     }
02683                     else{
02684                         $id_new = get('task_assign_to___none__');
02685                         if($id_new && $id_new != '__none__'){
02686                             $task_persons_new[] = $id_new;
02687                         }
02688                     }
02689 
02690                     $id_new = get('task_assign_to_0');
02691                     if($id_new != '__select_person__'){
02692                         if(!isset($task_assignments[$id_new])){
02693                             $task_persons_new[] = $id_new;
02694                         }
02695                     }
02696 
02697                     $change = true;
02698                 }
02699             }
02700 
02701 
02702             ### category ###
02703             $v= get('task_category');
02704             if(!is_null($v) && $v != '__dont_change__' && $v != $task->category) {
02705                 $task->category= $v;
02706                 $change= true;
02707             }
02708 
02709 
02710             ### status ###
02711             $status= get('task_status');
02712             if($status && $status != '__dont_change__' && $status != $task->status) {
02713                 $task->status= $status;
02714                 $change= true;
02715             }
02716 
02717             ### prio ###
02718             $prio= get('task_prio');
02719             if($prio && $prio != '__dont_change__' && $prio != $task->prio) {
02720                 $task->prio= $prio;
02721                 $change= true;
02722             }
02723 
02724             ### pub level ###
02725             $pub_level= get('task_pub_level');
02726             if($pub_level && $pub_level != '__dont_change__' && $pub_level != $task->pub_level) {
02727 
02728 
02729                if($pub_level > $task->getValidUserSetPublevel() ) {
02730                    $PH->abortWarning('invalid data',ERROR_RIGHTS);
02731                }
02732                $task->pub_level= $pub_level;
02733                $change= true;
02734             }
02735 
02736             ### label ###
02737             $label= get('task_label');
02738             if($label && $label != '__dont_change__' && $label != $task->label) {
02739                 $task->label= $label;
02740                 $change= true;
02741             }
02742 
02743             ### for milestone ###
02744             $fm= get('task_for_milestone');
02745             if(!is_null($fm) && $fm != '__dont_change__' && $task->for_milestone != $fm) {
02746                 if($fm) {
02747                     if(($m= Task::getVisibleById($fm)) && $m->is_milestone) {
02748                         $task->for_milestone= $fm;
02749                         $change= true;
02750                     }
02751                     else {
02752                         continue;
02753                     }
02754                 }
02755                 else {
02756                     $task->for_milestone= 0;
02757                     $change= true;
02758                 }
02759             }
02760 
02761             ### resolve version ###
02762             $rv= get('task_resolved_version');
02763 
02764             if((!is_null($rv)) && ($rv != '__dont_change__') && ($task->resolved_version != $rv)) {
02765                 if($rv && $rv != -1) {
02766                     if($v= Task::getVisibleById($rv)) {
02767                         if(($v->is_milestone) && ($v->is_released >= RELEASED_UPCOMMING)) {
02768                             $task->resolved_version= $rv;
02769                             $change= true;
02770                         }
02771                     }
02772                     else {
02773                         continue;
02774                     }
02775                 }
02776                 if($rv == -1) {
02777                     $task->resolved_version= $rv;
02778                     $change= true;
02779                 }
02780                 else {
02781                     $task->resolved_version= 0;
02782                     $change= true;
02783                 }
02784             }
02785 
02786             ### resolve reason ###
02787             $rs= get('task_resolve_reason');
02788             if($rs && $rs != '__dont_change__' && $rs != $rs->resolve_reason) {
02789                 $task->resolve_reason= $rs;
02790                 $change= true;
02791             }
02792 
02793 
02794             if($change) {
02795 
02796                 ### Check if now longer new ###
02797                 if($status_old == $task->status && $task->status == STATUS_NEW) {
02798                     global $auth;
02799                     if($task->created < $auth->cur_user->last_login) {
02800                         $task->status = STATUS_OPEN;
02801                     }
02802                 }
02803                 ## overwrite assigend persons ##
02804                 if(isset($task_persons_overwrite)){
02805                     if(isset($task_persons_delete)){
02806                         foreach($task_persons_delete as $tpd){
02807                             $tpd->delete();
02808                             
02809                         }
02810                     }
02811                     foreach($task_persons_overwrite as $tpo)
02812                     {
02813                         $task_pers_over = new TaskPerson(array(
02814                                         'person'=> $team[$tpo]->id,
02815                                         'task'  => $task->id,
02816                                         'comment'=>'',
02817                                         'project'=>$project->id,
02818                                         ));
02819                         $task_pers_over->insert();
02820                     }
02821                 }
02822 
02823                 ## add new person ##
02824                 if(isset($task_persons_new)){
02825                     foreach($task_persons_new as $tpn){
02826                         if(!isset($task_assigned_persons[$tpn]))
02827                         {
02828                             $task_pers_new = new TaskPerson(array(
02829                                          'person'=> $team[$tpn]->id,
02830                                          'task'  => $task->id,
02831                                          'comment'=>'',
02832                                          'project'=>$project->id,
02833                                           ));
02834                            $task_pers_new->insert();
02835                         }
02836                     }
02837 
02838                 }
02839 
02840                 ##update##
02841                 $task->update();
02842                 $task->nowChangedByUser();
02843             }
02844         }
02845         else {
02846             $errors++;
02847         }
02848     }
02849 
02850     ### compose message ###
02851     if($errors) {
02852         new FeedbackWarning(sprintf(__('%s tasks could not be written'), $errors));
02853     }
02854     else if($count) {
02855         new FeedbackMessage(sprintf(__('Updated %s tasks tasks'), $count));
02856     }
02857 
02858     ### return to from-page? ###
02859     if(!$PH->showFromPage()) {
02860         $PH->show('taskView',array('tsk'=>$task->id));
02861     }
02862 
02863 }
02864 
02865 
02866 
02867 
02868 
02869 
02875 function taskCollapseAllComments()
02876 {
02877     global $PH;
02878 
02879 
02884     ### get task ###
02885     $tsk=get('tsk');
02886 
02887     ### check sufficient user-rights ###
02888     if($task=Task::getEditableById($tsk)) {
02889         $ids= $task->getComments();
02890 
02891         foreach($ids as $obj) {
02892             if(!$comment=Comment::getEditableById($obj->id)) {
02893                 $PH->abortWarning('undefined comment','warning');
02894             }
02895             if(! $comment->view_collapsed) {
02896                 $comment->view_collapsed=1;
02897                 $comment->update();
02898             }
02899         }
02900     }
02901     else {
02906         ### abort, if not enough rights ###
02907         $PH->abortWarning(__('insuffient rights'),ERROR_RIGHTS);
02908     }
02909 
02910     ### display taskView ####
02911     if(!$PH->showFromPage()) {
02912         $PH->show('home');
02913     }
02914 }
02915 
02921 function taskExpandAllComments()
02922 {
02923     global $PH;
02924 
02929     ### get task ###
02930     $tsk= get('tsk');
02931 
02932     ### check sufficient user-rights ###
02933     if($task=Task::getEditableById($tsk)) {
02934         $ids= $task->getComments();
02935 
02936         foreach($ids as $obj) {
02937             if(!$comment=Comment::getEditableById($obj->id)) {
02938                 $PH->abortWarning('undefined comment','warning');
02939             }
02940 
02941             ### get all comments including all sub-comments
02942             $list= $comment->getAll();
02943             $list[]= $comment;
02944 
02945             foreach($list as $c) {
02946                 if($c->view_collapsed) {
02947                     $c->view_collapsed=0;
02948                     $c->update();
02949                 }
02950             }
02951         }
02952     }
02953     else {
02958         ### abort, if not enough rights ###
02959         $PH->abortWarning(__('insuffient rights'),ERROR_RIGHTS);
02960     }
02961 
02962     ### display taskView ####
02963     if(!$PH->showFromPage()) {
02964         $PH->show('home');
02965     }
02966 }
02967 
02973 function taskNoteOnPersonNew()
02974 {
02975     global $PH;
02976 
02977     ## get person ##
02978     $pid = getOnePassedId('person');
02979     if(!$person = Person::getById($pid)){
02980         $PH->abortWarning(__("ERROR: could not get Person"), ERROR_NOTE);
02981         return;
02982     }
02983 
02984     ## build new object ##
02985     $task_new = new Task(array(
02986             'id'        =>0,        # temporary new
02987             'name'      =>'',
02988             'state'     =>1,
02989              ));
02990 
02991     $PH->show('taskNoteOnPersonEdit',array('tsk'=>$task_new->id, 'person'=>$person->id), $task_new);
02992 }
02993 
02999 function taskNoteOnPersonEdit($task=NULL, $person=NULL)
03000 {
03001     global $PH;
03002     global $auth;
03003     global $g_pub_level_names;
03004     global $g_prio_names;
03005 
03006     if(!$task){
03007         $id = getOnePassedId('tsk');
03008 
03009         if(!$task = Task::getEditableById($id)) {
03010             $PH->abortWarning(__("Select a note to edit"), ERROR_NOTE);
03011             return;
03012         }
03013     }
03014 
03015     ## get person ##
03016     if(!$person){
03017         $pid = getOnePassedId('person');
03018         if(!$person = Person::getById($pid)) {
03019             $PH->abortWarning(__("ERROR: could not get Person"), ERROR_NOTE);
03020             return;
03021         }
03022     }
03023 
03024     ### set up page and write header ####
03025     {
03026         $page = new Page(array('use_jscalendar'=>false, 'autofocus_field'=>'task_name'));
03027         $page->cur_tab = 'people';
03028 
03029         if($person->id) {
03030             $page->crumbs=build_person_crumbs($person);
03031         }
03032         $page->crumbs[]=new NaviCrumb(array(
03033             'target_id' => 'taskNoteOnPersonEdit',
03034 
03035         ));
03036 
03037         $page->type=__("Note");
03038 
03039         if(!$task->id) {
03040             $page->title = __('Create new note');
03041             $page->title_minor=__('Edit');
03042             ## default title ##
03043             $date = gmdate("Y-m-d", time());
03044             $time = getGMTString();
03045             $dt = $date . " " . renderTime($time);
03046             $task->name = sprintf(__("New Note on %s, %s"),$person->name, $dt);
03047         }
03048         ## eventually needed later when note is a subcategory of task
03049         /*else {
03050             $page->title=$task->name;
03051             $page->title_minor=$task->short;
03052         }*/
03053 
03054         echo(new PageHeader);
03055     }
03056 
03057     echo (new PageContentOpen);
03058 
03059     ### write form #####
03060     {
03061         require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
03062 
03063         $form = new PageForm();
03064         $form->button_cancel=true;
03065 
03066         ## name field ##
03067         $form->add($task->fields['name']->getFormElement(&$task));
03068 
03069         ## description field ##
03070         $e = $task->fields['description']->getFormElement(&$task);
03071         $e->rows = 22;
03072         $form->add($e);
03073 
03074         ### public-level drop down menu ###
03075         $form->add(new Form_Dropdown('task_pub_level',  __("Publish to","Form label"), array_flip($g_pub_level_names), $task->pub_level));
03076 
03077         ## priority drop down menu##
03078         $form->add(new Form_Dropdown('task_prio',  __("Prio","Form label"),  array_flip($g_prio_names), $task->prio));
03079 
03080         ## project drop down menu ##
03081         {
03082             if($task->id == 0){
03083                 $proj_select = 0;
03084             }
03085             ## eventually needed later when note is a subcategory of task
03086             /*else {
03087                 if(!$project = $task->getProject()){
03088                     $PH->abortWarning(__("ERROR: could not get project"), ERROR_NOTE);
03089                     $proj_select = 0;
03090                 }
03091                 else{
03092                     $proj_select = $project->id;
03093                 }
03094             }*/
03095 
03096             $p_list = array();
03097             #$p_list[0] = __('Assigned Projects');
03098 
03099             $count = 1;
03100 
03101             $p_projects = $person->getProjects();
03102             $num = count($p_projects);
03103             /*if($num == 0){
03104                 $p_list['-1'] = __('- no assigend projects');
03105             }
03106             else{*/
03107             if($num > 0){
03108                 $p_list[0] = __('Assigned Projects');
03109                 foreach($p_projects as $pp){
03110                     $p_list[$pp->id] = "- " . $pp->name;
03111                     $count++;
03112                 }
03113             }
03114 
03115             #$p_list['-3'] = __('Company Projects');
03116 
03117             $p_companies = $person->getCompanies();
03118             $num = count($p_companies);
03119             /*if($num == 0){
03120                 $p_list['-4'] = __('- no company projects');
03121             }
03122             elseif($num == 1){
03123                 $c_id = $p_companies[0]->id;
03124                 $c_projects = Project::getAll(array('company'=>$c_id));
03125                 foreach($c_projects as $cp){
03126                     $p_list[$cp->id] = "- " . $cp->name;
03127                 }
03128             }
03129             else*/if($num > 0){
03130                 $p_list['-1'] = __('Company Projects');
03131                 foreach($p_companies as $pcs){
03132                     $c_id = $pcs->id;
03133                     $c_projects = Project::getAll(array('company'=>$c_id));
03134                     $count2 = 0;
03135                     foreach($c_projects as $cp){
03136                         $p_list[$cp->id] = "- " . $cp->name;
03137                     }
03138 
03139                 }
03140             }
03141 
03142             #$p_list['-5'] = __('All other Projects');
03143 
03144             if(!$projects = Project::getAll(array('order_by'=>'name ASC'))){
03145                 #$p_list['-6'] = __('- no other projects');
03146             }
03147             else{
03148                 $p_list['-2'] = __('All other Projects');
03149                 foreach($projects as $pj){
03150                     $p_list[$pj->id] = "- " . $pj->name;
03151                 }
03152             }
03153 
03154             $form->add(new Form_Dropdown('project',  __('For Project','form label'),array_flip($p_list), $proj_select, "id='proj_list'"));
03155         }
03156 
03157         ## new project ##
03158         if($task->id == 0){
03159             $form->add(new Form_checkbox('new_project',__('New Project','form label'), false, "id='proj_new_checkbox'"));
03160             $form->add(new Form_Input('new_project_name', __('Project name', 'form label'),false,NULL,false, "id='proj_new_input'","style='display:none'"));
03161         }
03162 
03163         ## Assignements ##
03164         {
03165             $checked1 = "";
03166             $checked2 = "";
03167 
03168             if($task->id == 0){
03169                 $checked1 = "checked";
03170                 $checked2 = "checked";
03171                 $person_select = -1;
03172             }
03173             ## eventually needed later when note is a subcategory of task
03174             /*else {
03175                 if(!$pperson = $task->getAssignedPersons()){
03176                     $PH->abortWarning(__("ERROR: could not get assigned persons"), ERROR_NOTE);
03177                 }
03178                 else{
03179                     foreach($pperson as $pp){
03180                         if($pp->id == $person->id){
03181                             $checked1= "checked";
03182                         }
03183                         elseif($pp->id == $auth->cur_user->id){
03184                             $checked2= "checked";
03185                         }
03186                         else{
03187                             $person_select = $pp->id;
03188                         }
03189                     }
03190                 }
03191             }*/
03192 
03193             $form->add(new Form_customHTML('<p><label>' . __('Assign to') . '</lable></p>', 'assigne_note'));
03194             if($person->id != $auth->cur_user->id){
03195                 $form->add(new Form_customHTML('<span class="checker"><input value="'.$person->id.'" name="task_assignement1" type="checkbox" ' . $checked1 .'><label for="task_assignement1">' . $person->name . '</label></span>', 'assigned_person1'));
03196                 $form->add(new Form_customHTML('<span class="checker"><input value="'.$auth->cur_user->id.'" name="task_assignement2" type="checkbox" ' . $checked2 .'><label for="task_assignement2">' . $auth->cur_user->name . '</label></span>', 'assigned_person2'));
03197             }
03198             else {
03199                 $form->add(new Form_customHTML('<span class="checker"><input value="'.$auth->cur_user->id.'" name="task_assignement2" type="checkbox" ' . $checked2 .'><label for="task_assignement2">' . $auth->cur_user->name . '</label></span>', 'assigned_person'));
03200             }
03201 
03202             $pers_list = array();
03203             $pers_list[-1] = __('undefined');
03204             if($persons = Person::getPersons(array('can_login'=>1))){
03205                 foreach($persons as $pers){
03206                     if($auth->cur_user->name <> $pers->name) {
03207                         $pers_list[$pers->id] = $pers->name;
03208                     }
03209                 }
03210             }
03211 
03212             $form->add(new Form_Dropdown('task_also_assign',  __('Also assign to') ,array_flip($pers_list), $person_select));
03213         }
03214 
03215         ## Book effort after submit ##
03216         $form->form_options[] = "<span class=option><input id='book_effort' name='book_effort' class='checker' type=checkbox>" . __("Book effort after submit") . "</span>";
03217 
03218         $form->add(new Form_HiddenField('tsk','',$task->id));
03219         $form->add(new Form_HiddenField('person_id','',$person->id));
03220         $form->add(new Form_HiddenField('creation_time','',$time));
03221 
03222         echo ($form);
03223 
03224         $PH->go_submit = 'taskNoteOnPersonEditSubmit';
03225     }
03226     echo (new PageContentClose);
03227     echo (new PageHtmlEnd);
03228 }
03229 
03230 
03236 function taskNoteOnPersonEditSubmit()
03237 {
03238     global $PH;
03239     global $auth;
03240     global $g_user_profile_names;
03241 
03242     ### cancel? ###
03243     if(get('form_do_cancel')) {
03244         if(!$PH->showFromPage()) {
03245             $PH->show('personView',array('person'=>getOnePassedId('person_id')));
03246         }
03247         exit();
03248     }
03249 
03250     ### temporary object or from database? ###
03251     $tsk_id = getOnePassedId('tsk','',true,'invalid id');
03252     if($tsk_id == 0) {
03253         $task = new Task(array(
03254                'id'=>0,
03255                ));
03256     }
03257     ## eventually needed later when note is a subcategory of task
03258     /*else {
03259         if(!$task= Task::getVisiblebyId($tsk_id)) {
03260             $PH->abortWarning(__("ERROR: could not get task"), ERROR_NOTE);
03261             return;
03262         }
03263     }*/
03264 
03265     ## other parameter ##
03266     $person_id = getOnePassedId('person_id');
03267     $prj_id = get('project');
03268     $prj_new = get('new_project');
03269     $prj_name = get('new_project_name');
03270     $assignement1 = get('task_assignement1');
03271     $assignement2 = get('task_assignement2');
03272     $also_assignement = get('task_also_assign');
03273 
03274     ### pub level ###
03275     if($pub_level = get('task_pub_level')) {
03276         if($task->id) {
03277              if($pub_level > $task->getValidUserSetPublevel() ) {
03278                  $PH->abortWarning('invalid data',ERROR_RIGHTS);
03279              }
03280         }
03281         #else {
03282         #    #@@@ check for person create rights
03283         #}
03284         $task->pub_level = $pub_level;
03285     }
03286 
03287     ## prio ##
03288     if($prio = get('task_prio')){
03289         $task->prio = $prio;
03290     }
03291 
03292     ## status ##
03293     if(!$task->id){
03294         $task->status = STATUS_NEW;
03295     }
03296 
03297     # retrieve all possible values from post-data (with field->view_in_forms == true)
03298     # NOTE:
03299     # - this could be an security-issue.
03300     # @@@ TODO: as some kind of form-edit-behaviour to field-definition
03301     foreach($task->fields as $f) {
03302         $name=$f->name;
03303         $f->parseForm(&$task);
03304     }
03305 
03306     ### validate ###
03307     $is_ok = true;
03308 
03309     ## no project ##
03310     if(($prj_id <= 0)) {
03311         if(((!isset($prj_new)) || (!isset($prj_name)))){
03312             new FeedbackWarning(__("Note requires project"));
03313 
03314             ## and no assignement ##
03315             if((!isset($assignement1) && !isset($assignement2) && $also_assignement == -1)) {
03316                 new FeedbackWarning(__("Note requires assigned person(s)"));
03317             }
03318             $is_ok= false;
03319         }
03320     }
03321 
03322     ## if project but no assignement ##
03323     if((!isset($assignement1) && !isset($assignement2) && $also_assignement == -1)) {
03324         $assignement1 = $auth->cur_user->id;
03325     }
03326 
03327     if(!$is_ok) {
03328         $PH->show('taskNoteOnPersonEdit',array('tsk'=>$task->id, 'person'=>$person_id), $task);
03329         exit();
03330     }
03331 
03332     ## new project
03333     if(isset($prj_new) && isset($prj_name)){
03334         $pperson = Person::getById($person_id);
03335         if($companies = $pperson->getCompanies()) {
03336             $company_id= $companies[0]->id;
03337         }
03338         else {
03339             $company_id= 0;
03340         }
03341 
03342         $new_project = new Project(array(
03343                        'name'=>$prj_name,
03344                        'company'=>$company_id,
03345                        'status'=>STATUS_NEW,
03346                        'prio'=>PRIO_NORMAL,
03347                        'pub_level'=>PUB_LEVEL_OPEN
03348                      ));
03349         $new_project->insert();
03350         $prj_id = $new_project->id;
03351         ## get project ##
03352         if(!$project = Project::getById($prj_id)){
03353              $PH->abortWarning(__("ERROR: could not get project"), ERROR_NOTE);
03354         }
03355     }
03356     else {
03357         ## get project ##
03358         if(!$project = Project::getById($prj_id)){
03359              $PH->abortWarning(__("ERROR: could not get project"), ERROR_NOTE);
03360         }
03361     }
03362 
03363     ## set project of task ##
03364     if(!$task->id){
03365         $task->project = $project->id;
03366     }
03367 
03368     ## assigne persons to task##
03369     $new_task_assignments = array();
03370     $count = 0;
03371     if(!$task->id){
03372         if(isset($assignement1)){
03373             $person = Person::getById($assignement1);
03374             $new_assignment1 = new TaskPerson(array(
03375                               'person'=> $assignement1,
03376                               'task'  => $task->id,
03377                               'comment'=>sprintf(__("formerly assigned to %s","task-assigment comment"), $person->name),
03378                               'project'=>$project->id,
03379                               ));
03380             $new_task_assignments[$count] = $new_assignment1;
03381             $count++;
03382         }
03383 
03384         if(isset($assignement2)){
03385             $person = Person::getById($assignement2);
03386             $new_assignment2 = new TaskPerson(array(
03387                               'person'=> $assignement2,
03388                               'task'  => $task->id,
03389                               'comment'=>sprintf(__("formerly assigned to %s","task-assigment comment"), $person->name),
03390                               'project'=>$project->id,
03391                               ));
03392             $new_task_assignments[$count] = $new_assignment2;
03393             $count++;
03394         }
03395 
03396         if($also_assignement != -1){
03397             $person = Person::getById($also_assignement);
03398             $new_assignment_also = new TaskPerson(array(
03399                                  'person'=> $also_assignement,
03400                                  'task'  => $task->id,
03401                                  'comment'=>sprintf(__("formerly assigned to %s","task-assigment comment"), $person->name),
03402                                  'project'=>$project->id,
03403                                  ));
03404             $new_task_assignments[$count] = $new_assignment_also;
03405             $count++;
03406         }
03407     }
03408     ## eventually needed later when note is a subcategory of task
03409     /*else {
03410         # ToDo: check if persons are assigned
03411     }*/
03412 
03413     ## assigne person to project ##
03414     $team = array();
03415     $new_project_assignments = array();
03416     $count = 0;
03417     if(!$task->id){
03418         $projperson = $project->getPersons(false);
03419         foreach($projperson as $projp){
03420             $team[$projp->id] = $projp->name;
03421         }
03422 
03423         if(isset($assignement1)){
03424             if(!isset($team[$assignement1])){
03425                 $person = Person::getById($assignement1);
03426                 $effort_style = ($person->settings & USER_SETTING_EFFORTS_AS_DURATION)
03427                               ? 2
03428                               : 1;
03429                 $pp_new1 = new ProjectPerson(array(
03430                     'person'                => $person->id,
03431                     'project'               => $project->id,
03432                     'name'                  => $g_user_profile_names[$person->profile],
03433                     'adjust_effort_style'   => $effort_style,
03434                 ));
03435                 $new_project_assignments[$count] = $pp_new1;
03436                 $count++;
03437             }
03438         }
03439 
03440         if(isset($assignement2)){
03441             if(!isset($team[$assignement2])){
03442                 $effort_style = ($person->settings & USER_SETTING_EFFORTS_AS_DURATION)
03443                               ? 2
03444                               : 1;
03445                 $person = Person::getById($assignement2);
03446                 $pp_new2 = new ProjectPerson(array(
03447                     'person'                => $person->id,
03448                     'project'               => $project->id,
03449                     'name'                  => $g_user_profile_names[$person->profile],
03450                     'adjust_effort_style'   => $effort_style,
03451                 ));
03452                 $new_project_assignments[$count] = $pp_new2;
03453                 $count++;
03454             }
03455         }
03456         if($also_assignement != -1){
03457             if(!isset($team[$also_assignement])){
03458                 $person = Person::getById($also_assignement);
03459                 $effort_style = ($person->settings & USER_SETTING_EFFORTS_AS_DURATION)
03460                               ? 2
03461                               : 1;
03462                 $pp_new_also = new ProjectPerson(array(
03463                     'person'                => $person->id,
03464                     'project'               => $project->id,
03465                     'name'                  => $g_user_profile_names[$person->profile],
03466                     'adjust_effort_style'   => $effort_style,
03467                 ));
03468                 $new_project_assignments[$count] = $pp_new_also;
03469                 $count++;
03470             }
03471         }
03472 
03473     }
03474     ## eventually needed later when note is a subcategory of task
03475     /*else{
03476         # ToDo: check if persons are assigned
03477     }*/
03478 
03479 
03480 
03481     ## Insert ##
03482     if($task->id == 0) {
03483         $task->insert();
03484 
03485         ### write task-assigments ###
03486         foreach($new_task_assignments as $nta) {
03487             $nta->task = $task->id;
03488             $nta->insert();
03489         }
03490 
03491         ### write project-assigments ###
03492         foreach($new_project_assignments as $npa) {
03493             $npa->insert();
03494         }
03495 
03496         new FeedbackMessage(sprintf(__("Created task %s with ID %s"),  $task->getLink(false),$task->id));
03497     }
03498     ## eventually needed later when note is a subcategory of task
03499     /*
03500     else{
03501     }
03502     */
03503 
03504     ### book effort ###
03505     $book_effort = get('book_effort');
03506     if($book_effort) {
03507         $as_duration = 0;
03508         if($pperson = $project->getProjectPersons()){
03509             foreach($pperson as $pp){
03510                 if(($pp->project == $project->id) && ($pp->person == $auth->cur_user->id)){
03511                     if($pp->adjust_effort_style == 1){
03512                         $as_duration = 0;
03513                     }
03514                     else{
03515                         $as_duration = 1;
03516                     }
03517                 }
03518             }
03519         }
03520         else{
03521             $as_duration = 0;
03522         }
03523 
03524         if(get('creation_time')){
03525             $start_time = get('creation_time');
03526         }
03527         else{
03528             $start_time = '';
03529         }
03530 
03531         ### build new object ###
03532         $newEffort= new Effort(array(
03533             'id'        =>0,
03534             'name'      =>'',
03535             'project'   =>$project->id,
03536             'task'      =>$task->id,
03537             'person'    =>$auth->cur_user->id,
03538             'as_duration' =>$as_duration,
03539             'time_start' =>$start_time,
03540             )
03541         );
03542         $PH->show('effortEdit',array('effort'=>$newEffort->id),$newEffort);
03543         exit();
03544     }
03545 
03546     ### display personList ####
03547     if(!$PH->showFromPage()) {
03548         $PH->show('personList',array());
03549     }
03550 
03551 }
03552 
03555 ?>

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