noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 02/04: Tache #0001875: Demande amélioration c


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 02/04: Tache #0001875: Demande amélioration calendrier Choix de commencer calendrier est une préférence utilisateur
Date: Sat, 16 Jan 2021 06:01:29 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 26bbcf61815d9e5ad544d7e0a542766ad748166b
Author: Dany De Bontridder <dany@alchimerys.be>
AuthorDate: Sat Jan 16 11:32:02 2021 +0100

    Tache #0001875: Demande amélioration calendrier
    Choix de commencer calendrier est une préférence utilisateur
---
 html/do.php                      |  3 ++
 include/ajax/ajax_preference.php | 29 +++++++++++++-
 include/class/user.class.php     | 70 ++++++++++++++++++++-------------
 include/lib/idate.class.php      | 83 +++++++++++++++++++++++++++++++++++++++-
 include/template/calendar.php    | 52 ++++++++++++++-----------
 5 files changed, 183 insertions(+), 54 deletions(-)

diff --git a/html/do.php b/html/do.php
index b91308f..47f180f 100644
--- a/html/do.php
+++ b/html/do.php
@@ -56,6 +56,9 @@ $cn = Dossier::connect();
 global $g_user, $cn,$g_parameter,$http;
 $g_user = new User($cn);
 $http=new HttpInput();
+if ( ! defined("FIRST_WEEK_DAY")) {
+    define ("FIRST_WEEK_DAY",$g_user->get_first_week_day());
+}
 /*
  * check that the database is not empty
  */
diff --git a/include/ajax/ajax_preference.php b/include/ajax/ajax_preference.php
index 3f7448b..95589e7 100644
--- a/include/ajax/ajax_preference.php
+++ b/include/ajax/ajax_preference.php
@@ -69,7 +69,7 @@ if ( $action == 'display_form' )
     echo HtmlInput::title_box(_('Préférence'), 'preference_div');
     echo '<DIV class="content">';
     echo '<p class="notice">';
-    echo _("Après validation, recharger si vous changez la langue");
+    echo _("Après validation, recharger pour appliquer les changements");
     echo '</p>';
     //----------------------------------------------------------------------
     //
@@ -145,6 +145,29 @@ if ( $action == 'display_form' )
                         
<?=$exercice->select("exercice_setting",$selected_exercice,$js)->input();?>
                     </td>
                 </tr>
+            <tr>
+                <td>
+                    <?=_("Premier jour semaine")?>
+                </td>
+                <td>
+                    <?php
+                        $aFirstDay=array(
+                            ["label"=>_("Lundi"),"value"=>1],
+                            ["label"=>_("Mardi"),"value"=>2],
+                            ["label"=>_("Mercredi"),"value"=>3],
+                            ["label"=>_("Jeudi"),"value"=>4],
+                            ["label"=>_("Vendredi"),"value"=>5],
+                            ["label"=>_("Samedi"),"value"=>6],
+                            ["label"=>_("Dimanche"),"value"=>0],
+                        );
+                        $selFirstDay=new ISelect("selFirstDay");
+                        $selFirstDay->value=$aFirstDay;
+                        $selFirstDay->selected=$g_user->get_first_week_day();
+                        echo $selFirstDay->input();
+                    ?>
+
+                </td>
+            </tr>
                <tr>
                     
                     <td><?php echo _('Période');?></td>
@@ -303,6 +326,7 @@ if ($action == 'save')
     $csv_fieldsep=$http->post("csv_fieldsep","number");
     $csv_decimal=$http->post("csv_decimal","number");
     $csv_encoding=$http->post("csv_encoding");
+    $firstday=$http->post("selFirstDay","number");
     
     if (strlen(trim($pass_1)) != 0 && strlen(trim($pass_2)) != 0)
     {
@@ -322,8 +346,9 @@ if ($action == 'save')
     $g_user->save_global_preference('csv_fieldsep', $csv_fieldsep);
     $g_user->save_global_preference('csv_decimal', $csv_decimal);
     $g_user->save_global_preference('csv_encoding', $csv_encoding);
+    $g_user->save_global_preference('first_week_day', $firstday);
     $g_user->save_email($p_email);
-    
+
     $_SESSION[SESSION_KEY.'g_theme']=$style_user;
     $_SESSION[SESSION_KEY.'g_pagesize']=$p_size;
     $_SESSION[SESSION_KEY.'g_lang']=$lang;
diff --git a/include/class/user.class.php b/include/class/user.class.php
index 3ad5bfe..0493b73 100644
--- a/include/class/user.class.php
+++ b/include/class/user.class.php
@@ -127,7 +127,7 @@ class User
                $this->login =strtolower($row['use_login']);
                $this->admin = $row['use_admin'];
                $this->password = $row['use_pass'];
-                $this->email=$row['use_email'];
+               $this->email=$row['use_email'];
        }
 
        function save()
@@ -555,16 +555,16 @@ class User
                        $type = $row['parameter_type'];
                        $l_array[$type] = $row['parameter_value'];
                }
