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
00010 require_once(confGet('DIR_STREBER') . 'db/class_task.inc.php');
00011 require_once(confGet('DIR_STREBER') . 'db/class_project.inc.php');
00012 require_once(confGet('DIR_STREBER') . 'db/db_itemperson.inc.php');
00013 require_once(confGet('DIR_STREBER') . 'render/render_list.inc.php');
00014 require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00015 require_once(confGet('DIR_STREBER') . 'lists/list_taskfolders.inc.php');
00016 require_once(confGet('DIR_STREBER') . 'lists/list_comments.inc.php');
00017 require_once(confGet('DIR_STREBER') . 'lists/list_tasks.inc.php');
00018
00019
00026 function itemView()
00027 {
00028 global $PH;
00029 if(!$id= intval(get('item'))) {
00030 $id= intval(get('id'));
00031 }
00032
00033 if($item= DbProjectItem::getVisibleById($id)) {
00034 switch($item->type) {
00035 case ITEM_TASK:
00036 $PH->show('taskView',array('tsk'=>$id));
00037 return;
00038 case ITEM_FILE:
00039 $PH->show('fileView',array('file'=>$id));
00040 return;
00041 case ITEM_COMMENT:
00042 $PH->show('commentView',array('comment'=>$id));
00043 return;
00044 case ITEM_EFFORT:
00045 $PH->show('effortView',array('effort'=>$id));
00046 return;
00047 case ITEM_PERSON:
00048 $PH->show('personView',array('person'=>$id));
00049 return;
00050 case ITEM_PROJECT:
00051 $PH->show('projView',array('prj'=>$id));
00052 return;
00053 case ITEM_COMPANY:
00054 $PH->show('companyView',array('company'=>$id));
00055 return;
00056 default:
00057 $PH->abortWarning("Unknown item");
00058 return;
00059 }
00060 }
00061 else {
00062 $PH->abortWarning("Unknown item");
00063 }
00064 }
00065
00066
00067
00068 function itemsSetPubLevel()
00069 {
00070 global $PH;
00071
00072 $ids= getPassedIds('item','items_*');
00073 global $g_pub_level_names;
00074
00075 if(!$ids) {
00076 $PH->abortWarning(__("Select some items(s) to change pub level"), ERROR_NOTE);
00077 return;
00078 }
00079 if(!($new_pub_level= get('item_pub_level'))
00080 ||
00081 !isset($g_pub_level_names[$new_pub_level])
00082 ) {
00083 $PH->abortWarning(__("itemsSetPubLevel requires item_pub_level"), ERROR_NOTE);
00084 return;
00085 }
00086
00087 $count = 0;
00088 $num_errors = 0;
00089
00090 foreach($ids as $id) {
00091 if($item = DbProjectItem::getEditableById($id)) {
00092
00093 $count++;
00094 $item->pub_level = $new_pub_level;
00095 $item->update();
00096 }
00097 else {
00098 $num_errors++;
00099 }
00100 }
00101 new FeedbackMessage(sprintf(__("Made %s items public to %s"),$count, $g_pub_level_names[$new_pub_level]));
00102 if($num_errors) {
00103 new FeedbackWarning(sprintf(__("%s error(s) occured"), $num_errors));
00104 }
00105
00106 ### return to from-page ###
00107 if(!$PH->showFromPage()) {
00108 $PH->show('home');
00109 }
00110 }
00111
00112
00116 function itemsAsBookmark()
00117 {
00118 global $PH;
00119 global $auth;
00120
00121 $count = 0;
00122 $valid = false;
00123
00124 if($ids = getPassedIds('task', 'tasks_*')){
00125 $valid = true;
00126 }
00127 elseif($ids = getPassedIds('person', 'persons_*')){
00128 $valid = true;
00129 }
00130 elseif($ids = getPassedIds('company', 'companies_*')){
00131 $valid = true;
00132 }
00133 elseif($ids = getPassedIds('proj', 'projects_*')){
00134 $valid = true;
00135 }
00136 elseif($ids = getPassedIds('effort', 'efforts_*')){
00137 $valid = true;
00138 }
00139 elseif($ids = getPassedIds('comment', 'comments_*')){
00140 $valid = true;
00141 }
00142 elseif($ids = getPassedIds('file', 'files_*')){
00143 $valid = true;
00144 }
00145 elseif($ids = getPassedIds('version', 'versions_*')){
00146 $valid = true;
00147 }
00148 else{
00149 $PH->abortWarning(__("No item(s) selected."), ERROR_NOTE);
00150 }
00151
00152 ## not a nice solution with 'bookmark'=>$ids[0], but the more important value is the '$ids' value ##
00153 if($valid){
00154 $PH->show('itemMonitorEdit', array('bookmark'=>$ids[0]), $ids);
00155 }
00156 }
00157
00161 function itemsRemoveBookmark()
00162 {
00163 global $PH;
00164 global $auth;
00165
00166 $count = 0;
00167 $error = 0;
00168 $valid = false;
00169
00170 $ids = getPassedIds('bookmark', 'bookmarks_*');
00171
00172 if(!$ids){
00173 if($ids = getPassedIds('task', 'tasks_*')){
00174 $valid = true;
00175 }
00176 elseif($ids = getPassedIds('person', 'persons_*')){
00177 $valid = true;
00178 }
00179 elseif($ids = getPassedIds('company', 'companies_*')){
00180 $valid = true;
00181 }
00182 elseif($ids = getPassedIds('proj', 'projects_*')){
00183 $valid = true;
00184 }
00185 elseif($ids = getPassedIds('effort', 'efforts_*')){
00186 $valid = true;
00187 }
00188 elseif($ids = getPassedIds('comment', 'comments_*')){
00189 $valid = true;
00190 }
00191 elseif($ids = getPassedIds('file', 'files_*')){
00192 $valid = true;
00193 }
00194 elseif($ids = getPassedIds('version', 'versions_*')){
00195 $valid = true;
00196 }
00197 }
00198
00199 if(!$ids){
00200 $PH->abortWarning(__("Select one or more bookmark(s)"), ERROR_NOTE);
00201 return;
00202 }
00203 else{
00204 foreach($ids as $id){
00205 if($item = ItemPerson::getAll(array(
00206 'person'=>$auth->cur_user->id,
00207 'item'=>$id)
00208 )){
00209 $item[0]->is_bookmark = false;
00210 $item[0]->update();
00211 $count++;
00212 }
00213 else{
00214 $error++;
00215 }
00216 }
00217
00218 if($count){
00219 new FeedbackMessage(sprintf(__("Removed %s bookmark(s)."),$count));
00220 }
00221
00222 if($error){
00223 new FeedbackMessage(sprintf(__('ERROR: Cannot remove %s bookmark(s). Please try again.'),$error));
00224 }
00225 }
00226
00227 if(!$PH->showFromPage()){
00228 $PH->show('home');
00229 }
00230 }
00231
00235 function itemMonitorEdit($bookmark=NULL)
00236 {
00237 global $PH;
00238 global $auth;
00239 global $g_notitychange_period;
00240
00241 $is_already_bookmark = FALSE;
00242
00243 ### if you edit bookmarks from bookmark list ###
00244 if(!$bookmark){
00245 $ids = getPassedIds('bookmark', 'bookmarks_*');
00246 if(!$ids){
00247 $PH->abortWarning(__("Select one or more bookmark(s)"), ERROR_NOTE);
00248 return;
00249 }
00250 elseif(count($ids) > 1) {
00251 $PH->show('itemMonitorEditMultiple');
00252 exit();
00253 }
00254
00255 if(!$bookmark = ItemPerson::getAll(array('item'=>$ids[0], 'person'=>$auth->cur_user->id, 'is_bookmark'=>1))) {
00256 $PH->abortWarning(__("An error occured"), ERROR_NOTE);
00257 }
00258 else{
00259 $editbookmark = $bookmark[0];
00260
00261 if(!$item = DbProjectItem::getById($editbookmark->item)) {
00262 $PH->abortWarning("FATAL error! Related information cannot be opened.");
00263 }
00264
00265 $is_already_bookmark = TRUE;
00266 }
00267 }
00268 ### if you add new bookmarks ###
00269 else{
00270 if(!$bookmark){
00271 $PH->abortWarning(__("An error occured"), ERROR_NOTE);
00272 return;
00273 }
00274 elseif(count($bookmark) > 1)
00275 {
00276 ## not a nice solution with 'bookmark'=>$ids[0], but the more important value is the '$ids' value ##
00277 $PH->show('itemMonitorEditMultiple', array('bookmark'=>$bookmark[0]), $bookmark);
00278 exit();
00279 }
00280
00281 if($bookmarkitem = ItemPerson::getAll(array('person'=>$auth->cur_user->id, 'item'=>$bookmark[0], 'is_bookmark'=>0))){
00282 $editbookmark = $bookmarkitem[0];
00283
00284 if(!$item = DbProjectItem::getById($editbookmark->item)){
00285 $PH->abortWarning("FATAL error! Related information cannot be opened.");
00286 }
00287 $is_already_bookmark = FALSE;
00288 }
00289 elseif($bookmarkitem = ItemPerson::getAll(array('person'=>$auth->cur_user->id, 'item'=>$bookmark[0], 'is_bookmark'=>1))){
00290 $editbookmark = $bookmarkitem[0];
00291
00292 if(!$item = DbProjectItem::getById($editbookmark->item)){
00293 $PH->abortWarning("FATAL error! Related information cannot be opened.");
00294 }
00295 $is_already_bookmark = TRUE;
00296 }
00297 else{
00298 $date = getGMTString();
00299 $editbookmark = new ItemPerson(array(
00300 'id'=>0,
00301 'item'=>$bookmark[0],
00302 'person'=>$auth->cur_user->id,
00303 'is_bookmark'=>1,
00304 'notify_on_change'=>false,
00305 'notify_if_unchanged'=>false,
00306 'created'=>$date));
00307
00308 if(!$item = DbProjectItem::getById($bookmark[0])){
00309 $PH->abortWarning("FATAL error! Related information cannot be opened.");
00310 }
00311 $is_already_bookmark = FALSE;
00312 }
00313 }
00314
00315 ## edit form ##
00316 {
00317 ## get item name ##
00318 $str_name = '';
00319 if($type = $item->type){
00320 switch($type) {
00321 case ITEM_TASK:
00322 require_once("db/class_task.inc.php");
00323 if($task = Task::getVisibleById($item->id)) {
00324 $str_name = $task->name;
00325 }
00326 break;
00327
00328 case ITEM_COMMENT:
00329 require_once("db/class_comment.inc.php");
00330 if($comment = Comment::getVisibleById($item->id)) {
00331 $str_name = $comment->name;
00332 }
00333 break;
00334
00335 case ITEM_PERSON:
00336 require_once("db/class_person.inc.php");
00337 if($person = Person::getVisibleById($item->id)) {
00338 $str_name = $person->name;
00339 }
00340 break;
00341
00342 case ITEM_EFFORT:
00343 require_once("db/class_effort.inc.php");
00344 if($e = Effort::getVisibleById($item->id)) {
00345 $str_name = $e->name;
00346 }
00347 break;
00348
00349 case ITEM_FILE:
00350 require_once("db/class_file.inc.php");
00351 if($f = File::getVisibleById($item->id)) {
00352 $str_name = $f->org_filename;
00353 }
00354 break;
00355
00356 case ITEM_PROJECT:
00357 require_once("db/class_project.inc.php");
00358 if($prj = Project::getVisibleById($item->id)) {
00359 $str_name = $prj->name;
00360 }
00361 break;
00362
00363 case ITEM_COMPANY:
00364 require_once("db/class_company.inc.php");
00365 if($c = Company::getVisibleById($item->id)) {
00366 $str_name = $c->name;
00367 }
00368 break;
00369
00370 case ITEM_VERSION:
00371 require_once("db/class_task.inc.php");
00372 if($tsk = Task::getVisibleById($item->id)) {
00373 $str_name = $tsk->name;
00374 }
00375 break;
00376
00377 default:
00378 break;
00379
00380 }
00381 }
00382
00383 ### set up page and write header ####
00384 {
00385 $page = new Page();
00386 $page->cur_tab = 'home';
00387
00388 $page->options = array(new NaviOption(array('target_id'=>'itemMonitorEdit','name'=>__('Edit bookmark'))));
00389
00390 $page->type= sprintf(__('Edit bookmark: "%s"', 'page title') , $str_name);
00391 $page->title = sprintf(__('Bookmark: "%s"') , $str_name);
00392 $page->title_minor = __('Edit');
00393
00394 echo(new PageHeader);
00395 }
00396
00397 echo (new PageContentOpen);
00398
00399 ### write form #####
00400 {
00401 require_once(confGet('DIR_STREBER') . 'render/render_form.inc.php');
00402
00403 $block = new PageBlock(array('id'=>'functions','reduced_header' => true,));
00404 $block->render_blockStart();
00405
00406 $form = new PageForm();
00407 $form->button_cancel = true;
00408
00409 $form->add($editbookmark->fields['comment']->getFormElement(&$editbookmark));
00410 $form->add(new Form_checkbox("notify_on_change", __('Notify on change'), $editbookmark->notify_on_change));
00411
00412 $form->add(new Form_Dropdown("notify_period", __('Notify if unchanged in'), array_flip($g_notitychange_period), $editbookmark->notify_if_unchanged));
00413
00414 $form->add(new Form_HiddenField('bookmark','',$editbookmark->item));
00415 $form->add(new Form_HiddenField('bookmark_id','',$editbookmark->id));
00416 $form->add(new Form_HiddenField('is_already_bookmark','',$is_already_bookmark));
00417
00418 echo($form);
00419
00420 $PH->go_submit = 'itemMonitorEditSubmit';
00421
00422 $block->render_blockEnd();
00423 }
00424
00425 echo (new PageContentClose);
00426 echo (new PageHtmlEnd);
00427 }
00428
00429 }
00430
00434 function itemMonitorEditSubmit()
00435 {
00436 global $PH;
00437 global $auth;
00438
00439 ### cancel ? ###
00440 if(get('form_do_cancel')) {
00441 if(!$PH->showFromPage()) {
00442 $PH->show('home',array());
00443 }
00444 exit();
00445 }
00446
00447 ### get bookmark ####
00448 $id = getOnePassedId('bookmark');
00449 $bm_id = getOnePassedId('bookmark_id');
00450 $is_already_bookmark = getOnePassedId('is_already_bookmark');
00451 $count = 0;
00452 if(($bm_id != 0) && ($is_already_bookmark)){
00453 if(!$bookmark = ItemPerson::getAll(array('item'=>$id, 'person'=>$auth->cur_user->id, 'is_bookmark'=>1))) {
00454 $PH->abortWarning(__('Could not get bookmark'));
00455 return;
00456 }
00457 }
00458 elseif(($bm_id != 0) && (!$is_already_bookmark)){
00459 if(!$bookmark = ItemPerson::getAll(array('item'=>$id, 'person'=>$auth->cur_user->id))) {
00460 $PH->abortWarning(__('Could not get bookmark'));
00461 return;
00462 }
00463 }
00464 elseif($bm_id == 0){
00465 $date = getGMTString();
00466 $bookmark = new ItemPerson(array(
00467 'id'=>0,
00468 'item'=>$id,
00469 'person'=>$auth->cur_user->id,
00470 'is_bookmark'=>1,
00471 'created'=>$date));
00472 }
00473
00474 if($bm_id != 0){
00475 $bookmark = $bookmark[0];
00476 }
00477
00478 # retrieve all possible values from post-data
00479 # NOTE:
00480 # - this could be an security-issue.
00481 # - TODO: as some kind of form-edit-behaviour to field-definition
00482 foreach($bookmark->fields as $f) {
00483 $f->parseForm(&$bookmark);
00484 }
00485
00486 $notify_on_change = get('notify_on_change');
00487
00488 if($notify_on_change){
00489 $bookmark->notify_on_change = true;
00490 $bookmark->notify_date = getGMTString();
00491 }
00492 else{
00493 $bookmark->notify_on_change = false;
00494 }
00495
00496 $notify_period = get('notify_period');
00497
00498 if(!is_null($notify_period)){
00499 $bookmark->notify_if_unchanged = $notify_period;
00500 }
00501
00502 if(($bm_id != 0) && ($is_already_bookmark)){
00503 $bookmark->update();
00504 }
00505 elseif(($bm_id != 0) && (!$is_already_bookmark)){
00506 $bookmark->is_bookmark = true;
00507 $bookmark->created = getGMTString();
00508 $bookmark->update();
00509 $count++;
00510 }
00511 elseif($bm_id == 0){
00512 $bookmark->insert();
00513 $count++;
00514 }
00515
00516 if($count){
00517 new FeedbackMessage(sprintf(__("Added %s bookmark(s)."),$count));
00518 }
00519
00520 ### display fromPage ####
00521 if(!$PH->showFromPage()) {
00522 $PH->show('home',array());
00523 }
00524 }
00525
00529 function itemMonitorEditMultiple($thebookmarks=NULL)
00530 {
00531 global $PH;
00532 global $auth;
00533 global $g_notitychange_period;
00534
00535 $is_already_bookmark = array();
00536 $bookmarks = array();
00537 $items = array();
00538
00539 $edit_fields=array(
00540 'notify_if_unchanged',
00541 'notify_on_change'
00542 );
00543 $different_fields=array(); # hash containing fieldnames which are different in bookmarks
00544
00545 if(!$thebookmarks){
00546 $item_ids = getPassedIds('bookmark', 'bookmarks_*');
00547
00548 foreach($item_ids as $is)
00549 {
00550 if($bookmark = ItemPerson::getAll(array('item'=>$is, 'person'=>$auth->cur_user->id))){
00551 if($item = DbProjectItem::getById($bookmark[0]->item)){
00552 $bookmarks[] = $bookmark[0];
00553 $items[] = $item;
00554 $is_already_bookmark[$bookmark[0]->id] = true;
00555 }
00556 }
00557 }
00558 }
00559 else{
00560 $item_ids = $thebookmarks;
00561
00562 foreach($item_ids as $is){
00563 if($bookmark = ItemPerson::getAll(array('item'=>$is, 'person'=>$auth->cur_user->id, 'is_bookmark'=>0))){
00564 if($item = DbProjectItem::getById($bookmark[0]->item)){
00565 $bookmarks[] = $bookmark[0];
00566 $items[] = $item;
00567 $is_already_bookmark[$bookmark[0]->id] = false;
00568 }
00569 }
00570 elseif($bookmark = ItemPerson::getAll(array('item'=>$is, 'person'=>$auth->cur_user->id, 'is_bookmark'=>1))){
00571 if($item = DbProjectItem::getById($bookmark[0]->item)){
00572 $bookmarks[] = $bookmark[0];
00573 $items[] = $item;
00574 $is_already_bookmark[$bookmark[0]->id] = true;
00575 }
00576 }
00577 else{
00578 $date = getGMTString();
00579 $bookmark = new ItemPerson(array(
00580 'id'=>0,
00581 'item'=>$is,
00582 'person'=>$auth->cur_user->id,
00583 'is_bookmark'=>1,
00584 'notify_if_unchanged'=>0,
00585 'notify_on_change'=>0,
00586 'created'=>$date));
00587
00588 if($item = DbProjectItem::getById($is)){
00589 $bookmarks[] = $bookmark;
00590 $items[] = $item;
00591 $is_already_bookmark[$bookmark->id] = false;
00592 }
00593 }
00594 }
00595 }
00596
00597 ## edit form ##
00598 {
00599 ### set up page and write header ####
00600 {
00601 $page = new Page();
00602 $page->cur_tab = 'home';
00603
00604 $page->options = array(new NaviOption(array('target_id'=>'itemMonitorEdit','name'=>__('Edit bookmarks'))));
00605
00606 $page->type= __('Edit multiple bookmarks', 'page title');
00607 $page->title = sprintf(__('Edit %s bookmark(s)'), count($items));
00608 $page->title_minor = __('Edit');
00609
00610 echo(new PageHeader);
00611 }
00612
00613 echo (new PageContentOpen);
00614
00615 echo "<ol>";
00616 foreach($items as $item){
00617
00618 ## get item name ##
00619 $str_link = '';
00620 if($type = $item->type){
00621 switch($type) {
00622 case ITEM_TASK:
00623 require_once("db/class_task.inc.php");
00624 if($task = Task::getVisibleById($item->id)) {
00625 $str_link = $task->getLink(false);
00626 }
00627 break;
00628
00629 case ITEM_COMMENT:
00630 require_once("db/class_comment.inc.php");
00631 if($comment = Comment::getVisibleById($item->id)) {
00632 $str_link = $comment->getLink(false);
00633 }
00634 break;
00635
00636 case ITEM_PERSON:
00637 require_once("db/class_person.inc.php");
00638 if($person = Person::getVisibleById($item->id)) {
00639 $str_link = $person->getLink(false);
00640 }
00641 break;
00642
00643 case ITEM_EFFORT:
00644 require_once("db/class_effort.inc.php");
00645 if($e = Effort::getVisibleById($item->id)) {
00646 $str_link = $e->getLink(false);
00647 }
00648 break;
00649
00650 case ITEM_FILE:
00651 require_once("db/class_file.inc.php");
00652 if($f = File::getVisibleById($item->id)) {
00653 $str_link = $f->getLink(false);
00654 }
00655 break;
00656
00657 case ITEM_PROJECT:
00658 require_once("db/class_project.inc.php");
00659 if($prj = Project::getVisibleById($item->id)) {
00660 $str_link = $prj->getLink(false);
00661 }
00662 break;
00663
00664 case ITEM_COMPANY:
00665 require_once("db/class_company.inc.php");
00666 if($c = Company::getVisibleById($item->id)) {
00667 $str_link = $c->getLink(false);
00668 }
00669 break;
00670
00671 case ITEM_VERSION:
00672 require_once("db/class_task.inc.php");
00673 if($tsk = Task::getVisibleById($item->id)) {
00674 $str_link = $tsk->getLink(false);
00675 }
00676 break;
00677
00678 default:
00679 break;
00680
00681 }
00682 }
00683
00684 echo "<li>" . $str_link . "</li>";
00685 }
00686 echo "</ol>";
00687
00688 foreach($bookmarks as $bookmark){
00689 foreach($edit_fields as $field_name) {
00690 if($bookmark->$field_name != $bookmarks[0]->$field_name) {
00691 $different_fields[$field_name]= true;
00692 }
00693 }
00694 }
00695
00696 $block = new PageBlock(array('id'=>'functions','reduced_header' => true,));
00697 $block->render_blockStart();
00698
00699 $form = new PageForm();
00700 $form->button_cancel = true;
00701
00702 ### notify on change ###
00703 {
00704 $b = array();
00705 $b[0] = __('no');
00706 $b[1] = __('yes');
00707 if(isset($different_fields['notify_on_change'])) {
00708 $b[-1]= __('-- keep different --');
00709 $form->add(new Form_Dropdown('notify_on_change',__("Notify on change"),array_flip($b), -1));
00710 }
00711 else {
00712 $form->add(new Form_Dropdown('notify_on_change',__("Notify on change"),array_flip($b), $bookmarks[0]->notify_on_change));
00713 }
00714 }
00715
00716 ### notify if unchanged ###
00717 {
00718 $a = array();
00719 foreach($g_notitychange_period as $key=>$value) {
00720 $a[$key] = $value;
00721 }
00722 if(isset($different_fields['notify_if_unchanged'])) {
00723 $a[-1]= __('-- keep different --');
00724 $form->add(new Form_Dropdown('notify_if_unchanged',__("Notify if unchanged in"),array_flip($a), -1));
00725 }
00726 else {
00727 $form->add(new Form_Dropdown('notify_if_unchanged',__("Notify if unchanged in"),array_flip($a), $bookmarks[0]->notify_if_unchanged));
00728 }
00729 }
00730
00731 $number = 0;
00732 foreach($bookmarks as $bm){
00733 $form->add(new Form_HiddenField("bookmark_id_{$number}",'',$bm->id));
00734 $form->add(new Form_HiddenField("bookmark_item_{$number}",'',$bm->item));
00735 $form->add(new Form_HiddenField("is_already_bookmark_{$number}",'',$is_already_bookmark[$bm->id]));
00736 $number++;
00737 }
00738
00739 $form->add(new Form_HiddenField("number",'',$number));
00740
00741 echo($form);
00742
00743 $block->render_blockEnd();
00744
00745 $PH->go_submit = 'itemMonitorEditMultipleSubmit';
00746
00747 echo (new PageContentClose);
00748 echo (new PageHtmlEnd);
00749 }
00750 }
00751
00755 function itemMonitorEditMultipleSubmit()
00756 {
00757 global $PH;
00758 global $auth;
00759
00760 ### cancel ? ###
00761 if(get('form_do_cancel')) {
00762 if(!$PH->showFromPage()) {
00763 $PH->show('home',array());
00764 }
00765 exit();
00766 }
00767
00768 $count = 0;
00769 $error = 0;
00770 $edit = 0;
00771 $bookmark_array = array();
00772 $is_bookmark = array();
00773
00774 $number = get('number');
00775
00776 for($i = 0; $i < $number; $i++)
00777 {
00778 $bm_id = get('bookmark_id_'.$i);
00779 $bm_item = get('bookmark_item_'.$i);
00780 $is_already_bookmark = get('is_already_bookmark_'.$i);
00781 $is_bookmark[$bm_id] = $is_already_bookmark;
00782
00783 if(($bm_id != 0) && ($is_already_bookmark)){
00784 if(!$bookmark = ItemPerson::getAll(array('id'=>$bm_id, 'person'=>$auth->cur_user->id, 'is_bookmark'=>1))) {
00785 $error++;
00786 }
00787 else{
00788 $bookmark_array[] = $bookmark[0];
00789 }
00790 }
00791 elseif(($bm_id != 0) && (!$is_already_bookmark)){
00792 if(!$bookmark = ItemPerson::getAll(array('id'=>$bm_id, 'person'=>$auth->cur_user->id, 'is_bookmark'=>0))) {
00793 $error++;
00794 }
00795 else{
00796 $bookmark_array[] = $bookmark[0];
00797 }
00798 }
00799 elseif($bm_id == 0){
00800 $date = getGMTString();
00801 $bookmark = new ItemPerson(array(
00802 'id'=>0,
00803 'item'=>$bm_item,
00804 'person'=>$auth->cur_user->id,
00805 'is_bookmark'=>1,
00806 'created'=>$date));
00807 $bookmark_array[] = $bookmark;
00808 }
00809 }
00810
00811 foreach($bookmark_array as $bma){
00812 #$change = false;
00813
00814 ### notify on change ###
00815 $noc = get('notify_on_change');
00816 if(!is_null($noc) && $noc != -1 && $noc != $bma->notify_on_change) {
00817 $bma->notify_on_change = $noc;
00818 #$change= true;
00819 }
00820
00821 ### notify if unchanged ###
00822 $niu = get('notify_if_unchanged');
00823 if(!is_null($niu) && $niu != -1 && $niu != $bma->notify_if_unchanged) {
00824 $bma->notify_if_unchanged = $niu;
00825 #$change= true;
00826 }
00827
00828 #if($change){
00829 if(($bma->id != 0) && ($is_bookmark[$bma->id])){
00830 $bma->update();
00831 $edit++;
00832 }
00833 elseif(($bma->id != 0) && (!$is_bookmark[$bma->id])){
00834 $bma->is_bookmark = true;
00835 $bma->created = getGMTString();
00836 $bma->update();
00837 $count++;
00838 }
00839 elseif($bma->id == 0){
00840 $bma->insert();
00841 $count++;
00842 }
00843 #}
00844 }
00845
00846 if($count){
00847 new FeedbackMessage(sprintf(__("Added %s bookmark(s)."),$count));
00848 }
00849
00850 if($edit){
00851 new FeedbackMessage(sprintf(__("Edited %s bookmark(s)."),$edit));
00852 }
00853
00854 if($error){
00855 new FeedbackWarning(sprintf(__('%s bookmark(s) could not be added.'), $error));
00856 }
00857 ### display fromPage ####
00858 if(!$PH->showFromPage()) {
00859 $PH->show('home',array());
00860 }
00861 }
00862
00866 function itemsSendNotification()
00867 {
00868 global $PH;
00869 global $auth;
00870 $valid = false;
00871
00872 if($ids = getPassedIds('task', 'tasks_*')){
00873 $valid = true;
00874 }
00875 elseif($ids = getPassedIds('person', 'persons_*')){
00876 $valid = true;
00877 }
00878 elseif($ids = getPassedIds('company', 'companies_*')){
00879 $valid = true;
00880 }
00881 elseif($ids = getPassedIds('proj', 'projects_*')){
00882 $valid = true;
00883 }
00884 elseif($ids = getPassedIds('effort', 'efforts_*')){
00885 $valid = true;
00886 }
00887 elseif($ids = getPassedIds('comment', 'comments_*')){
00888 $valid = true;
00889 }
00890 elseif($ids = getPassedIds('file', 'files_*')){
00891 $valid = true;
00892 }
00893 elseif($ids = getPassedIds('version', 'versions_*')){
00894 $valid = true;
00895 }
00896 else{
00897 $PH->abortWarning(__("No item(s) selected."), ERROR_NOTE);
00898 }
00899
00900 if($valid){
00901 foreach($ids as $id){
00902 if($item = ItemPerson::getAll(array('person'=>$auth->cur_user->id, 'item'=>$id))){
00903 $item[0]->notify_on_change = true;
00904 $item[0]->update();
00905 }
00906 else{
00907 $new_view = new ItemPerson(array(
00908 'item'=>$id,
00909 'person'=>$auth->cur_user->id,
00910 'notify_on_change'=>1));
00911
00912 $new_view->insert();
00913 }
00914 }
00915 }
00916
00917 if(!$PH->showFromPage()){
00918 $PH->show('home');
00919 }
00920 }
00921
00925 function itemsRemoveNotification()
00926 {
00927 global $PH;
00928 global $auth;
00929 $valid = false;
00930
00931 if($ids = getPassedIds('task', 'tasks_*')){
00932 $valid = true;
00933 }
00934 elseif($ids = getPassedIds('person', 'persons_*')){
00935 $valid = true;
00936 }
00937 elseif($ids = getPassedIds('company', 'companies_*')){
00938 $valid = true;
00939 }
00940 elseif($ids = getPassedIds('proj', 'projects_*')){
00941 $valid = true;
00942 }
00943 elseif($ids = getPassedIds('effort', 'efforts_*')){
00944 $valid = true;
00945 }
00946 elseif($ids = getPassedIds('comment', 'comments_*')){
00947 $valid = true;
00948 }
00949 elseif($ids = getPassedIds('file', 'files_*')){
00950 $valid = true;
00951 }
00952 elseif($ids = getPassedIds('version', 'versions_*')){
00953 $valid = true;
00954 }
00955 else{
00956 $PH->abortWarning(__("No item(s) selected."), ERROR_NOTE);
00957 }
00958
00959 if($valid){
00960 foreach($ids as $id){
00961 if($item = ItemPerson::getAll(array('item'=>$id, 'notify_on_change'=>true))){
00962 $item[0]->notify_on_change = false;
00963 $item[0]->update();
00964 }
00965 }
00966 }
00967
00968 if(!$PH->showFromPage()){
00969 $PH->show('home');
00970 }
00971 }
00972
00973
00974
00978 function itemViewDiff()
00979 {
00980 global $PH;
00981 global $auth;
00982
00983 require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00984
00985
00986
00987
00988
00989 ### get task ####
00990 $item_id=get('item');
00991
00992 if(!$item= DbProjectItem::getObjectById($item_id)) {
00993 $PH->abortWarning("invalid item-id",ERROR_FATAL);
00994 }
00995
00996 if(!$project= Project::getVisibleById($item->project)) {
00997 $PH->abortWarning("this item has an invalid project id", ERROR_DATASTRUCTURE);
00998 }
00999
01000 require_once(confGet('DIR_STREBER') . "db/db_itemchange.inc.php");
01001 $versions= ItemVersion::getFromItem($item);
01002
01003
01004 if(!$date1=get('date1')) {
01005 if(count($versions) > 1) {
01006 if($auth->cur_user->last_logout < $versions[count($versions)-2]->date_to)
01007 {
01008 $date1 = $auth->cur_user->last_logout;
01009 }
01010 else {
01011 $date1 = $versions[count($versions)-2]->date_from;
01012 }
01013 }
01014 else {
01015 $date1= "2000-01-01 01:01:01";
01016 }
01017 }
01018
01019 if(!$date2=get('date2')) {
01020 $date2 = getGMTString();
01021 }
01022
01023
01024 ### set up page and write header ####
01025 {
01026 $page= new Page();
01027 $page->cur_tab='projects';
01028
01029
01030 $page->crumbs= build_project_crumbs($project);
01031 $page->options= build_projView_options($project);
01032
01033 $page->title = $item->name;
01034 $page->title_minor= __('changes');
01035
01036
01037 ### page functions ###
01038 {
01039
01040 $page->add_function(new PageFunction(array(
01041 'target'=>'itemView',
01042 'params'=>array('item' => $item->id),
01043 'icon'=>'edit',
01044 'name'=>__('View item')
01045 )));
01046 }
01047
01048 ### render title ###
01049 echo(new PageHeader);
01050 }
01051
01052
01053 echo (new PageContentOpen);
01054
01055 ### list changes ###
01056 {
01057 if($date1 > $date2) {
01058 new FeedbackMessage(__("date1 should be smaller than date2. Swapped"));
01059 $t= $date1;
01060 $date1= $date2;
01061 $date2= $t;
01062 }
01063
01064
01065 if(count($versions) == 1) {
01066 echo __("item has not been edited history");
01067 }
01068 else {
01069 $old_version= NULL;
01070 $version_right= NULL;
01071 $version_left= $versions[0];
01072
01073 foreach($versions as $v) {
01074 if($v->date_from <= $date1) {
01075 $version_left= $v;
01076 }
01077 if($v->date_from >= $date2) {
01078
01079 if(isset($version_right)) {
01080 if($version_right->date_from > $v->date_from) {
01081 $version_right= $v;
01082 }
01083 }
01084 else {
01085 $version_right= $v;
01086 }
01087 }
01088 }
01089 if(!isset($version_right)) {
01090 $version_right = $versions[count($versions)-1];
01091 }
01092
01093 $options_left = array();
01094 $options_right= array();
01095
01096
01097 ### list versions left ###
01098 for($i=0; $i< count($versions)-1; $i++) {
01099
01100 $v= $versions[$i];
01101
01102 if($person = Person::getVisibleById($v->author)) {
01103 $author= $person->name;
01104 }
01105 else {
01106 $author= __('unknown');
01107 }
01108
01109 if($v->version_number == $version_left->version_number) {
01110
01111 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $versions[$i]->date_from, 'date2'=> $versions[$i]->date_to));
01112 $name= ' v.'.$v->version_number . ' -- '. $author. " -- ". $v->date_from ;
01113 $options_left[]="<option selected=1 value='".$str_link ."'>". $name. "</option>";
01114 }
01115 else if($v->version_number > $version_left->version_number) {
01116
01117 if($v->version_number < $version_right->version_number) {
01118 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $versions[$i]->date_from, 'date2'=> $versions[$i]->date_to));
01119 $name= '> v.'.$v->version_number . ' -- '. $author. " -- ". renderDate($v->date_from) ;
01120 }
01121 else {
01122 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $versions[$i]->date_from, 'date2'=> $version_right->date_to));
01123 $name= '>> v.'.$v->version_number . ' -- '. $author. " -- ". renderDate($v->date_from) ;
01124 }
01125 $options_left[]="<option value='".$str_link ."'>". $name. "</option>";
01126 }
01127 else {
01128 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $versions[$i]->date_from, 'date2'=> $version_right->date_from));
01129 $name= '< v.'.$v->version_number . ' -- '. $author. " -- ". renderDate($v->date_from) ;
01130 $options_left[]="<option value='".$str_link ."'>". $name. "</option>";
01131 }
01132 }
01133
01134
01135 ### list versions right ###
01136 for($i=1; $i< count($versions); $i++) {
01137
01138 $v= $versions[$i];
01139
01140 if($person = Person::getVisibleById($v->author)) {
01141 $author= $person->name;
01142 }
01143 else {
01144 $author= __('unknown');
01145 }
01146
01147 if($v->version_number == $version_right->version_number) {
01148
01149 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $versions[$i]->date_from, 'date2'=> $versions[$i]->date_to));
01150 $name= ' v.'.$v->version_number . ' -- '. $author. " -- ". $v->date_from ;
01151 $options_right[]="<option selected=1 value='".$str_link ."'>". $name. "</option>";
01152 }
01153 else if($v->version_number > $version_right->version_number) {
01154 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $version_left->date_from, 'date2'=> $versions[$i]->date_from));
01155 $name= '> v.'.$v->version_number . __(' -- '). $author. " -- ". renderDate($v->date_from);
01156 $options_right[]="<option value='".$str_link ."'>". $name. "</option>";
01157
01158 }
01159 else {
01160 if($v->version_number > $version_left->version_number) {
01161 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $version_left->date_from, 'date2'=> $versions[$i]->date_from));
01162 $name= '< v.'.$v->version_number . __(' -- '). $author. " -- ". renderDate($v->date_from);
01163 }
01164 else {
01165 $str_link= $PH->getUrl('itemViewDiff', array('item'=>$item->id, 'date1'=> $versions[$i]->date_from, 'date2'=> $versions[$i]->date_to));
01166 $name= '<< v.'.$v->version_number . __(' -- '). $author. " -- ". renderDate($v->date_from);
01167 }
01168
01169 $options_right[]="<option value='".$str_link ."'>". $name. "</option>";
01170 }
01171 }
01172
01173
01174 ### prev ###
01175 if($version_left->version_number > 1) {
01176 $link_prev= $PH->getLink(
01177 'itemViewDiff',
01178 '<< ' . __('prev change'),
01179 array(
01180 'item'=>$item->id,
01181 'date1'=>$versions[$version_left->version_number - 2]->date_from,
01182 'date2'=>$versions[$version_left->version_number - 2]->date_to,
01183 ), NULL, true
01184 );
01185 }
01186 else {
01187 $link_prev ='';
01188 }
01189
01190 ### next ###
01191 if($version_right->version_number < count($versions)) {
01192 $link_next= $PH->getLink(
01193 'itemViewDiff',
01194 __('next') . '>>',
01195 array(
01196 'item'=>$item->id,
01197 'date1'=>$versions[$version_right->version_number-1]->date_from,
01198 'date2'=>$versions[$version_right->version_number-1]->date_to,
01199 ), NULL, true);
01200 }
01201 else {
01202 $link_next ='';
01203 }
01204
01205 ### summary ###
01206 $link_summary= $PH->getLink(
01207 'itemViewDiff',
01208 __('summary'),
01209 array(
01210 'item'=>$item->id,
01211 'date1'=>$auth->cur_user->last_logout,
01212 'date2'=> getGMTString(),
01213 ), NULL, true);
01214
01215
01216 echo "<div class=diff>";
01217
01218 echo "<table class=nav><tr>";
01219 echo "<td class=older>"
01220 . "<select onChange='location.href=this.options[this.selectedIndex].value'>"
01221 . join(array_reverse($options_left))
01222 . "</select>"
01223 . '<br>'
01224 . $link_prev
01225 . "</td>";
01226
01227
01228 echo "<td class=newer>"
01229 . "<select onChange='location.href=this.options[this.selectedIndex].value'>"
01230 . join(array_reverse($options_right))
01231 . "</select>"
01232 . '<br'
01233 . $link_next
01234 . $link_summary
01235 . "</td>";
01236 echo "</table>";
01237
01238
01239 if(!$date2 || !$date1) {
01240 echo sprintf(__("Item did not exists at %s"), renderTime($date2));
01241 }
01242 else if($old_version == $version_right) {
01243 echo sprintf(__('no changes between %s and %s'), renderTime($date1), renderTime($date2));
01244 }
01245
01246
01247
01248 ### collect changes ###
01249 $old_field_values=array();
01250 $new_field_values=array();
01251 foreach($versions as $v) {
01252 if($v->version_number <= $version_left->version_number) {
01253 foreach($v->values as $name=>$value) {
01254 $old_field_values[$name]= $value;
01255 }
01256 }
01257
01258 if($v->version_number >= $version_left->version_number
01259 &&
01260 $v->version_number < $version_right->version_number
01261 ) {
01262 foreach($v->values_next as $name=>$value) {
01263 $new_field_values[$name]= $value;
01264 }
01265 }
01266 }
01267
01268 foreach($new_field_values as $field_name=>$value) {
01269
01270 echo "<h2>$field_name</h2>";
01271
01272 $old_value= isset($old_field_values[$field_name])
01273 ? $old_field_values[$field_name]
01274 : "";
01275 $new_value= isset($new_field_values[$field_name])
01276 ? $new_field_values[$field_name]
01277 : '';
01278
01279 $field_type= $item->fields[$field_name]->type;
01280 if($field_type == 'FieldText') {
01281 echo render_changes($old_value, $new_value);
01282 }
01283 else if($field_type == 'FieldOption'){
01284 if($field_name == 'status') {
01285 global $g_status_names;
01286 $old_value= isset($g_status_names[$old_value])
01287 ? $g_status_names[$old_value]
01288 : __('undefined');
01289 $new_value= isset($g_status_names[$new_value])
01290 ? $g_status_names[$new_value]
01291 : __('undefined');
01292 }
01293 else if($field_name == 'label') {
01294 if($project = Project::getVisibleById($item->project)) {
01295 $labels=split(",",$project->labels);
01296
01297 $old_value= isset($labels[$old_value-1])
01298 ? $labels[$old_value-1]
01299 : __('undefined');
01300
01301 $new_value= isset($labels[$new_value-1])
01302 ? $labels[$new_value-1]
01303 : __('undefined');
01304 }
01305 }
01306 echo render_changes($old_value, $new_value);
01307 }
01308 else if($field_type == 'FieldInternal') {
01309
01310 if($field_name == 'parent_item') {
01311 if($task_parent_old= Task::getVisibleById($old_value)) {
01312 $ar= array();
01313 foreach($task_parent_old->getFolder() as $f) {
01314 $ar[]=$f->name;
01315 }
01316 $ar[]= $task_parent_old->name;
01317 $old_value= join($ar," > ");
01318 }
01319 if($task_parent_new= Task::getVisibleById($new_value)) {
01320 $ar= array();
01321 foreach($task_parent_new->getFolder() as $f) {
01322 $ar[]=$f->name;
01323 }
01324 $ar[]= $task_parent_new->name;
01325 $new_value= join($ar," > ");
01326 }
01327 }
01328
01329 else if($field_name == 'state') {
01330 $old_value= ($old_value == -1)
01331 ? __('deleted')
01332 : __('ok');
01333 $new_value= ($new_value == -1)
01334 ? __('deleted')
01335 : __('ok');
01336 }
01337 else if($field_name == 'pub_level') {
01338 global $g_pub_level_names;
01339 $old_value= isset($g_pub_level_names[$old_value])
01340 ? $g_pub_level_names[$old_value]
01341 : __('undefined');
01342 $new_value= isset($g_pub_level_names[$new_value])
01343 ? $g_pub_level_names[$new_value]
01344 : __('undefined');
01345
01346 }
01347 echo render_changes($old_value, $new_value);
01348
01349 }
01350 else if($field_type == 'FieldPercentage') {
01351 echo render_changes($old_value, $new_value);
01352 }
01353 else if($field_type == 'FieldInt') {
01354
01355 echo render_changes($old_value, $new_value);
01356 }
01357 else if($field_type == 'FieldString') {
01358 echo render_changes($old_value, $new_value);
01359 }
01360 else if($field_type == 'FieldDate') {
01361 echo render_changes(renderDate($old_value), renderDate($new_value));
01362 }
01363 else if($field_type == 'FieldDatetime') {
01364 echo render_changes(renderTimestamp($old_value), renderTimestamp($new_value));
01365 }
01366
01367 }
01368 }
01369 }
01370 echo "</div>";
01371
01372 echo (new PageContentClose);
01373 echo (new PageHtmlEnd);
01374
01375 }
01376 ?>