Location: PHPKode > projects > MyPhpMoney > myphpmoney_2.0/public_html/book.php
<?php
/**
 * $Id: book.php 417 2007-05-08 17:55:39Z 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,0,1,1,1,1,1);

/**
 * DEFINE VARIABLE GLOBALS
 */
      $PageOrder              = 'book';
      $valid_mod              = '';
      $SoldBefore             = '';
      $SoldLast               = '';
      $_MPM['Block']          = array(); ## tab for template and size
      $_MPM['BlockInclude']   = 0;       ## for the include template
      $_MPM['SizeWidth']      = 0;       ## Size for display template

/**
 * RECUP THE VARIABLE POST AND AFFECT THE $OPT
 */
     ## DELETE THE ACCOUNT
     if (isset($_POST['SUP_COMPTE']) && strpos($_POST['SUP_COMPTE'],$sess_pid) !== false) {
           SQL_DeleteUpdateAccount(SQL_Clean($_POST['SUP_COMPTE']));
     }

     ## MODIFIED THE ACCOUNT
     if (isset($_POST['MOD_COMPTE'])) {
           $valid_mod = $_POST['MOD_COMPTE'];
     }

     ## ADD A NEW ACCOUNT SQL
     if (isset($_POST['IN']) && $_POST['IN'] == 3) {

      $_POST['nom_compte'] = SQL_Clean($_POST['nom_compte']);	
      if (!SQL_AddAccount($_POST['nom_compte'])) {

         $ids_detail_compte = SQL_RecupId(2);
         $T_Tiers           = SQL_RecupId(4);

           SQL_InsAccount($ids_detail_compte,$_POST['nom_compte']);
           SQL_InsertThird($T_Tiers,__PART_ID__,$_POST['nom_compte']);

           ## Insert the balance (in the account)
           if (strpos($_POST['paie'],'-') !== false) {
               $k = str_replace('-','',$_POST['paie']);
               $l = 0;
           } else {
               $k = 0;
               $l = $_POST['paie'];
           }

           SQL_InsertAccount
           (
                     SQL_RecupId(1),
                     '',
                     1,
                     1,
                     SQL_FirstDate(),
                     __OPEN_PART__,
                     SQL_ReturnOpenThird(),
                     0,
                     $_VAR['OPEN_ACCOUNT_BEGIN_COMMENT'],
                     SQL_Clean($k),
                     SQL_Clean($l),
                     $ids_detail_compte,
                     0,
                     0
           );
           SQL_RecupSolde($ids_detail_compte);

         ## JS CONFIRM THE CREATE
         XHTML_DisplayJs(sprintf($_VAR['MESSAGE_JS']['JS_BOOK_ADD_ACC_1'],$sess_user,$_POST['nom_compte'],$tools->formatage($_POST['paie'])));
      } else {
         ## JS MESSAGE EXIST ACCOUNT
         XHTML_DisplayJs(sprintf($_VAR['MESSAGE_JS']['JS_BOOK_ADD_ACC'],'[ '.$_POST['nom_compte'].' ]'));
      } ## end of SQL_AddAccount
   }

     ## RENAME THE ACCOUNT
     if (isset($_POST['NEWS_CPTE']) && isset($sess_pid)) {

       $_POST['NEWS_CPTE'] = SQL_Clean($_POST['NEWS_CPTE']);
       $_POST['NEWS_ID'] = SQL_Clean($_POST['NEWS_ID']);

       $Exist       = SQL_IdAccount($_POST['NEWS_CPTE']);
       $thisID      = SQL_SearchInThird(0,$_POST['NEWS_ID']);

         ## UPDATE THE ACCOUNT
         if ($Exist == '' || $Exist == $_POST['NEWS_ID']) {

            SQL_UpdateThird($thisID,$_POST['NEWS_CPTE']);
            SQL_UpAccount($_POST['NEWS_ID'],$_POST['NEWS_CPTE']);
            SQL_RecupSolde($_POST['NEWS_ID']);

         ## JS MESSAGE EXIST ACCOUNT
         } else {
         XHTML_DisplayJs(sprintf($_VAR['MESSAGE_JS']['JS_BOOK_ADD_ACC'],'[ '.$NEWS_CPTE.' ]'));
         } ## end of if $Exist
     }

