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
00006
00007 require_once(confGet('DIR_STREBER') . 'db/class_issue.inc.php');
00008
00009
00010
00011
00012
00013 define('LEVEL_NONE', -1);
00014 define('LEVEL_PARENTS', 0);
00015 define('LEVEL_NORMAL', 1);
00016 define('LEVEL_CHILDREN',2);
00017
00018
00019
00020
00031 class Block_DocuNavigation extends PageBlock
00032 {
00033 #public $title = "bla";
00034 public $current_task = NULL;
00035 public $project_id = NULL; # object
00036 public $reduced_header = true;
00037 private $tasks = array();
00038 public $root = NULL;
00039
00040
00041
00042 public function __construct($args=NULL) {
00043 $this->title= __("Documentation");
00044 $this->id = 'parent_task';
00045 parent::__construct($args);
00046 }
00047
00048
00049 private function initStructure()
00050 {
00051 $tasks= array();
00052
00053 if(!$this->project_id) {
00054 if(!$this->current_task) {
00055 trigger_error("At least current_task or project required");
00056 return;
00057 }
00058 $this->project_id = $this->current_task->project;
00059 }
00060
00061 ### start from a certain parent (e.g. a task) ###
00062 if($this->root) {
00063 foreach(Task::getDocuTasks($this->project_id, $this->root->id) as $p) {
00064 $p->level = LEVEL_NORMAL;
00065 if($p->id == $this->current_task->id && $p->category == TCATEGORY_FOLDER) {
00066 $p->view_collapsed = 0;
00067 $tasks[]= $p;
00068
00069 foreach(Task::getDocuTasks($this->project_id, $p->id) as $sp) {
00070 $sp->level = LEVEL_CHILDREN;
00071 $tasks[]= $sp;
00072 }
00073 }
00074 else {
00075 $p->view_collapsed= 1;
00076 $tasks[]= $p;
00077 }
00078 }
00079 }
00080 else if($this->current_task == NULL) {
00081 foreach(Task::getDocuTasks($this->project_id, 0) as $sp) {
00082 $sp->level = LEVEL_NORMAL;
00083 $tasks[]= $sp;
00084 }
00085
00086 }
00087 ### with parents ###
00088 else if($parents= $this->current_task->getFolder()) {
00089
00090 foreach($parents as $pt) {
00091 $pt->level = LEVEL_PARENTS;
00092 $tasks[]= $pt;
00093 }
00094 ### current level is children of last parent tasks ###
00095 foreach(Task::getDocuTasks($this->project_id, $pt->id) as $p) {
00096
00097 $p->level = LEVEL_NORMAL;
00098 $p->view_collapsed= 1;
00099 if($p->id == $this->current_task->id && $p->category == TCATEGORY_FOLDER) {
00100 $p->view_collapsed = 0;
00101 $tasks[]= $p;
00102
00103 foreach(Task::getDocuTasks($this->project_id, $p->id) as $sp) {
00104 $sp->level = LEVEL_CHILDREN;
00105 $tasks[]= $sp;
00106 }
00107 }
00108 else {
00109 $p->view_collapsed= 1;
00110 $tasks[]= $p;
00111 }
00112 }
00113 }
00114 ### at root level ##
00115 else {
00116 foreach(Task::getDocuTasks($this->project_id, 0) as $p) {
00117 $p->level = LEVEL_NORMAL;
00118 if($p->id == $this->current_task->id && $p->category == TCATEGORY_FOLDER) {
00119 $p->view_collapsed = 0;
00120 $tasks[]= $p;
00121
00122 foreach(Task::getDocuTasks($this->project_id, $p->id) as $sp) {
00123 $sp->level = LEVEL_CHILDREN;
00124 $tasks[]= $sp;
00125 }
00126 }
00127 else {
00128 $p->view_collapsed= 1;
00129 $tasks[]= $p;
00130 }
00131 }
00132 }
00133 $this->tasks = $tasks;
00134 return;
00135 }
00136
00137
00138
00139 public function print_all()
00140 {
00141 $this->initStructure();
00142 $this->render_BlockStart();
00143 echo "<div class=docuNavigation>";
00144
00145 $state = LEVEL_NONE;
00146 foreach($this->tasks as $t) {
00147 switch($state) {
00148 case LEVEL_NONE:
00149 if($t->level == LEVEL_PARENTS) {
00150 $state= LEVEL_PARENTS;
00151 echo '<ul class=parents>';
00152 echo '<li>' . $this->printLink($t) . '</li>';
00153 }
00154 else if($t->level == LEVEL_NORMAL) {
00155 $state= LEVEL_NORMAL;
00156 echo '<ul class=normal>';
00157 echo '<li>' . $this->printLink($t). '</li>';
00158
00159 }
00160 break;
00161
00162 case LEVEL_PARENTS:
00163 if($t->level == LEVEL_PARENTS) {
00164 echo '<li>' . $this->printLink($t). '</li>';
00165 }
00166 else {
00167 echo '</ul>';
00168 $state = LEVEL_NORMAL;
00169 echo '<ul class=normal>';
00170 echo '<li>' . $this->printLink($t) . '</li>';
00171 }
00172 break;
00173
00174 case LEVEL_NORMAL:
00175 if($t->level == LEVEL_NORMAL) {
00176 echo '<li>' . $this->printLink($t) . '</li>';
00177 }
00178 else if($t->level == LEVEL_CHILDREN) {
00179 echo '<ul class=children>';
00180 echo '<li>' . $this->printLink($t);
00181 $state= LEVEL_CHILDREN;
00182 }
00183 break;
00184
00185 case LEVEL_CHILDREN:
00186 if($t->level == LEVEL_CHILDREN) {
00187 echo '<li>' . $this->printLink($t) . '</li>';
00188 }
00189 else {
00190 echo '</ul>';
00191 $state= LEVEL_NORMAL;
00192 echo '</li>';
00193 echo '<li>' . $this->printLink($t) . '</li>';
00194 }
00195 break;
00196 }
00197
00198 }
00199 switch($state) {
00200 case LEVEL_NONE:
00201 break;
00202 case LEVEL_PARENTS:
00203 echo '</ul>';
00204 break;
00205 case LEVEL_NORMAL;
00206 echo '</ul>';
00207 break;
00208 case LEVEL_CHILDREN:
00209 echo '</ul>';
00210 echo '</ul>';
00211 break;
00212 }
00213 echo "</div>";
00214
00215
00216 $this->render_BlockEnd();
00217
00218 }
00219
00225 private function printLink($t)
00226 {
00227 global $PH;
00228 $style= NULL;
00229 if($t->category == TCATEGORY_FOLDER) {
00230 $style= 'folder';
00231 if($this->current_task && $t->id == $this->current_task->id) {
00232 $style= 'folder current';
00233 }
00234 }
00235 else if($this->current_task && $t->id == $this->current_task->id) {
00236 $style= 'current';
00237 }
00238
00239 return $PH->getLink('taskViewAsDocu', $t->name, array('tsk' => $t->id), $style );
00240 }
00241 }
00242
00243
00244
00245
00246
00247
00248
00249 ?>