Location: PHPKode > projects > MyPhpMoney > myphpmoney_2.0/public_html/listop.php
<?php
/**
 * $Id: listop.php 422 2007-05-26 19:11:34Z 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/
 *
 * Suggested by Bernard BOISJOT
 */

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

/**
 * TEMPLATE
 */
 if (isset($sess_pid) && is_object($sess) && $sess->is_registered('sess_pid')) {

     $_MPM['BlockInclude'] = MPM_IncludeTemp(0,'form_account_simple.tpl','form_account_double.tpl');
     $_MPM['BeginMixed'] = array
     (
         'IMG_ASC_DESC1'      => XHTML_ASC_DESC($PageOrder,'asc_0','desc_0',1),
         'LANG_ACCOUNT_15'    => $_VAR['LANG_ACCOUNT_15'],
         'LANG_ACCOUNT_17'    => $_VAR['LANG_ACCOUNT_17'],
         'LANG_ACCOUNT_18'    => $_VAR['LANG_ACCOUNT_18'],
         'LANG_ACCOUNT_21'    => $_VAR['LANG_ACCOUNT_21'],
         'LANG_BOOK_5'        => $_VAR['LANG_BOOK_5'],
         'MODIF'              => $_VAR['MODIF'],
         'HTTP_HOME_ACCOUNT'  => $_MPM['file_account'],
         'LANG_ACCOUNT_20'    => $_VAR['LANG_ACCOUNT_20'],
         'LANG_BOOK_0'        => $_VAR['LANG_BOOK_0'],
         'LANG_BOOK_3'        => $_VAR['LANG_BOOK_3'],
         'NAME_COMPTE'        => $name_account,
         'CHOIX_DATE_ACCOUNT' => XHTML_Select(3,$The_mois,SQL_SeachDay($_POST['ID'])),
         'SCROLL'             => $order == 'desc' ? 'THAT' : 'THIS',
         'CHOIX_ACCOUNT_LIST' => SQL_ChoiceAccount($_POST['ID'],1)
     );
     XHTML_SetFile($_MPM['BlockInclude'],'',0);
  
  #------------- list_records ---------#
     $total = "SELECT count(*) as QT FROM ".$_MPM['table'][1]." ";
     $total .= "WHERE TEMPID=1 AND USERID='$sess_pid' ";
     $total .= "AND ACCOUNT='".$_POST['ID']."' ";
     $total .= "AND DATE_FORMAT(DATES,'%m-%Y') LIKE '%$The_mois%' ";


      $db->query($total);
      $db->next_record();
      $total_regs = $db->f('QT');
//$total_regs = mysql_fetch_row($db->query($total));

      settype($_reg, "integer");
      settype($total_num_page, "integer");
      settype($last_page_num, "integer");
      settype($pag_num, "integer");

      $_reg = (int) __TOTAL_RECORDS__;
      $total_num_page = $last_page_num = ceil((int)$total_regs/$_reg);

      $last_page_num--;

      if(!isset($cur_pag)) {
      	settype($cur_pag, "integer");
     	$cur_pag = $last_page_num;
      } else if($last_page_num > $_POST['cur_pag']) {
      	settype($cur_pag, "integer");
	$cur_pag = intVal($_POST['cur_pag']);
      } else {
	settype($cur_pag, "integer");
     	$cur_pag = $last_page_num;
      }

      $pag_num = $cur_pag + 1;

      if ($_reg < $total_regs ) {
      	if ($pag_num > 1 ) {
		$prev_page = $pag_num - 1;
		$pag_beg = $prev_page;
		$prev_link = "Prev()";
		$submit_prev = "submit";
	} else {
		$prev_page = 1;
		$pag_beg = $prev_page;
		$prev_link = '';
		$submit_prev = "text";
	}
	if($pag_num < $total_num_page) {
		$next_page = $pag_num + 1;
		$pag_end = $next_page;
		$next_link = "Next()";
		$submit_next = "submit";
	} else {
		$next_page = $pag_num;
		$pag_end = $next_page;
		$next_link = '';
		$submit_next = "text";

	}
      }	else {
      	$submit_prev = '';
	$submit_next = '';
	$prev_link = '';
	$next_link = '';
	$prev_page = '';
	$next_page = '';
	$pag_beg = '';
	$pag_end = '';
	$cur_pag = '';
      }

#-------------- list_records ----------#

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

     if ($The_mois == 'CRITERIAS') {
      $sql .= "AND VALID_OP=0 ";
      $sql .= "ORDER BY VALID_OP $order, OPID $order ";
     } else {
      $sql .= "AND DATE_FORMAT(DATES,'%m-%Y') LIKE '$The_mois%' ";
      $sql .= "ORDER BY DATES $order, OPID $order LIMIT ".$cur_pag * $_reg." , ".$_reg." ";
     }
     $db->query($sql);

     $tpl->set_block('FILE_'.$_MPM['BlockInclude'],'BOUCLE_ACCOUNT_LIST','BLOCK_'.$_MPM['BlockInclude']);
     $z = 0; ## for validate xhtml 1.1
     while ($db->next_record()) {

//               $sum_spent    += str_replace(' ','',$db->f('OUT'));
//               $sum_received += str_replace(' ','',$db->f('IMP'));

                  if (($_POST['opt'] == 'ADD_ACCOUNT') && ($_N_ID == $db->f('OPID'))) {
                      $colors = __COLOR_SETPOINTER_1__;
                      $bgcols = 'pointer1';
                  }
                  else if (isset($id_mod) && $id_mod == $db->f('OPID')) {
                      $_xhtml = $db->f('OPID');
                      $_below = 1;
                      $colors = __COLOR_SETPOINTER_1__;
                      $bgcols = 'pointer1';
                  }
                  else if (isset($ids_mods) && $ids_mods == $db->f('OPID')) {
                      $_xhtml = $db->f('OPID');
                      $_below = 1;
                      $colors = __COLOR_SETPOINTER_1__;
                      $bgcols = 'pointer1';
                  }
                  else if (isset($hid[0]) && $hid[0] == $db->f('OPID')) {
                      $_xhtml = $db->f('OPID');
                      $_below = 1;
                      $colors = __COLOR_SETPOINTER_1__;
                      $bgcols = 'pointer1';
                  }
                  else if (isset($colors) && $colors == __COLOR_DISPLAY_1__) {
                      $colors = __COLOR_DISPLAY_2__;
                      $bgcols = 'display2';
                  }
                  else {
                      $colors  = __COLOR_DISPLAY_1__;
                      $bgcols  = 'display1';
                  }

      $tpl->set_var(array(
             'NAME_NAME'         => isset($_below) && isset($_xhtml) && $_below == 1 && $_xhtml == $db->f('OPID') ? $_VAR['BELOW'] : 'Null'.$z,
             'classbgcolor'      => $bgcols,
             'COLOR'             => $colors,
             'VAL_ID_ACCOUNT'    => $db->f('CAT') == __PART_ID__ ? __PART_ID__ : 0,
             'MESSAGE_JS'        => "if (!confirm('".$_VAR['MESSAGE_JS']['JS_BOOK_LISTING_1']." $sess_user \\n".$_VAR['MESSAGE_JS']['JS_VERIF_DEL_OPE']." ".$db->f('OPID')."\\n".$_VAR['MESSAGE_JS']['JS_ACCOUNT_LANG_1']." ".$name_account."\\n\\n".$_VAR['MESSAGE_JS']['JS_ACCOUNT_LANG_2']."')) return false;",
             'ID_ACCOUNT'        => $db->f('OPID'),
             'ACCOUNT_IMG'       => $db->f('VALID_OP') ? 'oui' : 'non',
             'VAL_IMG_ACCOUNT'   => $db->f('VALID_OP'),
             'FORMAT_ACC_DATE'   => $db->f('DATES'),
             'CHOIX_TERME'       => (($db->f('CAT') == __PART_ID__) ? (($db->f('SOUTT') == 0) ? $_VAR['LANG_ACCOUNT_32'] : $_VAR['LANG_ACCOUNT_31']): $_VAR['LANG_ACCOUNT_6']),
             'SEARCH_CATEGORIE'  => $tools->Reduit_chaine(SQL_SearchCat($db->f('CAT')),__LENGTH_COMMENT__,0),
             'SEARCH_TIERS'      => $tools->Reduit_chaine(SQL_SearchThird($db->f('THIRD')),__LENGTH_COMMENT__,0),
             'SEARCH_NUMEROID'   => $tools->Reduit_chaine($db->f('NUMID'),__LENGTH_NUMERO__,0),
             'COMMENT'           => $db->f('COMMENTS'),
             'FORMAT_DEP_1'      => $tools->formatage($db->f('SOUTT')),
             'FORMAT_DEP_2'      => $tools->formatage($db->f('SOUTT') * $_MPM['lang_euro']),
             'FORMAT_REC_1'      => $tools->formatage($db->f('IMP')),
             'FORMAT_REC_2'      => $tools->formatage($db->f('IMP') * $_MPM['lang_euro']),
             'COLOR_PLUS'        => (strpos($db->f('BALANCE'),'-') !== false ? 'menurouge' : 'menu'),
             'FORMAT_SOLDE_1'    => $tools->formatage($db->f('BALANCE')),
             'FORMAT_SOLDE_2'    => $tools->formatage($db->f('BALANCE') * $_MPM['lang_euro']),
	     "MONTH"		 => $The_mois,
	     "CUR_PAG"		 => $cur_pag,
	     "PREV_LINK"	 => $prev_link,
	     "SUBMIT_PREV"	 => $submit_prev,
	     "NEXT_LINK"	 => $next_link,
	     "SUBMIT_NEXT"	 => $submit_next,
	     "NAV_BEG"		 => $prev_page,
	     "NAV_END"		 => $next_page
      ));
      $tpl->parse('BLOCK_'.$_MPM['BlockInclude'],'BOUCLE_ACCOUNT_LIST',true);
      $z++;
      } ## end of while $db->next_record()

     $sql  = "SELECT OPID,NUMID,VALID_OP, ";
     $sql .= "SOUTT,IMP,BALANCE FROM ".$_MPM['table'][1]." ";
     $sql .= "WHERE TEMPID=1 AND USERID='$sess_pid' AND ACCOUNT='".$_POST['ID']."' ";

     if ($The_mois == 'CRITERIAS') {
      $sql .= "AND VALID_OP=0 ";
      $sql .= "ORDER BY VALID_OP $order, OPID $order";
     } else {
      $sql .= "AND DATE_FORMAT(DATES,'%m-%Y') LIKE '$The_mois%' ";
      $sql .= "ORDER BY DATES $order, OPID $order ";
     }
     $db->query($sql);

     while ($db->next_record()) {

               $sum_spent    += str_replace(' ','',$db->f('SOUTT'));
               $sum_received += str_replace(' ','',$db->f('IMP'));
     }

	$_MPM['BoucleMixed'] = array
      (
             'FORMAT_TOT_DEP_1'  => $tools->formatage($sum_spent),
             'FORMAT_TOT_DEP_2'  => $tools->formatage($sum_spent * $_MPM['lang_euro']),
             'FORMAT_TOT_REC_1'  => $tools->formatage($sum_received),
             'FORMAT_TOT_REC_2'  => $tools->formatage($sum_received * $_MPM['lang_euro']),
             'BALANCE_PLUS'      => (strpos($tools->formatage($sum_received - $sum_spent),'-') !== false ? 'menurouge' : 'menubleu'),
             'BALANCE_TOT_1'     => $tools->formatage($sum_received - $sum_spent),
             'BALANCE_TOT_2'     => $tools->formatage(($sum_received * $_MPM['lang_euro']) - ($sum_spent * $_MPM['lang_euro']))
      );
      $_MPM['BeginMixed'] = array_merge($_MPM['BeginMixed'],$_MPM['BoucleMixed']);
      XHTML_SetFile($_MPM['BlockInclude'],$_MPM['BeginMixed'],4);
}


Return current item: MyPhpMoney