/**
 * RECUP THE VARIABLE GET (ADD THE NEW ACCOUNT )
 */
    if (isset($_GET['opt']) && $_GET['opt'] == 'new') {

       echo XHTML_AccountList();

    } else {

       XHTML_VerifAccount();


       $_MPM['Block']         = explode('|',MPM_IncludeTemp(1,'form_book_listing_simple.tpl','form_book_listing_double.tpl'));
       $_MPM['BlockInclude']  = $_MPM['Block'][0];
       $_MPM['SizeWidth']     = $_MPM['Block'][1];

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

/**
 * TEMPLATE (form_book_listing_*.tpl)
 */
       $_MPM['BeginMixed'] = array
       (
          'IMG_ASC_DESC1'      => XHTML_ASC_DESC($PageOrder,'asc_0','desc_0',1),
          'LANG_BOOK_5'        => $_VAR['LANG_BOOK_5'],
          'LANG_BOOK_6'        => $_VAR['LANG_BOOK_6'],
          'HTTP_HOME_ALL'      => $_MPM['file_excel_d'],
          'LANG_ACCOUNT_10'    => $_VAR['LANG_ACCOUNT_10'],
          'IMAGE_EXCEL_ALT'    => $_VAR['IMAGE_EXCEL_ALT'],
          'OPEN_CLOSE'         => XHTML_OPEN_CLOSE(),
          'LANG_BOOK_1'        => $_VAR['LANG_BOOK_1'],
          'LANG_BOOK_3'        => $_VAR['LANG_BOOK_3'],
          'LANG_BOOK_4'        => $_VAR['LANG_BOOK_4'],
          'LANG_BOOK_7'        => $_VAR['LANG_BOOK_7'],
          'LANG_BANK'          => $_VAR['LANG_OPTION_SELECT_3'],
          'HTTP_HOME_ACCOUNT'  => $_MPM['file_account'],
          'WIDTH_IF'           => $_MPM['SizeWidth'],
          'DISPLAY_DATE'       => $_MPM['DATE_DAYS']
       );
       XHTML_SetFile($_MPM['BlockInclude'],'',0);

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

          $tpl->set_block('FILE_'.$_MPM['BlockInclude'], 'BOUCLE_BOOK_LISTING', 'BLOCK_'.$_MPM['BlockInclude']);
          while ($db->next_record()) {

          $Search_Soldes = SQL_SearchSolde($db->f('ACCOUNTID'),0,0);
          $SoldBefore   += $Search_Soldes;
          $SoldLast     += SQL_SearchSolde($db->f('ACCOUNTID'),1,0);

          $mess_js  = $_VAR['MESSAGE_JS']['JS_BOOK_LISTING_1'].' '.$sess_user."\\n";
          $mess_js .= $_VAR['MESSAGE_JS']['JS_BOOK_LISTING_2'];

          $tpl->set_var(array(
                'MESSAGE_JS'            => "if(!confirm('$mess_js')) return false;",
                'DETAIL_COMPTE'         => str_replace('"',"''",$db->f('ACCOUNT')),
                'MODIF'                 => $_VAR['MODIF'],
                'ID_DETAIL_COMPTE'      => $db->f('ACCOUNTID'),
                'FORMATAGE_0'           => $tools->formatage(SQL_SearchSolde($db->f('ACCOUNTID'),1,1)),
                'FORMATAGE_1'           => $tools->formatage($Search_Soldes),
                'FORMATAGE_2'           => $tools->formatage($Search_Soldes * $_MPM['lang_euro']),
                'classbgcolor'          => isset($colors) && $colors == __COLOR_DISPLAY_1__ ? 'display2' : 'display1',
                'COLOR'                 => isset($colors) && $colors == __COLOR_DISPLAY_1__ ? $colors = __COLOR_DISPLAY_2__ : $colors = __COLOR_DISPLAY_1__
          ));

        ## D'ONT MOUVE TOP
        $tpl->set_var(array(
               'CONDITION_BOOK_LISTING'=> $valid_mod == $db->f('ACCOUNTID') ? XHTML_SetFile('opt_book_listing_1.tpl','',1) : XHTML_SetFile('opt_book_listing.tpl','',1)
        ));
        $tpl->parse('BLOCK_'.$_MPM['BlockInclude'],'BOUCLE_BOOK_LISTING',true);
      } ## end of while

  $_MPM['BoucleMixed'] = array
  (
          'FORMATAGE_3'     => $tools->formatage($SoldBefore),
          'FORMATAGE_4'     => $tools->formatage($SoldBefore * $_MPM['lang_euro'])
  );
  $_MPM['BeginMixed'] = array_merge($_MPM['BeginMixed'],$_MPM['BoucleMixed']);

  if (SQL_LastDate() != '') {
         $_MPM['BoucleMixed'] = array
         (
           'LANG_ACCOUNT_8_BIS'   => $_VAR['LANG_ACCOUNT_8'],
           'DISPLAY_DATE_LAST'    => SQL_LastDate(),
           'FORMATAGE_5'          => $tools->formatage($SoldLast),
           'FORMATAGE_6'          => $tools->formatage($SoldLast * $_MPM['lang_euro'])
         );
  $_MPM['BeginMixed'] = array_merge($_MPM['BeginMixed'],$_MPM['BoucleMixed']);
  } ## end of SQL_LastDate

   XHTML_SetFile($_MPM['BlockInclude'],$_MPM['BeginMixed'],4);
 } ## end of if (isset($_GET['opt'])

     } else {
          XHTML_DisplayLogin();
     } ## end if (SQL_VerifSession())

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