Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.41 KB | None | 0 0
  1. <?php
  2. require_once ( '../config.php' );
  3. require_once ( $GLOBALS [ "Config" ] [ "Base_Dir" ] . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . "Bdd" . '.php' );
  4. require_once ( $GLOBALS [ "Config" ] [ "Base_Dir" ] . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . "Annonce" . '.php' );
  5.  
  6. Function Verif_Static ( ) {
  7.  
  8. if ( !is_string ( $_POST["type_transaction"] ) || !in_array ( $_POST["type_transaction"], Array ( 'vente', 'location') ) )
  9. Return "Veuillez choisir un type de transaction !";
  10.  
  11. if ( !is_string ( $_POST["type_prop"] ) || !in_array ( $_POST["type_prop"], Array ( 'appartement', 'bureau_local',
  12. 'immeuble', 'maison', 'terrain') ) )
  13. Return "Veuillez choisir un type de bien immobilier";
  14.  
  15. if ( !is_string ( $_POST["titre"] ) || empty ( $_POST["titre"] ) )
  16. Return "Veuillez entrer un titre";
  17.  
  18. if ( strlen ( $_POST["titre"] ) <= 20 )
  19. Return "Veuillez entrer un titre d'une longueur de plus de 20 catectaires";
  20.  
  21. if ( !is_string ( $_POST["description"] ) || empty ( $_POST["description"] ) )
  22. Return "Veuillez entrer une description";
  23.  
  24. if ( strlen ( $_POST["description"] ) <= 100 )
  25. Return "Veuillez entrer une description d'une longueur de plus de 100 catectaires";
  26.  
  27. if ( !is_string ( $_POST["superficie"] ) || !is_numeric ( $_POST["superficie"] ) )
  28. Return "Veuillez entrer une superficie valide";
  29.  
  30. if ( !is_string ( $_POST["prix"] ) || !is_numeric ( $_POST["prix"] ) )
  31. Return "Veuillez entrer un prix valide";
  32.  
  33. if ( !is_string ( $_POST["type_prix"] ) || !in_array ( $_POST["type_prix"], Array ( 'fixe', 'negociable') ) )
  34. Return "Veuillez l'etat de votre prix";
  35.  
  36. if ( !is_string ( $_POST["adresse"] ) || empty ( $_POST["adresse"] ) )
  37. Return "veuillez entrer votre adresse";
  38.  
  39. if ( !is_numeric ( $_POST["wilaya"] ) || $_POST["wilaya"] > 48 || $_POST["wilaya"] < 1 )
  40. Return "veuillez choisir une wilaya";
  41.  
  42. if ( !is_numeric ( $_POST["region_"] ) )
  43. Return "veuillez choisir une commune";
  44.  
  45. Return TRUE;
  46. }
  47.  
  48. Function Verif_Static2 ( $Type ) {
  49.  
  50. switch ( $Type ) {
  51.  
  52. case 'appartement':
  53.  
  54. if ( !is_numeric ( $_POST ["appartement"]['num_etages'] ) )
  55. Return "Veuillez choisir un numero d'etage";
  56.  
  57. if ( !is_numeric ( $_POST ["appartement"]['nbr_pieces'] ) )
  58. Return "Veuillez choisir le nomre de pieces";
  59.  
  60.  
  61. Return TRUE;
  62. break;
  63.  
  64. case 'bureau_local':
  65.  
  66. if ( !is_numeric ( $_POST ["bureau_local"]['nbr_etages'] ) )
  67. Return "Veuillez choisir un nombre d'etages";
  68.  
  69. Return TRUE;
  70. break;
  71.  
  72. case 'immeuble':
  73. if ( $_POST ["immeuble"]["type_appart_f2"] == 0 &&
  74. $_POST ["immeuble"]["type_appart_f3"] == 0 &&
  75. $_POST ["immeuble"]["type_appart_f4"] == 0 &&
  76. $_POST ["immeuble"]["type_appart_f5"] == 0 &&
  77. $_POST ["immeuble"]["type_appart_plus"] == 0 )
  78. Return "Veuillez designer de quelle type d'appartements vous disposez";
  79.  
  80. if ( !is_numeric ( $_POST ["immeuble"]['nbr_etages'] ) )
  81. Return "Veuillez choisir un nombre d'etages";
  82.  
  83. Return TRUE;
  84. break;
  85.  
  86. case 'maison':
  87.  
  88. if ( !is_numeric ( $_POST ["maison"]['nbr_etages'] ) )
  89. Return "Veuillez choisir un nombre d'etages";
  90.  
  91. if ( !is_numeric ( $_POST ["maison"]['nbr_pieces'] ) )
  92. Return "Veuillez choisir le nombre de pieces";
  93.  
  94. Return TRUE;
  95. break;
  96.  
  97. case 'terrain':
  98. Return TRUE;
  99. break;
  100.  
  101. default:
  102. Return FALSE;
  103. break;
  104. }
  105.  
  106. Return True;
  107. }
  108.  
  109. Function array_map_recursive ( ) {
  110.  
  111. $args = func_get_args();
  112. $callback = array_shift($args);
  113. $fn = __FUNCTION__;
  114.  
  115. $out = array();
  116. $max = count(max($args));
  117. for($i=0; $i<$max; $i++) {
  118. if(count($args)==1) {
  119. foreach($args[0] as $key=>$value) {
  120. if(is_array($value))
  121. $out[$key] = $fn($callback, $value);
  122. else
  123. $out[$key] = call_user_func($callback, $value);
  124. }
  125. } else {
  126. $is_array = false;
  127. $callbacks_args = array();
  128. foreach($args as $array) {
  129. $values = array_values($array);
  130. if(isset($values[$i]))
  131. $value = $values[$i];
  132. else
  133. $value = '';
  134.  
  135. if(is_array($value)) {
  136. $is_array = true;
  137. $callbacks_args[] = $value;
  138. } else {
  139. $callbacks_args[] = $value;
  140. }
  141. }
  142.  
  143. if($is_array) {
  144. $m = count(max($callbacks_args));
  145. $new_callback_args = array($callback);
  146. foreach($callbacks_args as $arg) {
  147. if(!is_array($arg))
  148. $new_callback_args[] = array_fill(0, $m, $arg);
  149. else
  150. $new_callback_args[] = $arg;
  151. }
  152. $out[] = call_user_func_array($fn, $new_callback_args);
  153. } else {
  154. $out[] = call_user_func_array($callback, $callbacks_args);
  155. }
  156. }
  157. }
  158.  
  159. return $out;
  160. }
  161.  
  162. Function Format_Post ( ) {
  163.  
  164. $_POST = array_map_recursive ('trim', $_POST );
  165. $_POST = array_map_recursive ('mysql_escape_string', $_POST );
  166.  
  167. switch ( $_POST['type_prop'] ) {
  168.  
  169. case 'appartement':
  170. $_POST ["appartement"]["meuble"] = ( isset ( $_POST ["appartement"]["meuble"] ) ? 1 : 0 );
  171. $_POST ["appartement"]["terrasse"] = ( isset ( $_POST ["appartement"]["terrasse"] ) ? 1 : 0 );
  172. $_POST ["appartement"]["balcons"] = ( isset ( $_POST ["appartement"]["balcons"] ) ? 1 : 0 );
  173. $_POST ["appartement"]["ascenseur"] = ( isset ( $_POST ["appartement"]["ascenseur"] ) ? 1 : 0 );
  174. $_POST ["appartement"]["cuisine"] = ( isset ( $_POST ["appartement"]["cuisine"] ) ? 1 : 0 );
  175. $_POST ["appartement"]["parking"] = ( isset ( $_POST ["appartement"]["parking"] ) ? 1 : 0 );
  176. break;
  177.  
  178. case 'bureau_local':
  179. $_POST ["bureau_local"]["sanitaires"] = ( isset ( $_POST ["bureau_local"]["sanitaires"] ) ? 1 : 0 );
  180. $_POST ["bureau_local"]["vestiaires"] = ( isset ( $_POST ["bureau_local"]["vestiaires"] ) ? 1 : 0 );
  181. $_POST ["bureau_local"]["douche"] = ( isset ( $_POST ["bureau_local"]["douche"] ) ? 1 : 0 );
  182. $_POST ["bureau_local"]["parking"] = ( isset ( $_POST ["bureau_local"]["parking"] ) ? 1 : 0 );
  183. $_POST ["bureau_local"]["accessibilite"]= ( isset ( $_POST ["bureau_local"]["accessibilite"] ) ? 1 : 0 );
  184. break;
  185.  
  186. case 'immeuble':
  187. $_POST ["immeuble"]["ascenseur"] = ( isset ( $_POST ["immeuble"]["ascenseur"] ) ? 1 : 0 );
  188. $_POST ["immeuble"]["commerce"] = ( isset ( $_POST ["immeuble"]["commerce"] ) ? 1 : 0 );
  189. $_POST ["immeuble"]["garage"] = ( isset ( $_POST ["immeuble"]["garage"] ) ? 1 : 0 );
  190. $_POST ["immeuble"]["parking"] = ( isset ( $_POST ["immeuble"]["parking"] ) ? 1 : 0 );
  191. $_POST ["immeuble"]["accessibilite"] = ( isset ( $_POST ["immeuble"]["accessibilite"] ) ? 1 : 0 );
  192. $_POST ["immeuble"]["type_appart_f2"] = ( isset ( $_POST ["immeuble"]["type_appart_f2"] ) ? 1 : 0 );
  193. $_POST ["immeuble"]["type_appart_f3"] = ( isset ( $_POST ["immeuble"]["type_appart_f3"] ) ? 1 : 0 );
  194. $_POST ["immeuble"]["type_appart_f4"] = ( isset ( $_POST ["immeuble"]["type_appart_f4"] ) ? 1 : 0 );
  195. $_POST ["immeuble"]["type_appart_f5"] = ( isset ( $_POST ["immeuble"]["type_appart_f5"] ) ? 1 : 0 );
  196. $_POST ["immeuble"]["type_appart_plus"] = ( isset ( $_POST ["immeuble"]["type_appart_plus"])? 1 : 0 );
  197. break;
  198.  
  199. case 'maison':
  200. $_POST ["maison"]["meubles"] = ( isset ( $_POST ["maison"]["meubles"] ) ? 1 : 0 );
  201. $_POST ["maison"]["terrasse"] = ( isset ( $_POST ["maison"]["terrasse"] ) ? 1 : 0 );
  202. $_POST ["maison"]["balcons"] = ( isset ( $_POST ["maison"]["balcons"] ) ? 1 : 0 );
  203. $_POST ["maison"]["ascenseur"] = ( isset ( $_POST ["maison"]["ascenseur"] ) ? 1 : 0 );
  204. $_POST ["maison"]["acces_handicapes"] = ( isset ( $_POST ["maison"]["acces_handicapes"] ) ? 1 : 0 );
  205. $_POST ["maison"]["jardin"] = ( isset ( $_POST ["maison"]["jardin"] ) ? 1 : 0 );
  206. $_POST ["maison"]["picine"] = ( isset ( $_POST ["maison"]["picine"] ) ? 1 : 0 );
  207. $_POST ["maison"]["garage"] = ( isset ( $_POST ["maison"]["garage"] ) ? 1 : 0 );
  208. break;
  209.  
  210. case 'terrain':
  211. $_POST ["terrain"]["accessibilite"] = ( isset ( $_POST ["terrain"]["accessibilite"] ) ? 1 : 0 );
  212. $_POST ["terrain"]["mitoyennete"] = ( isset ( $_POST ["terrain"]["mitoyennete"] ) ? 1 : 0 );
  213. break;
  214. }
  215. }
  216.  
  217. Function Format_Data ( $Type ) {
  218. switch ( $_POST['type_prop'] ) {
  219.  
  220. case 'appartement':
  221. Return Array (
  222. 'id' => '',
  223. 'num_etages' => $_POST ["appartement"]['num_etages'],
  224. 'nbr_pieces' => $_POST ["appartement"]['nbr_pieces'],
  225. 'meubles' => $_POST ["appartement"]["meuble"],
  226. 'terrasse' => $_POST ["appartement"]["terrasse"],
  227. 'balcons' => $_POST ["appartement"]["balcons"],
  228. 'ascenseur' => $_POST ["appartement"]["ascenseur"],
  229. 'cuisine_equipe'=> $_POST ["appartement"]["cuisine"],
  230. 'parking' => $_POST ["appartement"]["parking"]
  231. );
  232. break;
  233.  
  234. case 'bureau_local':
  235. Return Array (
  236. 'id' => '',
  237. 'nbr_etages' => $_POST ["bureau_local"]['nbr_etages'],
  238. 'parking' => $_POST ["bureau_local"]['parking'],
  239. 'accessibilite' => $_POST ["bureau_local"]['accessibilite'],
  240. 'douche' => $_POST ["bureau_local"]['douche'],
  241. 'vestiaires' => $_POST ["bureau_local"]['vestiaires'],
  242. 'sanitaires' => $_POST ["bureau_local"]['sanitaires']
  243. );
  244. break;
  245.  
  246. case 'immeuble':
  247.  
  248. $Type_Appart .= ( isset ( $_POST ["immeuble"]["type_appart_f2"] ) ? 'F2 ' : NULL );
  249. $Type_Appart .= ( isset ( $_POST ["immeuble"]["type_appart_f3"] ) ? 'F3 ' : NULL );
  250. $Type_Appart .= ( isset ( $_POST ["immeuble"]["type_appart_f4"] ) ? 'F4 ' : NULL );
  251. $Type_Appart .= ( isset ( $_POST ["immeuble"]["type_appart_f5"] ) ? 'F5 ' : NULL );
  252. $Type_Appart .= ( isset ( $_POST ["immeuble"]["type_appart_plus"])? 'Plus ' : NULL );
  253.  
  254. Return Array (
  255. 'id' => '',
  256. 'nbr_etages' => $_POST ["immeuble"]['nbr_etages'],
  257. 'type' => $Type_Appart,
  258. 'ascensseur' => $_POST ["immeuble"]['ascenseur'],
  259. 'commerce' => $_POST ["immeuble"]['commerce'],
  260. 'garage' => $_POST ["immeuble"]['garage'],
  261. 'parking' => $_POST ["immeuble"]['parking'],
  262. 'accessibilite' => $_POST ["immeuble"]['accessibilite']
  263. );
  264. break;
  265.  
  266. case 'maison':
  267. Return Array (
  268. 'id' => '',
  269. 'nbr_etages' => $_POST ["maison"]['nbr_etages'],
  270. 'nbr_pieces' => $_POST ["maison"]['nbr_pieces'],
  271. 'garage' => $_POST ["maison"]['garage'],
  272. 'piscine' => $_POST ["maison"]['piscine'],
  273. 'jardin' => $_POST ["maison"]['jardin'],
  274. 'meubles' => $_POST ["maison"]['meubles'],
  275. 'terrasse' => $_POST ["maison"]['terrasse'],
  276. 'balcons' => $_POST ["maison"]['balcons'],
  277. 'cuisine_equipe' => $_POST ["maison"]['cuisine'],
  278. 'acces_handicapes' => $_POST ["maison"]['acces_handicapes']
  279. );
  280. break;
  281.  
  282. case 'terrain':
  283. Return Array (
  284. 'id' => '',
  285. 'accesibilite' => $_POST ["terrain"]['accessibilite'],
  286. 'mitoyennete' => $_POST ["terrain"]['mitoyennete']
  287. );
  288. break;
  289. }
  290. }
  291.  
  292.  
  293.  
  294. Format_Post ( );
  295.  
  296.  
  297. if ( is_string ( Verif_Static ( ) ) ) {
  298. echo '<img title="" alt="" src="images/err2.png"><p>'.Verif_Static ( ).'</p>';
  299. }
  300.  
  301. else {
  302. if ( is_string ( Verif_Static2 ( $_POST['type_prop'] ) ) ) {
  303. echo '<img title="" alt="" src="images/err2.png"><p>'.Verif_Static2 ( $_POST['type_prop'] ).'</p>';
  304. }
  305. else
  306. {
  307. $Data = Format_Data ( $_POST['type_prop'] );
  308. $a = new Annonce ( );
  309. $a -> Insert_Advance_Data ( $_POST['type_prop'], $Data );
  310.  
  311. $a -> Insert_Basic_Data ( $_POST["prix"], $_POST["type_prix"], $_POST["superficie"], $_POST["region_"], $_POST["type_transaction"], $_POST["titre"], "0", $_POST["description"], $_POST["adresse"], $_SESSION['account']['id'] );
  312.  
  313. echo 1;
  314. }
  315. }
  316.  
  317.  
  318. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement