noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_calendar.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 Display the calendar
00024  */
00025 class Calendar
00026 {
00027     var $current_date;
00028     private static $nb_day=array(31,28,31,30,31,30,31,31,30,31,30,31);
00029 
00030     function __construct()
00031     {
00032         /* get the current month */
00033         $this->current_date=getdate();
00034         $this->month=$this->current_date['mon'];
00035         $this->day=self::$nb_day[$this->month-1];
00036         $this->year=$this->current_date['year'];
00037                 $this->action_div=array();
00038                 $this->action=array();
00039                 $this->title=array();
00040 
00041         if ( $this->year % 4 == 0 && $this->month=2)
00042             $this->day=29;
00043     }
00044 
00045     /*!\brief fill the array given as parameter with the data from action_gestion
00046      *\param $p_array array of the date of the month
00047      * \param $p_style is either short or long, short: for a small title, long for a complete one
00048      */
00049     function fill_from_action(&$p_array,$p_style)
00050     {
00051                 global $g_user;
00052                 $profile=$g_user->get_profile();
00053 
00054         $cn=new Database(dossier::id());
00055         $sql="select ag_id,to_char(ag_remind_date,'DD')::integer as ag_timestamp_day,ag_title,ag_hour,
00056              coalesce(name,'interne') as str_name
00057                         ".
00058              " from action_gestion ".
00059              "  left join vw_fiche_name  on (f_id=f_id_dest) ".
00060              " where ".
00061              " to_char(ag_remind_date,'MM')::integer=$1 ".
00062              " and to_char(ag_remind_date,'YYYY')::integer=$2 ".
00063              "  and ag_dest in (select p_granted from user_sec_action_profile where p_id =$3)
00064                                  and ag_state IN (2, 3)
00065                                 ";
00066 
00067                 $array=$cn->get_array($sql,array($this->month,$this->year,$profile));
00068         for ($i=0;$i<count($array);$i++)
00069         {
00070             $ind=$array[$i]['ag_timestamp_day'];
00071             $this->action[$ind][]=$array[$i]['ag_id'];
00072             $this->title[$ind][]=$array[$i]['ag_title'];
00073             $this->hour[$ind][]=$array[$i]['ag_hour'];
00074             $this->str_name[$ind][]=$array[$i]['str_name'];
00075 
00076         }
00077                 /*
00078                  * Fill foreach day
00079                  */
00080         if ( $p_style == "short")
00081         {
00082                 foreach ($this->action as $day=>$aAction)
00083                 {
00084                         if ($p_array[$day]=="")  {
00085                                 $p_array[$day]='<span class="input_text" onclick="display_task(\'tsk'.$day.'\');">'." ".count($aAction)." "._("Tâches").'</span>';
00086                         }
00087                         $this->action_div[$day]='<div id="tsk'.$day.'" class="inner_box" style="width:200;display:none">';
00088                         $this->action_div[$day].=HtmlInput::title_box($day."/".$this->month."/".$this->year, "tsk".$day, "hide");
00089                          $this->action_div[$day].="<ol>";
00090                         for ($i=0;$i<count($aAction);$i++)
00091                         {
00092                                 $this->action_div[$day].='<li>'.HtmlInput::detail_action($aAction[$i], $this->title[$day][$i]).'</li>';
00093                         }
00094                         $this->action_div[$day].='</ol></div>';
00095                 }
00096         }
00097         else if ( $p_style == "long")
00098         {
00099                 foreach ($this->action as $day=>$aAction)
00100                 {
00101                         $p_array[$day].="<ol>";
00102                         for ($i=0;$i<count($aAction);$i++)
00103                         {
00104                                 $p_array[$day].='<li>'.hb($this->str_name[$day][$i]).'&rarr;'.HtmlInput::detail_action($aAction[$i], $this->hour[$day][$i]." ".$this->title[$day][$i]).'</li>';
00105                         }
00106                         $p_array[$day].='</ol>';
00107                 }
00108         }
00109     }
00110     /*!\brief fill the array given as parameter with the data from todo
00111      *\param $p_array array of the date of the month
00112      * \param $p_style is either short or long, short: for a small title, long for a complete one
00113      */
00114     function fill_from_todo(&$p_array,$p_style)
00115     {
00116         $cn=new Database(dossier::id());
00117         if ($p_style=="short")
00118         {
00119             $sql="select count(*) as nb,to_char(tl_date,'DD')::integer as tl_date_day ".
00120                  " from todo_list ".
00121                  " where ".
00122                  " to_char(tl_date,'MM')::integer=$1 ".
00123                  " and to_char(tl_date,'YYYY')::integer=$2 ".
00124                  " and use_login=$3 group by to_char(tl_date,'DD')::integer ";
00125             $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
00126             for ($i=0;$i<count($array);$i++)
00127             {
00128                 $ind=$array[$i]['tl_date_day'];
00129                 $p_array[$ind].="<span style=\"display:block\" class=\"todo\">".h($array[$i]['nb'])." "._('Notes').'</span>';
00130             }
00131         } else if ($p_style=="long")
00132         {
00133             $sql="select to_char(tl_date,'DD')::integer as tl_date_day,tl_title ".
00134                  " from todo_list ".
00135                  " where ".
00136                  " to_char(tl_date,'MM')::integer=$1 ".
00137                  " and to_char(tl_date,'YYYY')::integer=$2 ".
00138                  " and use_login=$3  ";
00139             $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
00140             for ($i=0;$i<count($array);$i++)
00141             {
00142                 $ind=$array[$i]['tl_date_day'];
00143                 
00144                $p_array[$ind].="<span style=\"display:block\" class=\"todo\">".h($array[$i]['tl_title']).'</span>';
00145             }
00146         }
00147     }
00148     /*!\brief display a calendar after a call to Calendar::fill
00149      *\param $p_type long or short
00150      * 
00151      *\return HTML String
00152      */
00153     function display($p_type)
00154     {
00155         global $g_user;
00156         if  ($p_type != 'long' && $p_type != 'short') {
00157             throw new Exception("Calendar::display, unknow type");
00158         }
00159         $exercice_user=$g_user->get_exercice();
00160         /* day */
00161         $cell=array();
00162         for ($i=0;$i<42;$i++)
00163         {
00164             $cell[$i]="";
00165         }
00166         $this->set_month_year();
00167         /* weekday */
00168         $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
00169 
00170         $this->fill_from_action($cell,$p_type);
00171         $this->fill_from_todo($cell,$p_type);
00172         $wMonth=new ISelect('per');
00173         $cn=new Database(dossier::id());
00174         $wMonth->value=$cn->make_array("select p_id,to_char(p_start,'MM/YYYY') from parm_periode where p_exercice = '$exercice_user' order by p_start");
00175         $wMonth->selected=$this->default_periode;
00176         $wMonth->javascript="onchange=change_month(this)";
00177         $wMonth->set_attribute('gDossier',dossier::id());
00178         $wMonth->set_attribute('type_display',$p_type);
00179         $month_year=$wMonth->input().$wMonth->get_js_attr();
00180         ob_start();
00181         $zoom=($p_type=='short')?0:1;
00182         require_once('template/calendar.php');
00183 
00184                 if (count($this->action_div) > 0)
00185                 {
00186                         foreach ($this->action_div as $day)
00187                         {
00188                                 echo $day;
00189                         }
00190                 }
00191                 $ret=ob_get_contents();
00192         ob_end_clean();
00193         return $ret;
00194     }
00195     /**
00196      *@brief set correctly the month and the year with the default_periode
00197      */
00198     function set_month_year()
00199     {
00200         $cn=new Database(dossier::id());
00201         $array=$cn->get_array("select to_char(p_start,'MM') as month, to_char(p_start,'YYYY') as year ".
00202                               " from parm_periode where p_id=$1",array($this->default_periode));
00203         $this->month=(int)$array[0]['month'];
00204         $this->year=(int)$array[0]['year'];
00205         $this->day=self::$nb_day[$this->month-1];
00206         if ( $this->year % 4 == 0 && $this->month==2)
00207             $this->day=29;
00208     }
00209     /**
00210      *@brief get the periode from the preference of the current user
00211      * change the value of default_periode to today
00212      *@return $this->default_periode
00213      */
00214     function get_preference()
00215     {
00216         global $g_user;
00217         $cn=new Database(dossier::id());
00218         $today=date('d.m.Y');
00219         $p_id=$cn->get_value("
00220                 select p_id from parm_periode
00221                 where
00222                 p_start <= to_date($1,'DD.MM.YYYY')
00223                 and
00224                 p_end >= to_date($1,'DD.MM.YYYY')",
00225                 array($today));
00226         if ( $p_id == '')
00227         {
00228             $p_id=$g_user->get_periode();
00229         }
00230                 $this->default_periode=$p_id;
00231         return  $p_id;
00232     }
00233     /**
00234      *@brief set the periode to the parameter, change the value of $this->default_periode
00235      * there is no check on the periode
00236      */
00237     function set_periode($p_per)
00238     {
00239         $this->default_periode=$p_per;
00240     }
00241     /**
00242      * @brief zoom the calendar
00243      */
00244     function zoom()
00245     {
00246         global $g_user;
00247         $exercice_user=$g_user->get_exercice();
00248         /* day */
00249         $cell=array();
00250         for ($i=0;$i<42;$i++)
00251         {
00252             $cell[$i]="";
00253         }
00254         $this->set_month_year();
00255         /* weekday */
00256         $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
00257 
00258         $this->fill_from_action($cell,"long");
00259         $this->fill_from_todo($cell,"long");
00260         $wMonth=new ISelect('per_div');
00261         $cn=new Database(dossier::id());
00262         $wMonth->value=$cn->make_array("select p_id,to_char(p_start,'MM/YYYY') from parm_periode where p_exercice = '$exercice_user' order by p_start");
00263         $wMonth->selected=$this->default_periode;
00264         $wMonth->javascript=sprintf("onchange=calendar_zoom({gDossier:%d,invalue:'%s',outvalue:'%s'})",
00265             dossier::id(),'per_div','calendar_zoom_div');
00266         $wMonth->set_attribute('gDossier',dossier::id());
00267         $month_year=$wMonth->input().$wMonth->get_js_attr();
00268         $zoom=1;
00269         ob_start();
00270         require_once('template/calendar.php');
00271 
00272         if (count($this->action_div) > 0)
00273         {
00274                 foreach ($this->action_div as $day)
00275                 {
00276                         echo $day;
00277                 }
00278         }
00279         $ret=ob_get_contents();
00280         ob_end_clean();
00281         return $ret;
00282     }
00283     static function test_me() {
00284         
00285     }
00286 
00287 }
 All Data Structures Namespaces Files Functions Variables Enumerations