Location: PHPKode > projects > MyPhpMoney > myphpmoney_2.0/public_html/calendar.php
<?php
/**
 * $Id: calendar.php 420 2007-05-24 18:32:09Z hpfn $
 *
 * Author     : courou&#64;users.sourceforge.net
 * Website    : http://allreponse.ath.cx
 *
 * Support    : http://sourceforge.net/projects/myphpmoney/
 * CVS        : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/myphpmoney/
 */

/**
 * INCLUDE FILE
 */
     require_once 'config/settings.inc.php';

/**
 * ENTER IN THE SESSION OR BUILD THE LOGIN FORM
 */
     if (SQL_VerifSession()) {

/**
 * BUILD THE HEADER
 */
     XHTML_header(1,0,1,1,1,1,1,1);

/**
 * DEFINE VARIABLE GLOBALS
 */
      $PageOrder1    = 'caldisp';
      $PageOrder2    = 'calview';
      $cat           = array();
      $tiers         = array();
      $periodicity   = array();
      $third_part    = array();
      $id_acct       = array();
      $valid_op      = array();
      $acct          = array();
      $account       = array();
      $check         = array();
      $cont          = array();
      $_MPM['dates'] = array();
      $list_filter   = array(); ## for verif mode
      $amount1       = array(); ## euros
      $amount2       = array(); ## another money
      $list_op       = array(); ## expire date operation
      $check_img     = array(); ## image checked
      $TAVANT        = '';      ## euros
      $TBIS          = '';      ## another money
      $affecters     = '';      ## for + or -
      $paie          = '';      ## for depense or recette (modif)
      $_paie         = '';      ## for depense or recette (display)
      $_MPM['BlockInclude'] =0; ## for the include template
      $_MPM['BlockInclude2']=0; ## for the include template

/**
 * DEBUG MODE : ALERT FOR THE SOME DAYS BACK
 */
    $list_op = SQL_SearchListOp(__DAYS_BACK__);

    if (isset($list_op)
          && sizeof($list_op) >= 1 && !isset($sess_nb)) {

      XHTML_DisplayJs(sizeof($list_op) == 1
         ## SINGULIER
         ? sprintf($_VAR['MESSAGE_JS']['JS_CALEND_ALERT_1'],sizeof($list_op),__DAYS_BACK__,$_MPM['name'])
         ## PLURIEL
         : sprintf($_VAR['MESSAGE_JS']['JS_CALEND_ALERT_2'],sizeof($list_op),__DAYS_BACK__,$_MPM['name'])
      );
    $sess_nb = 1;
    $sess->register('sess_nb');
    } ## end of if (sizeof($list_op) >= 1)

/**
 * FOR XHTML (CLOSE FORM)
 * 'form_calendar_display_s.tpl','form_calendar_display_d.tpl'
 * 'form_calendar_view_s.tpl','form_calendar_view_d.tpl'
 */
    if (isset($_GET['NewsChoice']) && $_GET['NewsChoice'] == 'YES')

    $_POST['Choice'] = $_VAR['MESS_CALENDAR_NEW'];

    $tpl->set_var(array(
            'CONDITION_FERMER_1' => isset($_POST['Choice'])
                                   && ($_POST['Choice'] == $_VAR['MESS_CALENDAR_NEW'])
                                   || (isset($_POST['Choice'])
                                   && $_POST['Choice'] == $_VAR['MODIF'])
                                        ? '</form>' : '',
            'CONDITION_FERMER_2' => isset($_POST['Choice'])
                                   && ($_POST['Choice'] == $_VAR['MESS_CALENDAR_NEW'])
                                   || (isset($_POST['Choice'])
                                   && $_POST['Choice'] == $_VAR['MODIF'])
                                        ? '' : '</form>'
   ));

/**
 * CHECK THE CASE FOR ACTIVE THE SELECTED IN THE CHECKBOX VALUE
 */
 if (isset($_POST['Choice']) && $_POST['Choice'] == $_VAR['MESS_CALENDAR_NEW']) {
   unset($_POST['IDCOMPTE']);
 }
     if (isset($_POST['IDCOMPTE']) && is_array($_POST['IDCOMPTE'])) {
          while(list($name,$value)=each($_POST['IDCOMPTE'])) {
             $prevel         = explode('|',$value);
             $needs          = $prevel[1];
             $account[]     .= SQL_Clean($prevel[0]);   ## LIST OF DIFFERENT ACCOUNT
             $check[$needs]  = $needs;       ## NECESSARY FOR MODE COLOR
          }
     }

  if (isset($account) && is_array($account)) {
     ## List unique (no doublon)
     $new_array         = array_unique($account);
     $liste             = "'".join($new_array,"','")."'";

     ## list of corel
     $id_corel          = SQL_SearchAllCorel($liste);

     ## list unique + list corel
     $liste_cumul       = array_merge($new_array,$id_corel);
     $liste_supp        = "'".join($liste_cumul,"','")."'";

     ## FOR MODIFIED
     if (sizeof($new_array) >= 2 && isset($_POST['Choice']) && $_POST['Choice'] == $_VAR['MODIF']) {
       XHTML_DisplayJs($_VAR['MESSAGE_JS']['JS_CALENDAR_MODIF']);
        unset($check); unset($check_img);
     $_POST['Choice'] = '';
     } else if (isset($_POST['Choice']) && $_POST['Choice'] == $_VAR['MODIF']) {
        $_POST['CONTINUE_YES']  = 'YES';
     }
   } ## end of if (is_array($account))


/**
 * SWITCH -- ACTION FOR THE NEWS CALENDAR
 */
   $_N_ID     = SQL_RecupId(1);
   $id_cat    = SQL_RecupId(0);
   $id_tiers  = SQL_RecupId(4);

   if (isset($_POST['S_cat']) && $_POST['S_cat'] != '') {
     $explode_cat    = explode('|', $_POST['S_cat']);
     $_POST['cat']   = SQL_Clean($explode_cat[0]);
     $_POST['tiers'] = SQL_Clean($explode_cat[1]);
   }
   
   if (isset($_POST['S_compte'])) {
   	$_POST['S_compte'] = SQL_Clean($_POST['S_compte']);
   	$ID_TIERS = SQL_SearchInThird(0,$_POST['S_compte']);
   } else {
   	$ID_TIERS = '';
   }
   
   if ( isset($_POST['S_date']) ) {
   	$_POST['S_date'] = SQL_Clean($_POST['S_date']);
	$_DATE = preg_replace('/^([0-9]{1,2})-([0-9]{1,2})-([0-9]{2,4})$/', '\3-\2-\1', $_POST['S_date']);
   } else {
   	$_DATE = '';
   }
   $ID_COREL = isset($_POST['tiers']) ? SQL_SearchInThird(1,$_POST['tiers']) : '';


if (!isset($_POST['Action'])) $_POST['Action'] = '';
switch($_POST['Action']) {

      ## UPDATE THE IMAGE YES OR NOT
      default :

          if (isset($_POST['VALID_IMG']) && is_array($_POST['VALID_IMG'])) {
              while(list($kobj,$vobj) = each($_POST['VALID_IMG'])) {
               $hid = explode('|',$kobj);

               ## NECESSARY FOR MODE COLOR
               $need = $hid[1];
               $check_img[$need] = $need;
	       $hid[0] = SQL_Clean($hid[0]);
                       $IdAcct = SQL_SearchIdCorel(2,$hid[0]);
                       if ($hid[1] == 0) {
                          if ($IdAcct > 1) { SQL_UpdateAccount(0,'',1,'',2,$IdAcct); }
                       SQL_UpdateAccount(0,'',1,'',2,$hid[0]);
                       } else if ($hid[1] == 1) {
                          if ($IdAcct > 1) { SQL_UpdateAccount(0,'',0,'',2,$IdAcct); }
                        SQL_UpdateAccount(0,'',0,'',2,$hid[0]);
                       } ## end of $hid[1]

                 } ## end of while
           } ## end of is_array()

     break;

     ## DELETED THE OPERATION
     case $_VAR['LANG_BOOK_5'] :
        if ($liste_supp != '') {
          SQL_DeleteAccount(2,$liste_supp,'',2);
        } else {
          XHTML_DisplayJs($_VAR['MESSAGE_JS']['JS_CALEND_NO_ACT']);
        }
     unset($check);unset($check_img);
     break;

     ## ADD THE SELECTED IN THE CURRENT ACCOUNT
     case $_VAR['MESS_CALENDAR_SAISIE'] :

     $compte_value = array_count_values($account);
     while (list($_ids,$_qtes) = each($compte_value)) {

        $_id_corel      = SQL_SearchIdCorel(2,$_ids);
        $_periodicite   = SQL_SearchPeriod($_ids);

     if ($_id_corel == 0) {

            ## NOT CORRELATION
            for ($i=1; $i <= $_qtes; $i++) {
              $The_Compte = SQL_Search_AcctCorel(2,$_ids,0);
              $id_comptes = SQL_RecupId(1);

       $requete  = "SELECT VALID_OP, NUMID, DATES, CAT, THIRD, COREL, ";
       $requete .= "COMMENTS, SOUTT, IMP, ACCOUNT, BALANCE FROM ";
       $requete .= "".$_MPM['table'][1]." WHERE TEMPID=2 AND ";
       $requete .= "OPID='$_ids' AND USERID='$sess_pid'";
       $db->query($requete);

        while ($db->next_record()) {
                $VALIDE         = $db->f('VALID_OP');
                $NUMEROID       = $db->f('NUMID');
                $DATES          = $db->f('DATES');
                $CATEGORIE      = $db->f('CAT');
                $TIERS          = $db->f('THIRD');
                $COREL          = $db->f('COREL');
                $COMMENTAIRES   = $db->f('COMMENTS');
                $DEPENSE        = $db->f('SOUTT');
                $RECETTE        = $db->f('IMP');
                $COMPTES        = $db->f('ACCOUNT');
                $SOLDES         = $db->f('BALANCE');
        }

               SQL_InsertAccount
               (
                         $id_comptes,
                         $NUMEROID,
                         1,
                         $VALIDE,
                         $DATES,
                         $CATEGORIE,
                         $TIERS,
                         0,
                         $COMMENTAIRES,
                         $DEPENSE,
                         $RECETTE,
                         $COMPTES,
                         0,
                         0
               );

                if ($_periodicite == 1) $month = 1;
                if ($_periodicite == 2) $month = 3;
                if ($_periodicite == 3) $month = 6;
                if ($_periodicite == 4) $month = 0;
                if ($_periodicite == 5) $month = 2;
                if ($_periodicite == 6) $month = 12;

                if ($month != 0) {

                    SQL_UpdateAccount(5,'',$month,'',2,$_ids);
                    SQL_RecupSolde($The_Compte);

                } else {

                    SQL_DeleteAccount(2,$_ids,'',0);
                    SQL_RecupSolde($The_Compte);

                } ## end of if ($month != 0)
            } ## end of for ($i=1; $i <= $_qtes; $i++)


            } else {

            ## CORRELATION EXIST
            for ($i=1; $i <= $_qtes; $i++) {
               $requete  = "SELECT VALID_OP, NUMID, DATES, CAT, THIRD, COREL, COMMENTS, SOUTT, ";
               $requete .= "IMP, ACCOUNT, BALANCE FROM ".$_MPM['table'][1]." WHERE TEMPID=2 AND ";
               $requete .= "OPID='$_ids' AND USERID='$sess_pid'";
               $db->query($requete);

                while ($db->next_record()) {
                        $VALIDE         = $db->f('VALID_OP');
                        $NUMEROID       = $db->f('NUMID');
                        $DATES          = $db->f('DATES');
                        $CATEGORIE      = $db->f('CAT');
                        $TIERS          = $db->f('THIRD');
                        $COREL          = $db->f('COREL');
                        $COMMENTAIRES   = $db->f('COMMENTS');
                        $DEPENSE        = $db->f('SOUTT');
                        $RECETTE        = $db->f('IMP');
                        $COMPTES        = $db->f('ACCOUNT');
                        $SOLDES         = $db->f('BALANCE');
                }

                $id_comptes = SQL_RecupId(1);
                $id_cores   = bcadd($id_comptes,1);
                $The_Compte = SQL_Search_AcctCorel(2,$_id_corel,0);
                $ID_TIERS   = SQL_SearchInThird(0,$COMPTES);

                 SQL_InsertAccount
                 (
                           $id_comptes,
                           $NUMEROID,
                           1,
                           $VALIDE,
                           $DATES,
                           $CATEGORIE,
                           $TIERS,
                           $id_cores,
                           $COMMENTAIRES,
                           $DEPENSE,
                           $RECETTE,
                           $COMPTES,
                           0,
                           0
                 );
                 SQL_RecupSolde($COMPTES);

                 SQL_InsertAccount
                 (
                           $id_cores,
                           $NUMEROID,
                           1,
                           $VALIDE,
                           $DATES,
                           $CATEGORIE,
                           $ID_TIERS,
                           $id_comptes,
                           $COMMENTAIRES,
                           $RECETTE,
                           $DEPENSE,
                           $The_Compte,
                           0,
                           0
                 );
                 SQL_RecupSolde($The_Compte);

                if ($_periodicite == 1) $month = 1;
                if ($_periodicite == 2) $month = 3;
                if ($_periodicite == 3) $month = 6;
                if ($_periodicite == 4) $month = 0;
                if ($_periodicite == 5) $month = 2;
                if ($_periodicite == 6) $month = 12;

                  if ($month != 0) {
                    SQL_UpdateAccount(5,'',$month,'',2,$_ids);
                    SQL_UpdateAccount(5,'',$month,'',2,$_id_corel);
                  } else {
                    SQL_DeleteAccount(2,$_ids,'',0);
                    SQL_DeleteAccount(2,$_id_corel,'',0);
                  } ## end of if ($month != 0)

             } ## end of for ($i=1; $i <= $_qtes; $i++)
         } ## end of if ($_id_corel == 0)
      } ## end of while (list($_ids,$_qtes)
     break;

     ## ADD A NEWS OPERATION
     case 'ADD' :
     if (($_POST['S_compte'] && $_POST['S_date'] && $_POST['S_cat'] && $_POST['paie'] && $_POST['S_affecter']) != '') {
     	  $_POST['paie'] = SQL_Clean($_POST['paie']);
	  if ($_POST['S_affecter'] == 1) { $_RECETTE = 0; $_DEPENSE = $_POST['paie']; }
          if ($_POST['S_affecter'] == 2) { $_DEPENSE = 0; $_RECETTE = $_POST['paie']; }
          if ($_POST['cat'] == __PART_ID__) $_COREL = bcadd($_N_ID,1); else $_COREL = 0;

	$_POST['R'] = SQL_Clean($_POST['R']);
        $_POST['numero_id'] = SQL_Clean($_POST['numero_id']);
        $_POST['S_commentaires'] = SQL_Clean($_POST['S_commentaires']);
        $_POST['S_periode'] = SQL_Clean($_POST['S_periode']);
	$_POST['news_cat'] = SQL_Clean($_POST['news_cat']);
	$_POST['news_tiers'] = SQL_Clean($_POST['news_tiers']);
	

          ## NEWS ENTRY FOR THE THIRD AND PART
          if ($_POST['cat'] == __ANOTHER_ACCOUNT__) {
              if (($_POST['news_cat'] && $_POST['news_tiers']) != '') {

                              $result = SQL_VerifPostAcct
                                        (
                                             2,
                                             bcsub($_N_ID,1),
                                             0,
                                             $_POST['R'],
                                             $_POST['numero_id'],
                                             $_DATE,
                                             bcsub($id_cat,1),
                                             bcsub($id_tiers,1),
                                             $_POST['S_commentaires'],
                                             $_DEPENSE,
                                             $_RECETTE,
                                             $_POST['S_compte'],
                                             $_POST['S_periode'],
                                             0
                                        );

                 if (!$result) {
                       $id_cat    = SQL_BuildCat($_POST['news_cat'],$id_cat);
                       $id_tiers  = SQL_BuildTiers($_POST['news_tiers'],$id_cat,$id_tiers);
                       if (isset($id_cat) && $id_cat != __PART_ID__) {

                             SQL_InsertAccount
                             (
                                       $_N_ID,
                                       $_POST['numero_id'],
                                       2,
                                       $_POST['R'],
                                       $_DATE,
                                       $id_cat,
                                       $id_tiers,
                                       $_COREL,
                                       $_POST['S_commentaires'],
                                       $_DEPENSE,
                                       $_RECETTE,
                                       $_POST['S_compte'],
                                       0,
                                       $_POST['S_periode']
                             );

                       }
                   } ## end of !result

               } ## end of $_POST['news_cat'] && $_POST['news_tiers'] != ''
          } ## end of  of $_POST['cat'] == __ANOTHER_ACCOUNT__

          ## NEWS ENTRY FOR THE THIRD ONLY
          else if ($_POST['tiers'] == __ANOTHER_ACCOUNT__) {

                              $result = SQL_VerifPostAcct
                                        (
                                             2,
                                             bcsub($_N_ID,1),
                                             0,
                                             $_POST['R'],
                                             $_POST['numero_id'],
                                             $_DATE,
                                             $_POST['cat'],
                                             bcsub($id_tiers,1),
                                             $_POST['S_commentaires'],
                                             $_DEPENSE,
                                             $_RECETTE,
                                             $_POST['S_compte'],
                                             $_POST['S_periode'],
                                             0
                                        );

              if (!$result) {
                 $id_tiers = SQL_BuildTiers($_POST['news_tiers'],$_POST['cat'],$id_tiers);

                   SQL_InsertAccount
                   (
                             $_N_ID,
                             $_POST['numero_id'],
                             2,
                             $_POST['R'],
                             $_DATE,
                             $_POST['cat'],
                             $id_tiers,
                             $_COREL,
                             $_POST['S_commentaires'],
                             $_DEPENSE,
                             $_RECETTE,
                             $_POST['S_compte'],
                             0,
                             $_POST['S_periode']
                   );

               } ## end of $result

          } ## end of  of $_POST['tiers'] == __ANOTHER_ACCOUNT__

          ## NO NEWS ENTRY FOR THIRD AND PART
          else if ($_POST['cat'] != __ANOTHER_ACCOUNT__ && $_POST['tiers'] != __ANOTHER_ACCOUNT__) {
               if ($_POST['cat'] == __PART_ID__) {


                $result = SQL_VerifPostAcct
                          (
                                   2,
                                   $_N_ID,
                                   $_COREL,
                                   $_POST['R'],
                                   $_POST['numero_id'],
                                   $_DATE,
                                   $_POST['cat'],
                                   $_POST['tiers'],
                                   $_POST['S_commentaires'],
                                   $_DEPENSE,
                                   $_RECETTE,
                                   $_POST['S_compte'],
                                   $_POST['S_periode'],
                                   1
                            );

               } else {


                $result = SQL_VerifPostAcct
                          (
                               2,
                               bcsub($_N_ID,1),
                               0,
                               $_POST['R'],
                               $_POST['numero_id'],
                               $_DATE,
                               $_POST['cat'],
                               $_POST['tiers'],
                               $_POST['S_commentaires'],
                               $_DEPENSE,
                               $_RECETTE,
                               $_POST['S_compte'],
                               $_POST['S_periode'],
                               0
                          );
               } ## end of $_POST['cat'] != __ANOTHER_ACCOUNT__ || ...

              if (!$result) {

                     SQL_InsertAccount
                     (
                               $_N_ID,
                               $_POST['numero_id'],
                               2,
                               $_POST['R'],
                               $_DATE,
                               $_POST['cat'],
                               $_POST['tiers'],
                               $_COREL,
                               $_POST['S_commentaires'],
                               $_DEPENSE,
                               $_RECETTE,
                               $_POST['S_compte'],
                               0,
                               $_POST['S_periode']
                     );

                   if ($_POST['cat'] == __PART_ID__) {

                        SQL_InsertAccount
                        (
                                  $_COREL,
                                  $_POST['numero_id'],
                                  2,
                                  $_POST['R'],
                                  $_DATE,
                                  $_POST['cat'],
                                  $ID_TIERS,
                                  $_N_ID,
                                  $_POST['S_commentaires'],
                                  $_RECETTE,
                                  $_DEPENSE,
                                  $ID_COREL,
                                  0,
                                  $_POST['S_periode']
                        );

                   } ## end of $_POST['cat'] == __PART_ID__
              } ## end of $result

       } ## end of all $_POST != ''
    }
    break;

     ## MODIF THE OPERATION
     case 'MODIF' :
     $_POST['paie'] = SQL_Clean($_POST['paie']);
     if ($_POST['S_affecter'] == 1) { $_RECETTE = 0; $_DEPENSE = $_POST['paie']; }
     if ($_POST['S_affecter'] == 2) { $_DEPENSE = 0; $_RECETTE = $_POST['paie']; }

     $_POST['ID'] = SQL_Clean($_POST['ID']);

     $valid_db->query (
          "SELECT VALID_OP,NUMID,DATE_FORMAT(DATES,'%d-%m-%Y')
          AS DATES,THIRD,CAT,COMMENTS,SOUTT,IMP,COREL,ACCOUNT
          FROM ".$_MPM['table'][1]."
          WHERE TEMPID=2
          AND OPID='".$_POST['ID']."'
          AND USERID='$sess_pid'"
     );

     if ($valid_db->num_rows() == 1) {
      $valid_db->next_record();

         if (isset($_POST['R']) && $_POST['R'] != $valid_db->f('VALID_OP'))
             $cont[] .= "VALID_OP='".$_POST['R']."'";
         if ($_POST['S_date'] != $valid_db->f('DATES'))
             $cont[] .= "DATES='$_DATE'";
         if ($_POST['S_commentaires'] != $valid_db->f('COMMENTS'))
             $cont[] .= "COMMENTS='".$_POST['S_commentaires']."'";
         if ($_POST['cat'] == __PART_ID__ && $valid_db->f('CAT') != __PART_ID__) {
             $cont[] .= "COREL='".bcadd($_N_ID,1)."'";
         } else if ($valid_db->f('CAT') == __PART_ID__) {
             if ($_POST['cat'] == __PART_ID__) {
                $cont[] .= "COREL='".$valid_db->f('COREL')."'";

                SQL_UpdateAllAccount
                (
                     $_POST['R'],
                     $_POST['numero_id'],
                     $_DATE,
                     $ID_TIERS,
                     $_DEPENSE,
                     $_RECETTE,
                     $ID_COREL,
                     $_POST['S_commentaires'],
                     $_POST['S_periode'],
                     2,
                     $valid_db->f('COREL')
                );

             } else {
                $cont[] .= "COREL='0'";
                SQL_DeleteAccount(2,$valid_db->f('COREL'),'',0);
             }
         }
         else {
             $cont[] .= "COREL='0'";
         }


         if ($_POST['cat'] != $valid_db->f('CAT')) {
             if ($_POST['cat'] == __PART_ID__ && $valid_db->f('CAT') != __PART_ID__) {
                  $cont[] .= "CAT='".$_POST['cat']."'";

               SQL_InsertAccount
               (
                         bcadd($_N_ID,1),
                         $_POST['numero_id'],
                         2,
                         $_POST['R'],
                         $_DATE,
                         $_POST['cat'],
                         $ID_TIERS,
                         $_N_ID,
                         $_POST['S_commentaires'],
                         $_RECETTE,
                         $_DEPENSE,
                         $ID_COREL,
                         0,
                         $_POST['S_periode']
               );

             } else if ($_POST['cat'] == __ANOTHER_ACCOUNT__) {
                  $cont[] .= "CAT='".SQL_BuildCat($_POST['news_cat'],$id_cat)."'";
                  $id_tiers = SQL_BuildTiers($_POST['news_tiers'],$id_cat,$id_tiers);
                  $cont[] .= "THIRD='$id_tiers'";
             } else {
                  $cont[] .= "CAT='".$_POST['cat']."'";
             }
         }
         if ($_POST['tiers'] != $valid_db->f('THIRD')) {
             if ($_POST['tiers'] == __ANOTHER_ACCOUNT__) {
                  $id_tiers = SQL_BuildTiers($_POST['news_tiers'],$_POST['cat'],$id_tiers);
                  $cont[] .= "THIRD='$id_tiers'";
             }
             else if (isset($_POST['tiers'])) {
                  $cont[] .= "THIRD='".$_POST['tiers']."'";
             }
         }
     if ($_POST['S_compte'] != $valid_db->f('ACCOUNT')) {
              $cont[] .= "ACCOUNT='".$_POST['S_compte']."'";
     }
     if ($valid_db->f('IMP') == 0) { $paie = $valid_db->f('SOUTT');}
     else if ($valid_db->f('SOUTT') == 0) { $paie = $valid_db->f('IMP');}

     if ($_POST['paie'] != $paie) {
         if ($_POST['S_affecter'] == 1) {
              $cont[] .= "SOUTT='".$_POST['paie']."'";
              $cont[] .= "IMP='0'";
         } else if ($_POST['S_affecter'] == 2) {
              $cont[] .= "SOUTT='0'";
              $cont[] .= "IMP='".$_POST['paie']."'";
         }
     }
     if ($_POST['S_affecter'] == 1 && $valid_db->f('SOUTT') == 0) {
              $cont[] .= "IMP='0'";
              $cont[] .= "SOUTT='".$_POST['paie']."'";
     } else if ($_POST['S_affecter'] == 2 && $valid_db->f('IMP') == 0) {
              $cont[] .= "SOUTT='0'";
              $cont[] .= "IMP='".$_POST['paie']."'";
     }

     if (isset($_POST['numero_id']) && $_POST['numero_id'] != $valid_db->f('NUMID')) {
                      $cont[] .= "NUMID='".$_POST['numero_id']."'";
     } else {
                      $cont[] .= "NUMID='".$valid_db->f('NUMID')."'";
     }

        if (sizeof($cont) > 0) $liste = join($cont," , ");
             if ($_POST['cat'] != '' && $valid_db->f('CAT') == __PART_ID__) {
                 SQL_UpdateAccount(3,$liste,$_POST['S_periode'],'',2,$_POST['ID']);
             } else if ($_POST['cat'] == __PART_ID__ && $valid_db->f('CAT') != __PART_ID__) {
                 SQL_UpdateAccount(4,$liste,$_POST['S_periode'],$_N_ID,2,$_POST['ID']);
              } else {
                 SQL_UpdateAccount(3,$liste,$_POST['S_periode'],'',2,$_POST['ID']);
             }
     } ## end of $valid_db->rows == 1

     break;
} ## end of switch $_POST['Action']

/**
 * SQL ORDER BY ... ASC ... DESC
 */
       SQL_Orderby($PageOrder1,1);
       if (isset($_POST['order1'][$PageOrder1]) && strpos($_POST['order1'][$PageOrder1], "_") !== false) {
       $this_order = explode("_",$_POST['order1'][$PageOrder1]);
       	  $this_order[0] = SQL_Clean($this_order[0]);
          if ($this_order[1] == 0) $order = "OPID ".$this_order[0];
          if ($this_order[1] == 1) $order = "CAT ".$this_order[0];
          if ($this_order[1] == 2) $order = "THIRD ".$this_order[0];
          if ($this_order[1] == 3) $order = "ACCOUNT ".$this_order[0];
          if ($this_order[1] == 4) $order = "PERIOD ".$this_order[0];
          if (!isset($order))      $order = "OPID asc";
      } else {
        $order  = "OPID asc";
     }

/**
 * DISPLAY THE ADD AND LISTING FOR THE CALENDAR
 */
    $sql  = "SELECT VALID_OP, OPID, DATES, CAT, THIRD, COREL, COMMENTS, SOUTT, IMP, ACCOUNT, PERIOD ";
    $sql .= "FROM ".$_MPM['table'][1]." WHERE TEMPID=2 AND DATES <= '$annee-$mois-$Number_of_Days' ";
    $sql .= "AND USERID='$sess_pid' ORDER BY DATES, $order ";

    $db->query($sql);
    while ($db->next_record()) {

    $Terms = $db->f('CAT') == __PART_ID__ && $db->f('SOUTT') != 0 ? $_VAR['LANG_ACCOUNT_33'] : '/';
         if ($db->f('IMP') == 0) $MONTANT = "-".$db->f('SOUTT');
         if ($db->f('SOUTT') == 0) $MONTANT = $db->f('IMP');

         ## THE LIST EXTRACTED OF REQUEST SQL
         if ($db->f('CAT') == __PART_ID__) {
             if (($db->f('COREL') + 1) == $db->f('OPID')) {
             $_MPM['dates'][]   .= $db->f('DATES');
             $id_acct[]         .= $db->f('OPID');
             $acct[]            .= $db->f('ACCOUNT');
             $amount1[]         .= $MONTANT;
             $amount2[]         .= $MONTANT * $_MPM['lang_euro'];
             $periodicity[]     .= preg_replace('/^([^-]*)[(](.*)/','\1',$_VAR['LANG_CALEND_DIS_1'.$db->f('PERIOD').'']); ## For removed the commentaire beetween ()
             $valid_op[]        .= $db->f('VALID_OP');
             $third_part[]      .= $tools->Reduit_chaine(SQL_SearchCat($db->f('CAT')),__LENGTH_JUST_PART__,1)." $Terms ".$tools->Reduit_chaine(SQL_SearchThird($db->f('THIRD')),__LENGTH_JUST_THIRD__,1);
             $cat[]             .= SQL_SearchCat($db->f('CAT'));
             $tiers[]           .= SQL_SearchThird($db->f('THIRD'));
             }
         } else {
             $_MPM['dates'][]   .= $db->f('DATES');
             $id_acct[]         .= $db->f('OPID');
             $acct[]            .= $db->f('ACCOUNT');
             $amount1[]         .= $MONTANT;
             $amount2[]         .= $MONTANT * $_MPM['lang_euro'];
             $periodicity[]     .= preg_replace('/^([^-]*)[(](.*)/','\1',$_VAR['LANG_CALEND_DIS_1'.$db->f('PERIOD').'']); ## For removed the commentaire beetween ()
             $valid_op[]        .= $db->f('VALID_OP');
             $third_part[]      .= $tools->Reduit_chaine(SQL_SearchCat($db->f('CAT')),__LENGTH_JUST_PART__,1)." $Terms ".$tools->Reduit_chaine(SQL_SearchThird($db->f('THIRD')),__LENGTH_JUST_THIRD__,1);
             $cat[]             .= SQL_SearchCat($db->f('CAT'));
             $tiers[]           .= SQL_SearchThird($db->f('THIRD'));
         }

        ## CALCUL THE ECART BEETWEEN TWO DATES
        $expl_date = explode('-', $db->f('DATES'));
        $alpha = $tools->Nombre_Mois_ecouler($expl_date[1],$expl_date[0],$mois,$annee);
         switch($db->f('PERIOD')) {
             case 1: $choix = 1;  $alpha = $alpha;             break;
             case 2: $choix = 3;  $alpha = floor($alpha / 3);  break;
             case 3: $choix = 6;  $alpha = floor($alpha / 6);  break;
             case 4: $choix = 0;  $alpha = 0;                  break;
             case 5: $choix = 2;  $alpha = floor($alpha / 2);  break;
             case 6: $choix = 12; $alpha = floor($alpha / 12); break;
         }

         ## FOR FIX BUG THE MONTH (29,30,31)
         for ($i = 1; $i <= $alpha; $i++) {
          $_month = (($expl_date[1]) + ($i * $choix));
           $month = date('m',mktime(0,0,0,$_month));
             if ($expl_date[2] <= 28) {
                $Verif_date = date('Y-m-d',mktime(0,0,0,$_month,$expl_date[2],$expl_date[0]));
             } else if (($expl_date[2] > 28) && ($expl_date[2] < 32)) {
               $der_j = $shuffle->getDaysInMonth($month,$expl_date[0]);
               if ($der_j >= $expl_date[2]) $der_j = $expl_date[2]; else $der_j = $der_j;
                $Verif_date = date('Y-m-d',mktime(0,0,0,$_month,$der_j,$expl_date[0]));
             }

        ## THE LIST EXTRACTED OF DIFFERENT BEETWEEN TWO DATES
        if ($db->f('CAT') == __PART_ID__) {
           if (($db->f('COREL') + 1) == $db->f('OPID')) {
             $_MPM['dates'][]   .= $Verif_date;
             $id_acct[]         .= $db->f('OPID');
             $acct[]            .= $db->f('ACCOUNT');
             $amount1[]         .= $MONTANT;
             $amount2[]         .= $MONTANT * $_MPM['lang_euro'];
             $periodicity[]     .= preg_replace('/^([^-]*)[(](.*)/','\1',$_VAR['LANG_CALEND_DIS_1'.$db->f('PERIOD').'']); ## For removed the commentaire beetween ()
             $valid_op[]        .= $db->f('VALID_OP');
             $third_part[]      .= $tools->Reduit_chaine(SQL_SearchCat($db->f('CAT')),__LENGTH_JUST_PART__,1)." $Terms ".$tools->Reduit_chaine(SQL_SearchThird($db->f('THIRD')),__LENGTH_JUST_THIRD__,1);
             $cat[]             .= SQL_SearchCat($db->f('CAT'));
             $tiers[]           .= SQL_SearchThird($db->f('THIRD'));
             }
         } else {
             $_MPM['dates'][]   .= $Verif_date;
             $id_acct[]         .= $db->f('OPID');
             $acct[]            .= $db->f('ACCOUNT');
             $amount1[]         .= $MONTANT;
             $amount2[]         .= $MONTANT * $_MPM['lang_euro'];
             $periodicity[]     .= preg_replace('/^([^-]*)[(](.*)/','\1',$_VAR['LANG_CALEND_DIS_1'.$db->f('PERIOD').'']); ## For removed the commentaire beetween ()
             $valid_op[]        .= $db->f('VALID_OP');
             $third_part[]      .= $tools->Reduit_chaine(SQL_SearchCat($db->f('CAT')),__LENGTH_JUST_PART__,1)." $Terms ".$tools->Reduit_chaine(SQL_SearchThird($db->f('THIRD')),__LENGTH_JUST_THIRD__,1);
             $cat[]             .= SQL_SearchCat($db->f('CAT'));
             $tiers[]           .= SQL_SearchThird($db->f('THIRD'));
         } ## end of if ($db->f('CAT') == 1)
       } ## end of for ($i = 1; $i <= $alpha; $i++)
    } ## end of while $db->next_record()

/**
 * DISPLAY THE LIST BY ORDER DATE ASC
 */

   $_MPM['BlockInclude'] = MPM_IncludeTemp(0,'form_calendar_display_s.tpl','form_calendar_display_d.tpl');
   $_MPM['BeginMixed'] = array
   (
     'IMG_ASC_DESC1'     => XHTML_ASC_DESC($PageOrder1,'asc_0','desc_0',1),
     'IMG_ASC_DESC2'     => XHTML_ASC_DESC($PageOrder1,'asc_1','desc_1',1),
     'IMG_ASC_DESC3'     => XHTML_ASC_DESC($PageOrder1,'asc_2','desc_2',1),
     'IMG_ASC_DESC4'     => XHTML_ASC_DESC($PageOrder1,'asc_3','desc_3',1),
     'IMG_ASC_DESC5'     => XHTML_ASC_DESC($PageOrder1,'asc_4','desc_4',1),
     'LANG_ACCOUNT_15'   => $_VAR['LANG_ACCOUNT_15'],
     'LANG_BOOK_5'       => $_VAR['LANG_BOOK_5'],
     'MODIF'             => $_VAR['MODIF'],
     'Jour'              => $jour,
     'Mois'              => $mois,
     'Annee'             => $annee,
     'CURRENT_MONTH'     => $_VAR['THIS_MONTH'][$mois - 1]." $annee",
     'MESS_CALENDAR_NEW' => $_VAR['MESS_CALENDAR_NEW'],
     'OPEN_CLOSE'        => XHTML_OPEN_CLOSE(),
     'LANG_CALEND_DIS_3' => $_VAR['LANG_CALEND_DIS_3'],
     'LANG_CALEND_DIS_5' => $_VAR['LANG_CALEND_DIS_5'],
     'LANG_CALEND_DIS_6' => $_VAR['LANG_CALEND_DIS_6']
    );
    XHTML_SetFile($_MPM['BlockInclude'],'',0);

/**
 * SQL ORDER BY ... ASC ... DESC
 */
     if (isset($_POST['order1'][$PageOrder1]) && strpos($_POST['order1'][$PageOrder1], "_") !== false) {
          if ($this_order[1] == 0) $valeur = $_MPM['dates'];
          if ($this_order[1] == 1) $valeur = $cat;
          if ($this_order[1] == 2) $valeur = $tiers;
          if ($this_order[1] == 3) $valeur = $acct;
          if ($this_order[1] == 4) $valeur = $periodicity;
          if (!isset($valeur))     $valeur = $_MPM['dates'];
     } else {
        $valeur = $_MPM['dates'];
     }

/**
 * SQL ORDER BY ... ASC ... DESC
 * DOIT ETRE SI HAUT POUR REPRENDRE LES CASES PRE COCHER
 */
      if (isset($_POST['orderby2']) && isset($_POST['IDCOMPTE'])) {
         $_POST['Choice']   = $_VAR['MESS_CALENDAR_VERIF'];
         $_POST['IDCOMPTE'] = $_POST['IDCOMPTE'];
      }

## BECAREFUL BEFORE is_array
$tpl->set_block('FILE_'.$_MPM['BlockInclude'],'BOUCLE_CALENDAR_LIST','BLOCK_'.$_MPM['BlockInclude']);
  if (isset($_MPM['dates']) && is_array($_MPM['dates'])) {

     if (stripos($order,'asc') !== false) asort($valeur); else arsort($valeur);
     reset($valeur);
     while (list($counter,$v) = each($valeur)) { ## TRI

        if (sizeof($list_op) > 0 && (isset($sess_nb)) && $sess_nb == 1) {
           if (in_array($id_acct[$counter], $list_op)) {
                 $colors = __COLOR_SETPOINTER_1__;
                 $checked = ' checked="checked"';
                 $bgcols = 'pointer1';
              } else if (!in_array($id_acct[$counter], $list_op)) {
                       if (isset($colors) && $colors == __COLOR_DISPLAY_1__) {
                           $colors = __COLOR_DISPLAY_2__;
                           $bgcols = 'display2';
                       } else {
                           $colors = __COLOR_DISPLAY_1__;
                           $bgcols = 'display1';
                       }
              $checked = '';
              }
        } else if (isset($hid[1]) && $hid[1] == 0 && $hid[0] == $id_acct[$counter]) {
            $colors = __COLOR_SETPOINTER_1__;
            $checked = ' checked="checked"';
            $bgcols = 'pointer1';
        } else if (!isset($hid[1]) && isset($_POST['Choice']) && $_POST['Choice'] != $_VAR['MESS_CALENDAR_VAL_MODIF'] && isset($check[$counter]) && $check[$counter] != '' && $check[$counter] == $counter) {
            $colors = __COLOR_SETPOINTER_1__;
            $checked = ' checked="checked"';
            $bgcols = 'pointer1';
        } else if (isset($_POST['Choice']) && $_POST['Choice'] == $_VAR['MESS_CALENDAR_VAL_MODIF'] && $_POST['ID'] == $id_acct[$counter]) {
            $colors = __COLOR_SETPOINTER_1__;
            $checked = ' checked="checked"';
            $bgcols = 'pointer1';
        } else if (isset($_POST['Action']) && $_POST['Action'] == 'ADD' && ($id_acct[$counter] == $_N_ID || $id_acct[$counter] == $_COREL)) {
            $colors = __COLOR_SETPOINTER_1__;
            $checked = ' checked="checked"';
            $bgcols = 'pointer1';
        } else if (isset($colors) && $colors == __COLOR_DISPLAY_1__) {
            $colors = __COLOR_DISPLAY_2__;
            $checked = '';
            $bgcols = 'display2';
        } else {
            $colors = __COLOR_DISPLAY_1__;
            $checked = '';
            $bgcols = 'display1';
        }

      $tpl->set_var(array(
        'COUNTER'           => $counter,
        'CHECKS'            => $checked,
        'classbgcolor'      => $bgcols,
        'COLOR'             => $colors,
        'FORMAT_ACC_DATE'   => preg_replace('/^([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})$/', '\3-\2-\1', $_MPM['dates'][$counter]),
        'ID_ACCOUNT'        => $id_acct[$counter],
        'ACCOUNT_IMG'       => $valid_op[$counter] ? 'oui' : 'non',
        'VAL_IMG_ACCOUNT'   => $valid_op[$counter],
        'CHOIX_TERME'       => $third_part[$counter],
        'SEARCH_ACCOUNT'    => $tools->Reduit_chaine(SQL_NameAccount($acct[$counter]),(__LENGTH_COMMENT__ - 1),0),
        'MONTANT_EUROS'     => $tools->formatage($amount1[$counter]),
        'MONTANT_ANOTHER'   => $tools->formatage($amount2[$counter]),
        'SEARCH_PERIODE'    => $periodicity[$counter]
      ));
      $tpl->parse('BLOCK_'.$_MPM['BlockInclude'],'BOUCLE_CALENDAR_LIST',true);
      }

 $sess_nb = 2;
 $sess->register('sess_nb');
 } ## end of isset($_MPM['dates']) && is_array($_MPM['dates'])

   ## FOR COCHER - DECOHER ALL OPERATION (CHECKBOX)
   if (!isset($_POST['Choice'])) $_POST['Choice'] = '';

       $_MPM['BoucleMixed'] = array
       (
          'COND_MESS'    => (isset($_MPM['dates']) && isset($IDCOMPTE)
                             && sizeof($_MPM['dates']) != 0
                             && sizeof($IDCOMPTE) != 0
                             && sizeof($_MPM['dates']) == sizeof($IDCOMPTE)
                             && $_POST['Choice'] == $_VAR['MESS_CALENDAR_VERIF'])
                                   ? $_VAR['MESS_CALENDAR_DESELECT']
                                   : $_VAR['MESS_CALENDAR_SELECT']
       );
       $_MPM['BeginMixed'] = array_merge($_MPM['BeginMixed'],$_MPM['BoucleMixed']);
       XHTML_SetFile($_MPM['BlockInclude'],$_MPM['BeginMixed'],4);

/**
 * SWITCH -- TEMPLATE  FOR THE NEWS CALENDAR
 */
switch($_POST['Choice']) {
     case $_VAR['MESS_CALENDAR_NEW'] : ## FORM ADDED OPERATION
     case $_VAR['MODIF'] :             ## FORM MODIFIED OPERATION

      ## RECUP THE VALUE FOR CONTRUCT THE MODIFIED ACCOUNT FORMULAIRE
      if (isset($_POST['CONTINUE_YES']) && $_POST['CONTINUE_YES'] == 'YES') {

         $db->query (
               "SELECT OPID, NUMID, VALID_OP, COREL,
               DATE_FORMAT(DATES,'%d') AS D,
               DATE_FORMAT(DATES,'%m') AS M,
               DATE_FORMAT(DATES,'%Y') AS Y,
               CAT, THIRD, COMMENTS, SOUTT, IMP, ACCOUNT, PERIOD
               FROM ".$_MPM['table'][1]."
               WHERE TEMPID=2
               AND OPID='".$account[0]."'
               AND USERID='$sess_pid'"
         );

         while ($db->next_record()) {

              if ($db->f('IMP') == 0) {
                    $_paie = $db->f('SOUTT');
                    $affecters = 1;
              }

              if ($db->f('SOUTT') == 0) {
                    $_paie = $db->f('IMP');
                    $affecters = 2;
              }

                 $_POST['S_compte']            = $db->f('ACCOUNT');
                 $_POST['S_cat']               = $db->f('CAT').'|'.$db->f('THIRD');
                 $_POST['S_affecter']          = $affecters;
                 $_POST['S_paie']              = $_paie;
                 $_POST['numero_id']           = $db->f('NUMID');
                 $_POST['S_commentaires']      = $db->f('COMMENTS');
                 $_POST['R']                   = $db->f('VALID_OP');
                 $_POST['S_periode']           = $db->f('PERIOD');
                 $_POST['ID']                  = $db->f('OPID');

          $_MPM['BoucleMixed'] = array
          (
                         'Jour'           => $db->f('D'),
                         'Mois'           => $db->f('M'),
                         'Annee'          => $db->f('Y')
          );
        } ## end of while ($db->next_record())
      } ## end of if (isset($_POST['CONTINUE_YES']) && ...


      $_MPM['BeginMixed'] = array
      (
       'LANG_ACCOUNT_17'     => $_VAR['LANG_ACCOUNT_17'],
       'LANG_ACCOUNT_18'     => $_VAR['LANG_ACCOUNT_18'],
       'LANG_ACCOUNT_24'     => $_VAR['LANG_ACCOUNT_24'],
       'LANG_ACCOUNT_25'     => $_VAR['LANG_ACCOUNT_25'],
       'LANG_ACCOUNT_26'     => $_VAR['LANG_ACCOUNT_26'],
       'LANG_ACCOUNT_27'     => $_VAR['LANG_ACCOUNT_27'],
       'LANG_ACCOUNT_21'     => $_VAR['LANG_ACCOUNT_21'],
       'LANG_CALEND_DIS_6'   => $_VAR['LANG_CALEND_DIS_6'],
       'LANG_CALEND_DIS_10'  => $_VAR['LANG_CALEND_DIS_10'],
       'LANG_CALEND_DIS_11'  => $_VAR['LANG_CALEND_DIS_11'],
       'LANG_CALEND_DIS_12'  => $_VAR['LANG_CALEND_DIS_12'],
       'LANG_CALEND_DIS_13'  => $_VAR['LANG_CALEND_DIS_13'],
       'LANG_CALEND_DIS_14'  => $_VAR['LANG_CALEND_DIS_14'],
       'LANG_CALEND_DIS_15'  => $_VAR['LANG_CALEND_DIS_15'],
       'LANG_CALEND_DIS_16'  => $_VAR['LANG_CALEND_DIS_16'],
       'THIS_ACTION_MODE'    => isset($_POST['CONTINUE_YES']) && $_POST['CONTINUE_YES'] == 'YES' ? 'MODIF' : 'ADD',
       'THIS_ACTION_NAME'    => isset($_POST['CONTINUE_YES']) && $_POST['CONTINUE_YES'] == 'YES' ? 'IDCOMPTE[]' : '',
       'THIS_ACTION_VALUE'   => isset($_POST['CONTINUE_YES']) && $_POST['CONTINUE_YES'] == 'YES' ? $_POST['IDCOMPTE'][0] : '',
       'ID_CALENDAR'         => isset($_POST['ID']) ? $_POST['ID'] : '',
       'CHOIX_LANG_CALENDAR' => isset($_POST['CONTINUE_YES']) && $_POST['CONTINUE_YES'] == 'YES'
                                      ? $_VAR['MESS_CALENDAR_MODIF'] : $_VAR['MESS_CALENDAR_NEW'],
       'SELECTED_AFF_1'      => isset($_POST['S_affecter']) && $_POST['S_affecter'] == 1 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'SELECTED_AFF_2'      => isset($_POST['S_affecter']) && $_POST['S_affecter'] == 2 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'SELECTED_AFF_3'      => isset($_POST['S_periode']) && $_POST['S_periode'] == 1 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'SELECTED_AFF_4'      => isset($_POST['S_periode']) && $_POST['S_periode'] == 2 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'SELECTED_AFF_5'      => isset($_POST['S_periode']) && $_POST['S_periode'] == 3 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'SELECTED_AFF_6'      => isset($_POST['S_periode']) && $_POST['S_periode'] == 4 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'SELECTED_AFF_7'      => isset($_POST['S_periode']) && $_POST['S_periode'] == 5 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'SELECTED_AFF_8'      => isset($_POST['S_periode']) && $_POST['S_periode'] == 6 && $_POST['Choice'] == $_VAR['MODIF']
                                      ? ' selected="selected"' : '',
       'ACCOUNT_ADD_VAL_4'   => isset($_POST['numero_id']) && $_POST['numero_id'] != '' && $_POST['Choice'] == $_VAR['MODIF']
                                      ? $_POST['numero_id'] : '',
       'ACCOUNT_ADD_VAL_3'   => isset($_POST['S_paie']) && $_POST['Choice'] == $_VAR['MODIF']
                                       ? $_POST['S_paie'] : '0.00',
       'ACCOUNT_ADD_VAL_2'   => isset($_POST['S_commentaires']) && $_POST['Choice'] == $_VAR['MODIF']
                                       ? stripslashes($_POST['S_commentaires']) : '',
       'CHECKED_R_1'         => (isset($_POST['R']) && $_POST['R'] == 1) || ($_POST['Choice'] == $_VAR['MODIF'])
                                       ? ' checked="checked"' : '',
       'CHECKED_R_2'         => !isset($_POST['R']) || isset($_POST['R']) && $_POST['R'] == 0 ? ' checked="checked"' : '',
       'CHOIX_ACCOUNT_LIST'  => SQL_ChoiceAccount(isset($_POST['S_compte']) ? $_POST['S_compte'] : '',2),
       'LIST_THIRD_PART'     => SQL_ListRecursive(isset($_POST['S_cat']) ? SQL_Clean($_POST['S_cat']) : '',1,'Moins'),
       'CHOIX_MODIF'         => isset($_POST['CONTINUE_YES']) && $_POST['CONTINUE_YES'] == 'YES'
                                       ? $_VAR['MESS_CALENDAR_VAL_MODIF'] : $_VAR['MESS_CALENDAR_ADD']
     );
     $_MPM['BoucleMixed'] = array_merge($_MPM['BoucleMixed'],$_MPM['BeginMixed']);
     XHTML_SetFile('form_calendar_add.tpl',$_MPM['BoucleMixed'],2);
break;

     default : ## AFFICHAGE PAR DEFAULT
     case $_VAR['MESS_CALENDAR_VERIF'] : ## VERIFY THE SELECTION

     /**
      * SQL ORDER BY ... ASC ... DESC
      */
      SQL_Orderby($PageOrder2,2);
        if (isset($_POST['order2'][$PageOrder2]) && strpos($_POST['order2'][$PageOrder2], "_") !== false) {
         $_this_order = explode('_',$_POST['order2'][$PageOrder2]);
             if ($_this_order[1] == 0) $_order = $_this_order[0];
             if (!isset($_order))      $_order = 'asc';
        } else {
           $_order  = 'asc';
        }

          $_MPM['BlockInclude2'] = MPM_IncludeTemp(0,'form_calendar_view_s.tpl','form_calendar_view_d.tpl');
          $_MPM['BeginMixed'] = array
          (
            'MESS_CALENDAR_NEW'    => $_VAR['MESS_CALENDAR_NEW'],
            'MESS_CALENDAR_VERIF'  => $_VAR['MESS_CALENDAR_VERIF'],
            'MESS_CALENDAR_SAISIE' => $_VAR['MESS_CALENDAR_SAISIE'],
            'LANG_CALEND_DIS_4'    => $_VAR['LANG_CALEND_DIS_4'],
            'LANG_CALEND_DIS_7'    => $_VAR['LANG_CALEND_DIS_7'],
            'LANG_CALEND_DIS_8'    => $_VAR['LANG_CALEND_DIS_8'],
            'LANG_ACCOUNT_24'      => $_VAR['LANG_ACCOUNT_24'],
            'IMG_ASC_DESC6'        => $_POST['Choice'] == $_VAR['MESS_CALENDAR_VERIF']
                                          ? XHTML_ASC_DESC($PageOrder2,'asc_0','desc_0',2) : '',
            'LIMIT_OF_DISPLAY'     => $_POST['Choice'] == $_VAR['MESS_CALENDAR_VERIF']
                                          ? "$Number_of_Days ".$_VAR['THIS_MONTH'][$mois - 1]." $annee" : ''
          );
          XHTML_SetFile($_MPM['BlockInclude2'],'',0);

 $tpl->set_block('FILE_'.$_MPM['BlockInclude2'].'', 'BOUCLE_CALENDAR_DEFAULT', 'BLOCK_'.$_MPM['BlockInclude2'].'');
 if ($_POST['Choice'] == $_VAR['MESS_CALENDAR_VERIF']) {
      $list_filter = SQL_FilterCalendar($account,$liste_supp);

      if (is_array($list_filter)) {
        $db->query (
          "SELECT ACCOUNTID,ACCOUNT FROM ".$_MPM['table'][2]."
          WHERE USERID='$sess_pid' ORDER BY ACCOUNT $_order"
        );

        while ($db->next_record()) {

         $AVANT  = SQL_SearchSolde($db->f('ACCOUNTID'),1,0);
         $BIS    = isset($list_filter[$db->f('ACCOUNTID')]) ? $list_filter[$db->f('ACCOUNTID')] : 0;
         $TAVANT += $AVANT;
         $TBIS   += $BIS;

        $tpl->set_var(array(
           'classbgcolor'   => 'pointer1',
           'COLOR'          => __COLOR_SETPOINTER_1__,
           'THIS_ACCOUNT'   => $tools->Reduit_chaine($db->f('ACCOUNT'),__LENGTH_ACCOUNT__,0),
           'SOMME_1'        => $tools->formatage($AVANT),
           'SOMME_2'        => $tools->formatage($AVANT * $_MPM['lang_euro']),
           'COLOR_MOINS'    => strpos($AVANT,'-') !== false ? 'menurouge' : 'menu',
           'SOMME_BIS_1'    => $tools->formatage($BIS),
           'SOMME_BIS_2'    => $tools->formatage($BIS * $_MPM['lang_euro']),
           'COLOR_PLUS'     => strpos($BIS,'-') !== false ? 'menurouge' : 'menu',
           'SOMME_3'        => $tools->formatage(($AVANT + $BIS)),
           'SOMME_4'        => $tools->formatage(($AVANT + $BIS) * $_MPM['lang_euro']),
           'COLOR_FIND'     => strpos(($AVANT + $BIS),'-') !== false ? 'menurouge' : 'menu'
        ));
        $tpl->parse('BLOCK_'.$_MPM['BlockInclude2'].'','BOUCLE_CALENDAR_DEFAULT',true);
        } ## end of while ($db->next_record())

          $_MPM['BoucleMixed'] = array
          (
            'TOTAL_1'         => $tools->formatage($TAVANT),
            'TOTAL_2'         => $tools->formatage($TAVANT * $_MPM['lang_euro']),
            'TOTAL_BIS_1'     => $tools->formatage($TBIS),
            'TOTAL_BIS_2'     => $tools->formatage($TBIS * $_MPM['lang_euro']),
            'TOTAL_3'         => $tools->formatage(($TAVANT + $TBIS)),
            'TOTAL_4'         => $tools->formatage(($TAVANT + $TBIS) * $_MPM['lang_euro'])
          );

     } else {
       XHTML_DisplayJs($_VAR['MESSAGE_JS']['JS_CALEND_NO_ACT']);
     } ## end of if (is_array($list_filter))
  } ## end of if ($_POST['Choice'] == $_VAR['MESS_CALENDAR_VERIF'])

     $_MPM['BeginMixed'] = array_merge($_MPM['BeginMixed'],$_MPM['BoucleMixed']);
     XHTML_SetFile($_MPM['BlockInclude2'],$_MPM['BeginMixed'],4);
 break;
 }
     } else {
          XHTML_DisplayLogin();
     } ## end if (SQL_VerifSession())

/**
 * BUILD THE FOOTER
 */
     XHTML_footer();
Return current item: MyPhpMoney