[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/filemanager/inc/ -> class.uifilemanager.inc.php (source)

   1  <?php
   2      /**************************************************************************\
   3      * eGroupWare - Filemanager                                                 *
   4      * http://www.egroupware.org                                                *
   5      * ------------------------------------------------------------------------ *
   6      *  This program is free software; you can redistribute it and/or modify it *
   7      *  under the terms of the GNU General Public License as published by the   *
   8      *  Free Software Foundation; either version 2 of the License, or (at your  *
   9      *  option) any later version.                                              *
  10      \**************************************************************************/
  11  
  12      /* $Id: class.uifilemanager.inc.php 22445 2006-09-16 22:12:24Z omgs $ */
  13  
  14      class uifilemanager
  15      {
  16          var $public_functions = array(
  17              'index' => True,
  18              'help'  => True,
  19              'view'  => True,
  20              'history' => True,
  21              'edit'  => True,
  22              'download'=>True
  23          );
  24  
  25          //keep
  26          var $bo;
  27          var $t; //template object
  28          var $dispath;
  29          var $cwd;
  30          var $lesspath;
  31          var $readable_groups;
  32          var $files_array;
  33          var $numoffiles;
  34          var $dispsep;
  35  
  36          var $target;
  37  
  38          var $prefs;//array
  39  
  40          var $groups_applications;
  41  
  42          //originally post_vars
  43          //        var $goto;
  44          var $goto_x;
  45          var $download_x;
  46          var $todir;
  47          var $changedir; // for switching dir.
  48          var $cdtodir; // for switching dir.
  49  //        var $createdir;
  50          var $newfile_or_dir;
  51          var $newdir_x;
  52          var $newfile_x;
  53          var $createfile_var;
  54          var $delete_x;
  55          var $renamefiles;
  56          var $rename_x;
  57          var $move_to_x;
  58          //        var $copy_to;
  59          var $copy_to_x;
  60          var $edit_x;
  61          var $edit_comments_x;
  62          var $edit_file;
  63          var $edit_preview_x;
  64          var $edit_save_x;
  65          var $edit_save_done_x;
  66          var $edit_cancel_x;
  67          var $comment_files;
  68          var $upload_x;
  69          var $uploadprocess;
  70  
  71          // this ones must be checked thorougly;
  72          var $fileman = Array();
  73          //var $fileman;
  74          var $path;
  75          var $file; // FIXME WHERE IS THIS FILLED?
  76          var $sortby;
  77          var $messages = array();
  78          var $show_upload_boxes;
  79  
  80          var $debug = false;
  81          var $now;
  82  
  83  		function uifilemanager()
  84          {
  85              //            error_reporting(8);
  86              $GLOBALS['egw']->browser =& CreateObject('phpgwapi.browser');
  87              
  88              $this->dateformat=$GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
  89  
  90              $this->now = date('Y-m-d');
  91  
  92              $this->bo =& CreateObject('filemanager.bofilemanager');
  93  
  94              $this->t = $GLOBALS['egw']->template;
  95  
  96              // here local vars are created from the HTTP vars
  97              @reset($_POST);
  98              while(list($name,) = @each($_POST))
  99              {
 100                  $this->$name = $_POST[$name];
 101              }
 102  
 103              @reset($_GET);
 104              while(list($name,) = @each($_GET))
 105              {
 106                  $$name = $_GET[$name];
 107              }
 108  
 109              $to_decode = array
 110              (
 111                  /*
 112                  Decode
 113                  'var'    when      'avar' == 'value'
 114                  or
 115                  'var'    when      'var'  is set
 116                  */
 117                  'op'    => array('op' => ''),
 118                  'path'    => array('path' => ''),
 119                  'file'    => array('file' => ''),
 120                  'sortby'    => array('sortby' => ''),
 121                  //                'fileman'    => array('fileman' => ''),
 122                  'messages'    => array('messages'    => ''),
 123                  //                'help_name'    => array('help_name' => ''),
 124                  //                'renamefiles'    => array('renamefiles' => ''),
 125                  'comment_files'    => array('comment_files' => ''),
 126                  'show_upload_boxes'    => array('show_upload_boxes' => '')
 127              );
 128  
 129              reset($to_decode);
 130              while(list($var, $conditions) = each($to_decode))
 131              {
 132                  while(list($condvar, $condvalue) = each($conditions))
 133                  {
 134                      if(isset($$condvar) && ($condvar == $var || $$condvar == $condvalue))
 135                      {
 136                          if(is_array($$var))
 137                          {
 138                              $temp = array();
 139                              while(list($varkey, $varvalue) = each($$var))
 140                              {
 141                                  if(is_int($varkey))
 142                                  {
 143                                      $temp[$varkey] = stripslashes(base64_decode(urldecode(($varvalue))));
 144                                  }
 145                                  else
 146                                  {
 147                                      $temp[stripslashes(base64_decode(urldecode(($varkey))))] = $varvalue;
 148                                  }
 149                              }
 150                              $this->$var = $temp;
 151                          }
 152                          elseif(isset($$var))
 153                          {
 154                              $this->$var = stripslashes(base64_decode(urldecode($$var)));
 155                          }
 156                      }
 157                  }
 158              }
 159  
 160              // get appl. and user prefs
 161              $pref =& CreateObject('phpgwapi.preferences', $this->bo->userinfo['username']);
 162              $pref->read_repository();
 163              //            $GLOBALS['egw']->hooks->single('add_def_pref', $GLOBALS['appname']);
 164              $pref->save_repository(True);
 165              $pref_array = $pref->read_repository();
 166              $this->prefs = $pref_array[$this->bo->appname]; //FIXME check appname var in _debug_array
 167  
 168              //always show name
 169  
 170              $this->prefs['name'] = 1;
 171  
 172              if($this->prefs['viewinnewwin'])
 173              {
 174                  $this->target = '_blank';
 175              }
 176  
 177              /*
 178                  Check for essential directories
 179                  admin must be able to disable these tests
 180              */
 181  
 182              // check if basedir exist
 183              $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
 184              if($test['mime_type'] != 'Directory')
 185              {
 186                  die('Base directory does not exist, Ask adminstrator to check the global configuration.');
 187              }
 188  
 189              $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
 190              if($test['mime_type'] != 'Directory')
 191              {
 192                  $this->bo->vfs->override_acl = 1;
 193  
 194                  $this->bo->vfs->mkdir(array(
 195                      'string' => $this->bo->fakebase,
 196                      'relatives' => array(RELATIVE_NONE)
 197                  ));
 198  
 199                  $this->bo->vfs->override_acl = 0;
 200  
 201                  //test one more time
 202                  $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->fakebase, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
 203  
 204                  if($test['mime_type']!='Directory')
 205                  {
 206                      die('Fake Base directory does not exist and could not be created, please ask the administrator to check the global configuration.');
 207                  }
 208                  else
 209                  {
 210                      $this->messages[]= $GLOBALS['egw']->common->error_list(array(
 211                          lang('Fake Base Dir did not exist, eGroupWare created a new one.')
 212                      ));
 213                  }
 214              }
 215  
 216  //            die($this->bo->homedir);
 217              $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
 218              if($test['mime_type'] != 'Directory')
 219              {
 220                  $this->bo->vfs->override_acl = 1;
 221  
 222                  $this->bo->vfs->mkdir(array(
 223                      'string' => $this->bo->homedir,
 224                      'relatives' => array(RELATIVE_NONE)
 225                  ));
 226  
 227                  $this->bo->vfs->override_acl = 0;
 228  
 229                  //test one more time
 230                  $test=$this->bo->vfs->get_real_info(array('string' => $this->bo->basedir.$this->bo->homedir, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
 231  
 232                  if($test['mime_type'] != 'Directory')
 233                  {
 234                      die('Your Home Dir does not exist and could not be created, please ask the adminstrator to check the global configuration.');
 235                  }
 236                  else
 237                  {
 238                      $this->messages[]= $GLOBALS['egw']->common->error_list(array(
 239                          lang('Your Home Dir did not exist, eGroupWare created a new one.')
 240                      ));
 241                      // FIXME we just created a fresh home dir so we know there nothing in it so we have to remove all existing content
 242                  }
 243              }
 244          }
 245  
 246  		function index()
 247          {
 248              if($noheader || $nofooter || ($this->download_x && (count($this->fileman) > 0)))
 249              {
 250                  $noheader = True;
 251                  $nofooter = True;
 252                  $noappheader= True;
 253                  $nonavbar= True;
 254              }
 255              else
 256              {
 257                  $GLOBALS['egw_info']['flags'] = array
 258                  (
 259                      'currentapp'    => 'filemanager',
 260                      'noheader'    => $noheader,
 261                      'nonavbar' => $nonavbar,
 262                      'nofooter'    => $nofooter,
 263                      'noappheader'    => $noappheader,
 264                      'enable_browser_class'    => True
 265                  );
 266  
 267                  $GLOBALS['egw']->common->egw_header();
 268              }
 269  
 270              # Page to process users
 271              # Code is fairly hackish at the beginning, but it gets better
 272              # Highly suggest turning wrapping off due to long SQL queries
 273  
 274              ###
 275              # Some hacks to set and display directory paths correctly
 276              ###
 277  /*
 278              if($this->goto || $this->goto_x)
 279              {
 280                  $this->path = $this->cdtodir;
 281              }
 282  */
 283              // new method for switching to a new dir.
 284              if($this->changedir=='true' && $this->cdtodir || $this->goto_x)
 285              {
 286                  $this->path = $this->cdtodir;
 287              }
 288  
 289              if(!$this->path)
 290              {
 291                  $this->path = $this->bo->vfs->pwd();
 292  
 293                  if(!$this->path || $this->bo->vfs->pwd(array('full' => False)) == '')
 294                  {
 295                      $this->path = $this->bo->homedir;
 296                  }
 297              }
 298  
 299              $this->bo->vfs->cd(array('string' => False, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
 300              $this->bo->vfs->cd(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE), 'relative' => False));
 301  
 302              $pwd = $this->bo->vfs->pwd();
 303  
 304              if(!$this->cwd = substr($this->path, strlen($this->bo->homedir) + 1))
 305              {
 306                  $this->cwd = '/';
 307              }
 308              else
 309              {
 310                  $this->cwd = substr($pwd, strrpos($pwd, '/') + 1);
 311              }
 312  
 313              $this->disppath = $this->path;
 314  
 315              /* This just prevents // in some cases */
 316              if($this->path == '/')
 317              {
 318                  $this->dispsep = '';
 319              }
 320              else
 321              {
 322                  $this->dispsep = '/';
 323              }
 324  
 325              if(!($this->lesspath = substr($this->path, 0, strrpos($this->path, '/'))))
 326              {
 327                  $this->lesspath = '/';
 328              }
 329  
 330              # Get their readable groups to be used throughout the script
 331              $groups = array();
 332  
 333              $groups = $GLOBALS['egw']->accounts->get_list('groups');
 334  
 335              $this->readable_groups = array();
 336  
 337              while(list($num, $account) = each($groups))
 338              {
 339                  if($this->bo->vfs->acl_check(array('owner_id' => $account['account_id'],'operation' => EGW_ACL_READ)))
 340                  {
 341                      $this->readable_groups[$account['account_lid']] = Array('account_id' => $account['account_id'], 'account_name' => $account['account_lid']);
 342                  }
 343              }
 344  
 345              $this->groups_applications = array();
 346  
 347              while(list($num, $group_array) = each($this->readable_groups))
 348              {
 349                  $group_id = $GLOBALS['egw']->accounts->name2id($group_array['account_name']);
 350  
 351                  $applications =& CreateObject('phpgwapi.applications', $group_id);
 352                  $this->groups_applications[$group_array['account_name']] = $applications->read_account_specific();
 353              }
 354  
 355              # We determine if they're in their home directory or a group's directory,
 356              # and set the VFS working_id appropriately
 357              if((preg_match('+^'.$this->bo->fakebase.'\/(.*)(\/|$)+U', $this->path, $matches)) && $matches[1] != $this->bo->userinfo['account_lid']) //FIXME matches not defined
 358              {
 359                  $this->bo->vfs->working_id = $GLOBALS['egw']->accounts->name2id($matches[1]);//FIXME matches not defined
 360              }
 361              else
 362              {
 363                  $this->bo->vfs->working_id = $this->bo->userinfo['username'];
 364              }
 365  
 366              # FIXME # comment waht happens here
 367              if($this->path != $this->bo->homedir && $this->path != $this->bo->fakebase && $this->path != '/' && !$this->bo->vfs->acl_check(array('string' => $this->path, 'relatives' => array(RELATIVE_NONE),'operation' => EGW_ACL_READ)))
 368              {
 369                  $this->messages[]= $GLOBALS['egw']->common->error_list(array(lang('You do not have access to %1', $this->path)));
 370                  $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->homedir, lang('Go to your home directory'));
 371  
 372                  $GLOBALS['egw']->common->egw_footer();
 373                  $GLOBALS['egw']->common->egw_exit();
 374              }
 375  
 376              $this->bo->userinfo['working_id'] = $this->bo->vfs->working_id;
 377              $this->bo->userinfo['working_lid'] = $GLOBALS['egw']->accounts->id2name($this->bo->userinfo['working_id']);
 378  
 379              # If their home directory doesn't exist, we try to create it
 380              # Same for group directories
 381  
 382  
 383          // Moved to constructor
 384          /*
 385              if(($this->path == $this->homedir)    && !$this->bo->vfs->file_exists($pim_tmp_arr))
 386              {
 387                  $this->bo->vfs->override_acl = 1;
 388  
 389                  if(!$this->bo->vfs->mkdir(array(
 390                      'string' => $this->bo->homedir,
 391                      'relatives' => array(RELATIVE_NONE)
 392                  )))
 393                  {
 394                      $p = $this->bo->vfs->path_parts($pim_tmp_arr);
 395  
 396                      $this->messages[]= $GLOBALS['egw']->common->error_list(array(
 397                          lang('Could not create directory %1',
 398                          $this->bo->homedir . ' (' . $p->real_full_path . ')'
 399                      )));
 400                  }
 401  
 402                  $this->bo->vfs->override_acl = 0;
 403              }
 404              */
 405  
 406              # Verify path is real
 407              if($this->path != $this->bo->homedir && $this->path != '/' && $this->path != $this->bo->fakebase)
 408              {
 409                  if(!$this->bo->vfs->file_exists(array(
 410                      'string' => $this->path,
 411                      'relatives' => array(RELATIVE_NONE)
 412                  )))
 413                  {
 414                      $this->messages[] = $GLOBALS['egw']->common->error_list(array(lang('Directory %1 does not exist', $this->path)));
 415                      $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->bo->homedir, lang('Go to your home directory'));
 416  
 417                      $GLOBALS['egw']->common->egw_footer();
 418                      $GLOBALS['egw']->common->egw_exit();
 419                  }
 420              }
 421  
 422              /* Update if they request it, or one out of 20 page loads */
 423              srand((double) microtime() * 1000000);
 424              if($_GET['update'] || rand(0, 19) == 4)
 425              {
 426                  $this->bo->vfs->update_real(array(
 427                      'string' => $this->path,
 428                      'relatives' => array(RELATIVE_NONE)
 429                  ));
 430              }
 431  
 432              # Check available permissions for $this->path, so we can disable unusable operations in user interface
 433              if($this->bo->vfs->acl_check(array(
 434                  'string' => $this->path,
 435                  'relatives' => array(RELATIVE_NONE),
 436                  'operation' => EGW_ACL_ADD
 437              )))
 438              {
 439                  $this->can_add = True;
 440              }
 441  
 442              # Default is to sort by name
 443              if(!$this->sortby)
 444              {
 445                  $this->sortby = 'name';
 446              }
 447  
 448              if($this->debug)
 449              {
 450                  $this->debug_filemanager();
 451              }
 452  
 453              # main action switch
 454              // FIXME this will become a switch
 455              if($this->newfile_x && $this->newfile_or_dir) // create new textfile
 456              {
 457                  $this->createfile();
 458              }
 459              elseif($this->newfile_or_dir && $this->newdir_x)
 460              {
 461                  $this->createdir();
 462              }
 463              elseif($this->uploadprocess)
 464              {
 465                  $this->fileUpload();
 466              }
 467              elseif($this->upload_x || $this->show_upload_boxes)
 468              {
 469                  $this->showUploadboxes();
 470              }
 471              elseif($this->copy_to_x)
 472              {
 473                  $this->copyTo();
 474              }
 475              elseif($this->move_to_x)
 476              {
 477                  $this->moveTo();
 478              }
 479              elseif($this->download_x)
 480              {
 481                  $this->download();
 482              }
 483              elseif($this->renamefiles)
 484              {
 485                  $this->rename();
 486              }
 487              elseif($this->comment_files)
 488              {
 489                  $this->editComment();
 490              }
 491              elseif($this->edit_cancel_x)
 492              {
 493                  $this->readFilesInfo();
 494                  $this->fileListing();
 495              }
 496              elseif($this->edit_x || $this->edit_preview_x || $this->edit_save_x || $this->edit_save_done_x)
 497              {
 498                  $this->edit();
 499              }
 500              elseif($this->delete_x)
 501              {
 502                  $this->delete();
 503              }
 504              else
 505              {
 506                  $this->readFilesInfo();
 507                  $this->fileListing();
 508              }
 509          }
 510  
 511  		function fileListing()
 512          {
 513              $this->t->set_file(array('filemanager_list_t' => 'filelisting.tpl'));
 514              $this->t->set_block('filemanager_list_t','filemanager_header','filemanager_header');
 515              $this->t->set_block('filemanager_list_t','column','column');
 516              $this->t->set_block('filemanager_list_t','row','row');
 517              $this->t->set_block('filemanager_list_t','filemanager_footer','filemanager_footer');
 518  
 519              $vars['form_action']=$this->encode_href('/index.php', 'menuaction=filemanager.uifilemanager.index','path='.$this->path);
 520              if($this->numoffiles || $this->cwd)
 521              {
 522                  while(list($num, $name) = each($this->prefs))
 523                  {
 524                      if($name)
 525                      {
 526                          $columns++;
 527                      }
 528                  }
 529                  $columns++;
 530  
 531                  $vars['toolbar0'] = $this->toolbar('location');
 532                  $vars['toolbar1'] = $this->toolbar('list_nav');
 533  
 534                  if(count($this->messages)>0)
 535                  {
 536                      foreach($this->messages as $msg)
 537                      {
 538                          $messages.='<p>'.$msg.'</p>';
 539                      }
 540                  }
 541  
 542                  $vars['messages'] = $messages;
 543  
 544                  $this->t->set_var($vars);
 545                  $this->t->pparse('out','filemanager_header');
 546  
 547                  ###
 548                  # Start File Table Column Headers
 549                  # Reads values from $file_attributes array and preferences
 550                  ###
 551                  $this->t->set_var('actions',lang('select'));
 552  
 553                  reset($this->bo->file_attributes);
 554  
 555                  if($this->numoffiles>0)
 556                  {
 557                      while(list($internal, $displayed) = each($this->bo->file_attributes))
 558                      {
 559                          if($this->prefs[$internal])
 560                          {
 561                              $col_data='<span><a href="'.$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path.'&sortby='.$internal).'">'.$displayed.'</a></span>';
 562                              $this->t->set_var('col_data',$col_data);
 563                              $this->t->parse('columns','column',True);
 564                          }
 565                      }
 566  
 567                      $this->t->set_var('row_tr_color','#dedede');
 568  
 569                      //kan dit weg?
 570                      $this->t->parse('rows','row');
 571  
 572                      $this->t->pparse('out','row');
 573                  }
 574                  else
 575                  {
 576                      $lang_nofiles=lang('No files in this directory.');
 577                  }
 578                  $vars['lang_no_files'] = $lang_nofiles;
 579  
 580                  if($this->prefs['dotdot'] && $this->prefs['name'] && $this->path != '/')
 581                  {
 582                      $this->t->set_var('actions','');
 583  
 584                      $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
 585  
 586                      $col_data='<a href="'.$link.'"><img src="'.$GLOBALS['egw']->common->image('filemanager','mime16up').' "alt="'.lang('Folder Up').'" /></a>';
 587                      $col_data.='&nbsp;<a href="'.$link.'">..</a>';
 588  
 589                      $this->t->set_var('col_data',$col_data);
 590                      $this->t->parse('columns','column');
 591  
 592                      if($this->prefs['mime_type'])
 593                      {
 594                          $col_data=lang('Directory');
 595                          $this->t->set_var('col_data',$col_data);
 596                          $this->t->parse('columns','column',True);
 597                      }
 598  
 599                      $this->t->set_var('row_tr_color',$tr_color);
 600                      $this->t->parse('rows','row');
 601                      $this->t->pparse('out','row');
 602                  }
 603  
 604                  # List all of the files, with their attributes
 605                  @reset($this->files_array);
 606                  for($i = 0; $i != $this->numoffiles; $i++)
 607                  {
 608                      $files = $this->files_array[$i];
 609  
 610                      if($this->rename_x || $this->edit_comments_x)
 611                      {
 612                          unset($this_selected);
 613                          unset($renamethis);
 614                          unset($edit_this_comment);
 615  
 616                          for($j = 0; $j != $this->numoffiles; $j++)
 617                          {
 618                              if($this->fileman[$j] == $files['name'])
 619                              {
 620                                  $this_selected = 1;
 621                                  break;
 622                              }
 623                          }
 624  
 625                          if($this->rename_x && $this_selected)
 626                          {
 627                              $renamethis = 1;
 628                          }
 629                          elseif($this->edit_comments_x && $this_selected)
 630                          {
 631                              $edit_this_comment = 1;
 632                          }
 633                      }
 634  
 635                      if(!$this->prefs['dotfiles'] && ereg("^\.", $files['name']))
 636                      {
 637                          continue;
 638                      }
 639  
 640                      # Checkboxes
 641                      if(!$this->rename_x && !$this->edit_comments_x && $this->path != $this->bo->fakebase && $this->path != '/')
 642                      {
 643                          $cbox='<input type="checkbox" name="fileman['.$i.']" value="'.$files['name'].'">';
 644                          $this->t->set_var('actions',$cbox);
 645                      }
 646                      elseif($renamethis)
 647                      {
 648                          $cbox=$this->html_form_input('hidden', 'fileman[' . base64_encode($files['name']) . ']', $files['name'], NULL, NULL, 'checked');
 649                          $this->t->set_var('actions',$cbox);
 650                      }
 651                      else
 652                      {
 653                          $this->t->set_var('actions','');
 654                      }
 655  
 656                      # File name and icon
 657                      if($renamethis)
 658                      {
 659                          $col_data=$this->mime_icon($files['mime_type']);
 660                          $col_data.='<input type="text" maxlength="255" name="renamefiles[' . $files['name'] . ']" value="'.$files['name'].'">';
 661                      }
 662                      else
 663                      {
 664                          if($files['mime_type'] == 'Directory')
 665                          {
 666                              $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path.$this->dispsep.$files['name']);
 667  
 668                              $icon=$this->mime_icon($files['mime_type']);
 669  
 670                              $col_data='<a href="'.$link.'">'.$icon.'</a>&nbsp;';
 671                              $col_data.='<a href="'.$link.'">'.$files['name'].'</a>&nbsp;';
 672                          }
 673                          else
 674                          {
 675  
 676                              if($this->prefs['viewonserver'] && isset($this->bo->filesdir) && !$files['link_directory'])
 677                              {
 678                                  #FIXME
 679                                  $clickview = $this->filesdir.$pwd.'/'.$files['name'];
 680  
 681                                  if($phpwh_debug)
 682                                  {
 683                                      echo 'Setting clickview = '.$clickview.'<br>'."\n";
 684                                      $this->html_link($clickview,'', '',$files['name'], 0, 1, 0, '');
 685                                  }
 686                              }
 687                              else
 688                              {
 689                                  $icon=$this->mime_icon($files['mime_type']);
 690                                  $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.view','file='.$files['name'].'&path='.$this->path);
 691  
 692                                  $col_data='<a href="'.$link.'" target="'.$this->target.'">'.$icon.'</a>&nbsp;<a href="'.$link.'" target="'.$this->target.'">'.$files['name'].'</a>';
 693                              }
 694                          }
 695                      }
 696  
 697                      $this->t->set_var('col_data',$col_data);
 698                      $this->t->parse('columns','column');
 699  
 700                      # MIME type
 701                      if($this->prefs['mime_type'])
 702                      {
 703                          $col_data=$files['mime_type'];
 704                          $this->t->set_var('col_data',$col_data);
 705                          $this->t->parse('columns','column',True);
 706                      }
 707  
 708                      # File size
 709                      if($this->prefs['size'])
 710                      {
 711                          $tmp_arr=array(
 712                              'string'    => $files['directory'] . '/' . $files['name'],
 713                              'relatives'    => array(RELATIVE_NONE)
 714                          );
 715                          if($files['mime_type'] != 'Directory') $tmp_arr['checksubdirs'] = false;
 716  
 717                          $size = $this->bo->vfs->get_size($tmp_arr);
 718  
 719                          $col_data=$this->bo->borkb($size);
 720  
 721                          $this->t->set_var('col_data',$col_data);
 722                          $this->t->parse('columns','column',True);
 723                      }
 724  
 725                      # Date created
 726                      if($this->prefs['created'])
 727                      {
 728                          $col_data=date($this->dateformat,strtotime($files['created']));
 729                          $this->t->set_var('col_data',$col_data);
 730                          $this->t->parse('columns','column',True);
 731                      }
 732  
 733                      # Date modified
 734                      if($this->prefs['modified'])
 735                      {
 736                          if($files['modified'] != '0000-00-00')
 737                          {
 738                              $col_data=date($this->dateformat,strtotime($files['modified']));
 739                          }
 740                          else
 741                          {
 742                              $col_data='';
 743                          }
 744  
 745                          $this->t->set_var('col_data',$col_data);
 746                          $this->t->parse('columns','column',True);
 747                      }
 748  
 749                      # Owner name
 750                      if($this->prefs['owner'])
 751                      {
 752                          $this->t->set_var('col_data',$GLOBALS['egw']->accounts->id2name($files['owner_id']));
 753                          $this->t->parse('columns','column',True);
 754                      }
 755  
 756                      # Creator name
 757                      if($this->prefs['createdby_id'])
 758                      {
 759                          $this->html_table_col_begin();
 760                          if($files['createdby_id'])
 761                          {
 762                              $col_data=$GLOBALS['egw']->accounts->id2name($files['createdby_id']);
 763                          }
 764                          else $col_data='';
 765  
 766                          $this->t->set_var('col_data',$col_data);
 767                          $this->t->parse('columns','column',True);
 768                      }
 769  
 770                      # Modified by name
 771                      if($this->prefs['modifiedby_id'])
 772                      {
 773                          if($files['modifiedby_id'])
 774                          {
 775                              $col_data=$GLOBALS['egw']->accounts->id2name($files['modifiedby_id']);
 776                          }
 777                          else $col_data='';
 778                          $this->t->set_var('col_data',$col_data);
 779                          $this->t->parse('columns','column',True);
 780                      }
 781  
 782                      # Application
 783                      if($this->prefs['app'])
 784                      {
 785                          $col_data=$files['app'];
 786                          $this->t->set_var('col_data',$col_data);
 787                          $this->t->parse('columns','column',True);
 788                      }
 789  
 790                      # Comment
 791                      if($this->prefs['comment'])
 792                      {
 793                          if($edit_this_comment)
 794                          {
 795                              $col_data='<input type="text" name="comment_files[' . $files['name'] . ']" value="'.$files['comment'].'" maxlength="255">';
 796                          }
 797                          else
 798                          {
 799                              $col_data=$files['comment'];
 800                          }
 801                          $this->t->set_var('col_data',$col_data);
 802                          $this->t->parse('columns','column',True);
 803                      }
 804  
 805                      # Version
 806                      if($this->prefs['version'])
 807                      {
 808                          $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.history','file='.$files['name'].'&path='.$this->path);
 809                          $col_data='<a href="'.$link.'" target="_blank">'.$files['version'].'</a>';
 810                          $this->t->set_var('col_data',$col_data);
 811                          $this->t->parse('columns','column',True);
 812                      }
 813  
 814                      if($files['mime_type'] == 'Directory')
 815                      {
 816                          $usedspace += $fileinfo[0];
 817                      }
 818                      else
 819                      {
 820                          $usedspace += $files['size'];
 821                      }
 822  
 823                      $this->t->set_var('row_tr_color','');
 824                      $this->t->parse('rows','row');
 825                      $this->t->pparse('out','row');
 826                  }
 827  
 828                  // when renaming or changing comments render extra sumbmit button
 829                  if($this->rename_x || $this->edit_comments_x)
 830                  {
 831                      $col_data='<br/><input type="submit" name="save_changes" value="'.lang('Save changes').'">';
 832                      $this->t->set_var('col_data',$col_data);
 833                      $this->t->parse('columns','column');
 834                      $this->t->set_var('row_tr_color','');
 835                      $this->t->parse('rows','row');
 836                      $this->t->pparse('out','row');
 837                  }
 838              }
 839  
 840              // The file and directory information
 841              $vars['lang_files_in_this_dir'] = lang('Files in this directory');
 842              $vars['files_in_this_dir'] = $this->numoffiles;
 843  
 844              $vars['lang_used_space'] = lang('Used space');
 845              $vars['used_space'] = $this->bo->borkb($usedspace, NULL, 1);
 846  
 847              if($this->path == $this->bo->homedir || $this->path == $this->bo->fakebase)
 848              {
 849                  $vars['lang_unused_space'] = lang('Unused space');
 850                  $vars['unused_space'] = $this->bo->borkb($this->bo->userinfo['hdspace'] - $usedspace, NULL, 1);
 851  
 852                  $tmp_arr=array(
 853                      'string'    => $this->path,
 854                      'relatives'    => array(RELATIVE_NONE)
 855                  );
 856  
 857                  $ls_array = $this->bo->vfs->ls($tmp_arr);
 858  
 859                  $vars['lang_total_files'] = lang('Total Files');
 860                  $vars['total_files'] = count($ls_array);
 861              }
 862  
 863              $this->t->set_var($vars);
 864              $this->t->pparse('out','filemanager_footer');
 865  
 866              $GLOBALS['egw']->common->egw_footer();
 867              $GLOBALS['egw']->common->egw_exit();
 868          }
 869  
 870  		function readFilesInfo()
 871          {
 872              // start files info
 873  
 874              # Read in file info from database to use in the rest of the script
 875              # $fakebase is a special directory.  In that directory, we list the user's
 876              # home directory and the directories for the groups they're in
 877              $this->numoffiles = 0;
 878              if($this->path == $this->bo->fakebase)
 879              {
 880                  // FIXME this test can be removed
 881                  if(!$this->bo->vfs->file_exists(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE))))
 882                  {
 883                      $this->bo->vfs->mkdir(array('string' => $this->bo->homedir, 'relatives' => array(RELATIVE_NONE)));
 884                  }
 885  
 886                  $ls_array = $this->bo->vfs->ls(array(
 887                      'string' => $this->bo->homedir,
 888                      'relatives' => array(RELATIVE_NONE),
 889                      'checksubdirs' => False,
 890                      'nofiles' => True
 891                  ));
 892                  $this->files_array[] = $ls_array[0];
 893                  $this->numoffiles++;
 894  
 895                  reset($this->readable_groups);
 896                  while(list($num, $group_array) = each($this->readable_groups))
 897                  {
 898                      # If the group doesn't have access to this app, we don't show it
 899                      if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
 900                      {
 901                          continue;
 902                      }
 903  
 904                      if(!$this->bo->vfs->file_exists(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'    => array(RELATIVE_NONE))))
 905                      {
 906                          $this->bo->vfs->override_acl = 1;
 907                          $this->bo->vfs->mkdir(array(
 908                              'string' => $this->bo->fakebase.'/'.$group_array['account_name'],
 909                              'relatives' => array(RELATIVE_NONE)
 910                          ));
 911  
 912                          // FIXME we just created a fresh group dir so we know there nothing in it so we have to remove all existing content
 913  
 914                          $this->bo->vfs->override_acl = 0;
 915  
 916                          $this->bo->vfs->set_attributes(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'    => array(RELATIVE_NONE),'attributes' => array('owner_id' => $group_array['account_id'],'createdby_id' => $group_array['account_id'])));
 917                      }
 918  
 919                      $ls_array = $this->bo->vfs->ls(array('string' => $this->bo->fakebase.'/'.$group_array['account_name'],'relatives'    => array(RELATIVE_NONE),'checksubdirs' => False,'nofiles' => True));
 920  
 921                      $this->files_array[] = $ls_array[0];
 922  
 923                      $this->numoffiles++;
 924                  }
 925              }
 926              else
 927              {
 928                  $ls_array = $this->bo->vfs->ls(array(
 929                      'string' => $this->path,
 930                      'relatives'    => array(RELATIVE_NONE),
 931                      'checksubdirs' => False,
 932                      'nofiles'    => False,
 933                      'orderby'    => $this->sortby
 934                  ));
 935  
 936                  if($phpwh_debug)
 937                  {
 938                      echo '# of files found in "'.$this->path.'" : '.count($ls_array).'<br>'."\n";
 939                  }
 940  
 941                  while(list($num, $file_array) = each($ls_array))
 942                  {
 943                      $this->numoffiles++;
 944                      $this->files_array[] = $file_array;
 945                      if($phpwh_debug)
 946                      {
 947                          echo 'Filename: '.$file_array['name'].'<br>'."\n";
 948                      }
 949                  }
 950              }
 951  
 952              if(!is_array($this->files_array))
 953              {
 954                  $this->files_array = array();
 955              }
 956              // end file count
 957          }
 958  
 959  		function toolbar($type)
 960          {
 961              switch($type)
 962              {
 963                  case 'location':
 964                      $toolbar='
 965                      <div id="fmLocation">
 966                      <table cellspacing="1" cellpadding="0" border="0">
 967                      <tr>
 968                      ';
 969                      $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
 970                      $toolbar.='
 971                      <td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
 972  
 973                      // go up icon when we're not at the top, dont allow to go outside /home = fakebase
 974                      if($this->path != '/' && $this->path != $this->bo->fakebase)
 975                      {
 976                          $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->lesspath);
 977                          $toolbar.=$this->buttonImage($link,'up',lang('go up'));
 978                      }
 979  
 980                      // go home icon when we're not home already
 981                      if($this->path != $this->bo->homedir)
 982                      {
 983                          $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->bo->homedir);
 984                          $toolbar.=$this->buttonImage($link,'home',lang('go home'));
 985                      }
 986  
 987                      // reload button with this url
 988                      $link=$this->encode_href('/index.php','menuaction=filemanager.uifilemanager.index&update=1','path='.$this->path);
 989                      $toolbar.=$this->buttonImage($link,'reload',lang('reload'));
 990  
 991                      $toolbar.='<td>'.lang('Location').':&nbsp;';
 992                      //$toolbar.='<input id="fmInputLocation" type="text" size="20" disabled="disabled" name="location" value="'.$this->disppath.'"/>&nbsp;';
 993                      $current_option='<option>'.$this->disppath.'</option>';
 994                      // selectbox for change/move/and copy to
 995                      $dirs_options=$this->all_other_directories_options();
 996                      $toolbar.='<select name="cdtodir" onChange="document.formfm.changedir.value=\'true\';document.formfm.submit()">'.$current_option.$dirs_options.'</select>
 997                      <input type="hidden" name="changedir" value="false"></td>
 998                      ';
 999                      $toolbar.=$this->inputImage('goto','goto',lang('Quick jump to'));
1000                      // upload button
1001                      if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1002                      {
1003  
1004                          $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1005                          $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1006                          $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1007  
1008                          //                        $toolbar.=$this->inputImage('download','download',lang('Download'));
1009                          // upload button
1010                          $toolbar.=$this->inputImage('upload','upload',lang('Upload'));
1011                      }
1012                      $toolbar.='</tr></table>';
1013                      $toolbar.='</div>';
1014                      break;
1015                  case 'list_nav':
1016                      $toolbar='
1017                      <table cellspacing="1" cellpadding="0" border="0">
1018                      <tr>';
1019                      // selectbox for change/move/and copy to
1020                      // submit buttons for
1021                      if($this->path != '/' && $this->path != $this->bo->fakebase)
1022                      {
1023                          $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1024                          $toolbar.='
1025                          <td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1026  
1027                          if(!$this->rename_x && !$this->edit_comments_x)
1028                          {
1029                              // edit text file button
1030                              $toolbar.=$this->inputImage('edit','edit',lang('edit'));
1031                          }
1032  
1033                          if(!$this->edit_comments_x)
1034                          {
1035                              $toolbar.=$this->inputImage('rename','rename',lang('Rename'));
1036                          }
1037  
1038                          if(!$this->rename_x && !$this->edit_comments_x)
1039                          {
1040                              $toolbar.=$this->inputImage('delete','delete',lang('Delete'));
1041                          }
1042  
1043                          if(!$this->rename_x)
1044                          {
1045                              $toolbar.=$this->inputImage('edit_comments','edit_comments',lang('Edit comments'));
1046                          }
1047                          $toolbar.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1048                      }
1049  
1050                      //    $toolbar.='</tr></table>';
1051                      if(!$this->rename_x && !$this->edit_comments_x)
1052                      {
1053                          // copy and move buttons
1054                          if($this->path != '/' && $this->path != $this->bo->fakebase)
1055                          {
1056                              $toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1057                              $toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1058  
1059                              $dirs_options=$this->all_other_directories_options();
1060                              $toolbar3.='<td><select name="todir">'.$dirs_options.'</select></td>';
1061  
1062                              $toolbar3.=$this->inputImage('copy_to','copy_to',lang('Copy to'));
1063                              $toolbar3.=$this->inputImage('move_to','move_to',lang('Move to'));
1064  
1065                              $toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1066  
1067                          }
1068  
1069                          // create dir and file button
1070                          if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1071                          {
1072                              $toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('phpgwapi','buttonseparator').'" height="27" width="8"></td>';
1073                              $toolbar3.='<td><img alt="spacer" src="'.$GLOBALS['egw']->common->image('filemanager','spacer').'" height="27" width="1"></td>';
1074  
1075                              $toolbar3.='<td><input type=text size="15" name="newfile_or_dir" value="" /></td>';
1076                              $toolbar3.=$this->inputImage('newdir','createdir',lang('Create Folder'));
1077                              $toolbar3.=$this->inputImage('newfile','createfile',lang('Create File'));
1078                          }
1079  
1080                          if($toolbar3)
1081                          {
1082                              $toolbar.=$toolbar3;
1083                          /*    $toolbar.='
1084                              <table cellspacing="1" cellpadding="0" border="0">
1085                              <tr>'.$toolbar3;*/
1086                          }
1087                      }
1088                      $toolbar.='</tr></table>';
1089  
1090                      break;
1091                  default:$x='';
1092              }
1093  
1094              if($toolbar)
1095              {
1096                  return $toolbar;
1097              }
1098          }
1099  
1100          // move to bo
1101          # Handle File Uploads
1102  		function fileUpload()
1103          {
1104              if($this->path != '/' && $this->path != $this->bo->fakebase)
1105              {
1106                  for($i = 0; $i != $this->show_upload_boxes; $i++)
1107                  {
1108                      if($badchar = $this->bo->bad_chars($_FILES['upload_file']['name'][$i], True, True))
1109                      {
1110                          $this->messages[]= $GLOBALS['egw']->common->error_list(array($this->bo->html_encode(lang('File names cannot contain "%1"', $badchar), 1)));
1111  
1112                          continue;
1113                      }
1114  
1115                      # Check to see if the file exists in the database, and get its info at the same time
1116                      $ls_array = $this->bo->vfs->ls(array(
1117                          'string'=> $this->path . '/' . $_FILES['upload_file']['name'][$i],
1118                          'relatives'    => array(RELATIVE_NONE),
1119                          'checksubdirs'    => False,
1120                          'nofiles'    => True
1121                      ));
1122  
1123                      $fileinfo = $ls_array[0];
1124  
1125                      if($fileinfo['name'])
1126                      {
1127                          if($fileinfo['mime_type'] == 'Directory')
1128                          {
1129                              $this->messages[]= $GLOBALS['egw']->common->error_list(array(lang('Cannot replace %1 because it is a directory', $fileinfo['name'])));
1130                              continue;
1131                          }
1132                      }
1133  
1134                      if($_FILES['upload_file']['size'][$i] > 0)
1135                      {
1136                          if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
1137                          {
1138                              $tmp_arr=array(
1139                                  'string'=> $_FILES['upload_file']['name'][$i],
1140                                  'relatives'    => array(RELATIVE_ALL),
1141                                  'attributes'    => array(
1142                                      'owner_id' => $this->bo->userinfo['username'],
1143                                      'modifiedby_id' => $this->bo->userinfo['username'],
1144                                      'modified' => $this->now,
1145                                      'size' => $_FILES['upload_file']['size'][$i],
1146                                      'mime_type' => $_FILES['upload_file']['type'][$i],
1147                                      'deleteable' => 'Y',
1148                                      'comment' => stripslashes($_POST['upload_comment'][$i])
1149                                  )
1150                              );
1151                              $this->bo->vfs->set_attributes($tmp_arr);
1152  
1153                              $tmp_arr=array(
1154                                  'from'    => $_FILES['upload_file']['tmp_name'][$i],
1155                                  'to'    => $_FILES['upload_file']['name'][$i],
1156                                  'relatives'    => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1157                              );
1158                              $this->bo->vfs->cp($tmp_arr);
1159  
1160                              $this->messages[]=lang('Replaced %1', $this->disppath.'/'.$_FILES['upload_file']['name'][$i]);
1161                          }
1162                          else
1163                          {
1164                              $this->bo->vfs->cp(array(
1165                                  'from'=> $_FILES['upload_file']['tmp_name'][$i],
1166                                  'to'=> $_FILES['upload_file']['name'][$i],
1167                                  'relatives'    => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
1168                              ));
1169  
1170                              $this->bo->vfs->set_attributes(array(
1171                                  'string'=> $_FILES['upload_file']['name'][$i],
1172                                  'relatives'    => array(RELATIVE_ALL),
1173                                  'attributes'=> array(
1174                                      'mime_type' => $_FILES['upload_file']['type'][$i],
1175                                      'comment' => stripslashes($_POST['upload_comment'][$i])
1176                                  )
1177                              ));
1178  
1179                              $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $_FILES['upload_file']['size'][$i]);
1180                          }
1181                      }
1182                      elseif($_FILES['upload_file']['name'][$i])
1183                      {
1184                          $this->bo->vfs->touch(array(
1185                              'string'=> $_FILES['upload_file']['name'][$i],
1186                              'relatives'    => array(RELATIVE_ALL)
1187                          ));
1188  
1189                          $this->bo->vfs->set_attributes(array(
1190                              'string'=> $_FILES['upload_file']['name'][$i],
1191                              'relatives'    => array(RELATIVE_ALL),
1192                              'attributes'=> array(
1193                                  'mime_type' => $_FILES['upload_file']['type'][$i],
1194                                  'comment' => stripslashes($_POST['upload_comment'][$i])
1195                              )
1196                          ));
1197  
1198                          $this->messages[]=lang('Created %1,%2', $this->disppath.'/'.$_FILES['upload_file']['name'][$i], $file_size[$i]);
1199                      }
1200                  }
1201  
1202                  $this->readFilesInfo();
1203                  $this->filelisting();
1204              }
1205          }
1206  
1207          # Handle Editing comments
1208  		function editComment()
1209          {
1210              while(list($file) = each($this->comment_files))
1211              {
1212                  if($badchar = $this->bo->bad_chars($this->comment_files[$file], False, True))
1213                  {
1214                      $this->messages[]=$GLOBALS['egw']->common->error_list(array($file . $this->bo->html_encode(': ' . lang('Comments cannot contain "%1"', $badchar), 1)));
1215                      continue;
1216                  }
1217  
1218                  $this->bo->vfs->set_attributes(array(
1219                      'string'    => $file,
1220                      'relatives'    => array(RELATIVE_ALL),
1221                      'attributes'    => array(
1222                          'comment' => stripslashes($this->comment_files[$file])
1223                      )
1224                  ));
1225  
1226                  $this->messages[]=lang('Updated comment for %1', $this->path.'/'.$file);
1227              }
1228  
1229              $this->readFilesInfo();
1230              $this->filelisting();
1231          }
1232  
1233          # Handle Renaming Files and Directories
1234  		function rename()
1235          {
1236              while(list($from, $to) = each($this->renamefiles))
1237              {
1238                  if($badchar = $this->bo->bad_chars($to, True, True))
1239                  {
1240                      $this->messages[]=$GLOBALS['egw']->common->error_list(array($this->bo->html_encode(lang('File names cannot contain "%1"', $badchar), 1)));
1241                      continue;
1242                  }
1243  
1244                  if(ereg("/", $to) || ereg("\\\\", $to))
1245                  {
1246                      $this->messages[]=$GLOBALS['egw']->common->error_list(array(lang("File names cannot contain \\ or /")));
1247                  }
1248                  elseif(!$this->bo->vfs->mv(array(
1249                      'from'    => $from,
1250                      'to'    => $to
1251                  )))
1252                  {
1253                      $this->messages[]= $GLOBALS['egw']->common->error_list(array(lang('Could not rename %1 to %2', $this->disppath.'/'.$from, $this->disppath.'/'.$to)));
1254                  }
1255                  else
1256                  {
1257                      $this->messages[]=lang('Renamed %1 to %2', $this->disppath.'/'.$from, $this->disppath.'/'.$to);
1258                  }
1259              }
1260              $this->readFilesInfo();
1261              $this->filelisting();
1262          }
1263  
1264          # Handle Moving Files and Directories
1265  		function moveTo()
1266          {
1267              if(!$this->todir)
1268              {
1269                  $this->messages[] = $GLOBALS['egw']->common->error_list(array(lang('Could not move file because no destination directory is given ', $this->disppath.'/'.$file)));
1270  
1271              }
1272              else
1273              {
1274  
1275                  while(list($num, $file) = each($this->fileman))
1276                  {
1277                      if($this->bo->vfs->mv(array(
1278                          'from'    => $file,
1279                          'to'    => $this->todir . '/' . $file,
1280                          'relatives'    => array(RELATIVE_ALL, RELATIVE_NONE)
1281                      )))
1282                      {
1283                          $moved++;
1284                          $this->messages[]=lang('Moved %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1285                      }
1286                      else
1287                      {
1288                          $this->messages[] = $GLOBALS['egw']->common->error_list(array(lang('Could not move %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file)));
1289                      }
1290                  }
1291              }
1292  
1293              if($moved)
1294              {
1295                  $x=0;
1296              }
1297  
1298              $this->readFilesInfo();
1299              $this->filelisting();
1300          }
1301  
1302          // Handle Copying of Files and Directories
1303  		function copyTo()
1304          {
1305              if(!$this->todir)
1306              {
1307                  $this->messages[] = $GLOBALS['egw']->common->error_list(array(lang('Could not copy file because no destination directory is given ', $this->disppath.'/'.$file)));
1308  
1309              }
1310              else
1311              {
1312                  while(list($num, $file) = each($this->fileman))
1313                  {
1314                      if($this->bo->vfs->cp(array(
1315                          'from'    => $file,
1316                          'to'    => $this->todir . '/' . $file,
1317                          'relatives'    => array(RELATIVE_ALL, RELATIVE_NONE)
1318                      )))
1319                      {
1320                          $copied++;
1321                          $this->message .= lang('Copied %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file);
1322                      }
1323                      else
1324                      {
1325                          $this->message .= $GLOBALS['egw']->common->error_list(array(lang('Could not copy %1 to %2', $this->disppath.'/'.$file, $this->todir.'/'.$file)));
1326                      }
1327                  }
1328              }
1329              if($copied)
1330              {
1331                  $x=0;
1332              }
1333  
1334              $this->readFilesInfo();
1335              $this->filelisting();
1336          }
1337  
1338  		function createdir()
1339          {
1340              if($this->newdir_x && $this->newfile_or_dir)
1341              {
1342                  if($this->bo->badchar = $this->bo->bad_chars($this->newfile_or_dir, True, True))
1343                  {
1344                      $this->messages[]= $GLOBALS['egw']->common->error_list(array($this->bo->html_encode(lang('Directory names cannot contain "%1"', $badchar), 1)));
1345                  }
1346  
1347                  /* TODO is this right or should it be a single $ ? */
1348                  if($$this->newfile_or_dir[strlen($this->newfile_or_dir)-1] == ' ' || $this->newfile_or_dir[0] == ' ')
1349                  {
1350                      $this->messages[]= $GLOBALS['egw']->common->error_list(array(lang('Cannot create directory because it begins or ends in a space')));
1351                  }
1352  
1353                  $ls_array = $this->bo->vfs->ls(array(
1354                      'string'    => $this->path . '/' . $this->newfile_or_dir,
1355                      'relatives'    => array(RELATIVE_NONE),
1356                      'checksubdirs'    => False,
1357                      'nofiles'    => True
1358                  ));
1359  
1360                  $fileinfo = $ls_array[0];
1361  
1362                  if($fileinfo['name'])
1363                  {
1364                      if($fileinfo['mime_type'] != 'Directory')
1365                      {
1366                          $this->messages[]= $GLOBALS['egw']->common->error_list(array(
1367                              lang('%1 already exists as a file',
1368                              $fileinfo['name'])
1369                          ));
1370                      }
1371                      else
1372                      {
1373                          $this->messages[]= $GLOBALS['egw']->common->error_list(array(lang('Directory %1 already exists', $fileinfo['name'])));
1374                      }
1375                  }
1376                  else
1377                  {
1378                      if($this->bo->vfs->mkdir(array('string' => $this->newfile_or_dir)))
1379                      {
1380                          $this->messages[]=lang('Created directory %1', $this->disppath.'/'.$this->newfile_or_dir);
1381                      }
1382                      else
1383                      {
1384                          $this->messages[]=$GLOBALS['egw']->common->error_list(array(lang('Could not create %1', $this->disppath.'/'.$this->newfile_or_dir)));
1385                      }
1386                  }
1387  
1388                  $this->readFilesInfo();
1389                  $this->filelisting();
1390              }
1391          }
1392  
1393  		function delete()
1394          {
1395              if( is_array($this->fileman) && count($this->fileman) >= 1)
1396              {
1397                  foreach($this->fileman as $filename)
1398                  {
1399                      if($this->bo->vfs->delete(array('string' => $filename)))
1400                      {
1401                          $this->messages[]= lang('Deleted %1', $this->disppath.'/'.$filename).'<br/>';
1402                      }
1403                      else
1404                      {
1405                          $this->messages[]=$GLOBALS['egw']->common->error_list(array(lang('Could not delete %1', $this->disppath.'/'.$filename)));
1406                      }
1407                  }
1408              }
1409              else
1410              {
1411                  // make this a javascript func for quicker respons
1412                  $this->messages[]=$GLOBALS['egw']->common->error_list(array(lang('Please select a file to delete.')));
1413              }
1414              $this->readFilesInfo();
1415              $this->filelisting();
1416          }
1417  
1418  		function debug_filemanager()
1419          {
1420              error_reporting(8);
1421  
1422              echo "<b>Filemanager debug:</b><br>
1423              path: {$this->path}<br>
1424              disppath: {$this->disppath}<br>
1425              cwd: {$this->cwd}<br>
1426              lesspath: {$this->lesspath}
1427              <p>
1428              <b>eGroupware debug:</b><br>
1429              real getabsolutepath: " . $this->bo->vfs->getabsolutepath(array('target' => False, 'mask' => False, 'fake' => False)) . "<br>
1430              fake getabsolutepath: " . $this->bo->vfs->getabsolutepath(array('target' => False)) . "<br>
1431              appsession: " . $GLOBALS['egw']->session->appsession('vfs','') . "<br>
1432              pwd: " . $this->bo->vfs->pwd() . "<br>";
1433  
1434              echo '<p></p>';
1435              var_dump($this);
1436          }
1437  
1438  		function showUploadboxes()
1439          {
1440              $this->t->set_file(array('upload' => 'upload.tpl'));
1441              $this->t->set_block('upload','upload_header','upload_header');
1442              $this->t->set_block('upload','row','row');
1443              $this->t->set_block('upload','upload_footer','upload_footer');
1444  
1445              # Decide how many upload boxes to show
1446              if(!$this->show_upload_boxes || $this->show_upload_boxes <= 0)
1447              {
1448                  if(!$this->show_upload_boxes = $this->prefs['show_upload_boxes'])
1449                  {
1450                      $this->show_upload_boxes = 1;
1451                  }
1452              }
1453  
1454              # Show file upload boxes. Note the last argument to html().  Repeats $this->show_upload_boxes times
1455              if($this->path != '/' && $this->path != $this->bo->fakebase && $this->can_add)
1456              {
1457                  $vars['form_action']=$GLOBALS['egw']->link('/index.php','menuaction=filemanager.uifilemanager.index');
1458                  $vars['path']=$this->path;
1459                  $vars['lang_file']=lang('File');
1460                  $vars['lang_comment']=lang('Comment');
1461                  $vars['num_upload_boxes']=$this->show_upload_boxes;
1462                  $this->t->set_var($vars);
1463                  $this->t->pparse('out','upload_header');
1464  
1465                  for($i=0;$i<$this->show_upload_boxes;$i++)
1466                  {
1467                      $this->t->set_var('row_tr_color',$tr_color);
1468                      $this->t->parse('rows','row');
1469                      $this->t->pparse('out','row');
1470                  }
1471  
1472                  $vars['lang_upload']=lang('Upload files');
1473                  $vars['change_upload_boxes'].=lang('Show') . '&nbsp;';
1474                  $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=5', '5');
1475                  $links.='&nbsp;';
1476                  $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=10', '10');
1477                  $links.='&nbsp;';
1478                  $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=20', '20');
1479                  $links.='&nbsp;';
1480                  $links.= $this->html_link('/index.php','menuaction=filemanager.uifilemanager.index','show_upload_boxes=50', '50');
1481                  $links.='&nbsp;';
1482                  $links.= lang('upload fields');
1483                  $vars['change_upload_boxes'].=$links;
1484                  $this->t->set_var($vars);
1485                  $this->t->pparse('out','upload_footer');
1486              }
1487          }
1488  
1489          /* create textfile */
1490  		function createfile()
1491          {
1492              $this->createfile_var=$this->newfile_or_dir;
1493              if($this->createfile_var)
1494              {
1495                  if($badchar = $this->bo->bad_chars($this->createfile_var, True, True))
1496                  {
1497                      $this->messages[] = $GLOBALS['egw']->common->error_list(array(
1498                          lang('File names cannot contain "%1"',$badchar),
1499                          1)
1500                      );
1501  
1502                      $this->fileListing();
1503                  }
1504  
1505                  if($this->bo->vfs->file_exists(array(
1506                      'string'=> $this->createfile_var,
1507                      'relatives'    => array(RELATIVE_ALL)
1508                  )))
1509                  {
1510                      $this->messages[]=$GLOBALS['egw']->common->error_list(array(lang('File %1 already exists. Please edit it or delete it first.', $this->createfile_var)));
1511                      $this->fileListing();
1512                  }
1513  
1514                  if($this->bo->vfs->touch(array(
1515                      'string'    => $this->createfile_var,
1516                      'relatives'    => array(RELATIVE_ALL)
1517                  )))
1518                  {
1519                      $this->fileman = array();
1520                      $this->fileman[0] = $this->createfile_var;
1521                      $this->edit = 1;
1522                      $this->numoffiles++;
1523                      $this->edit();
1524                  }
1525                  else
1526                  {
1527                      $this->messages[]=$GLOBALS['egw']->common->error_list(array(lang('File %1 could not be created.', $this->createfile_var)));
1528                      $this->fileListing();
1529                  }
1530              }
1531          }
1532  
1533          # Handle Editing files
1534  		function edit()
1535          {
1536              $this->readFilesInfo();
1537  
1538              $this->t->set_file(array('filemanager_edit' => 'edit_file.tpl'));
1539              $this->t->set_block('filemanager_edit','row','row');
1540  
1541              $vars['preview_content'] = '';
1542              if($this->edit_file)
1543              {
1544                  $this->edit_file_content = stripslashes($this->edit_file_content);
1545              }
1546  
1547              if($this->edit_preview_x)
1548              {
1549                  $content = $this->edit_file_content;
1550  
1551                  $vars['lang_preview_of'] = lang('Preview of %1', $this->path.'/'.$edit_file);
1552  
1553                  $vars['preview_content'] = nl2br($content);
1554              }
1555              elseif($this->edit_save_x || $this->edit_save_done_x)
1556              {
1557                  $content = $this->edit_file_content;
1558                  //die( $content);
1559                  if($this->bo->vfs->write(array(
1560                      'string'    => $this->edit_file,
1561                      'relatives'    => array(RELATIVE_ALL),
1562                      'content'    => $content
1563                  )))
1564                  {
1565                      $this->messages[]=lang('Saved %1', $this->path.'/'.$this->edit_file);
1566  
1567                      if($this->edit_save_done_x)
1568                      {
1569                          $this->readFilesInfo();
1570                          $this->fileListing();
1571                          exit;
1572                      }
1573                  }
1574                  else
1575                  {
1576                      $this->messages[]=lang('Could not save %1', $this->path.'/'.$this->edit_file);
1577                  }
1578              }
1579  
1580              # Now we display the edit boxes and forms
1581              for($j = 0; $j != $this->numoffiles; $j++)
1582              {
1583                  # If we're in preview or save mode, we only show the file
1584                  # being previewed or saved
1585                  if($this->edit_file &&($this->fileman[$j] != $this->edit_file))
1586                  {
1587                      continue;
1588                  }
1589  
1590                  if($this->fileman[$j] && $this->bo->vfs->file_exists(array(
1591                      'string'    => $this->fileman[$j],
1592                      'relatives'    => array(RELATIVE_ALL)
1593                  )))
1594                  {
1595                      if($this->edit_file)
1596                      {
1597                          $content = stripslashes($this->edit_file_content);
1598                      }
1599                      else
1600                      {
1601                          $content = $this->bo->vfs->read(array('string' => $this->fileman[$j]));
1602                      }
1603  
1604                      $vars['form_action'] = $GLOBALS['egw']->link('/index.php','menuaction=filemanager.uifilemanager.index','path='.$this->path);
1605                      $vars['edit_file'] = $this->fileman[$j];
1606  
1607                      # We need to include all of the fileman entries for each file's form,
1608                      # so we loop through again
1609                      for($i = 0; $i != $this->numoffiles; $i++)
1610                      {
1611                          if($this->fileman[$i])
1612                          {
1613                              $value='value="'.$this->fileman[$i].'"';
1614                          }
1615                          $vars['filemans_hidden'] = '<input type="hidden" name="fileman['.$i.']" '.$value.' />';
1616                      }
1617  
1618                      $vars['file_content'] = $content;
1619  
1620                      $vars['buttonPreview'] = $this->inputImage('edit_preview','edit_preview',lang('Preview %1', $this->bo->html_encode($this->fileman[$j], 1)));
1621                      $vars['buttonSave'] = $this->inputImage('edit_save','save',lang('Save %1', $this->bo->html_encode($this->fileman[$j], 1)));
1622                      $vars['buttonDone'] = $this->inputImage('edit_save_done','ok',lang('Save %1, and go back to file listing ', $this->bo->html_encode($this->fileman[$j], 1)));
1623                      $vars['buttonCancel'] = $this->inputImage('edit_cancel','cancel',lang('Cancel editing %1 without saving', $this->bo->html_encode($this->fileman[$j], 1)));
1624                      $this->t->set_var($vars);
1625                      $this->t->parse('rows','row');
1626                      $this->t->pparse('out','row');
1627  
1628                  }
1629              }
1630          }
1631  
1632  		function history()
1633          {
1634              if($this->file) // FIXME this-file is never defined
1635              {
1636                  $journal_array = $this->bo->vfs->get_journal(array(
1637                      'string'    => $this->file,//FIXME
1638                      'relatives'    => array(RELATIVE_ALL)
1639                  ));
1640  
1641                  if(is_array($journal_array))
1642                  {
1643                      $this->html_table_begin();
1644                      $this->html_table_row_begin();
1645                      $this->html_table_col_begin();
1646                      echo lang('Date');
1647                      $this->html_table_col_end();
1648                      $this->html_table_col_begin();
1649                      echo lang('Version');
1650                      $this->html_table_col_end();
1651                      $this->html_table_col_begin();
1652                      echo lang('Who');
1653                      $this->html_table_col_end();
1654                      $this->html_table_col_begin();
1655                      echo lang('Operation');
1656                      $this->html_table_col_end();
1657                      $this->html_table_row_end();
1658  
1659                      while(list($num, $journal_entry) = each($journal_array))
1660                      {
1661                          $this->html_table_row_begin();
1662                          $this->html_table_col_begin();
1663                          $this->bo->html_text($journal_entry['created'] . '&nbsp;&nbsp;&nbsp;');
1664                          $this->html_table_col_end();
1665                          $this->html_table_col_begin();
1666                          $this->bo->html_text($journal_entry['version'] . '&nbsp;&nbsp;&nbsp;' );
1667                          $this->html_table_col_end();
1668                          $this->html_table_col_begin();
1669                          $this->bo->html_text($GLOBALS['egw']->accounts->id2name($journal_entry['owner_id']) . '&nbsp;&nbsp;&nbsp;');
1670                          $this->html_table_col_end();
1671                          $this->html_table_col_begin();
1672                          $this->bo->html_text($journal_entry['comment']);
1673                          $this->html_table_col_end();
1674                      }
1675  
1676                      $this->html_table_end();
1677                      $GLOBALS['egw']->common->egw_footer();
1678                      $GLOBALS['egw']->common->egw_exit();
1679                  }
1680                  else
1681                  {
1682                      echo lang('No version history for this file/directory');
1683                  }
1684              }
1685          }
1686  
1687  		function view()
1688          {
1689              if($this->file) //FIXME
1690              {
1691                  $ls_array = $this->bo->vfs->ls(array(
1692                      'string'    => $this->path.'/'.$this->file,//FIXME
1693                      'relatives'    => array(RELATIVE_ALL),
1694                      'checksubdirs'    => False,
1695                      'nofiles'    => True
1696                  ));
1697  
1698                  if($ls_array[0]['mime_type'])
1699                  {
1700                      $mime_type = $ls_array[0]['mime_type'];
1701                  }
1702                  elseif($this->prefs['viewtextplain'])
1703                  {
1704                      $mime_type = 'text/plain';
1705                  }
1706                  else
1707                  {
1708                      list($_first,$_ext) = split("\.",$this->file);
1709                      $mime_type = ExecMethod('phpgwapi.mime_magic.ext2mime',$_ext);
1710                  }
1711                  $viewable = array('','text/plain','text/csv','text/html','text/text');
1712  
1713                  if(in_array($mime_type,$viewable) && !$_GET['download'])
1714                  {
1715                      header('Content-type: ' . $mime_type);
1716                      header('Content-disposition: filename="' . $this->file . '"');//FIXME
1717                      Header("Pragma: public");
1718                  }
1719                  else
1720                  {
1721  
1722                      $GLOBALS['egw']->browser->content_header($this->file,$mime_type);//FIXME
1723                  }
1724                  echo $this->bo->vfs->read(array(
1725                      'string'    => $this->path.'/'.$this->file,//FIXME
1726                      'relatives'    => array(RELATIVE_NONE)
1727                  ));
1728                  $GLOBALS['egw']->common->egw_exit();
1729              }
1730          }
1731  
1732  		function download()
1733          {
1734              for($i = 0; $i != $this->numoffiles; $i++)
1735              {
1736                  if(!$this->fileman[$i])
1737                  {
1738                      continue;
1739                  }
1740  
1741                  $download_browser =& CreateObject('phpgwapi.browser');
1742                  $download_browser->content_header($this->fileman[$i]);
1743                  echo $this->bo->vfs->read(array('string' => $this->fileman[$i]));
1744                  $GLOBALS['egw']->common->egw_exit();
1745              }
1746          }
1747  
1748          //give back an array with all directories except current and dirs that are not accessable
1749  		function all_other_directories_options()
1750          {
1751              # First we get the directories in their home directory
1752              $dirs = array();
1753              $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $this->bo->userinfo['account_lid']);
1754  
1755              $tmp_arr=array(
1756                  'string'    => $this->bo->homedir,
1757                  'relatives'    => array(RELATIVE_NONE),
1758                  'checksubdirs'    => True,
1759                  'mime_type'    => 'Directory'
1760              );
1761  
1762              $ls_array = $this->bo->vfs->ls($tmp_arr);
1763  
1764              while(list($num, $dir) = each($ls_array))
1765              {
1766                  $dirs[] = $dir;
1767              }
1768  
1769  
1770              # Then we get the directories in their readable groups' home directories
1771              reset($this->readable_groups);
1772              while(list($num, $group_array) = each($this->readable_groups))
1773              {
1774                  # Don't list directories for groups that don't have access
1775                  if(!$this->groups_applications[$group_array['account_name']][$this->bo->appname]['enabled'])
1776                  {
1777                      continue;
1778                  }
1779  
1780                  $dirs[] = array('directory' => $this->bo->fakebase, 'name' => $group_array['account_name']);
1781  
1782                  $tmp_arr=array(
1783                      'string'    => $this->bo->fakebase.'/'.$group_array['account_name'],
1784                      'relatives'    => array(RELATIVE_NONE),
1785                      'checksubdirs'    => True,
1786                      'mime_type'    => 'Directory'
1787                  );
1788  
1789                  $ls_array = $this->bo->vfs->ls($tmp_arr);
1790                  while(list($num, $dir) = each($ls_array))
1791                  {
1792                      $dirs[] = $dir;
1793                  }
1794              }
1795  
1796              reset($dirs);
1797              while(list($num, $dir) = each($dirs))
1798              {
1799                  if(!$dir['directory'])
1800                  {
1801                      continue;
1802                  }
1803  
1804                  # So we don't display //
1805                  if($dir['directory'] != '/')
1806                  {
1807                      $dir['directory'] .= '/';
1808                  }
1809  
1810                  # No point in displaying the current directory, or a directory that doesn't exist
1811                  if((($dir['directory'] . $dir['name']) != $this->path) && $this->bo->vfs->file_exists(array('string' => $dir['directory'] . $dir['name'],'relatives' => array(RELATIVE_NONE))))
1812                  {
1813                      //FIXME replace the html_form_option function
1814                      $options .= $this->html_form_option($dir['directory'] . $dir['name'], $dir['directory'] . $dir['name']);
1815                  }
1816              }
1817  
1818              return $options;
1819          }
1820  
1821          /* seek icon for mimetype else return an unknown icon */
1822  		function mime_icon($mime_type, $size=16)
1823          {
1824              if(!$mime_type)
1825              {
1826                  $mime_type='unknown';
1827              }
1828  
1829              $mime_type=    str_replace	('/','_',$mime_type);
1830  
1831              $img=$GLOBALS['egw']->common->image('filemanager','mime'.$size.'_'.strtolower($mime_type));
1832              if(!$img)
1833              {
1834                  $img = $GLOBALS['egw']->common->image('filemanager','mime'.$size.'_unknown');
1835              }
1836  
1837              $icon='<img src="'.$img.' "alt="'.lang($mime_type).'" />';
1838              return $icon;
1839          }
1840  
1841  		function buttonImage($link,$img='',$help='')
1842          {
1843              $image=$GLOBALS['egw']->common->image('filemanager','button_'.strtolower($img));
1844  
1845              if($img)
1846              {
1847                  return '<td class="fmButton" align="center" valign="middle" height="28" width="28">
1848                  <a href="'.$link.'" title="'.$help.'"><img src="'.$image.'" alt="'.$help.'"/></a>
1849                  </td>';
1850              }
1851          }
1852  
1853  		function inputImage($name,$img='',$help='')
1854          {
1855              $image=$GLOBALS['egw']->common->image('filemanager','button_'.strtolower($img));
1856  
1857              if($img)
1858              {
1859                  return '<td class="fmButton" align="center" valign="middle" height="28" width="28">
1860                  <input title="'.$help.'" name="'.$name.'" type="image" alt="'.$name.'" src="'.$image.'" value="clicked" />
1861                  </td>';
1862              }
1863          }
1864  
1865  		function html_form_input($type = NULL, $name = NULL, $value = NULL, $maxlength = NULL, $size = NULL, $checked = NULL, $string = '', $return = 1)
1866          {
1867              $text = ' ';
1868              if($type != NULL && $type)
1869              {
1870                  if($type == 'checkbox')
1871                  {
1872                      $value = $this->bo->string_encode($value, 1);
1873                  }
1874                  $text .= 'type="'.$type.'" ';
1875              }
1876              if($name != NULL && $name)
1877              {
1878                  $text .= 'name="'.$name.'" ';
1879              }
1880              if($value != NULL && $value)
1881              {
1882                  $text .= 'value="'.$value.'" ';
1883              }
1884              if(is_int($maxlength) && $maxlength >= 0)
1885              {
1886                  $text .= 'maxlength="'.$maxlength.'" ';
1887              }
1888              if(is_int($size) && $size >= 0)
1889              {
1890                  $text .= 'size="'.$size.'" ';
1891              }
1892              if($checked != NULL && $checked)
1893              {
1894                  $text .= 'checked ';
1895              }
1896  
1897              return '<input'.$text.$string.'>';
1898          }
1899  
1900  		function html_form_option($value = NULL, $displayed = NULL, $selected = NULL, $return = 0)
1901          {
1902              $text = ' ';
1903              if($value != NULL && $value)
1904              {
1905                  $text .= ' value="'.$value.'" ';
1906              }
1907              if($selected != NULL && $selected)
1908              {
1909                  $text .= ' selected';
1910              }
1911              return  '<option'.$text.'>'.$displayed.'</option>';
1912          }
1913  
1914  		function encode_href($href = NULL, $args = NULL , $extra_args)
1915          {
1916              $href = $this->bo->string_encode($href, 1);
1917              $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1918  
1919              $address = $GLOBALS['egw']->link($href, $all_args);
1920  
1921              return $address;
1922          }
1923  
1924  		function html_link($href = NULL, $args = NULL , $extra_args, $text = NULL, $return = 1, $encode = 1, $linkonly = 0, $target = NULL)
1925          {
1926              //    unset($encode);
1927              if($encode)
1928              {
1929                  $href = $this->bo->string_encode($href, 1);
1930                  $all_args = $args.'&'.$this->bo->string_encode($extra_args, 1);
1931              }
1932              else
1933              {
1934                  //                $href = $this->bo->string_encode($href, 1);
1935                  $all_args = $args.'&'.$extra_args;
1936              }
1937              ###
1938              # This decodes / back to normal
1939              ###
1940              //            $all_args = preg_replace("/%2F/", "/", $all_args);
1941              //            $href = preg_replace("/%2F/", "/", $href);
1942  
1943              /* Auto-detect and don't disturb absolute links */
1944              if(!preg_match("|^http(.{0,1})://|", $href))
1945              {
1946                  //Only add an extra / if there isn't already one there
1947  
1948                  // die(SEP);
1949                  if(!($href[0] == SEP))
1950                  {
1951                      $href = SEP . $href;
1952                  }
1953  
1954                  /* $GLOBALS['egw']->link requires that the extra vars be passed separately */
1955                  //                $link_parts = explode("?", $href);
1956                  $address = $GLOBALS['egw']->link($href, $all_args);
1957                  //                $address = $GLOBALS['egw']->link($href);
1958              }
1959              else
1960              {
1961                  $address = $href;
1962              }
1963  
1964              /* If $linkonly is set, don't add any HTML */
1965              if($linkonly)
1966              {
1967                  $rstring = $address;
1968              }
1969              else
1970              {
1971                  if($target)
1972                  {
1973                      $target = 'target='.$target;
1974                  }
1975  
1976                  $text = trim($text);
1977                  $rstring = '<a href="'.$address.'" '.$target.'>'.$text.'</a>';
1978              }
1979  
1980              return($this->bo->eor($rstring, $return));
1981          }
1982  
1983  		function html_table_begin($width = NULL, $border = NULL, $cellspacing = NULL, $cellpadding = NULL, $rules = NULL, $string = '', $return = 0)
1984          {
1985              if($width != NULL && $width)
1986              {
1987                  $width = "width=$width";
1988              }
1989              if(is_int($border) && $border >= 0)
1990              {
1991                  $border = "border=$border";
1992              }
1993              if(is_int($cellspacing) && $cellspacing >= 0)
1994              {
1995                  $cellspacing = "cellspacing=$cellspacing";
1996              }
1997              if(is_int($cellpadding) && $cellpadding >= 0)
1998              {
1999                  $cellpadding = "cellpadding=$cellpadding";
2000              }
2001              if($rules != NULL && $rules)
2002              {
2003                  $rules = "rules=$rules";
2004              }
2005  
2006              $rstring = "<table $width $border $cellspacing $cellpadding $rules $string>";
2007              return($this->bo->eor($rstring, $return));
2008          }
2009  
2010  		function html_table_end($return = 0)
2011          {
2012              $rstring = "</table>";
2013              return($this->bo->eor($rstring, $return));
2014          }
2015  
2016  		function html_table_row_begin($align = NULL, $halign = NULL, $valign = NULL, $bgcolor = NULL, $string = '', $return = 0)
2017          {
2018              if($align != NULL && $align)
2019              {
2020                  $align = "align=$align";
2021              }
2022              if($halign != NULL && $halign)
2023              {
2024                  $halign = "halign=$halign";
2025              }
2026              if($valign != NULL && $valign)
2027              {
2028                  $valign = "valign=$valign";
2029              }
2030              if($bgcolor != NULL && $bgcolor)
2031              {
2032                  $bgcolor = "bgcolor=$bgcolor";
2033              }
2034              $rstring = "<tr $align $halign $valign $bgcolor $string>";
2035              return($this->bo->eor($rstring, $return));
2036          }
2037  
2038  		function html_table_row_end($return = 0)
2039          {
2040              $rstring = "</tr>";
2041              return($this->bo->eor($rstring, $return));
2042          }
2043  
2044  		function html_table_col_begin($align = NULL, $halign = NULL, $valign = NULL, $rowspan = NULL, $colspan = NULL, $string = '', $return = 0)
2045          {
2046              if($align != NULL && $align)
2047              {
2048                  $align = "align=$align";
2049              }
2050              if($halign != NULL && $halign)
2051              {
2052                  $halign = "halign=$halign";
2053              }
2054              if($valign != NULL && $valign)
2055              {
2056                  $valign = "valign=$valign";
2057              }
2058              if(is_int($rowspan) && $rowspan >= 0)
2059              {
2060                  $rowspan = "rowspan=$rowspan";
2061              }
2062              if(is_int($colspan) && $colspan >= 0)
2063              {
2064                  $colspan = "colspan=$colspan";
2065              }
2066  
2067              $rstring = "<td $align $halign $valign $rowspan $colspan $string>";
2068              return($this->bo->eor($rstring, $return));
2069          }
2070  
2071  		function html_table_col_end($return = 0)
2072          {
2073              $rstring = "</td>";
2074              return($this->bo->eor($rstring, $return));
2075          }
2076      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7