-                $repo=new Database();
-                $a_global_pref=$repo->get_array("select 
parameter_type,parameter_value from user_global_pref 
-                                            where 
-                                            upper(user_id) = 
upper($1)",[$this->login]);
-                $nb_global=count($a_global_pref);
-                for ( $i = 0 ;$i< $nb_global ; $i++) {
-                    $idx=$a_global_pref[$i]['parameter_type'];
-                    $value=$a_global_pref[$i]['parameter_value'];
-                    $l_array[$idx]=$value;
-                }
+               $repo=new Database();
+               $a_global_pref=$repo->get_array("select 
parameter_type,parameter_value from user_global_pref 
+                                                                       where 
+                                                                       
upper(user_id) = upper($1)",[$this->login]);
+               $nb_global=count($a_global_pref);
+               for ( $i = 0 ;$i< $nb_global ; $i++) {
+                       $idx=$a_global_pref[$i]['parameter_type'];
+                       $value=$a_global_pref[$i]['parameter_value'];
+                       $l_array[$idx]=$value;
+               }
 
                return $l_array;
        }
@@ -663,7 +663,8 @@ class User
                     'g_lang' => 'LANG',
                     'csv_fieldsep'=>'csv_fieldsep',
                     'csv_decimal'=>'csv_decimal' ,
-                    'csv_encoding'=>'csv_encoding');
+                    'csv_encoding'=>'csv_encoding',
+                                       'first_week_day'=>'first_week_day');
                 
                foreach ($array_pref as $name => $parameter)
                {
@@ -690,29 +691,28 @@ class User
        {
 
                $default_parameter = array("THEME" => "classic",
-                       "PAGESIZE" => "50",
-                       'TOPMENU' => 'TEXT',
-                       'LANG' => 'fr_FR.utf8',
+                                               "PAGESIZE" => "50",
+                                               'TOPMENU' => 'TEXT',
+                                               'LANG' => 'fr_FR.utf8',
                         'csv_fieldsep'=>'0',
                         'csv_decimal'=>'0',
-                        'csv_encoding'=>'utf8'
+                        'csv_encoding'=>'utf8',
+                                               'first_week_day'=>1
                     );
                $cn = new Database();
-               $Sql = "insert into 
user_global_pref(user_id,parameter_type,parameter_value)
-             values ('%s','%s','%s')";
+               $sql = "insert into 
user_global_pref(user_id,parameter_type,parameter_value)
+             values ($1,$2,$3)";
                if ($p_type == "")
                {
                        foreach ($default_parameter as $name => $value)
                        {
-                               $Insert = sprintf($Sql, $this->login, $name, 
$value);
-                               $cn->exec_sql($Insert);
+                               
$cn->exec_sql($sql,array($this->login,$name,$value));
                        }
                }
                else
                {
                        $value = ($p_value == "") ? $default_parameter[$p_type] 
: $p_value;
-                       $Insert = sprintf($Sql, $this->login, $p_type, $value);
-                       $cn->exec_sql($Insert);
+                       $cn->exec_sql($sql,array($this->login,$p_type,$value));
                }
        }
 
@@ -727,12 +727,13 @@ class User
        function update_global_pref($p_type, $p_value = "")
        {
                $default_parameter = array("THEME" => "classic",
-                       "PAGESIZE" => "50",
-                       "LANG" => 'fr_FR.utf8',
-                       'TOPMENU' => 'SELECT',
+                                               "PAGESIZE" => "50",
+                                               "LANG" => 'fr_FR.utf8',
+                                               'TOPMENU' => 'SELECT',
                         'csv_fieldsep'=>'0',
                         'csv_decimal'=>'0',
-                        'csv_encoding'=>'utf8'
+                        'csv_encoding'=>'utf8',
+                                               'first_week_day'=>1
                     );
                $cn = new Database();
                $Sql = "update user_global_pref set parameter_value=$1
@@ -1479,6 +1480,21 @@ class User
             $this->db->exec_sql("update user_active_security set us_action=$1 
where us_login = $2",[$flag,$this->login]);
         }
     }
+
+       /**
+        *
+        */
+    function get_first_week_day()
+       {
+               $repocn=new Database();
+               $result=$repocn->get_value("select parameter_value from 
user_global_pref where parameter_type=$1 and user_id=$2 ",
+                               array("first_week_day",$this->login));
+               if ($repocn->count() == 0 ) {
+                       $this->save_global_preference("first_week_day",1);
+                       return 1;
+               }
+               return $result;
+       }
 }
 
-?>
+?>
\ No newline at end of file
diff --git a/include/lib/idate.class.php b/include/lib/idate.class.php
index 3deb069..805041b 100644
--- a/include/lib/idate.class.php
+++ b/include/lib/idate.class.php
@@ -37,6 +37,7 @@ class IDate extends HtmlInput
     var $placeholder;
     var $title;
     var $autofocus;
