forms
[ class tree: forms ] [ index: forms ] [ all elements ]

Source for file FileSelect.class.php

Documentation is available at FileSelect.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package    forms
  9.  * @subpackage items
  10.  */
  11. if !defined"CLASSPATH" ) )
  12. {
  13.    echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  14.    echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  15.    exit();
  16. }
  17.  
  18. /**
  19.  *
  20.  */
  21. require_onceCLASSPATH."filesystem/FilesystemToolkit.class.php" );
  22. /**
  23.  *
  24.  */
  25. require_onceCLASSPATH."forms/items/HTMLSelect.class.php" );
  26.  
  27. /**
  28.  * A class to generate select fields to choose a file on the filesystem.
  29.  *
  30.  * @package    forms
  31.  * @subpackage items
  32.  * @version    0.1.4
  33.  * @author     Daniel Plücken <daniel@debakel.net>
  34.  * @license    http://www.gnu.org/copyleft/lesser.html
  35.  *              GNU Lesser General Public License
  36.  * @copyright  Copyright (C) 2004 Daniel Plücken <daniel@debakel.net>
  37.  *
  38.  *  This library is free software; you can redistribute it and/or
  39.  *  modify it under the terms of the GNU Lesser General Public
  40.  *  License as published by the Free Software Foundation; either
  41.  *  version 2.1 of the License.
  42.  *
  43.  *  This library is distributed in the hope that it will be useful,
  44.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  45.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  46.  *  GNU Lesser General Public License for more details.
  47.  *
  48.  *  You should have received a copy of the GNU Lesser General
  49.  *  Public License along with this library; if not, write to the
  50.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  51.  *  Boston, MA 02111-1307 USA
  52.  */
  53. class FileSelect extends HTMLSelect
  54. {
  55.     /**
  56.      * @var    string  $dir 
  57.      * @access private
  58.      */
  59.     var $dir;
  60.     /**
  61.      * @var    integer $outputKind 
  62.      * @access private
  63.      */
  64.     var $outputKind;
  65.     
  66.     
  67.     
  68.     /**
  69.      * Constructor
  70.      *
  71.      * @version 1.4
  72.      * @since   0.1.0
  73.      * @author  Daniel Plücken <daniel@debakel.net>
  74.      * @access  public
  75.      * @uses
  76.      * @param   string  $name          Name of the select.
  77.      * @param   string  $dir           The directory to read.
  78.      * @param   string  $selectedFile  The selected file in the read directory.
  79.      * @param   string  $onChangeOrder The javascript order that should execute
  80.      *                                  if the value of the select changes.
  81.      * @param   integer $outputKind    The defined integer code to manipulate
  82.      *                                  the behaviour of the select, in the kind
  83.      *                                  that only files will be show, only
  84.      *                                  folder will be show or both, files
  85.      *                                  and folder, will be display. See the uses
  86.      *                                  part for more information.
  87.      */
  88.     function FileSelect(
  89.                          $name,
  90.                          $dir,
  91.                          $selectedFile  "",
  92.                          $onChangeOrder "",
  93.                          $outputKind    FILEORFOLDER
  94.                        )
  95.     {
  96.         $this->dir = $dir;
  97.         $this->SOKH$outputKind );
  98.  
  99.         if!is_dir$this->dir ) )
  100.         {
  101.           echo "<b>'".$this->dir."' is no directory.</b>\r\n";
  102.           // echo "You are here ".."\r\n";
  103.           
  104.         }
  105.         else
  106.         {
  107.           $this->selectedValue basename$selectedFile );
  108.           
  109.           $folder opendir$this->dir );
  110.           # Save folder and files each in separate arrays
  111.           while$file readdir$folder ) )
  112.           {
  113.             if(
  114.                 $file != "."
  115.              && $file != ".."
  116.               )
  117.             {
  118.                ifis_dir$this->dir.$file ) )
  119.                  $tempDirArr[]  $file;
  120.                else
  121.                  $tempFileArr[$file;
  122.             }
  123.           }
  124.           closedir$folder );
  125.  
  126.  
  127.           if(
  128.               $this->outputKind == FOLDER
  129.            || $this->outputKind == FILEORFOLDER
  130.             )
  131.           
  132.              ifcount$tempDirArr )
  133.                sort$tempDirArr );
  134.              
  135.              for$i 0$i count$tempDirArr )$i++ )
  136.                $valueAndLabelArr[$tempDirArr[$i];
  137.           }
  138.  
  139.           if
  140.               $this->outputKind == FILE
  141.            || $this->outputKind == FILEORFOLDER
  142.             )
  143.           {
  144.              ifcount$tempFileArr )
  145.                sort$tempFileArr );
  146.              
  147.              for$i 0$i count$tempFileArr )$i++ )
  148.                $valueAndLabelArr[$tempFileArr[$i];
  149.           }
  150.           
  151.           # Setup the select
  152.           $this->HTMLSelect(
  153.                               $name,
  154.                               $valueAndLabelArr,
  155.                               $valueAndLabelArr,
  156.                               $this->selectedValue,
  157.                               $onChangeOrder,
  158.                               true
  159.                             );
  160.         }
  161.     }
  162.  
  163.  
  164.  
  165.     /**
  166.      * Returns a clone of this object.
  167.      *
  168.      * @version 1.2
  169.      * @since   0.1.2
  170.      * @author  Daniel Plücken <daniel@debakel.net>
  171.      * @access  public
  172.      * @param   string $newName 
  173.      * @return  object 
  174.      */
  175.     function getClone(
  176.                        $newName,
  177.                        $selectedValue 
  178.                      )
  179.     {
  180.       $newInstance new FileSelect(
  181.                                       $newName,
  182.                                       $this->dir,
  183.                                       $selectedValue,
  184.                                       $this->onChangeOrder,
  185.                                       $this->outputKind
  186.                                    );
  187.       return $newInstance;
  188.     }
  189.  
  190.  
  191.  
  192.     /**
  193.      * Returns the directory which content should be display by this select.
  194.      *
  195.      * @version 1.4
  196.      * @since   0.1.0
  197.      * @author  Daniel Plücken <daniel@debakel.net>
  198.      * @access  public
  199.      * @return  string 
  200.      */
  201.     function getDir()
  202.     return $this->dir}
  203.  
  204.  
  205.  
  206.     /**
  207.      * Returns the value of the kind of output ( FILE, FOLDER, FILEORFOLDER ).
  208.      *
  209.      * @version 1.4
  210.      * @since   0.1.0
  211.      * @author  Daniel Plücken <daniel@debakel.net>
  212.      * @access  public
  213.      * @return  integer 
  214.      */
  215.     function getOutputKind()
  216.     return $this->outputKind}
  217.  
  218.  
  219.  
  220.     /**
  221.      * Sets the directory which content should be display by this select.
  222.      *
  223.      * @version 1.4
  224.      * @since   0.1.0
  225.      * @author  Daniel Plücken <daniel@debakel.net>
  226.      * @access  public
  227.      * @return  string 
  228.      */
  229.     function setDir$dir )
  230.     {
  231.        $this->dir = $dir;
  232.  
  233.        $this->refresh();
  234.     }
  235.  
  236.  
  237.  
  238.     /**
  239.      * Sets the value of the kind of output ( FILE, FOLDER, FILEORFOLDER ).
  240.      *
  241.      * @version 1.4
  242.      * @since   0.1.0
  243.      * @author  Daniel Plücken <daniel@debakel.net>
  244.      * @access  public
  245.      * @return  integer 
  246.      */
  247.     function setOutputKind$int )
  248.     {
  249.        $this->SOKH$int );
  250.  
  251.        $this->refresh();
  252.     }
  253.     
  254.     
  255.     /**
  256.      * This method is importantly only for private use of the class, otherwise
  257.      * there it can cause side effects, because the object attributes will not
  258.      * be refresh.
  259.      *
  260.      * @version 1.1
  261.      * @since   0.1.2
  262.      * @author  Daniel Plücken <daniel@debakel.net>
  263.      * @param   integer  $int 
  264.      * @access  private
  265.      * @return  void 
  266.      */
  267.     function SOKH$int )
  268.     {
  269.        if$int >= && $int <= 2  )
  270.          $this->outputKind = $int;
  271.        else
  272.          $this->outputKind = FILEORFOLDER;
  273.     }
  274.  
  275.  
  276.  
  277.     /**
  278.      * This method refreshes the new entries.
  279.      *
  280.      * @version 1.1
  281.      * @since   0.1.2
  282.      * @author  Daniel Plücken <daniel@debakel.net>
  283.      * @access  public
  284.      * @return  void 
  285.      */
  286.     function refresh()
  287.     {
  288.        $this->FileSelect(
  289.                            $this->name,
  290.                            $this->dir,
  291.                            $this->outputKind
  292.                         );
  293.     }
  294. // End of class FileSelect
  295. ?>

Documentation generated on Thu, 05 Jun 2008 19:11:29 +0200 by phpDocumentor 1.4.1