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_file.inc.php');
00008
00009
00010 class ListGroupingMimetype extends ListGrouping
00011 {
00012
00013 public function __construct($args=NULL) {
00014 $this->id = 'mimetype';
00015 $this->name= __('Type');
00016 parent::__construct($args);
00017 }
00018
00022 public function render(&$item)
00023 {
00024 if(! ($item instanceof DbProjectItem)) {
00025 trigger_error("can't group for mimetype",E_USER_NOTICE);
00026 return "---";
00027 }
00028 else {
00029 return $item->mimetype;
00030 }
00031 }
00032 }
00033
00034 class ListGroupingParentItem extends ListGrouping
00035 {
00036
00037 public function __construct($args=NULL) {
00038 $this->id = 'parent_item';
00039 $this->name= __('Parent item');
00040 parent::__construct($args);
00041 }
00042
00046 public function render(&$item)
00047 {
00048 if(! ($item instanceof DbProjectItem)) {
00049 trigger_error("can't group for parent_item",E_USER_NOTICE);
00050 return "---";
00051 }
00052 else {
00053 if($task= Task::getVisibleById($item->parent_item)) {
00054
00055 return $task->getFolderLinks(false).'>'. $task->getLink(false);
00056 }
00057 else {
00058 return "/";
00059 }
00060 }
00061 }
00062 }
00063
00074 class ListBlock_files extends ListBlock
00075 {
00076
00077 public function __construct($args=NULL)
00078 {
00079 parent::__construct($args);
00080
00081 global $PH;
00082 $this->id='files';
00083 $this->bg_style='bg_time';
00084 $this->title="Files";
00085
00086
00087 $this->query_options['latest_only']=true;
00088
00089 ### columns ###
00090 $this->add_col( new ListBlockColSelect());
00091 $this->add_col( new ListBlockCol_FileThumbnail());
00092 $this->add_col( new ListBlockCol_FileName());
00093 $this->add_col( new ListBlockColFormat(array(
00094 'key'=>'version',
00095 'name'=>__("Version"),
00096 'sort'=>0,
00097 'format'=>'{?version}'
00098 )));
00099 $this->add_col( new ListBlockCol_CreatedBy());
00100 $this->add_col( new ListBlockColDate());
00101 $this->add_col( new ListBlockCol_FileSummary());
00102
00103 ### functions ###
00104 $this->add_function(new ListFunction(array(
00105 'target'=>$PH->getPage('fileEdit')->id,
00106 'name' =>__('Edit file'),
00107 'id' =>'fileEdit',
00108 'icon' =>'edit',
00109 'context_menu'=>'submit',
00110 )));
00111 $this->add_function(new ListFunction(array(
00112 'target'=>$PH->getPage('filesDelete')->id,
00113 'name' =>__('Delete'),
00114 'id' =>'filesDelete',
00115 'icon' =>'delete',
00116 'context_menu'=>'submit',
00117 )));
00118
00119 $this->add_function(new ListFunction(array(
00120 'target'=>$PH->getPage('filesMoveToFolder')->id,
00121 'name' =>__('Move files'),
00122 'id' =>'filesMoveToFolder',
00123 'context_menu'=>'submit'
00124 )));
00125 $this->add_function(new ListFunction(array(
00126 'target'=>$PH->getPage('itemsAsBookmark')->id,
00127 'name' =>__('Mark as bookmark'),
00128 'id' =>'itemsAsBookmark',
00129 'context_menu'=>'submit',
00130 )));
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 ### block style functions ###
00142 $this->add_blockFunction(new BlockFunction(array(
00143 'target'=>'changeBlockStyle',
00144 'key'=>'list',
00145 'name'=>'List',
00146 'params'=>array(
00147 'style'=>'list',
00148 'block_id'=>$this->id,
00149 'page_id'=>$PH->cur_page->id,
00150 # 'use_collapsed'=>true,
00151 ),
00152 'default'=>true,
00153 )));
00154 $this->groupings= new BlockFunction_grouping(array(
00155 'target'=>'changeBlockStyle',
00156 'key'=>'grouped',
00157 'name'=>'Grouped',
00158 'params'=>array(
00159 'style'=>'grouped',
00160 'block_id'=>$this->id,
00161 'page_id'=>$PH->cur_page->id,
00162 ),
00163 ));
00164
00165
00166 $this->add_blockFunction($this->groupings);
00167
00168 ### list groupings ###
00169 $this->groupings->groupings= array(
00170 new ListGroupingStatus(),
00171 new ListGroupingMimetype(),
00172 new ListGroupingCreatedBy(),
00173 new ListGroupingParentItem(),
00174
00175 );
00176
00177
00178 }
00179
00180
00181
00191 public function print_automatic(&$project = NULL)
00192 {
00193 global $PH;
00194
00195 if(!$this->active_block_function=$this->getBlockStyleFromCookie()) {
00196 $this->active_block_function = 'list';
00197 }
00198
00199 if($project) {
00200 $this->query_options['project']= $project->id;
00201 }
00202
00203 $this->group_by= get("blockstyle_{$PH->cur_page->id}_{$this->id}_grouping");
00204
00205
00206 $s_cookie= "sort_{$PH->cur_page->id}_{$this->id}_{$this->active_block_function}";
00207 if($sort= get($s_cookie)) {
00208 $this->query_options['order_by']= $sort;
00209 }
00210
00211 ### add filter options ###
00212 #foreach($this->filters as $f) {
00213 # foreach($f->getQuerryAttributes() as $k=>$v) {
00214 # $this->query_options[$k]= $v;
00215 # }
00216 #}
00217
00218 if(!$this->no_items_html) {
00219 $this->no_items_html= __("No files uploaded");
00220 }
00221
00222
00223 ### grouped view ###
00224 if($this->active_block_function == 'grouped') {
00225
00226 ### prepend key to sorting ###
00227 if(isset($this->query_options['order_by'])) {
00228 $this->query_options['order_by'] = $this->groupings->getActiveFromCookie() . ",".$this->query_options['order_by'];
00229
00230 }
00231 else {
00232 $this->query_options['order_by'] = $this->groupings->getActiveFromCookie();
00233 }
00234
00240 if(isset($this->columns[ $this->group_by ])) {
00241 unset($this->columns[$this->group_by]);
00242 }
00243 }
00244 ### list view ###
00245 else {
00246 $foo= true;
00247
00248 }
00249 $files= File::getAll($this->query_options);
00250 $this->render_list(&$files);
00251 }
00252 }
00253
00254
00255
00256 class ListBlockCol_FileDownload extends ListBlockCol
00257 {
00258
00259 public function __construct($args=NULL)
00260 {
00261 parent::__construct($args);
00262 $this->name=__('Download','Column header');
00263 $this->id='download';
00264 $this->width='90';
00265 }
00266
00267
00268 function render_tr(&$file, $style="")
00269 {
00270 global $PH;
00271 if(!isset($file) || !$file instanceof File) {
00272 return;
00273 }
00274 $buffer='';
00275
00276 if($file->mimetype == 'image/png'
00277 ||
00278 $file->mimetype == 'image/jpeg'
00279 ||
00280 $file->mimetype == 'image/pjpeg'
00281 ||
00282 $file->mimetype == 'image/jpg'
00283 ||
00284 $file->mimetype == 'image/gif'
00285 )
00286 {
00287 $buffer= "<a target='blank' href='".$PH->getUrl('fileDownloadAsImage',array('file'=>$file->id))."'><img class='left' title='".asHtml($file->name)."' alt='".asHtml($file->name)."' src='".$PH->getUrl('fileDownloadAsImage',array('file'=>$file->id,'max_size'=>100))."'></a>";
00288
00289 }
00290 else {
00291 $buffer= $PH->getLink('fileDownload',$file->name, array('file'=>$file->id));
00292 }
00293 print "<td>$buffer</td>";
00294 }
00295 }
00296
00297
00298 class ListBlockCol_FileName extends ListBlockCol
00299 {
00300
00301 public function __construct($args=NULL)
00302 {
00303 parent::__construct($args);
00304 $this->name=__('File','Column header');
00305 $this->id='name';
00306 $this->width='80%';
00307 $this->key='name';
00308 }
00309
00310 function render_tr(&$file, $style="")
00311 {
00312 global $PH;
00313 if(!isset($file) || !$file instanceof File) {
00314 return;
00315 }
00316
00317 require_once(confGet('DIR_STREBER') . 'render/render_wiki.inc.php');
00318
00319 $buffer='<b>';
00320
00321 $buffer.= $PH->getLink('fileDownload',$file->name, array('file'=>$file->id));
00322 $buffer.= '</b>'
00323 .'<br />';
00324
00325 ### name ###
00326 #$buffer = '<b>'
00327 # . $PH->getLink('fileView',$file->name, array('file'=>$file->id),'item file')
00328 # .'</b>'
00329 # . '<br>';
00330
00331 ### parent task ###
00332 $diz_buffer="";
00333
00334 if($file->parent_item && $item=DbProjectItem::getVisibleById($file->parent_item)) {
00335 if($item->type == ITEM_TASK) {
00336 if($task= Task::getVisibleById($file->parent_item)) {
00337 $tmp= $task->getFolderLinks();
00338 if($tmp) {
00339 $tmp=$tmp.">";
00340 }
00341 $diz_buffer.= __("in","... folder"). ": ". $tmp. $task->getLink(false). "<br/>";
00342 }
00343 }
00344 }
00345
00346 ### details ###
00347 $diz_buffer .= $file->filesize ." bytes"
00348 . ' / '
00349 . asHtml($file->mimetype)
00350 . ' / '
00351 . sprintf(__("ID %s"), $file->id)
00352 . ' / '
00353 . "<span class=sub>" . $PH->getLink('fileView', __('Show Details'), array('file'=>$file->id)). "</span>"
00354 ."<br/>";
00355
00356
00357
00358 ### description ###
00359 $diz_buffer.= wiki2html($file->description, $file->project);
00360
00361 if($diz_buffer) {
00362 $buffer.='<span class=sub>'. $diz_buffer. "</span>";
00363 }
00364
00365
00366
00367 echo '<td>'. $buffer .'</td>';
00368
00369 #$str= $PH->getLink('fileView',$obj->name, array('file'=>$obj->id),'item file');
00370 #print "<td>$str</td>";
00371 }
00372 }
00373
00374
00375
00376 class ListBlockCol_ParentTask extends ListBlockCol
00377 {
00378
00379 public function __construct($args=NULL)
00380 {
00381 parent::__construct($args);
00382 $this->name=__('Attached to','Column header');
00383 $this->id='parent_task';
00384 }
00385
00386
00387 function render_tr(&$obj, $style="")
00388 {
00389 global $PH;
00390 if(!isset($obj) || !$obj instanceof File) {
00391 return;
00392 }
00393
00394 if($task= Task::getVisibleById($obj->parent_item)) {
00395 print '<td>'. $task->getLink(false). '</td>';
00396 }
00397 else {
00398 print '<td></td>';
00399 }
00400 }
00401 }
00402
00403
00407 class ListBlockCol_FileSummary extends ListBlockCol
00408 {
00409
00410 public function __construct($args=NULL)
00411 {
00412 parent::__construct($args);
00413 $this->name=__('Summary','Column header');
00414 $this->id='summary';
00415 }
00416
00417
00418 function render_tr(&$file, $style="")
00419 {
00420 global $PH;
00421 if(!isset($file) || !$file instanceof File) {
00422 return;
00423 }
00424
00425 #$buffer = $PH->getLink('fileView',__("Details"), array('file'=>$file->id),'item file');
00426
00427 $buffer='';
00428
00429
00430 if($file->mimetype == 'image/png'
00431 ||
00432 $file->mimetype == 'image/jpeg'
00433 ||
00434 $file->mimetype == 'image/pjpeg'
00435 ||
00436 $file->mimetype == 'image/jpg'
00437 ||
00438 $file->mimetype == 'image/gif'
00439 )
00440 {
00441 $buffer.= "<span class=sub><a target='blank' href='".$PH->getUrl('fileDownloadAsImage',array('file'=>$file->id))."'><img class='left' title='".asHtml($file->name)."' alt='".asHtml($file->name)."' src='".$PH->getUrl('fileDownloadAsImage',array('file'=>$file->id,'max_size'=>100))."'><br>"
00442 . ""
00443 . asHtml($file->name)
00444 . "</a>"
00445 . "<br>"
00446 . "<span class=sub>" . $file->filesize ." bytes" ." / ". sprintf(__("ID %s"), $file->id) ." / ". renderDateHtml($file->created) . "</span>"
00447 . "<br>"
00448 . $PH->getLink('fileView', __('Show Details'), array('file'=>$file->id))
00449 . "</span>";
00450
00451
00452 }
00453 else {
00454 $buffer.= "<b>" . $PH->getLink('fileDownload',$file->name, array('file'=>$file->id)). "</b>"
00455 . "<br>"
00456 . "<span class=sub>" . $file->filesize ." bytes" ." / ". sprintf(__("ID %s"), $file->id) ." / " . renderDateHtml($file->created) . "</span>"
00457 . "<br>"
00458 . "<span class=sub>" . $PH->getLink('fileView', __('Show Details'), array('file'=>$file->id)). "</span>"
00459 ;
00460
00461 }
00462
00463 print "<td class='summary'>$buffer</td>";
00464 }
00465 }
00466
00467
00468 class ListBlockCol_FileThumbnail extends ListBlockCol
00469 {
00470
00471 public function __construct($args=NULL)
00472 {
00473 parent::__construct($args);
00474 $this->name=__('Thumbnail','Column header');
00475 $this->id='thumbnail';
00476 $this->width='10';
00477 }
00478
00479
00480 function render_tr(&$file, $style="")
00481 {
00482 global $PH;
00483 if(!isset($file) || !$file instanceof File) {
00484 return;
00485 }
00486
00487 #$buffer = $PH->getLink('fileView',__("Details"), array('file'=>$file->id),'item file');
00488
00489 $buffer='';
00490
00491
00492 if($file->mimetype == 'image/png'
00493 ||
00494 $file->mimetype == 'image/jpeg'
00495 ||
00496 $file->mimetype == 'image/pjpeg'
00497 ||
00498 $file->mimetype == 'image/jpg'
00499 ||
00500 $file->mimetype == 'image/gif'
00501 )
00502 {
00503 $buffer.= "<a target='blank' href='".$PH->getUrl('fileDownloadAsImage',array('file'=>$file->id))."'><img class='left' title='".asHtml($file->name)."' alt='".asHtml($file->name)."' src='".$PH->getUrl('fileDownloadAsImage',array('file'=>$file->id,'max_size'=>100))."'></a>";
00504
00505 }
00506
00507 print "<td>$buffer</td>";
00508 }
00509 }
00510
00511 ?>