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
00012 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00013 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00014 require_once(confGet('DIR_STREBER') . 'db/class_effort.inc.php');
00015 require_once(confGet('DIR_STREBER') . 'render/render_list.inc.php');
00016 require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00017
00018
00022 function effortView()
00023 {
00024 global $PH;
00025 global $auth;
00026 require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00027
00028 ### get effort ####
00029 $ids= getPassedIds('effort','efforts_*');
00030
00031 if(!$ids) {
00032 $PH->abortWarning(__("Select one or more efforts"));
00033 return;
00034 }
00035 else if(count($ids) > 1) {
00036 $PH->show('effortViewMultiple');
00037 exit();
00038 }
00039 else if(!$effort= Effort::getEditableById($ids[0])) {
00040 $PH->abortWarning(__("You do not have enough rights"), ERROR_RIGHTS);
00041 }
00042
00043 ## get project ##
00044 if(!$project= Project::getVisibleById($effort->project)) {
00045 $PH->abortWarning("invalid project-id",ERROR_FATAL);
00046 }
00047
00048 ## get task #
00049 $task = $effort->task
00050 ? Task::getVisibleById($effort->task)
00051 : NULL;
00052
00053 ### create from handle ###
00054 $from_handle= $PH->defineFromHandle(array('effort'=>$effort->id));
00055
00056 ## is viewed by user ##
00057 $effort->nowViewedByUser();
00058
00059 ### set up page and write header ####
00060 {
00061 $page= new Page();
00062 $page->cur_tab='projects';
00063
00064 $page->cur_crumb= 'effortView';
00065 $page->crumbs= build_project_crumbs($project);
00066 $page->options= build_projView_options($project);
00067
00068 $type= __('Effort of task','page type');
00069
00070 if($task) {
00071 $folder= $task->getFolderLinks() ."<em>></em>". $task->getLink();
00072 $page->type= $folder."<em>></em>". $type;
00073 }
00074 else {
00075 $page->type= $type;
00076 }
00077
00078 $page->title=$effort->name;
00079 $page->title_minor=__("Overview");
00080
00081 ### page functions ###
00082 $page->add_function(new PageFunction(array(
00083 'target' =>'effortEdit',
00084 'params' =>array('effort'=>$effort->id),
00085 'icon' =>'edit',
00086 'tooltip' =>__('Edit this effort'),
00087 'name' =>__('Edit')
00088 )));
00089
00090 $item = ItemPerson::getAll(array('person'=>$auth->cur_user->id,'item'=>$effort->id));
00091 if((!$item) || ($item[0]->is_bookmark == 0)){
00092 $page->add_function(new PageFunction(array(
00093 'target' =>'itemsAsBookmark',
00094 'params' =>array('effort'=>$effort->id),
00095 'tooltip' =>__('Mark this effort as bookmark'),
00096 'name' =>__('Bookmark'),
00097 )));
00098 }
00099 else{
00100 $page->add_function(new PageFunction(array(
00101 'target' =>'itemsRemoveBookmark',
00102 'params' =>array('effort'=>$effort->id),
00103 'tooltip' =>__('Remove this bookmark'),
00104 'name' =>__('Remove Bookmark'),
00105 )));
00106 }
00107
00108 ### render title ###
00109 echo(new PageHeader);
00110 }
00111
00112 echo (new PageContentOpen);
00113
00114 ### details ###
00115 {
00116 $block = new PageBlock(array(
00117 'title'=>__('Details'),
00118 'id'=>'details',
00119 ));
00120
00121 $block->render_blockStart();
00122
00123 echo '<div class="text">';
00124
00125 if($project) {
00126 echo "<p><label>" . __('Project','label') . "</label>". $project->getLink(false) ."</p>";
00127 }
00128
00129 if($task){
00130 if($task->parent_task != 0) {
00131 $folder= $task->getFolderLinks(false) ."<em> > </em>". $task->getLink(false);
00132 echo "<p><label>" . __('Task','label') . "</label>" . $folder . "</p>";
00133 }
00134 else {
00135 echo "<p><label>" . __('Task','label') . "</label>" . $task->getLink(false) . "</p>";
00136 }
00137 }
00138 else {
00139 echo "<p><label>" . __('Task','label') . "</label>" . __('No task related') . "</p>";
00140 }
00141
00142 if(!$person = Person::getById($effort->person)){
00143 echo "<p><label>" . __('Created by','label') . "</label>" . __('not available') . "</p>";
00144 }
00145 else {
00146 echo "<p><label>" . __('Created by','label') . "</label>" . $person->getLink() . "</p>";
00147 }
00148
00149 if($effort){
00150 $duration = round((strToGMTime($effort->time_end) - strToGMTime($effort->time_start))/60/60,1)." h";
00151 if($effort->as_duration){
00152 echo "<p><label>" . __('Created at','label') . "</label>" . renderDateHtml($effort->time_start) . "</p>";
00153 echo "<p><label>" . __('Duration','label') . "</label>" . asHtml($duration) . "</p>";
00154 }
00155 else {
00156 echo "<p><label>" . __('Time start','label') . "</label>" . renderTimestampHtml($effort->time_start) . "</p>";
00157 echo "<p><label>" . __('Time end','label') . "</label>" . renderTimestampHtml($effort->time_end) . "</p>";
00158 echo "<p><label>" . __('Duration','label') . "</label>" . asHtml($duration) . "</p>";
00159 }
00160 }
00161
00162 echo "</div>";
00163
00164 $block->render_blockEnd();
00165 }
00166
00167 ### description ###
00168 {
00169 $block = new PageBlock(array(
00170 'title'=>__('Description'),
00171 'id'=>'description',
00172 ));
00173
00174 $block->render_blockStart();
00175
00176 if($effort->description != "") {
00177 echo '<div class="text">';
00178 echo wiki2html($effort->description, $effort);
00179
00180 ### update effort if relative links have been converted to ids ###
00181 global $g_wiki_auto_adjusted;
00182 if(isset($g_wiki_auto_adjusted) && $g_wiki_auto_adjusted) {
00183 $effort->description= $g_wiki_auto_adjusted;
00184 $effort->update(array('description'),false);
00185 }
00186
00187 echo "</div>";
00188 }
00189 else {
00190 if($auth->cur_user->user_rights & RIGHT_PROJECT_ASSIGN) {
00191 echo '<div class="empty">' . $PH->getLink('effortEdit','',array('effort'=>$effort->id)) . "</div>";
00192 }
00193 else {
00194 echo '<div class="text">' . __('No description available') . "</div>";
00195 }
00196 }
00197 $block->render_blockEnd();
00198 }
00199 echo (new PageContentClose);
00200 echo (new PageHtmlEnd);
00201 }
00202
00206 function effortViewMultiple()
00207 {
00208 global $PH;
00209 global $auth;
00210 require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00211
00212 ### get effort ####
00213 $ids= getPassedIds('effort','efforts_*');
00214
00215 if(!$ids) {
00216 $PH->abortWarning(__("Select one or more efforts"));
00217 return;
00218 }
00219
00220 $number = 0;
00221 $sum = 0;
00222 $count = 0;
00223
00224
00225 foreach($ids as $id) {
00226 if($e= Effort::getEditableById($id)) {
00227 ## array with all efforts ##
00228 $e_array[] = $e;
00229 ## array with all effort ids (for Effort::getMinMaxTime())##
00230 $e_ids[] = $e->id;
00231
00232 ## is viewed by user ##
00233 $e->nowViewedByUser();
00234
00235 ## number of efforts ##
00236 $number++;
00237 ## sum of all efforts ##
00238 $sum += round((strToGMTime($e->time_end) - strToGMTime($e->time_start))/60/60,1);
00239
00240 ### check project of first effort
00241 if(count($e_array) == 1) {
00242 if(!$project = Project::getVisibleById($e->project)) {
00243 $PH->abortWarning('could not get project');
00244 }
00245 }
00246 else {
00247 $count = 0;
00248 ### check if the efforts are related to the same task ###
00249 if($e->task != $e_array[0]->task) {
00250 $count++;
00251 }
00252 }
00253 }
00254 else {
00255 $PH->abortWarning(__("You do not have enough rights"), ERROR_RIGHTS);
00256 }
00257 }
00258
00259 ### set up page and write header ####
00260 {
00261 $page= new Page();
00262 $page->cur_tab='projects';
00263
00264 $page->cur_crumb= 'effortViewMultiple';
00265 $page->crumbs= build_project_crumbs($project);
00266 $page->options= build_projView_options($project);
00267
00268 $type= __('Multiple Efforts','page type');
00269
00270 ## same tasks ##
00271 if($count == 0) {
00272 $task = $e_array[0]->task
00273 ? Task::getVisibleById($e_array[0]->task)
00274 : NULL;
00275
00276 if($task) {
00277 $folder= $task->getFolderLinks() ."<em>></em>". $task->getLink();
00278 $page->type= $folder."<em>></em>". $type;
00279 }
00280 else {
00281 $page->type= $type;
00282 }
00283 }
00284 ## different tasks ##
00285 else {
00286 $page->type= $project->getLink() . "<em>></em>" . $type;
00287 }
00288
00289 $page->title=__('Multiple Efforts');
00290 $page->title_minor=__('Overview');
00291
00292 ### render title ###
00293 echo(new PageHeader);
00294 }
00295
00296 echo (new PageContentOpen);
00297
00298 ### summary ###
00299
00300 ### title ###
00301 echo '<div class="text"><h3>' . __('summary') . "</h3></div>";
00302 {
00303 ### content ###
00304 $block = new PageBlock(array(
00305 'title'=>__('Information'),
00306 'id'=>'info',
00307 ));
00308
00309 $block->render_blockStart();
00310
00311 echo '<div class="text">';
00312
00313 if($number){
00314 echo "<p><label>" . __('Number of efforts','label') . "</label>". asHtml($number) ."</p>";
00315 }
00316
00317 if($sum) {
00318 echo "<p><label>" . __('Sum of efforts','label') . "</label>". asHtml($sum) ." h</p>";
00319 }
00320
00321 $content['e_ids'] = $e_ids;
00322
00323 $time = Effort::getMinMaxTime($content);
00324 if($time) {
00325 $line = "<p><label>" . __('from','time label') . "</label>" . renderDateHtml($time[0]) . "</p>";
00326 $line .= "<p><label>" . __('to','time label') . "</label>" . renderDateHtml($time[1]) . "</p>";
00327 echo $line;
00328 }
00329 else {
00330 echo "<p><label>" . __('Time','label') . "</label>" . __('not available') . "</p>";
00331 }
00332
00333 echo "</div>";
00334
00335 $block->render_blockEnd();
00336 }
00337
00338 ### start to list efforts ###
00339 foreach($e_array as $effort)
00340 {
00341 ### title ###
00342 echo '<div class="text"><h3>' . asHtml($effort->name) . "</h3></div>";
00343
00344 ### details ###
00345 {
00346 $block = new PageBlock(array(
00347 'title'=>__('Details'),
00348 'id'=>'details' . $effort->id,
00349 ));
00350
00351 $block->render_blockStart();
00352
00353 echo '<div class="text">';
00354
00355 if($project) {
00356 echo "<p><label>" . __('Project','label') . "</label>" . $project->getLink(false) ."</p>";
00357 }
00358
00359 $task = $effort->task
00360 ? Task::getVisibleById($effort->task)
00361 : NULL;
00362
00363 if($task){
00364 if($task->parent_task != 0) {
00365 $folder= $task->getFolderLinks(false) ."<em> > </em>". $task->getLink(false);
00366 echo "<p><label>" . __('Task','label') . "</label>" . $folder . "</p>";
00367 }
00368 else {
00369 echo "<p><label>" . __('Task','label') . "</label>" . $task->getLink(false) . "</p>";
00370 }
00371 }
00372 else {
00373 echo "<p><label>" . __('Task','label') . "</label>" . __('No task related') . "</p>";
00374 }
00375
00376 if(!$person = Person::getById($effort->person)){
00377 echo "<p><label>" . __('Created by','label') . "</label>" . __('not available') . "</p>";
00378 }
00379 else {
00380 echo "<p><label>" . __('Created by','label') . "</label>" . $person->getLink() . "</p>";
00381 }
00382
00383 if($effort){
00384 $duration = round((strToGMTime($effort->time_end) - strToGMTime($effort->time_start))/60/60,1)." h";
00385 if($effort->as_duration){
00386 echo "<p><label>" . __('Created at','label') . "</label>" . renderDateHtml($effort->time_start) . "</p>";
00387 echo "<p><label>" . __('Duration','label') . "</label>" . asHtml($duration) . "</p>";
00388 }
00389 else {
00390 echo "<p><label>" . __('Time start','label') . "</label>" . renderTimestampHtml($effort->time_start) . "</p>";
00391 echo "<p><label>" . __('Time end','label') . "</label>" . renderTimestampHtml($effort->time_end) . "</p>";
00392 echo "<p><label>" . __('Duration','label') . "</label>" . asHtml($duration) . "</p>";
00393 }
00394 }
00395
00396 echo "</div>";
00397
00398 $block->render_blockEnd();
00399 }
00400
00401 ### description ###
00402 {
00403 $block = new PageBlock(array(
00404 'title'=>__('Description'),
00405 'id'=>'description' . $effort->id,
00406 ));
00407
00408 $block->render_blockStart();
00409
00410 if($effort->description != "") {
00411 echo '<div class="text">';
00412 echo wiki2html($effort->description, $effort);
00413
00414 ### update effort if relative links have been converted to ids ###
00415 global $g_wiki_auto_adjusted;
00416 if(isset($g_wiki_auto_adjusted) && $g_wiki_auto_adjusted) {
00417 $effort->description= $g_wiki_auto_adjusted;
00418 $effort->update(array('description'),false);
00419 }
00420
00421 echo "</div>";
00422 }
00423 else {
00424 if($auth->cur_user->user_rights & RIGHT_PROJECT_ASSIGN) {
00425 echo '<div class="empty">' . $PH->getLink('effortEdit','',array('effort'=>$effort->id)) . "</div>";
00426 }
00427 else {
00428 echo '<div class="text">' . __('No description available') . "</div>";
00429 }
00430 }
00431 $block->render_blockEnd();
00432 }
00433 }
00434
00435 echo (new PageContentClose);
00436 echo (new PageHtmlEnd);
00437 }
00438
00439
00443 function effortNew()
00444 {
00445 global $PH;
00446 global $auth;
00447
00448 $name=get('new_name')
00449 ? get('new_name')
00450 :__("New Effort");
00451
00452 ### first try single project-id ###
00453 $project=NULL;
00454 if($ids=getPassedIds('prj','projects_*')) {
00455 if(!$project= Project::getVisibleById($ids[0])) {
00456 $PH->abortWarning("ERROR: could not get Project");
00457 return;
00458 }
00459 }
00460
00461 ### try to get task ###
00462 $task_id=0;
00463 if($task_ids= getPassedIds('parent_task','tasks_*')) {
00464 if(count($task_ids) > 1) {
00465 new FeedbackWarning(__("only expected one task. Used the first one."));
00466 }
00467 $task_id= $task_ids[0];
00468 }
00469
00470
00471 ### try to get folder ###
00472 else if($task_ids= getPassedIds('','folders_*')) {
00473 if(count($task_ids) > 1) {
00474 new FeedbackWarning( __("only expected one task. Used the first one."));
00475 }
00476 $task_id= $task_ids[0];
00477 }
00478
00479
00480 if(!$project) {
00481 if( !$task_id) {
00482 $PH->abortWarning("Could not get project",ERROR_NOTE);
00483 }
00484 if(!$task= Task::getVisibleById($task_id)) {
00485 $PH->abortWarning("Invalid task id?", ERROR_BUG);
00486 }
00487 if(!$project= Project::getVisibleById($task->project)) {
00488 $PH->abortWarning("Invalid project for task?", ERROR_BUG);
00489 }
00490 }
00491
00492 $now= getGMTString();
00493
00494 ### last effort selected? ###
00495 if($effort_ids= getPassedIds('','efforts_*')) {
00496 $last_effort= Effort::getVisibleById($effort_ids[0]);
00497
00498 $last=$last_effort->time_end;
00499 $now=$last_effort->time_end;
00500 }
00501 ### guess start-time from last effort / start at 10:00 if new day ###
00502 else {
00503 if($last=Effort::getDateCreatedLast()) {
00504 $last_day=getdate(strToGMTime($last));
00505 }
00506 else {
00507 $last_day="1980-01-01";
00508 }
00509
00510 $today=getdate(time());
00511 if($last_day['yday'] != $today['yday']) {
00512 $last= getGMTString();
00513 }
00514 }
00515
00516 ### log efforts as durations? ###
00517 $as_duration= 0;
00518 if($pp= $project->getCurrentProjectPerson()) {
00519 if($pp->adjust_effort_style == 2) {
00520
00521 if($last=Effort::getDateCreatedLast()) {
00522 $last_day=$last;
00523 }
00524 else {
00525 $last_day="1980-01-01";
00526 }
00527 $str_time=sprintf("%02d:%02d:%02d",
00528 floor( (time()-strToGMTime($last_day))/60/60%24),
00529 floor( (time()-strToGMTime($last_day))/60%60),
00530 floor( (time()-strToGMTime($last_day))%60)
00531 );
00532
00533 $now= gmdate("Y-m-d", time()) ." ". $str_time;
00534 $last= gmdate("Y-m-d") ." ". "00:00:00";
00535
00536 $as_duration=1;
00537 }
00538 }
00539
00540
00541 ### build new object ###
00542 $newEffort= new Effort(array(
00543 'id' =>0,
00544 'name' =>$name,
00545 'project' =>$project->id,
00546 'time_start'=>$last,
00547 'time_end' =>$now,
00548 'task' =>$task_id,
00549 'as_duration'=>$as_duration,
00550 'person' =>$auth->cur_user->id,
00551 )
00552 );
00553 $PH->show('effortEdit',array('effort'=>$newEffort->id),$newEffort);
00554 }
00555
00556
00560 function effortEdit($effort=NULL)
00561 {
00562 global $PH;
00563 global $g_effort_status_names;
00564
00565 if(!$effort) {
00566 $ids = getPassedIds('effort','efforts_*');
00567
00568 if(!$ids) {
00569 $PH->abortWarning(__("Select some efforts(s) to edit"), ERROR_NOTE);
00570 return;
00571 }
00572 else if(count($ids) > 1) {
00573 $PH->show('effortEditMultiple');
00574 exit();
00575 }
00576 else if(!$effort = Effort::getEditableById($ids[0])) {
00577 $PH->abortWarning("ERROR: could not get Effort");
00578 return;
00579 }
00580 }
00581
00582 if(!$project=Project::getVisibleById($effort->project)) {
00583 $PH->abortWarning("ERROR: could not get Project",ERROR_BUG);
00584 }
00585
00586 $task= Task::getVisibleById($effort->task);
00587
00588 ### set up page and write header ####
00589 {
00590 $page= new Page(array('use_jscalendar'=>true, 'autofocus_field'=>'effort_name'));
00591 $page->cur_tab='projects';
00592 $page->type=__('Edit Effort','page type');
00593 $page->title=$effort->name;
00594
00595 if($task) {
00596 $page->crumbs= build_task_crumbs($task);
00597 }
00598 else {
00599 $page->crumbs= build_project_crumbs($project);
00600 }
00601 $page->crumbs[]= new NaviCrumb(array(
00602 'target_id' => 'effortEdit',
00603 ));
00604
00605 if($effort->id) {
00606 $page->title=__('Edit Effort','page title');
00607 }
00608 else {
00609 $page->title=__('New Effort','page title');
00610 }
00611
00612 $page->title_minor= sprintf(__('On project %s','page title add on'),$project->name);
00613
00614
00615 echo(new PageHeader);
00616 }
00617 echo (new PageContentOpen);
00618
00619 ### write form #####
00620 {
00621 $block=new PageBlock(array(
00622 'id' =>'edit',
00623 'reduced_header' => true,
00624 ));
00625 $block->render_blockStart();
00626
00627
00628 require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00629
00630 $form=new PageForm();
00631 $form->button_cancel=true;
00632
00633 ### automatically write fields ###
00634 # foreach($effort->fields as $field) {
00635 # $form->add($field->getFormElement(&$effort));
00636 # }
00637
00638 $form->add($effort->fields['name']->getFormElement(&$effort));
00639
00640 if($effort->as_duration) {
00648 $effort->time_end=clientTimeStrToGMTString($effort->time_end);
00649
00650 $tmp_edit= $effort->fields['time_end']->getFormElement(&$effort);
00651 $tmp_edit->title=__("Date / Duration","Field label when booking time-effort as duration");
00652 $form->add($tmp_edit);
00653 }
00654 else {
00655 $form->add($effort->fields['time_start']->getFormElement(&$effort));
00656 $form->add($effort->fields['time_end']->getFormElement(&$effort));
00657 }
00658 $form->add($effort->fields['description']->getFormElement(&$effort));
00659 $form->add(new Form_Dropdown("effort_status", __('Status'), array_flip($g_effort_status_names), $effort->status));
00660
00661 ### get meta-tasks / folders ###
00662 #$folders= $project->getFolders();
00663 $folders= Task::getAll(array(
00664 'sort_hierarchical'=>true,
00665 'parent_task'=> 0,
00666 'show_folders'=>true,
00667 'folders_only'=>false,
00668 'status_min'=> STATUS_UPCOMING,
00669 'status_max'=> STATUS_CLOSED,
00670 'project'=> $project->id,
00671
00672 ));
00673 if($folders) {
00674 $folder_list= array("undefined"=>"0");
00675
00676 if($effort->task) {
00677 if($task= Task::getVisibleById($effort->task)) {
00678 ### add, if normal task (folders will added below) ###
00679 if(! $task->category == TCATEGORY_FOLDER) {
00680 $folder_list[$task->name]= $task->id;
00681 }
00682 }
00683 }
00684
00685 foreach($folders as $f) {
00686 $str= '';
00687 foreach($f->getFolder() as $pf) {
00688 $str.=$pf->getShort(). " > ";
00689 }
00690 $str.=$f->name;
00691
00692 $folder_list[$str]= $f->id;
00693
00694 }
00695 $form->add(new Form_Dropdown('effort_task', __("For task"),$folder_list, $effort->task));
00696
00697 }
00698
00699 ### public-level ###
00700 if(($pub_levels= $effort->getValidUserSetPublevel())
00701 && count($pub_levels)>1) {
00702 $form->add(new Form_Dropdown('effort_pub_level', __("Publish to"),$pub_levels,$effort->pub_level));
00703 }
00704
00705
00706 echo ($form);
00707 $block->render_blockEnd();
00708
00709 $PH->go_submit='effortEditSubmit';
00710 echo "<input type=hidden name='effort_as_duration' value='$effort->as_duration'>";
00711 echo "<input type=hidden name='effort' value='$effort->id'>";
00712 echo "<input type=hidden name='effort_project' value='$effort->project'>";
00713 echo "<input type=hidden name='effort_person' value='$effort->person'>";
00714 }
00715 echo (new PageContentClose);
00716 echo (new PageHtmlEnd);
00717 }
00718
00722 function effortEditSubmit()
00723 {
00724 global $PH;
00725
00726
00727 ### get effort ####
00728 $id= getOnePassedId('effort');
00729
00730 if($id == 0) {
00731 $effort= new Effort(array('id'=>0));
00732 }
00733 else {
00734 $effort= Effort::getEditableById($id);
00735 if(!$effort) {
00736 $PH->abortWarning(__("Could not get effort"));
00737 return;
00738 }
00739 }
00740
00741 ### cancel ###
00742 if(get('form_do_cancel')) {
00743 if(!$PH->showFromPage()) {
00744 $PH->show('projView',array('prj'=>$effort->project));
00745 }
00746 exit();
00747 }
00748
00749 ### get project ###
00750 $effort->project=get('effort_project');
00751 if(!$project = Project::getVisibleById($effort->project)) {
00752 $PH->abortWarning(__("Could not get project of effort"));
00753 }
00754
00755 ### get person ###
00756 if($effort->person=get('effort_person')) {
00757 if(!$person = Person::getVisibleById($effort->person)) {
00758 $PH->abortWarning(__("Could not get person of effort"));
00759 }
00760 }
00761
00762 # retrieve all possible values from post-data
00763 # NOTE:
00764 # - this could be an security-issue.
00765 # - TODO: as some kind of form-edit-behaviour to field-definition
00766 foreach($effort->fields as $f) {
00767 $name=$f->name;
00768 $f->parseForm(&$effort);
00769 }
00770
00771 ### times as duration ###
00772 if($as_duration= get('effort_as_duration')) {
00773 $effort->as_duration= $as_duration;
00774
00775 ### make sure day of time_end stays the same if date changes... ###
00776 if(($time_start= $effort->time_start) && ($time_end= $effort->time_end)) {
00777
00778 $effort->time_end=
00779 gmdate("Y-m-d", strToClientTime($time_end) )
00780 ." ".
00781 gmdate("H:i:s", strToClientTime($time_end) );
00782
00783 $effort->time_start=
00784 gmdate("Y-m-d", strToClientTime($time_end) )
00785 ." ".
00786 gmdate("00:00:00", strToClientTime($time_end) );
00787
00788 }
00789 else {
00790 trigger_error("Getting time_start and time_end failed",E_USER_WARNING);
00791 }
00792 }
00793
00794
00795 ### pub level ###
00796 if($pub_level=get('effort_pub_level')) {
00797
00798 ### not a new effort ###
00799 if($effort->id) {
00800 if($pub_level > $effort->getValidUserSetPublevel() ) {
00801 $PH->abortWarning('invalid data',ERROR_RIGHTS);
00802 }
00803 }
00804 #else {
00805 # #@@@ check for person create rights
00806 #}
00807 $effort->pub_level = $pub_level;
00808 }
00809
00810 ## effort status ##
00811 if($effort_status = get('effort_status')){
00812 $effort->status = $effort_status;
00813 }
00814
00815 ### link to task ###
00816 if($task_id = get('effort_task')) {
00817 if($task= Task::getVisibleById($task_id)) {
00818 $effort->task = $task->id;
00819 }
00820 }
00821
00822
00823 ### go back to from if validation fails ###
00824 $failure= false;
00825 if(!$effort->name) {
00826 $failure= true;
00827 new FeedbackWarning(__("Name required"));
00828 }
00829 if(strToGMTime($effort->time_end) - strToGMTime($effort->time_start) < 0) {
00830 $failure= true;
00831 new FeedbackWarning(__("Cannot start before end."));
00832 }
00833 if($failure) {
00834 $PH->show('effortEdit',NULL,$effort);
00835 exit();
00836 }
00837
00838
00839 ### write to db ###
00840 if($effort->id == 0) {
00841 $effort->insert();
00842 }
00843 else {
00844 $effort->update();
00845 }
00846
00847 ### display taskView ####
00848 if(!$PH->showFromPage()) {
00849 $PH->show('projView',array('prj'=>$effort->project));
00850 }
00851 }
00852
00856 function effortEditMultiple()
00857 {
00858 global $PH;
00859 global $g_effort_status_names;
00860
00861 $effort_ids = getPassedIds('effort','efforts_*');
00862
00863 if(!$effort_ids) {
00864 $PH->abortWarning(__("Select some efforts(s) to edit"));
00865 exit();
00866 }
00867
00868 $efforts = array();
00869 $different_fields=array();
00870
00871 $edit_fields = array(
00872 'status',
00873 'pub_level',
00874 'task'
00875 );
00876
00877 foreach($effort_ids as $id){
00878 if($effort = Effort::getEditableById($id)) {
00879
00880 $efforts[] = $effort;
00881
00882 ### check project for first task
00883 if(count($efforts) == 1) {
00884
00885 ### make sure all are of same project ###
00886 if(!$project = Project::getVisibleById($effort->project)) {
00887 $PH->abortWarning('could not get project');
00888 }
00889 }
00890 else {
00891 if($effort->project != $efforts[0]->project) {
00892 $PH->abortWarning(__("For editing all efforts must be of same project."));
00893 }
00894
00895 foreach($edit_fields as $field_name) {
00896 if($effort->$field_name != $efforts[0]->$field_name) {
00897 $different_fields[$field_name] = true;
00898 }
00899 }
00900 }
00901 }
00902 }
00903
00904 ### set up page and write header ####
00905 {
00906 $page = new Page(array('use_jscalendar'=>true,'autofocus_field'=>'effort_name'));
00907 $page->cur_tab = 'projects';
00908
00909
00910 #$page->crumbs=build_task_crumbs($task,$project);
00911 $page->options[] = new naviOption(array(
00912 'target_id' =>'effortEdit',
00913 ));
00914
00915 $page->type = __("Edit multiple efforts","Page title");
00916 $page->title = sprintf(__("Edit %s efforts","Page title"), count($efforts));
00917
00918 echo(new PageHeader);
00919 }
00920 echo (new PageContentOpen);
00921
00922 {
00923 echo "<ol>";
00924 foreach($efforts as $e) {
00925 echo "<li>" . $e->getLink(false). "</li>";
00926 }
00927 echo "</ol>";
00928
00929 $block = new PageBlock(array('id'=>'functions','reduced_header' => true,));
00930 $block->render_blockStart();
00931
00932 $form = new PageForm();
00933 $form->button_cancel = true;
00934
00935 ### status ###
00936 {
00937 $st = array();
00938 foreach($g_effort_status_names as $key=>$value) {
00939 $st[$key] = $value;
00940 }
00941 if(isset($different_fields['status'])) {
00942 $st[-1]= ('-- ' . __('keep different'). ' --');
00943 $form->add(new Form_Dropdown('effort_status',__("Status"),array_flip($st), -1));
00944 }
00945 else {
00946 $form->add(new Form_Dropdown('effort_status',__("Status"),array_flip($st), $efforts[0]->status));
00947 }
00948 }
00949
00950 ### get meta-tasks / folders ###
00951 $folders= Task::getAll(array(
00952 'sort_hierarchical'=>true,
00953 'parent_task'=> 0,
00954 'show_folders'=>true,
00955 'folders_only'=>false,
00956 'status_min'=> STATUS_UPCOMING,
00957 'status_max'=> STATUS_CLOSED,
00958 'project'=> $project->id,
00959
00960 ));
00961 if($folders) {
00962 $folder_list = array("undefined"=>"0");
00963
00964 if($effort->task) {
00965 if($task = Task::getVisibleById($effort->task)) {
00966 ### add, if normal task (folders will added below) ###
00967 if(! $task->category == TCATEGORY_FOLDER) {
00968 $folder_list[$task->name] = $task->id;
00969 }
00970 }
00971 }
00972
00973 foreach($folders as $f) {
00974 $str = '';
00975 foreach($f->getFolder() as $pf) {
00976 $str.=$pf->getShort(). " > ";
00977 }
00978 $str .= $f->name;
00979
00980 $folder_list[$str] = $f->id;
00981
00982 }
00983
00984 if(isset($different_fields['task'])) {
00985 $folder_list[('-- ' . __('keep different'). ' --')] = -1;
00986 $form->add(new Form_Dropdown('effort_task',__("For task"),$folder_list, -1));
00987 }
00988 else {
00989 $form->add(new Form_Dropdown('effort_task',__("For task"),$folder_list, $efforts[0]->task));
00990 }
00991
00992 }
00993
00994 ### public level ###
00995 {
00996 if(($pub_levels = $effort->getValidUserSetPublevel()) && count($pub_levels)>1) {
00997 if(isset($different_fields['pub_level'])) {
00998 $pub_levels[('-- ' . __('keep different'). ' --')] = -1;
00999 $form->add(new Form_Dropdown('effort_pub_level',__("Publish to"),$pub_levels, -1));
01000 }
01001 else {
01002 $form->add(new Form_Dropdown('effort_pub_level',__("Publish to"),$pub_levels,$efforts[0]->pub_level));
01003 }
01004 }
01005 }
01006
01007 $number = 0;
01008 foreach($efforts as $e){
01009 $form->add(new Form_HiddenField("effort_id_{$number}",'',$e->id));
01010 $number++;
01011 }
01012
01013 $form->add(new Form_HiddenField("number",'',$number));
01014
01015 echo($form);
01016
01017 $block->render_blockEnd();
01018
01019 $PH->go_submit = 'effortEditMultipleSubmit';
01020 if($return = get('return')) {
01021 echo "<input type=hidden name='return' value='$return'>";
01022 }
01023 }
01024
01025 echo (new PageContentClose);
01026 echo (new PageHtmlEnd);
01027
01028 exit();
01029
01030 }
01031
01035 function effortEditMultipleSubmit()
01036 {
01037 global $PH;
01038 global $auth;
01039
01040 $ids = array();
01041 $count = 0;
01042 $error = 0;
01043 $changes = false;
01044
01045 ### cancel ? ###
01046 if(get('form_do_cancel')) {
01047 if(!$PH->showFromPage()) {
01048 $PH->show('home',array());
01049 }
01050 exit();
01051 }
01052
01053 $number = get('number');
01054
01055 for($i = 0; $i < $number; $i++){
01056 $effort_id = get('effort_id_'.$i);
01057 $ids[] = $effort_id;
01058 }
01059
01060 if(!$ids) {
01061 $PH->abortWarning(__("Select some efforts(s) to edit"), ERROR_NOTE);
01062 return;
01063 }
01064
01065 foreach($ids as $id){
01066 if($effort = Effort::getEditableById($id)){
01067
01068 $status = get('effort_status');
01069 if(!is_null($status) && $status != -1 && $status != $effort->status){
01070 $effort->status = $status;
01071 $changes = true;
01072 }
01073
01074 $task_id = get('effort_task');
01075 if(!is_null($task_id) && $task_id != -1 && $task_id != $effort->task) {
01076 if($task = Task::getVisibleById($task_id)) {
01077 $effort->task = $task->id;
01078 $changes = true;
01079 }
01080 }
01081
01082 $pub_level = get('effort_pub_level');
01083 if(!is_null($pub_level) && $pub_level != -1 && $pub_level != $effort->pub_level){
01084 if($pub_level > $effort->getValidUserSetPublevel() ) {
01085 $PH->abortWarning('invalid data',ERROR_RIGHTS);
01086 }
01087 $effort->pub_level = $pub_level;
01088 $changes = true;
01089 }
01090 }
01091 else{
01092 $error++;
01093 }
01094
01095 if($changes){
01096 $effort->update();
01097 $effort->nowChangedByUser();
01098 $count++;
01099 }
01100 }
01101
01102 if($count){
01103 new FeedbackMessage(sprintf(__("Edited %s effort(s)."),$count));
01104 }
01105
01106 if($error){
01107 new FeedbackWarning(sprintf(__('Error while editing %s effort(s).'), $error));
01108 }
01109
01110 ### return to from-page? ###
01111 if(!$PH->showFromPage()) {
01112 $PH->show('home');
01113 }
01114 }
01115
01119 function effortsDelete()
01120 {
01121 global $PH;
01122
01123 ### get effort ####
01124 $ids= getPassedIds('effort','efforts_*');
01125
01126 if(!$ids) {
01127 $PH->abortWarning(__("Select some efforts to delete"));
01128 return;
01129 }
01130
01131 $counter=0;
01132 $errors=0;
01133 foreach($ids as $id) {
01134 $e= Effort::getEditableById($id);
01135 if(!$e) {
01136 $PH->abortWarning("Invalid effort-id!");
01137 }
01138 if($e->delete()) {
01139 $counter++;
01140 }
01141 else {
01142 $errors++;
01143 }
01144 }
01145 if($errors) {
01146 new FeedbackWarning(sprintf(__("Failed to delete %s efforts"), $errors));
01147 }
01148 else {
01149 new FeedbackMessage(sprintf(__("Moved %s efforts to trash"),$counter));
01150 }
01151
01152 if(!$PH->showFromPage()) {
01153 $PH->show('home');
01154 }
01155 }
01156
01157
01158 ?>