00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit();}
00002 # streber - a php based project management system
00003 # Copyright (c) 2005 Thomas Mann - thomas@pixtur.de
00004 # Distributed under the terms and conditions of the GPL as stated in docs/license.txt
00005
00009 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00010 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00011 require_once(confGet('DIR_STREBER') . 'db/class_comment.inc.php');
00012 require_once(confGet('DIR_STREBER') . 'render/render_list.inc.php');
00013 require_once(confGet('DIR_STREBER') . 'render/render_misc.inc.php');
00014
00015
00021 function commentView(){
00022 global $PH;
00023 global $auth;
00024
00025 require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00026
00027 ### get task ####
00028 if(!$comment=Comment::getVisibleById(get('comment'))) {
00029 $PH->abortWarning("invalid comment-id",ERROR_FATAL);
00030 }
00031
00032 if(!$project= Project::getVisibleById($comment->project)) {
00033 $PH->abortWarning("invalid project-id",ERROR_FATAL);
00034 }
00035
00036 $task = $comment->task
00037 ? Task::getVisibleById($comment->task)
00038 : NULL;
00039
00040 ### create from handle ###
00041 $from_handle= $PH->defineFromHandle(array('comment'=>$comment->id));
00042
00043 ## is viewed by user ##
00044 $comment->nowViewedByUser();
00045
00046 ### set up page and write header ####
00047 {
00048 $page= new Page();
00049 $page->cur_tab='projects';
00050
00051
00052 #if($task) {
00053 # $page->crumbs=build_task_crumbs($task);
00054 #}
00055 #else {
00056 $page->cur_crumb= 'projViewTasks';
00057 $page->crumbs= build_project_crumbs($project);
00058 $page->options= build_projView_options($project);
00059 #}
00060 #$page->crumbs[]=new NaviCrumb(array(
00061 # 'target_id' => 'commentView',
00062 #
00063 #));
00064
00065 $type= __('Comment on task','page type');
00066
00067 if($task) {
00068 $folder= $task->getFolderLinks() ."<em>></em>". $task->getLink();
00069 $page->type= $folder." > ". $type;
00070 }
00071 else {
00072 $page->type= $type;
00073 }
00074
00075 $page->title=$comment->name;
00076 $page->title_minor="";;
00077 if($comment->state== -1) {
00078 $page->title_minor=sprintf(__('(deleted %s)','page title add on with date of deletion'),renderTimestamp($comment->deleted));
00079 }
00080
00081 ### page functions ###
00082 $page->add_function(new PageFunction(array(
00083 'target' =>'commentEdit',
00084 'params' =>array('comment'=>$comment->id),
00085 'icon' =>'edit',
00086 'tooltip' =>__('Edit this comment'),
00087 'name' =>__('Edit')
00088 )));
00089
00090 $item = ItemPerson::getAll(array('person'=>$auth->cur_user->id,'item'=>$comment->id));
00091 if((!$item) || ($item[0]->is_bookmark == 0)){
00092 $page->add_function(new PageFunction(array(
00093 'target' =>'itemsAsBookmark',
00094 'params' =>array('comment'=>$comment->id),
00095 'tooltip' =>__('Mark this comment as bookmark'),
00096 'name' =>__('Bookmark'),
00097 )));
00098 }
00099 else{
00100 $page->add_function(new PageFunction(array(
00101 'target' =>'itemsRemoveBookmark',
00102 'params' =>array('comment'=>$comment->id),
00103 'tooltip' =>__('Remove this bookmark'),
00104 'name' =>__('Remove Bookmark'),
00105 )));
00106 }
00107
00108 if($comment->state == ITEMSTATE_DELETED) {
00109
00110 $page->add_function(new PageFunction(array(
00111 'target' =>'commentsUndelete',
00112 'params' =>array('comment'=>$comment->id),
00113 'icon' =>'delete',
00114 'tooltip' =>__('Delete this comment'),
00115 'name' =>__('Restore')
00116 )));
00117 }
00118 else {
00119 $page->add_function(new PageFunction(array(
00120 'target' =>'commentsDelete',
00121 'params' =>array('comment'=>$comment->id),
00122 'icon' =>'delete',
00123 'tooltip' =>__('Delete this comment'),
00124 'name' =>__('Delete')
00125 )));
00126
00127 }
00128
00129
00130 ### render title ###
00131 echo(new PageHeader);
00132 }
00133 echo (new PageContentOpen);
00134
00135
00136 #--- summary ----------------------------------------------------------------
00137 {
00138 $block=new PageBlock(array(
00139 'title' =>__('Description'),
00140 'id' =>'description',
00141 'noshade' =>true,
00142 ));
00143 $block->render_blockStart();
00144 $str= wiki2html($comment->description, $project);
00145
00146 echo "<div class=text>";
00147 echo "$str";
00148 echo "</div>";
00149
00150 $block->render_blockEnd();
00151 }
00152
00153 #--- list comments -------------------------------------------------------------
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 echo '<input type="hidden" name="prj" value="'.$comment->project.'">';
00164
00168 #echo '<input type="hidden" name="parent_task" value="'.$task->id.'">';
00169
00170 echo (new PageContentClose);
00171 echo (new PageHtmlEnd);
00172 }
00173
00174
00175
00176
00177
00185 function commentNew() {
00186 global $PH;
00187 global $COMMENTTYPE_VALUES;
00188
00189 $project=NULL;
00190
00191 $name=get('new_name')
00192 ? get('new_name')
00193 :__('New Comment','Default name of new comment');
00194
00195
00196 ### build new object ###
00197 $newComment= new Comment(array(
00198 'id'=>0,
00199 'name'=>$name,
00200 ));
00201
00202
00203 ### try single project-id ###
00204 if($id=getOnePassedId('prj','projects_*',false)) { #no not abort if not found
00205 if($project= Project::getVisibleById($id)) {
00206 $newComment->project= $project->id;
00207 }
00208 }
00209
00210
00211 ### try single task-id ###
00212 $task=NULL;
00213 if($id=getOnePassedId('tsk','tasks_*',false)) { #no not abort if not found
00214 if($task= Task::getVisibleById($id)) {
00215 $newComment->task= $task->id;
00216
00217 ### try to figure project-id from task ###
00218 if(!$newComment->project) {
00219 $newComment->project= $task->getProject()->id;
00220 }
00221 }
00222 }
00223
00224
00225 ### subtask? ###
00226 if(!$task) {
00227 if($task_id= get('parent_task')) {
00228 if($task= Task::getVisibleById($task_id)) {
00229 $newComment->task= $task->id;
00230
00231 ### try to figure project-id from task ###
00232 if(!$newComment->project) {
00233 $newComment->project= $task->getProject()->id;
00234 }
00235 }
00236 }
00237 }
00238
00239 ### try single company-id ###
00240 if($id=getOnePassedId('company','companies_*',false)) { #no not abort if not found
00241 if($company= Company::getVisibleById($id)) {
00242 $newComment->company= $company->id;
00243 }
00244 }
00245
00246 ### try single person-id ###
00247 if($id=getOnePassedId('person','persons_*',false)) { #no not abort if not found
00248 if($person= Person::getVisibleById($id)) {
00249 $newComment->person= $person->id;
00250 }
00251 }
00252
00253 ### try comment on comment ###
00254 if($id=getOnePassedId('comment','comments_*',false)) { #no not abort if not found
00255 if($comment= Comment::getById($id)) {
00256 $newComment->comment= $comment->id;
00257 $newComment->name=__('Reply to ','prefix for name of new comment on another comment').$comment->name;
00258 $newComment->occasion=$COMMENTTYPE_VALUES['Reply'];
00259
00260 }
00261 }
00262
00263 ### get current project ###
00264 if(!$project) {
00265 if($task) {
00266 if(!$project= Project::getVisibleById($task->project)) {
00267 $PH->abortWarning('invalid project id',ERROR_FATAL);
00268 }
00269 }
00270 else {
00271 $PH->abortWarning('canīt access project',ERROR_BUG);
00272 }
00273 }
00274
00275
00276 ### set a valid create-level ###
00277 $newComment->pub_level= $project->getCurrentLevelCreate();
00278 if($newComment->pub_level < 1) {
00279
00280 ### abort, if not enough rights ###
00281 $PH->abortWarning(__('insuffient rights'),ERROR_RIGHTS);
00282
00283 }
00284
00285 ### render form ###
00286 $PH->show('commentEdit',array('comment'=>$newComment->id), $newComment);
00287 }
00288
00289
00295 function commentEdit($comment=NULL)
00296 {
00297 global $PH;
00298 global $auth;
00299
00300 ### edit existing object or get from database ? ###
00301 if(!$comment) {
00302 $id= getOnePassedId('comment','comments*'); # WARNS if multiple; ABORTS if no id found
00303 $comment= Comment::getVisibleById($id);
00304 if(!$comment) {
00305 $PH->abortWarning("could not get Comment", ERROR_FATAL);
00306 return;
00307 }
00308 }
00309
00310
00311 ### check user-rights ###
00312 if(!$project= Project::getVisibleById($comment->project)) {
00313 $PH->abortWarning("comment without project?", ERROR_BUG);
00314 }
00315 $project->validateEditItem($comment); # aborts if not enough rights to edit
00316 $task= Task::getVisibleById($comment->task);
00317
00318 ### set up page and write header ####
00319 {
00320 $page= new Page(array('use_jscalendar'=>true, 'autofocus_field'=>'comment_name'));
00321 $page->cur_tab='projects';
00322
00323
00324 if($task) {
00325 $page->crumbs=build_task_crumbs($task);
00326 }
00327 else {
00328 $page->crumbs=build_project_crumbs($project);
00329 }
00330 $page->crumbs[]=new NaviCrumb(array(
00331 'target_id' => 'commentEdit',
00332
00333 ));
00334
00335 $page->type=__("Comment");
00336 if($comment->id) {
00337 $page->title=__("Edit Comment","Page title");
00338 }
00339 else {
00340 $page->title=__("New Comment","Page title");
00341 }
00342
00343 if($comment->task && ($task= Task::getVisibleById($comment->task))) {
00344 $page->title_minor= sprintf(__('On task %s','page title add on'),$task->name);
00345 }
00346
00347 else if($project= Project::getVisibleById($comment->project)) {
00348 $page->title_minor= sprintf(__('On project %s','page title add on'),$project->name);
00349 }
00350
00351 echo(new PageHeader);
00352 }
00353 echo (new PageContentOpen);
00354
00355
00356 ### write form #####
00357 {
00358 global $COMMENTTYPE_VALUES;
00359 global $PUB_LEVEL_VALUES;
00360 require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00361
00362 $block=new PageBlock(array(
00363 'id' =>'edit',
00364 'reduced_header' => true,
00365 ));
00366 $block->render_blockStart();
00367
00368
00369 $form=new PageForm();
00370 $form->button_cancel=true;
00371
00372 #foreach($comment->fields as $field) {
00373 # $form->add($field->getFormElement(&$comment));
00374 #}
00375
00376
00377 $form->add($comment->fields['name']->getFormElement(&$comment));
00378 $e= $comment->fields['description']->getFormElement(&$comment);
00379 $e->rows=22;
00380 $form->add($e);
00381
00382 $form->add(new Form_HiddenField('comment_project', '', $comment->project));
00383
00384 $form->add(new Form_HiddenField('comment_task', '', $comment->task));
00385 $form->add(new Form_HiddenField('comment_comment', '', $comment->comment));
00386
00387 #$form->add(new Form_Dropdown('comment_occasion', __('Occasion','form label'),$COMMENTTYPE_VALUES,$comment->occasion));
00388
00389 ### public-level ###
00390 if(($pub_levels=$comment->getValidUserSetPublevel())
00391 && count($pub_levels)>1) {
00392 $form->add(new Form_Dropdown('comment_pub_level', __('Publish to','form label'),$pub_levels,$comment->pub_level));
00393 }
00394
00395 if($auth->cur_user->id == confGet('ANONYMOUS_USER')) {
00396 $form->addCaptcha();
00397 }
00398
00399 echo ($form);
00400
00401 $block->render_blockEnd();
00402
00403 #echo($form);
00404
00405 $PH->go_submit= 'commentEditSubmit';
00406 echo "<input type=hidden name='comment' value='$comment->id'>";
00407 }
00408 echo (new PageContentClose);
00409 echo (new PageHtmlEnd);
00410 }
00411
00412
00416 function commentEditSubmit(){
00417 global $PH;
00418 global $auth;
00419
00420 ### cancel ###
00421 if(get('form_do_cancel')) {
00422 if(!$PH->showFromPage()) {
00423 $PH->show('home');
00424 }
00425 exit();
00426 }
00427
00428
00429 ### get comment ####
00430 $id= getOnePassedId('comment');
00431
00432 ### new object? ###
00433 if($id == 0) {
00434 $comment= new Comment(array());
00435 }
00436 ### ...or from db ###
00437 else {
00438 $comment= Comment::getVisibleById($id);
00439 if(!$comment) {
00440 $PH->abortWarning("Could not get comment");
00441 return;
00442 }
00443 }
00444
00445 $comment->validateEditRequestTime();
00446 validateFormCaptcha(true);
00447
00448
00449 # retrieve all possible values from post-data
00450 # NOTE:
00451 # - this could be an security-issue.
00452 # - TODO: as some kind of form-edit-behaviour to field-definition
00453 foreach($comment->fields as $f) {
00454 $name=$f->name;
00455 $f->parseForm(&$comment);
00456 }
00457 if($tmp= get('comment_project')) {
00458 $comment->project= $tmp;
00459 }
00460 if($tmp= get('comment_task')) {
00461 if($task = Task::getVisibleById($tmp)) {
00462
00463 $comment->task= $task->id;
00464 }
00465 }
00466 if($tmp= get('comment_occasion')) {
00467 $comment->occasion= $tmp;
00468 }
00469
00470
00471 if($tmp= get('comment_pub_level')) {
00472 $comment->pub_level= $tmp;
00473 }
00474
00475
00476 ### be sure the comment is connected somewhere ###
00477 if(!$comment->project && !$comment->task && !$comment->comment && !$comment->company && !$comment->person) {
00478 $PH->abortWarning("ERROR:Comment not connected anywhere. This is an internal error and should be reported");
00479 }
00480
00481 ### write to db ###
00482 if($comment->id == 0) {
00483 $comment->insert();
00484 }
00485 else {
00486 $comment->update();
00487 }
00488
00489 ### change task update modification date ###
00490 if(isset($task)) {
00491
00492 ### Check if now longer new ###
00493 if($task->status == STATUS_NEW) {
00494 global $auth;
00495 if($task->created < $auth->cur_user->last_login) {
00496 $task->status = STATUS_OPEN;
00497 }
00498 }
00499 $task->update(array('modified','status'));
00500
00501
00502 }
00503
00504 ### display taskView ####
00505 if(!$PH->showFromPage()) {
00506 $PH->show('home');
00507 }
00508 }
00509
00510
00514 function commentsDelete()
00515 {
00516 global $PH;
00517
00518 ### get comment ####
00519 $ids= getPassedIds('comment','comments_*');
00520
00521 if(!$ids) {
00522 $PH->abortWarning(__("Select some comments to delete"));
00523 return;
00524 }
00525
00526 $counter=0;
00527 $errors=0;
00528 foreach($ids as $id) {
00529 $c= Comment::getEditableById($id);
00530 if(!$c) {
00531 $PH->abortWarning("Not enought rights");
00532 }
00533
00537 if($c->delete()) {
00538 if($sub_comments= $c->getSubComments()) {
00539 foreach($sub_comments as $sc) {
00543 $sc->comment= $c->comment;
00544 $sc->update();
00545 }
00546 }
00547 $counter++;
00548 }
00549 else {
00550 $errors++;
00551 }
00552 }
00553 if($errors) {
00554 new FeedbackWarning(sprintf(__("Failed to delete %s comments"),$errors));
00555 }
00556 else {
00557 new FeedbackMessage(sprintf(__("Moved %s comments to trash"), $counter));
00558 }
00559
00560 ### display taskView ####
00561 if(!$PH->showFromPage()) {
00562 $PH->show('home');
00563 }
00564 }
00565
00566
00567
00571 function commentsUndelete()
00572 {
00573 global $PH;
00574
00575 ### get comment ####
00576 $ids= getPassedIds('comment','comments_*');
00577
00578 if(!$ids) {
00579 $PH->abortWarning(__("Select some comments to restore"));
00580 return;
00581 }
00582
00583 $counter=0;
00584 $errors=0;
00585 foreach($ids as $id) {
00586 $c= Comment::getEditableById($id);
00587 if(!$c) {
00588 $PH->abortWarning("Not enought rights");
00589 }
00590
00591 if($c->state == ITEMSTATE_DELETED) {
00592 $c->state = ITEMSTATE_NORMAL;
00593 if($c->update()) {
00594 $counter++;
00595 }
00596 else {
00597 $errors++;
00598 }
00599 }
00600 else {
00601 $errors++;
00602 }
00603 }
00604 if($errors) {
00605 new FeedbackWarning(sprintf(__("Failed to restore %s comments"),$errors));
00606 }
00607 else {
00608 new FeedbackMessage(sprintf(__("Restored %s comments"), $counter));
00609 }
00610
00611 ### display taskView ####
00612 if(!$PH->showFromPage()) {
00613 $PH->show('home');
00614 }
00615 }
00616
00617
00621 function commentToggleViewCollapsed()
00622 {
00623 global $PH;
00624
00625 ### get comment ####
00626 $id= getOnePassedId('comment','comments_*');
00627
00628 if(!$comment=Comment::getEditableById($id)) {
00629 $PH->abortWarning("undefined comment");
00630 }
00631 if($comment->view_collapsed) {
00632 $comment->view_collapsed=0;
00633 }
00634 else {
00635 $comment->view_collapsed=1;
00636 }
00637 $comment->update();
00638
00639 ### display taskView ####
00640 if(!$PH->showFromPage()) {
00641 $PH->show('home');
00642 }
00643 }
00644
00645
00651 function commentsCollapseView()
00652 {
00653 global $PH;
00654
00655 ### get comment ####
00656 #$ids= getPassedIds('comment','comments_*');
00657
00662 $tsk=get('tsk');
00663 if($task=Task::getEditableById($tsk)) {
00664 $ids= $task->getComments();
00665
00666 foreach($ids as $obj) {
00667 if(!$comment=Comment::getEditableById($obj->id)) {
00668 $PH->abortWarning('undefined comment','warning');
00669 }
00670 if(! $comment->view_collapsed) {
00671 $comment->view_collapsed=1;
00672 $comment->update();
00673 }
00674 }
00675 }
00676 else {
00681 ### abort, if not enough rights ###
00682 $PH->abortWarning(__('insuffient rights'),ERROR_RIGHTS);
00683 }
00684
00685 ### display taskView ####
00686 if(!$PH->showFromPage()) {
00687 $PH->show('home');
00688 }
00689 }
00690
00691 function commentsExpandView()
00692 {
00693 global $PH;
00694
00695 ### get comment ####
00696 #$ids= getPassedIds('comment','comments_*');
00697
00702 $tsk= get('tsk');
00703 if($task=Task::getEditableById($tsk)) {
00704 $ids= $task->getComments();
00705
00706 foreach($ids as $obj) {
00707 if(!$comment=Comment::getEditableById($obj->id)) {
00708 $PH->abortWarning('undefined comment','warning');
00709 }
00710 $list= $comment->getSubComments();
00711 $list[]= $comment;
00712
00713 foreach($list as $c) {
00714 if( $c->view_collapsed) {
00715 $c->view_collapsed= 0;
00716 $c->update();
00717 }
00718 }
00719 }
00720 }
00721 else {
00726 ### abort, if not enough rights ###
00727 $PH->abortWarning(__('insuffient rights'),ERROR_RIGHTS);
00728 }
00729
00730 ### display taskView ####
00731 if(!$PH->showFromPage()) {
00732 $PH->show('home');
00733 }
00734 }
00735
00736
00737
00738
00739
00740
00741
00742
00743
00749 function commentsMoveToFolder()
00750 {
00751 global $PH;
00752
00753 $comment_ids= getPassedIds('comment','comments_*');
00754
00755 if(!$comment_ids) {
00756 $PH->abortWarning(__("Select some comments to move"));
00757 return;
00758 }
00759
00763 $target_id=-1; # target is unknown
00764 $folder_ids= getPassedIds('folder','folders_*');
00765
00766 if(count($folder_ids) == 1) {
00767 if($folder_task= Task::getVisibleById($folder_ids[0])) {
00768 $target_id= $folder_task->id;
00769 }
00770 }
00771 else if(get('from_selection')) {
00772 $target_id=0; # to ungrout to root?
00773 }
00774 if($target_id != -1) {
00775
00776 if($target_id != 0){
00777 if(!$target_task= Task::getEditableById($target_id)) {
00778 $PH->abortWarning(__("insufficient rights"));
00779 }
00780 }
00781
00782 $count=0;
00783 foreach($comment_ids as $id) {
00784 if($comment= Comment::getEditableById($id)) {
00785
00786 $comment->task= $target_id;
00787
00793 $comment->comment= 0;
00794 $comment->update();
00795 }
00796 else {
00797 new FeedbackWarning(sprintf(__("Can not edit comment %s"), asHtml($comment->name)));
00798 }
00799 }
00800
00801 ### return to from-page? ###
00802 if(!$PH->showFromPage()) {
00803 $PH->show('home');
00804 }
00805 exit();
00806 }
00807
00808
00812 require_once(confGet('DIR_STREBER') . 'lists/list_tasks.inc.php');
00813
00814 ### get project ####
00815 if(!$comment= Comment::getVisibleById($comment_ids[0])) {
00816 $PH->abortWarning("could not get comment", ERROR_BUG);
00817 }
00818
00819 if(!$project= Project::getVisibleById($comment->project)) {
00820 $PH->abortWarning("task without project?", ERROR_BUG);
00821 }
00822
00823
00824 ### set up page and write header ####
00825 {
00826 $page= new Page(array('use_jscalendar'=>false, 'autofocus_field'=>'company_name'));
00827 $page->cur_tab='projects';
00828 $page->type= __("Edit tasks");
00829 $page->title= $project->name;
00830 $page->title_minor=__("Select one folder to move comments into");
00831
00832 $page->crumbs= build_project_crumbs($project);
00833
00834 $page->options[]= new NaviOption(array(
00835 'target_id' =>'commentsMoveToFolder',
00836 ));
00837
00838 echo(new PageHeader);
00839 }
00840 echo (new PageContentOpen);
00841
00842 echo __("... or select nothing to move to project root");
00843
00844 ### write form #####
00845 {
00846 ### write selected comments as hidden fields ###
00847 foreach($comment_ids as $id) {
00848 if($comment= Comment::getEditableById($id)) {
00849 echo "<input type=hidden name='comments_{$id}_chk' value='1'>";
00850 }
00851 }
00852
00853
00854 ### write list of folders ###
00855 {
00856 $list= new ListBlock_tasks();
00857 $list->reduced_header= true;
00858 $list->query_options['show_folders']= true;
00859 $list->query_options['folders_only']= true;
00860 $list->query_options['project']= $project->id;
00861 $list->groupings= NULL;
00862 $list->block_functions= NULL;
00863 $list->id= 'folders';
00864 unset($list->columns['project']);
00865 unset($list->columns['status']);
00866 unset($list->columns['date_start']);
00867 unset($list->columns['days_left']);
00868 unset($list->columns['created_by']);
00869 unset($list->columns['label']);
00870 $list->no_items_html=__("No folders in this project...");
00871
00872 $list->functions= array();
00873
00874 $list->active_block_function = 'tree';
00875
00876
00877 $list->print_automatic($project);
00878 }
00879
00880
00881 echo "<input type=hidden name='from_selection' value='1'>"; # keep flag to ungroup comments
00882 echo "<input type=hidden name='project' value='$project->id'>";
00883 $button_name=__("Move items");
00884 echo "<input class=button2 type=submit value='$button_name'>";
00885
00886 $PH->go_submit='commentsMoveToFolder';
00887
00888 }
00889 echo (new PageContentClose);
00890 echo (new PageHtmlEnd());
00891
00892 }
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 ?>