noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_iperiod.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief Html Input
00024  */
00025 /*! \brief          Generate the form for the periode
00026 * Data Members
00027  *   - $cn connexion to the current folder
00028  *   - $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL, IT MUST BE SET
00029  *   - $filter_year make a filter on the default exercice by default true
00030  *   - $user if a filter_year is required then we need who is the user (object User)
00031  *   - $show_end_date; $show_end_date is not set or false, do not show the end date  default = true
00032  *   - $show_start_date; $show_start_date is not set or false, do not show the start date  default=true
00033 */
00034 require_once('class_html_input.php');
00035 class IPeriod extends HtmlInput
00036 {
00037     var $type; /*!< $type the type of the periode OPEN CLOSE NOTCENTRALIZED or ALL */
00038     var $cn;  /*!< $cn is the database connection */
00039     var $show_end_date; /*!< $show_end_date is not set or false, do not show the end date */
00040     var $show_start_date; /*!< $show_start_date is not set or false, do not show the start date */
00041     var $filter_year; /*!< $filter_year make a filter on the default exercice by default yes */
00042     var $user;  /*! $user if a filter is required then we need who is the user (object User)*/
00043     function __construct($p_name="",$p_value="",$p_exercice='')
00044     {
00045         $this->name=$p_name;
00046         $this->readOnly=false;
00047         $this->size=20;
00048         $this->width=50;
00049         $this->heigh=20;
00050         $this->value=$p_value;
00051         $this->selected="";
00052         $this->table=0;
00053         $this->disabled=false;
00054         $this->javascript="";
00055         $this->extra2="all";
00056         $this->show_start_date=true;
00057         $this->show_end_date=true;
00058                 $this->exercice=$p_exercice;
00059     }
00060     /*!
00061      * \brief show the input html for a periode
00062      *\param $p_name is the name of the widget
00063      *\param $p_value is the default value
00064      *\param $p_exercice is the exercice, if not set then the user preference is used
00065      * \return string containing html code for the HTML
00066      *
00067      *
00068      */
00069     public function input($p_name=null,$p_value=null)
00070     {
00071         foreach (array('type','cn') as $a)
00072         {
00073             if ( ! isset ($this->$a) ) throw new Exception('Variable non définie [ '.$a.']');
00074         }
00075         $this->name=($p_name==null)?$this->name:$p_name;
00076         $this->value=($p_value==null)?$this->value:$p_value;
00077         if ( $this->readOnly==true) return $this->display();
00078 
00079         switch ($this->type)
00080         {
00081         case CLOSED:
00082             $sql_closed="where p_closed=true and p_central = false ";
00083             break;
00084         case OPEN:
00085             $sql_closed="where p_closed=false";
00086             break;
00087         case NOTCENTRALIZED:
00088             $sql_closed="where p_closed=true and p_central = false ";
00089             break;
00090         case ALL:
00091             $sql_closed="";
00092             break;
00093         default:
00094             throw new Exception("invalide p_type in ".__FILE__.':'.__LINE__);
00095         }
00096         $sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start_string,
00097              to_char(p_end,'DD.MM.YYYY') as p_end_string
00098              from parm_periode
00099              $sql_closed ";
00100 
00101         $cond="";
00102 
00103 
00104         /* Create a filter on the current exercice */
00105         if ( ! isset($this->filter_year) || (isset($this->filter_year) && $this->filter_year==true))
00106         {
00107           if ( $this->exercice=='')
00108             {
00109               if (! isset($this->user) ) throw new Exception (__FILE__.':'.__LINE__.' user is not set');
00110               $this->exercice=$this->user->get_exercice();
00111             }
00112 
00113             $cond='';
00114             if ( $sql_closed=="") $and=" where " ; else $and=" and ";
00115             if ($this->type == 'all' ) $cond=$and.'   true ';
00116             $cond.=" $and p_exercice='".sql_string($this->exercice)."'";
00117         }
00118 
00119         $sql.=$cond."  order by p_start,p_end";
00120 
00121         $Res=$this->cn->exec_sql($sql);
00122         $Max=$this->cn->size($Res);
00123         if ( $Max == 0 )  throw new Exception(_('Aucune periode trouvée'),1);
00124         $ret='<SELECT NAME="'.$this->name.'" '.$this->javascript.'>';
00125         for ( $i = 0; $i < $Max;$i++)
00126         {
00127             $l_line=$this->cn->fetch($i);
00128             if ( $this->value==$l_line['p_id'] )
00129                 $sel="SELECTED";
00130             else
00131                 $sel="";
00132 
00133             if ( $this->show_start_date == true && $this->show_end_date==true )
00134             {
00135                 $ret.=sprintf('<OPTION VALUE="%s" %s>%s - %s',$l_line['p_id']
00136                               ,$sel
00137                               ,$l_line['p_start_string']
00138                               ,$l_line['p_end_string']);
00139             }
00140             else if ($this->show_start_date == true )
00141             {
00142                 $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
00143                               ,$sel
00144                               ,$l_line['p_start_string']
00145                              );
00146             }
00147             else if ( $this->show_end_date == true )
00148             {
00149                 $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
00150                               ,$sel
00151                               ,$l_line['p_end_string']
00152                              );
00153             }
00154 
00155         }
00156         $ret.="</SELECT>";
00157         return $ret;
00158 
00159 
00160     }
00161     /*!\brief print in html the readonly value of the widget*/
00162     public function display()
00163     {
00164         $r="not implemented ".__FILE__.":".__LINE__;
00165         return $r;
00166 
00167     }
00168     static public function test_me()
00169     {
00170     }
00171 }
 All Data Structures Namespaces Files Functions Variables Enumerations