+    var $firstDate; //<! first day in the calendar : 0 for sunday
 
     function __construct($name='', $value='', $p_id="")
     {
@@ -46,7 +47,83 @@ class IDate extends HtmlInput
         $this->extra="";
         $this->style=' class="input_text" ';
         $this->autofocus=false;
+        $this->firstDate=(defined("FIRST_WEEK_DAY"))?FIRST_WEEK_DAY:0;
     }
+    /**
+     * @return string
+     */
+    public function get_placeholder()
+    {
+        return $this->placeholder;
+        return $this;
+    }
+
+    /**
+     * @param string $placeholder
+     */
+    public function set_placeholder($placeholder)
+    {
+        $this->placeholder = $placeholder;
+        return $this;
+    }
+
+    /**
+     * @return string
+     */
+    public function get_title()
+    {
+        return $this->title;
+        return $this;
+    }
+
+    /**
+     * @param string $title
+     */
+    public function set_title($title)
+    {
+        $this->title = $title;
+        return $this;
+    }
+
+    /**
+     * @return false
+     */
+    public function get_autofocus()
+    {
+        return $this->autofocus;
+        return $this;
+    }
+
+    /**
+     * @param false $autofocus
+     */
+    public function set_autofocus($autofocus)
+    {
+        $this->autofocus = $autofocus;
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function get_firstDate()
+    {
+        return $this->firstDate;
+        return $this;
+    }
+
+    /**
+     * @param mixed $firstDate
+     */
+    public function set_firstDate($firstDate)
+    {
+        if (isNumber($firstDate)==0){
+            throw new Exception("IDATE1: invalide data");
+        }
+        $this->firstDate = $firstDate;
+        return $this;
+    }
+
 
     /*!\brief show the html  input of the widget */
 
@@ -83,10 +160,12 @@ class IDate extends HtmlInput
             button         :    "%s_trigger",  
             align          :    "Bl",         
             singleClick    :    true,
-            firstDay:0 
+            firstDay:%s 
         });
             </script>'
-                ,$this->id,$this->id);
+                ,$this->id,
+                $this->id,
+                $this->firstDate);
         return $r;
     }
 
diff --git a/include/template/calendar.php b/include/template/calendar.php
index 7b921e6..88effb6 100644
--- a/include/template/calendar.php
+++ b/include/template/calendar.php
@@ -18,41 +18,47 @@
     <?php endif; ?>
 <tr>
 <?php
+$nFirstDay=$g_user->get_first_week_day();
+$nDay=$nFirstDay;
 for ($i=0;$i<=6;$i++){
        echo "<th>";
-       echo $week[$i];
+       $nDay=($nDay>6)?0:$nDay;
+       echo $week[$nDay];
+       $nDay++;
        echo "</th>";
 }
 ?>
 </tr>
 <?php
 $ind=1;
-$week=0;
+$week=$nFirstDay;
+$nCol=0;
 $today_month=date('m');
 $today_day=date('j');
 while ($ind <= $this->day) {
-if ( $week == 0 ) echo "<tr>";
-$class="workday";
-if ( $week == 0 || $week == 6) $class="weekend";
-// compute the date
-$timestamp_date=mktime(0,0,0,$this->month,$ind,$this->year);
-$date_calendar=date('w',$timestamp_date);
-$st="";
-if ( $today_month==$this->month && $today_day==$ind)
-  $st='  style="border:1px solid red" ';
-if ( $date_calendar == $week ) {
-       echo '<td class="'.$class.'" '.$st.'>'.'<span 
class="day">'.$ind."</span>";
-       echo $cell[$ind];
-       echo '</td>';
-       $ind++;$week++;
-} else {
-   echo "<td></td>";
-   $week++;
+    if ( $nCol == 0 ) echo "<tr>";
+    $class="workday";
+    if ( $week == 0 || $week == 6) $class="weekend";
+    // compute the date
+    $timestamp_date=mktime(0,0,0,$this->month,$ind,$this->year);
+    $date_calendar=date('w',$timestamp_date);
+    $st="";
+    if ( $today_month==$this->month && $today_day==$ind)
+      $st='  style="border:1px solid red" ';
+    if ( $date_calendar == $week ) {
+        echo '<td class="'.$class.'" '.$st.'>'.'<span 
class="day">'.$ind."</span>";
+        echo $cell[$ind];
+        echo '</td>';
+        $ind++;$week++;$nCol++;
+    } else {
+       echo "<td></td>";
+       $week++;$nCol++;
+    }
+    //if ( $ind > $this->day ) exit();
+    if ( $nCol == 7 ) { echo "</tr>";$nCol=0;}
+    if ( $week == 7 ) { $week=0;}
 }
-//if ( $ind > $this->day ) exit();
-if ( $week == 7 ) { echo "</tr>";$week=0;}
-}
-if ( $week != 0 ) { echo "</tr>";}
+if ( $nCol != 0 ) { echo "</tr>";}
 ?>
 
 </table>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]