1<?php 2/** 3 * $Id: operate.php,v 1.18 2003/04/02 12:16:54 courou Exp $ 4 * 5 * Author : courou@users.sourceforge.net 6 * Website : http://allreponse.ath.cx 7 * 8 * Support : http://sourceforge.net/projects/myphpmoney/ 9 * CVS : http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/myphpmoney/ 10 */ 11 12/** 13 * INCLUDE FILE 14 */ 15 require_once 'config/settings.inc.php'; 16 17/** 18 * ENTER IN THE SESSION OR BUILD THE LOGIN FORM 19 */ 20 if (SQL_VerifSession()) { 21 22/** 23 * BUILD THE HEADER 24 */ 25 XHTML_header(1,0,1,1,1,1,1,1); 26 27/** 28 * DEFINE VARIABLE GLOBALS 29 */ 30 $PageOrder = 'operate'; 31 $sum_spent = ''; 32 $sum_received = ''; 33 $_POST['yearthird'] = isset($_POST['yearthird']) ? $_POST['yearthird'] : ''; 34 $_MPM['BlockInclude'] = 0; ## for the include template 35 $_MPM['BlockInclude2'] = 0; ## for the include template 36 37/** 38 * SWITCH -- VALIDE THE ACTION 39 */ 40if (isset($_POST['ok'])) { 41 42 switch($_POST['ok']) { 43 44 ## ADD THE NEWS PART 45 case 1 : 46 if ($_POST['ajout_tiers'] != '') { 47 48 $result = SQL_SearchIdThird(1,$_POST['cat'],htmlspecialchars($_POST['ajout_tiers'])); 49 50 if (!$result) { 51 $id = SQL_RecupId(4); 52 53 SQL_InsertThird($id,$_POST['cat'],htmlspecialchars($_POST['ajout_tiers'])); 54 $_POST['S_cat'] = $_POST['cat'].'|'.$id; 55 unset($_POST['opt']); 56 } 57 } 58 break; 59 60 ## ADD THE NEWS THIRD AND NEWS PART 61 case 2 : 62 $id_cat = SQL_RecupId(0); 63 $id_tiers = SQL_RecupId(4); 64 65 $id_cat = SQL_BuildCat(htmlspecialchars($_POST['N_cat']),$id_cat); 66 $id_tiers = SQL_BuildTiers(htmlspecialchars($_POST['N_tiers']),$id_cat,$id_tiers); 67 68 $_POST['S_cat'] = $id_cat.'|'.$id_tiers; 69 unset($_POST['opt']); 70 break; 71 72 ## RENAME THE PART 73 case 3 : 74 if ($_POST['cat'] != __PART_ID__ && $_POST['cat'] != __OPEN_PART__) { 75 76 $result = SQL_SearchIdThird(1,$_POST['cat'],htmlspecialchars($_POST['news_tiers'])); 77 78 if (!$result) { 79 SQL_UpdateThird($_POST['tiers'],htmlspecialchars($_POST['news_tiers'])); 80 } else { 81 XHTML_DisplayJs($_VAR['MESSAGE_JS']['JS_PART_EXITE']); 82 } 83 84 $_POST['S_cat'] = $_POST['cat'].'|'.$_POST['tiers']; 85 unset($_POST['opt']); 86 } 87 88 break; 89 90 ## RENAME THIRD 91 case 4 : 92 if (SQL_IdCat(htmlspecialchars($_POST['news_cat'])) == '') { 93 94 if ($_POST['cat'] == __PART_ID__ && $_POST['cat'] == __OPEN_PART__) { 95 XHTML_DisplayJs(sprintf( 96 $_VAR['MESSAGE_JS']['JS_THIRD_DISPAY_1'], 97 $_MPM['lang_file_name'])); 98 } else { 99 SQL_UpdateCat(htmlspecialchars($_POST['news_cat']),$_POST['cat'],$sess_pid); 100 } 101 } else { 102 XHTML_DisplayJs($_VAR['MESSAGE_JS']['JS_THIRD_EXITE']); 103 } ## end of SQL_IdCat() 104 105 $_POST['S_cat'] = $_POST['cat']; 106 unset($_POST['opt']); 107 break; 108 109 ## DELETE THE THIRD OR THE PART 110 case $_VAR['ACTION_END']['P_FILE_SUPP'] : 111 112 if ($_POST['cat'] != __PART_ID__ && $_POST['cat'] != __OPEN_PART__) { 113 114 ## DELETE THE THIRD AND THE PART 115 if($_POST['tiers'] != '' && $_POST['tiers'] != __ANOTHER_ACCOUNT__) { 116 117 SQL_DeleteThird(1,$_POST['cat'],$_POST['tiers']); 118 SQL_DeleteAccount(1,$_POST['cat'],$_POST['tiers'],4); 119 120 if (SQL_CountThird($_POST['cat']) == 0) {SQL_DeleteCat($_POST['cat']);} 121 SQL_UpdateSolde($_POST['cat'],$_POST['tiers'],1); 122 SQL_DeleteAccount(2,$_POST['cat'],$_POST['tiers'],4); 123 124 ## DELETE THE THIRD 125 } else { 126 SQL_DeleteCat($_POST['cat']); 127 SQL_DeleteThird(2,$_POST['cat'],''); 128 129 SQL_DeleteAccount(1,$_POST['cat'],'',3); 130 SQL_DeleteAccount(2,$_POST['cat'],'',3); 131 132 SQL_UpdateSolde($_POST['cat'],'',2); 133 } 134 } ## end of if $_POST['cat'] != __PART_ID__ && $_POST['cat'] != __OPEN_PART__ 135 136 unset($_POST['S_cat']); 137 unset($_POST['opt']); 138 break; 139 } 140} ## end of if (isset($_POST['ok'])) 141 142 143/** 144 * THE TEMPLATES -- BUILD HEADER OF THIRD PART 145 */ 146 if (isset($_GET['S_cat']) && isset($_GET['page'])) $_POST['S_cat'] = $_GET['S_cat']; 147 148 $_MPM['BlockInclude2'] = MPM_IncludeTemp(0,'header_third_part_simple.tpl','header_third_part_double.tpl'); 149 $_MPM['BeginMixed'] = array 150 ( 151 'LANG_BOOK_13' => sprintf($_VAR['LANG_BOOK_13'],$_VAR['IMG_TXT_EUROS'],$_MPM['lang_money_country']), 152 'LANG_BOOK_14' => sprintf 153 ( 154 $_VAR['LANG_BOOK_14'], 155 __DISPLAY_EURO__ == 2 ? $_MPM['lang_money_country'] : $_VAR['IMG_TXT_EUROS'] 156 ), 157 'OPEN_CLOSE' => XHTML_OPEN_CLOSE(), 158 'OPT_THIRD_DEFAULT_1' => $_VAR['OPT_THIRD_DEFAULT_1'], 159 'LIST_THIRD_PART' => SQL_ListRecursive(isset($_POST['S_cat']) ? $_POST['S_cat'] : '',0,'Plus') 160 ); 161 XHTML_SetFile($_MPM['BlockInclude2'],$_MPM['BeginMixed'],2); 162 163/** 164 * CONDITION FOR THE CHOICE SWITCH OPTION 165 */ 166 if (isset($_POST['S_cat']) && $_POST['S_cat'] != '') { 167 168 if (strstr($_POST['S_cat'],'|')) { 169 $explode = explode('|', $_POST['S_cat']); 170 if ($explode[0] == __ANOTHER_ACCOUNT__ && $explode[1] == __ANOTHER_ACCOUNT__) $_POST['opt'] = 3; 171 if ($explode[0] != __ANOTHER_ACCOUNT__ && $explode[1] == __ANOTHER_ACCOUNT__) { 172 $_POST['cat'] = $explode[0]; 173 $_POST['tiers'] = $explode[1]; 174 $_POST['opt'] = 2; 175 } 176 } else { 177 $explode[0] = $_POST['S_cat']; 178 $explode[1] = ''; 179 } ## end of strstr 180 181/** 182 * SWITCH -- CHOICE TEMPLATES HTML 183 */ 184 if (!isset($_POST['opt'])) $_POST['opt'] = ''; 185 switch($_POST['opt']) { 186 187 // DISPLAY THE OPERATION 188 default : 189 190 if (isset($_GET['S_Year']) && isset($_GET['page'])) $_POST['yearthird'] = $_GET['S_Year']; 191 if ($explode[0] != '') { 192 $search_explode_cat = SQL_SearchCat($explode[0]); 193 $search_explode_third = SQL_SearchThird($explode[1]); 194 195 /** 196 * SQL ORDER BY ... ASC ... DESC 197 */ 198 SQL_Orderby($PageOrder,1); 199 if (isset($_POST['order1'][$PageOrder]) && ereg("_",$_POST['order1'][$PageOrder])) { 200 $this_order = explode("_",$_POST['order1'][$PageOrder]); 201 if ($this_order[1] == 0) $order = "DATES ".$this_order[0]; 202 if ($this_order[1] == 1) $order = "ACCOUNT ".$this_order[0]; 203 if ($this_order[1] == 2) $order = "NUMID ".$this_order[0]; 204 if ($this_order[1] == 3) $order = "COMMENTS ".$this_order[0]; 205 if (!isset($order)) $order = "DATES asc"; 206 } else { 207 $order = "DATES asc"; 208 } 209 210 $_MPM['BlockInclude'] = MPM_IncludeTemp(0,'form_third_part_simple.tpl','form_third_part_double.tpl'); 211 $_MPM['BeginMixed'] = array 212 ( 213 'IMG_ASC_DESC1' => XHTML_ASC_DESC($PageOrder,'asc_0','desc_0',1), 214 'IMG_ASC_DESC2' => XHTML_ASC_DESC($PageOrder,'asc_1','desc_1',1), 215 'IMG_ASC_DESC3' => XHTML_ASC_DESC($PageOrder,'asc_2','desc_2',1), 216 'IMG_ASC_DESC4' => XHTML_ASC_DESC($PageOrder,'asc_3','desc_3',1), 217 'LANG_ACCOUNT_21' => $_VAR['LANG_ACCOUNT_21'], 218 '_ID_PAYS' => $_MPM['lang_country_id'], 219 'IMG_TXT_EUROS' => __DISPLAY_EURO__ == 2 ? $_MPM['lang_money_country'] : $_VAR['IMG_TXT_EUROS'], 220 'IMG_ALT_EUROS' => __DISPLAY_EURO__ == 2 ? $_MPM['lang_money_country'] : $_VAR['IMG_ALT_EUROS'], 221 'DISPLAY_CAT' => $explode[0], 222 'DISPLAY_TIERS' => $explode[1], 223 'DISPLAY_S_CAT' => $_POST['S_cat'], 224 'SEARCH_CAT' => '['.$search_explode_cat.']', 225 'MESS_PART' => $explode[1] != '' && $explode[1] != __ANOTHER_ACCOUNT__ ? $_VAR['MESS_PART'] : '', 226 'SEARCH_TIERS' => $explode[1] != '' && $explode[1] != __ANOTHER_ACCOUNT__ ? '['.$search_explode_third.']' : '', 227 'MESS_THIRD' => $_VAR['MESS_THIRD'], 228 'LANG_ACCOUNT_9' => $_VAR['LANG_ACCOUNT_9'], 229 'SELECT_YEAR' => XHTML_SelectYearMonth(4,$_POST['yearthird'],SQL_SearchYearOperate($explode[0],$explode[1]),'yearthird') 230 ); 231 XHTML_SetFile($_MPM['BlockInclude'],'',0); 232 233 if (empty($_GET['page'])) $_GET['page'] = 1; 234 if (empty($total)) { 235 $nbre_rows = "SELECT count(*) as QTE FROM ".$_MPM['table'][1]." WHERE"; 236 if (isset($_POST['yearthird']) && strlen($_POST['yearthird']) == 4) { 237 $nbre_rows .= " DATES LIKE '%".$_POST['yearthird']."%' AND"; 238 } 239 $nbre_rows .= " TEMPID=1 AND USERID='$sess_pid' AND "; 240 if($explode[1] != "" && $explode[1] != __ANOTHER_ACCOUNT__) { 241 $nbre_rows .= "CAT='$explode[0]' AND "; 242 } else { 243 $nbre_rows .= "CAT='$explode[0]' OR "; 244 } 245 $nbre_rows .= "THIRD='$explode[1]' ORDER BY ".$order; 246 $db->query($nbre_rows); 247 $db->next_record(); 248 $total=$db->f('QTE'); 249 } 250 251 $debut = ($_GET['page'] - 1) * __NB_OF_PAGE__; 252 253 ## For current display 254 $select = "SELECT OPID,NUMID,DATE_FORMAT(DATES,'%d-%m-%Y') as THE_DATES,THIRD,COMMENTS,OUT,IMP,ACCOUNT "; 255 $select .= "FROM ".$_MPM['table'][1]." WHERE"; 256 if (isset($_POST['yearthird']) && strlen($_POST['yearthird']) == 4) { 257 $select .= " DATES LIKE '%".$_POST['yearthird']."%' AND"; 258 } 259 $select .= " TEMPID=1 AND USERID='$sess_pid' AND CAT='$explode[0]' "; 260 $select .= (($explode[1] != "" && $explode[1] != __ANOTHER_ACCOUNT__) ? 'AND ': 'OR ' ); 261 $select .= "THIRD='$explode[1]' ORDER BY ".$order." LIMIT $debut,".__NB_OF_PAGE__; 262 263 $db->query($select); 264 265 $tpl->set_block('FILE_'.$_MPM['BlockInclude'].'','BOUCLE_THIRD_PART','BOUCLE_BEGIN_THIRD'); 266 267 while ($db->next_record()) { 268 $_tiers=$db->f('THIRD'); 269 $_depense=$db->f('OUT'); 270 $_recette=$db->f('IMP'); 271 272 $sum_spent += $_depense; 273 $sum_received += $_recette; 274 if ($_depense == 0 || $_recette == '') { $_montant = $_recette; $color = 'menu';} 275 if ($_recette == 0 || $_depense == '') { $_montant = - $_depense; $color = 'menurouge';} 276 277 $tpl->set_var(array( 278 'IMAGE_LOUPE' => $_MPM['img_loupe'], 279 'HTTP_HOME_ACCOUNT' => $_MPM['file_account'], 280 'B_THIRD_ID' => $db->f('OPID'), 281 'B_THIRD_DATE' => $db->f('THE_DATES'), 282 'BB_THIRD_ACCOUNT' => $db->f('ACCOUNT'), 283 'BB_THIRD_DATE' => ereg_replace('^([0-9]{1,2})-([0-9]{1,2})-([0-9]{2,4})$', '\2-\3', $db->f('THE_DATES')), 284 'B_THIRD_ACCOUNT' => $tools->Reduit_chaine(SQL_NameAccount($db->f('ACCOUNT')),__LENGTH_ACCOUNT__,0), 285 'B_THIRD_NUMEROID' => $tools->Reduit_chaine($db->f('NUMID'),__LENGTH_NUMERO__,0), 286 'B_THIRD_COMMENT' => $tools->Reduit_chaine($db->f('COMMENTS'),__LENGTH_COMMENT__,0), 287 'B_THIRD_AMOUNT' => $tools->formatage($_montant), 288 'B_THIRD_AMOUNT_OTHER' => $tools->formatage($_montant * $_MPM['lang_euro']), 289 'FORMAT_COLOR' => $color, 290 'DISPLAY_DATE' => $_MPM['DATE_DAYS'], 291 'classbgcolor' => isset($colors) && $colors == __COLOR_DISPLAY_1__ ? 'display2' : 'display1', 292 'COLOR' => isset($colors) && $colors == __COLOR_DISPLAY_1__ ? $colors = __COLOR_DISPLAY_2__ : $colors = __COLOR_DISPLAY_1__ 293 )); 294 $tpl->parse('BOUCLE_BEGIN_THIRD','BOUCLE_THIRD_PART',true); 295 } ## end of while $db 296 297 298 $_result = $sum_received - $sum_spent; 299 $the_cat = str_replace('"', "'", $tools->add_slashes($search_explode_cat)); 300 $the_tiers = str_replace('"', "'", $tools->add_slashes($search_explode_third)); 301 $nbpages = ceil($total / __NB_OF_PAGE__); 302 if ($nbpages == '' || $nbpages == 0) $nbpages = 1; 303 304 $tpl->set_var(array( 305 'RENAME' => $_VAR['RENAME'], 306 'B_THIRD_RESULT' => $tools->formatage($_result), 307 'B_THIRD_RESULT_OTHER' => $tools->formatage($_result * $_MPM['lang_euro']), 308 'FORMAT_COLOR' => isset($color) ? $color : 'Chiffre', 309 'ACTION_BEGIN_THIRD_PART'=> $_VAR['ACTION_END']['P_FILE_SUPP'] 310 )); 311 $tpl->set_block('FILE_'.$_MPM['BlockInclude'].'','BOUCLE_THIRD_PAGE','BOUCLE_BEGIN_THIRD_PAGE'); 312 313 for ($i = 1; $i <= $nbpages; $i++) { 314 315 $tpl->set_var(array( 316 'II_PAGES' => $i == $_GET['page'] 317 ? $i 318 : '<a class="menu" href="'.$_SERVER['PHP_SELF'].'?S_cat='.$_POST['S_cat'].'&page='.$i.'&S_Year='.$_POST['yearthird'].'#'.$_VAR['BELOW'].'"> '.$i.' </a>' 319 )); 320 $tpl->parse('BOUCLE_BEGIN_THIRD_PAGE','BOUCLE_THIRD_PAGE',true); 321 } ## end of for $i <= $nbpages 322 323 324 if ($explode[0] != __PART_ID__ && $explode[0] != __OPEN_PART__) { 325 326 $mes = $_VAR['MESSAGE_JS']['JS_THIRD_BEGIN_DEL']." : "; 327 if ($explode[1] == '') { 328 $mes .= $_VAR['MESSAGE_JS']['JS_THIRD_BEGIN']." [$the_cat] "; 329 $mes .= $_VAR['MESSAGE_JS']['JS_THIRD_DISPAY']; 330 } else { 331 $mes .= $_VAR['MESSAGE_JS']['JS_PART_BEGIN_DEL']." [$the_tiers] "; 332 $mes .= $_VAR['DUMP_SEPARATOR']." ".$_VAR['MESSAGE_JS']['JS_THIRD_BEGIN']; 333 $mes .= "[$the_cat] ".$_VAR['MESSAGE_JS']['JS_THIRD_DISPAY']; 334 } 335 336 $_MPM['BoucleMixed'] = array 337 ( 338 'CONDITION_FORM' => XHTML_SetFile('form_opt_third_1.tpl','',1), 339 'CONDITION_THIRD' => XHTML_SetFile('form_third_submit.tpl','',1), 340 'THIRD_ADD' => $_VAR['THIRD_ADD'], 341 'MESS_ADD_PART' => $_VAR['MESS_ADD_PART'], 342 'MESSAGE_JS_1' => "if(confirm('$mes')) return true; else return false;" 343 ); 344 345 } else { 346 347 $mes = sprintf($_VAR['MESSAGE_JS']['JS_THIRD_DISPAY_1'],$_MPM['lang_file_name']); 348 $_MPM['BoucleMixed'] = array 349 ( 350 'CONDITION_FORM' => XHTML_SetFile('form_opt_third_2.tpl','',1), 351 'CONDITION_THIRD'=> '', 352 'THIRD_ADD' => $_VAR['THIRD_ADD'], 353 'RENAME' => $_VAR['RENAME'], 354 'MESSAGE_JS_1' => "if(confirm('$mes')) return false; else return false;" 355 ); 356 357 } ## end of $explode[0] != __PART_ID__ && $explode[0] != __OPEN_PART__ 358 359 $_MPM['BeginMixed'] = array_merge($_MPM['BeginMixed'],$_MPM['BoucleMixed']); 360 XHTML_SetFile($_MPM['BlockInclude'],$_MPM['BeginMixed'],4); 361 } ## end of $explode[0] != '' 362 break; 363 364 // TEMPLATE FORM FOR THE ADD NEWS THIRD 365 case 2 : 366 case $_VAR['MESS_ADD_PART'] : 367 $search_cat = SQL_SearchCat($_POST['cat']); 368 if ($search_cat != '' ) { 369 $_MPM['BeginMixed'] = array 370 ( 371 'THE_CAT' => str_replace('"', "'",$search_cat), 372 'MESS_PART_FORM_HOME' => $_VAR['MESS_PART_FORM_HOME'], 373 'MESS_PART_SIMPLE' => $_VAR['MESS_PART_SIMPLE'], 374 'MESS_NOW_PART' => $_VAR['MESS_NOW_PART'], 375 'CAT' => $_POST['cat'], 376 'TIERS' => $_POST['tiers'], 377 'ADD_TIERS' => isset($_POST['ajout_tiers']) ? $_POST['ajout_tiers'] : '' 378 ); 379 XHTML_SetFile('form_news_part.tpl',$_MPM['BeginMixed'],2); 380 } 381 break; 382 383 // TEMPLATE FORM FOR THE ADD NEWS THIRD AND PART 384 case 3 : 385 case $_VAR['THIRD_ADD'] : 386 387 $_MPM['BeginMixed'] = array 388 ( 389 'THIRD_NEWS_THIRD' => $_VAR['THIRD_NEWS_THIRD'], 390 'MESS_CALENDAR_NEW' => $_VAR['MESS_CALENDAR_NEW'], 391 'MESS_THIRD_FORM_HOME' => $_VAR['MESS_THIRD_FORM_HOME'], 392 'MESS_PART_SIMPLE' => $_VAR['MESS_PART_SIMPLE'], 393 'N_CAT' => isset($_POST['N_cat']) ? $_POST['N_cat'] : '', 394 'N_TIERS' => isset($_POST['N_tiers']) ? $_POST['N_tiers'] : '' 395 ); 396 XHTML_SetFile('form_news_third.tpl',$_MPM['BeginMixed'],2); 397 break; 398 399 // TEMPLATE FORM FOR RENAME THE THIRD OR THE PART 400 case $_VAR['RENAME'] : 401 402 $_MPM['BeginMixed'] = array 403 ( 404 'THIRD_VALID_MODIF' => $_VAR['THIRD_VALID_MODIF'], 405 'RENAME_CAT' => $_POST['cat'], 406 'RENAME_TIERS' => $_POST['tiers'], 407 'MESS_RENAME_FORM_HOME' => $_POST['tiers'] != '' ? $_VAR['MESS_MODIF_PART'] : $_VAR['MESS_CALENDAR_MODIF'], 408 'CHOICE_RENAME_JS' => $_POST['tiers'] != '' ? 'return Verif_modif_tiers(this);' : 'return Verif_modif_cat(this);', 409 'CHOICE_RENAME_LANG_1' => $_POST['tiers'] != '' ? $_VAR['MESS_OLD_PART'] : $_VAR['MESS_OLD_THIRD'], 410 'CHOICE_RENAME_TXT' => $_POST['tiers'] != '' 411 ? stripslashes(str_replace('"', "'", SQL_SearchThird($_POST['tiers']))) 412 : stripslashes(str_replace('"', "'", SQL_SearchCat($_POST['cat']))), 413 'CHOICE_RENAME_LANG_2' => $_POST['tiers'] != '' ? $_VAR['MESS_PART_SIMPLE'] : $_VAR['MESS_CALENDAR_NEW'], 414 'CHOICE_RENAME_NAME' => $_POST['tiers'] != '' ? 'news_tiers' : 'news_cat', 415 'CHOICE_RENAME_VALUE' => isset($_POST['news_tiers']) 416 ? $_POST['news_tiers'] 417 : isset($_POST['news_cat']) 418 ? $_POST['news_cat'] 419 : '', 420 'CHOICE_RENAME_T' => $_POST['tiers'] != '' ? 3 : 4 421 ); 422 XHTML_SetFile('form_rename_third_part.tpl',$_MPM['BeginMixed'],2); 423 break; 424 } ## end of switch $_POST['opt'] 425} ## end of if (isset($_POST['S_cat']) && $_POST['S_cat'] != '') 426 427 } else { 428 XHTML_DisplayLogin(); 429 } ## end if (SQL_VerifSession()) 430 431/** 432 * BUILD THE FOOTER 433 */ 434 XHTML_footer();