Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

action.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <?php
  2. header("Content-Type: text/html; charset=utf-8");
  3. header("Cache-Control: no-cache");
  4. if (!$_POST) exit;
  5. require_once dirname(__FILE__)."/config.php";
  6. require_once dirname(__FILE__)."/constants.php";
  7. require_once dirname(__FILE__)."/helpers.php";
  8. /************************************************/
  9. /* Validation */
  10. /************************************************/
  11. /* Debug config array */
  12. if (isset($config["debug"]) && $config["debug"]){
  13. $config["debug_array"] = config_check($config);
  14. if ( !empty($config["debug_array"]) ){
  15. debugger( array(DEBUG_CONFIG_MESSAGE, $config["debug_array"]) );
  16. exit;
  17. }
  18. }
  19. /* Arrays */
  20. $form_data = array();
  21. $config["errors"] = array();
  22. /* Validate POST array, delete all special symbols */
  23. $post = post_array_check($_POST);
  24. /* Combine arrays */
  25. foreach ($config["rules"] as $field => $rules) {
  26. if (substr($field, -2) === "[]"){
  27. $field = substr($field, 0, -2);
  28. }
  29. if (isset($_FILES[$field])){
  30. continue;
  31. }
  32. if ($field === "recaptcha") {
  33. $form_data[$field] = isset($post["g-recaptcha-response"]) ? $post["g-recaptcha-response"] : false;
  34. continue;
  35. }
  36. if (!isset($post[$field])) {
  37. $form_data[$field] = false;
  38. continue;
  39. }
  40. $form_data[$field] = $post[$field];
  41. }
  42. /* Validation apply to form data except files */
  43. foreach ($form_data as $field => $value) {
  44. /* Token validation */
  45. if ($field === "token" && $config["rules"][$field]["required"]) {
  46. require_once dirname(__FILE__)."/csrf.php";
  47. if ( token_check($form_data[$field], $config["rules"][$field]) ){
  48. debugger( array($config["messages"][$field]["required"]) );
  49. exit;
  50. }
  51. }
  52. /* reCaptcha validation */
  53. if ($field === "recaptcha" && $config["rules"][$field]["required"]) {
  54. require_once dirname(__FILE__)."/reCaptcha/autoload.php";
  55. if ( isset($config["rules"][$field]["alternative_mode"]) && $config["rules"][$field]["alternative_mode"] ) {
  56. // If file_get_contents() is locked down on your PHP installation to disallow
  57. // its use with URLs, then you can use the alternative request method instead.
  58. // This makes use of fsockopen() instead.
  59. $re_captcha = new \ReCaptcha\ReCaptcha(RECAPTCHA_SERVER_SECRET_KEY, new \ReCaptcha\RequestMethod\SocketPost());
  60. } else {
  61. // Create an instance of the service using your secret key
  62. $re_captcha = new \ReCaptcha\ReCaptcha(RECAPTCHA_SERVER_SECRET_KEY);
  63. }
  64. // Make the call to verify the response and also pass the user's IP address
  65. $valid_captcha = $re_captcha->verify($form_data[$field], $_SERVER["REMOTE_ADDR"]);
  66. if (!$valid_captcha->isSuccess()) {
  67. debugger( array($config["messages"][$field]["required"]) );
  68. exit;
  69. }
  70. }
  71. /* Input fields validation */
  72. foreach ($config["rules"][$field] as $rule => $rule_value){
  73. switch ($rule) {
  74. case "required":
  75. if ($rule_value === true) {
  76. if ( min_length_check($form_data[$field], 1) ){
  77. $config["errors"][] = $config["messages"][$field][$rule];
  78. continue 3;
  79. }
  80. }
  81. break;
  82. case "email":
  83. if ($rule_value === true) {
  84. if ( email_check($form_data[$field]) ){
  85. $config["errors"][] = $config["messages"][$field][$rule];
  86. continue 3;
  87. }
  88. }
  89. break;
  90. case "url":
  91. if ($rule_value === true) {
  92. if ( url_check($form_data[$field]) ){
  93. $config["errors"][] = $config["messages"][$field][$rule];
  94. continue 3;
  95. }
  96. }
  97. break;
  98. case "integer":
  99. if ($rule_value === true) {
  100. if ( integer_сheck($form_data[$field]) ){
  101. $config["errors"][] = $config["messages"][$field][$rule];
  102. continue 3;
  103. }
  104. }
  105. break;
  106. case "number":
  107. if ($rule_value === true) {
  108. if ( number_сheck($form_data[$field]) ){
  109. $config["errors"][] = $config["messages"][$field][$rule];
  110. continue 3;
  111. }
  112. }
  113. break;
  114. case "minlength":
  115. if ( min_length_check( $form_data[$field], $rule_value ) ){
  116. $config["errors"][] = $config["messages"][$field][$rule];
  117. continue 3;
  118. }
  119. break;
  120. case "maxlength":
  121. if ( max_length_check( $form_data[$field], $rule_value ) ){
  122. $config["errors"][] = $config["messages"][$field][$rule];
  123. continue 3;
  124. }
  125. break;
  126. case "rangelength":
  127. if ( range_length_check( $form_data[$field], $rule_value ) ){
  128. $config["errors"][] = $config["messages"][$field][$rule];
  129. continue 3;
  130. }
  131. break;
  132. case "minvalue":
  133. if ( min_value_сheck( $form_data[$field], $rule_value ) ){
  134. $config["errors"][] = $config["messages"][$field][$rule];
  135. continue 3;
  136. }
  137. break;
  138. case "maxvalue":
  139. if ( max_value_сheck( $form_data[$field], $rule_value ) ){
  140. $config["errors"][] = $config["messages"][$field][$rule];
  141. continue 3;
  142. }
  143. break;
  144. case "rangevalue":
  145. if ( range_value_сheck( $form_data[$field], $rule_value ) ){
  146. $config["errors"][] = $config["messages"][$field][$rule];
  147. continue 3;
  148. }
  149. break;
  150. case "equalTo":
  151. if ( equal_to_check( $form_data[$field], $form_data[$rule_value] ) ){
  152. $config["errors"][] = $config["messages"][$field][$rule];
  153. continue 3;
  154. }
  155. break;
  156. case "requiredFromGroup":
  157. $group = $rule_value[1];
  158. $count = 0;
  159. /* Validate every field */
  160. foreach ($group as $group_item) {
  161. if ( !min_length_check($form_data[$group_item], 1) ){
  162. $count++;
  163. }
  164. }
  165. /* Add error message */
  166. if ($count < $rule_value[0]){
  167. $config["errors"][] = $config["messages"][$field][$rule];
  168. continue 3;
  169. }
  170. break;
  171. }
  172. }
  173. }
  174. /* Validation apply to form files */
  175. if ( isset($_FILES) ){
  176. require_once dirname(__FILE__)."/mime_types.php";
  177. foreach ($_FILES as $file => $data) {
  178. $res = file_check($file, $config["rules"][$file], $config["messages"][$file], $default_mime_types);
  179. if ($res){
  180. $config["errors"][] = $res;
  181. }
  182. }
  183. }
  184. /* If validation error occurs */
  185. if (!empty($config["errors"])) {
  186. debugger( array(ERROR_MESSAGE, $config["errors"]) );
  187. exit;
  188. }
  189. /* Remove token */
  190. if (array_key_exists("token", $form_data)) {
  191. unset($form_data["token"]);
  192. }
  193. /* Remove reCaptcha */
  194. if (array_key_exists("recaptcha", $form_data)) {
  195. unset($form_data["recaptcha"]);
  196. }
  197. /************************************************/
  198. /* File processing */
  199. /************************************************/
  200. if (isset($config["file"])){
  201. foreach ($config["file"] as $file => $rules) {
  202. if ($file === "directory"){
  203. continue;
  204. }
  205. /* Upload file to server */
  206. foreach ($rules as $rule => $value) {
  207. if ($rule === "upload" && $value === true) {
  208. /* Save file name */
  209. $form_data[$file] = upload_file($file, directory_check($config["file"]["directory"]) );
  210. /* Create service variable with path to file */
  211. $form_data["_"]["files"][$file] = directory_check($config["file"]["directory"]).$form_data[$file];
  212. }
  213. }
  214. /* Save default file name */
  215. if ( !isset($form_data[$file]) ){
  216. $form_data[$file] = FILE_DEFAULT_NAME;
  217. }
  218. }
  219. }
  220. /************************************************/
  221. /* Duplicate info to a CSV file */
  222. /************************************************/
  223. if (isset($config["csv"])){
  224. if ($config["csv"]["save"]) {
  225. $path_csv = directory_check($config["csv"]["directory"]);
  226. /* New file for every form submission */
  227. if ( $config["csv"]["new_file"] ) {
  228. $single_name = date("Ymd_His")."_".mt_rand(1000,9999);
  229. $file_csv = $path_csv.$single_name.".csv";
  230. }
  231. /* General file */
  232. if ( $config["csv"]["general_file"] ){
  233. $file_csv = $path_csv.$config["csv"]["general_file_name"].".csv";
  234. }
  235. /* Debug */
  236. if (!isset($file_csv)){
  237. if ($config["debug"]){
  238. debugger( array(DEBUG_MESSAGE, CSV_ERROR_MESSAGE) );
  239. exit;
  240. }
  241. debugger( array(DEBUG_GENERAL_MESSAGE) );
  242. exit;
  243. }
  244. // Split the array with data to headers and values
  245. foreach ($form_data as $header => $value) {
  246. /* Skip service values */
  247. if ($header === "_"){
  248. continue;
  249. }
  250. $header_csv[] = $header; // headers for rows in the CSV file
  251. $value_csv[] = $value; // values for rows in the CSV file
  252. }
  253. /* If CSV file doesn't exist */
  254. if (!file_exists($file_csv)) {
  255. // Open CSV file
  256. $processing_csv = fopen($file_csv, 'a');
  257. // Add special symbols for correct encoding
  258. fwrite($processing_csv, "\xEF\xBB\xBF");
  259. // Add headers for the rows
  260. fputcsv($processing_csv, $header_csv);
  261. // Add variables to the file
  262. fputcsv($processing_csv, $value_csv);
  263. /* If CSV file exists */
  264. } else {
  265. // Open CSV file
  266. $processing_csv = fopen($file_csv, 'a');
  267. // Add variables to the file
  268. fputcsv($processing_csv, $value_csv);
  269. }
  270. fclose($processing_csv);
  271. /* Add to total array */
  272. $form_data["_"]["csv"] = $file_csv;
  273. }
  274. }
  275. /************************************************/
  276. /* Duplicate info to a PDF file */
  277. /************************************************/
  278. if (isset($config["pdf"])){
  279. if ($config["pdf"]["save"]) {
  280. $path_pdf = directory_check($config["pdf"]["directory"]);
  281. /* New file for every form submission */
  282. if ( $config["pdf"]["new_file"] ) {
  283. $single_name = date("Ymd_His")."_".mt_rand(1000,9999);
  284. $file_pdf = $path_pdf.$single_name.".pdf";
  285. }
  286. /* General file */
  287. if ( $config["pdf"]["general_file"] ){
  288. $file_pdf = $path_pdf.$config["pdf"]["general_file_name"].".pdf";
  289. }
  290. /* Debug */
  291. if (!isset($file_pdf)){
  292. if ($config["debug"]){
  293. debugger( array(DEBUG_MESSAGE, PDF_ERROR_MESSAGE) );
  294. exit;
  295. }
  296. debugger( array(DEBUG_GENERAL_MESSAGE) );
  297. exit;
  298. }
  299. /* Create new record */
  300. require_once dirname(__FILE__)."/tcpdf/tcpdf.php";
  301. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, "UTF-8", false);
  302. $pdf->AddPage();
  303. /* Header */
  304. $pdf->SetFont("freeserif", "", 20);
  305. $pdf->Cell(190, 15, $config["your_subject"], 1, 1, "C");
  306. /* Body */
  307. foreach ($form_data as $field => $value) {
  308. /* Skip service values */
  309. if ($field === "_"){
  310. continue;
  311. }
  312. // Fields
  313. $pdf->SetFont("freeserif", "", 13);
  314. $pdf->Cell(35, 10, row_name($field).":", 0, 0);
  315. // Values
  316. $pdf->SetFont("freeserif", "", 15);
  317. // If value is longer than 74 chars
  318. if (mb_strlen($value, "UTF-8") > 74) {
  319. $pdf->MultiCell(155, 10, $value, 0, 1);
  320. continue;
  321. }
  322. $pdf->Cell(155, 10, $value, 0, 1);
  323. }
  324. /* If PDF file doesn't exist */
  325. if (!file_exists($file_pdf)) {
  326. $pdf->Output($file_pdf, "F");
  327. } else {
  328. require_once dirname(__FILE__)."/tcpdf/fpdf_merge.php";
  329. // Temporary PDF file
  330. $temp_pdf = dirname(__FILE__).$config["pdf"]["directory"]."temp.pdf";
  331. // Create temporay PDF file
  332. $pdf->Output($temp_pdf, "F");
  333. // Merge main PDF file with temporary PDF file
  334. $merge = new FPDF_Merge();
  335. $merge->add($file_pdf);
  336. $merge->add($temp_pdf);
  337. $merge->output($file_pdf, "F");
  338. unlink($temp_pdf);
  339. }
  340. /* Add to total array */
  341. $form_data["_"]["pdf"] = $file_pdf;
  342. }
  343. }
  344. /************************************************/
  345. /* Duplicate info to a database */
  346. /************************************************/
  347. if (isset($config["database"])){
  348. if ($config["database"]["save"]) {
  349. require_once dirname(__FILE__)."/database_helpers.php";
  350. /* Remove service values */
  351. if (array_key_exists("_", $form_data)) {
  352. unset($form_data["_"]);
  353. }
  354. /* Mysqli connection to DB */
  355. if ($config["database"]["mysqli"]) {
  356. $db_result = mysqli($form_data);
  357. }
  358. /* PDO connection to DB */
  359. if ($config["database"]["pdo"]) {
  360. $db_result = pdo($form_data);
  361. }
  362. /* Debug */
  363. if (is_string($db_result)){
  364. if ($config["debug"]){
  365. debugger( array(DEBUG_MESSAGE, $db_result) );
  366. exit;
  367. }
  368. debugger( array(DEBUG_GENERAL_MESSAGE) );
  369. exit;
  370. }
  371. }
  372. }
  373. /************************************************/
  374. /* Send letter */
  375. /************************************************/
  376. if (isset($config["data"])){
  377. /* Send letter */
  378. if (isset($config["data"]["send"]) && $config["data"]["send"]) {
  379. require_once dirname(__FILE__)."/phpmailer/PHPMailerAutoload.php";
  380. require_once dirname(__FILE__)."/template_mail.php";
  381. /* Send letter using sendmail or mail function */
  382. if ($config["data"]["method"]["sendmail"] || $config["data"]["method"]["mail"]) {
  383. $mail = new PHPMailer;
  384. if (!$config["data"]["method"]["mail"]){
  385. $mail->isSendmail();
  386. }
  387. $mail->IsHTML(true);
  388. $mail->CharSet = "UTF-8";
  389. $mail->From = $config["your_email"];
  390. $mail->FromName = $config["your_name"];
  391. $mail->Encoding = "base64";
  392. $mail->ContentType = "text/html";
  393. $mail->addAddress($config["your_email"], $config["your_name"]);
  394. $mail->Subject = $config["your_subject"];
  395. $mail->Body = $letter;
  396. $mail->AltBody = "Use an HTML compatible email client";
  397. }
  398. /* Send letter using smtp function */
  399. if ($config["data"]["method"]["smtp"]["use_smtp"]){
  400. $mail = new PHPMailer;
  401. $mail->isSMTP();
  402. $mail->Host = $config["data"]["method"]["smtp"]["host"];
  403. $mail->SMTPAuth = $config["data"]["method"]["smtp"]["auth"];
  404. $mail->Username = $config["data"]["method"]["smtp"]["username"];
  405. $mail->Password = $config["data"]["method"]["smtp"]["password"];
  406. $mail->SMTPSecure = $config["data"]["method"]["smtp"]["secure"];
  407. $mail->Port = $config["data"]["method"]["smtp"]["port"];
  408. $mail->IsHTML(true);
  409. $mail->From = $config["your_email"];
  410. $mail->CharSet = "UTF-8";
  411. $mail->FromName = $config["your_name"];
  412. $mail->Encoding = "base64";
  413. $mail->Timeout = 200;
  414. $mail->SMTPDebug = $config["data"]["method"]["smtp"]["debug"];
  415. $mail->ContentType = "text/html";
  416. $mail->addAddress($config["your_email"], $config["your_name"]);
  417. $mail->Subject = $config["your_subject"];
  418. $mail->Body = $letter;
  419. $mail->AltBody = "Use an HTML compatible email client";
  420. }
  421. /* Sending form files as an attachments */
  422. if (isset($config["file"])){
  423. foreach ($config["file"] as $file => $rules){
  424. if ($file === "directory"){
  425. continue;
  426. }
  427. foreach ($rules as $rule => $value) {
  428. if ($rule === "attachment" && $value === true) {
  429. if ( is_file($form_data["_"]["files"][$file]) ){
  430. $mail->AddAttachment($form_data["_"]["files"][$file]);
  431. }
  432. }
  433. }
  434. }
  435. }
  436. /* Sending CSV file */
  437. if (isset($config["csv"])){
  438. if ($config["csv"]["attachment"]){
  439. if ( is_file($form_data["_"]["csv"]) ){
  440. $mail->AddAttachment($form_data["_"]["csv"]);
  441. }
  442. }
  443. }
  444. /* Sending PDF file */
  445. if (isset($config["pdf"])){
  446. if ($config["pdf"]["attachment"]){
  447. if ( is_file($form_data["_"]["pdf"]) ){
  448. $mail->AddAttachment($form_data["_"]["pdf"]);
  449. }
  450. }
  451. }
  452. /* Multiple letter recepients */
  453. if (isset($config["data"]["recipient"]) && $config["data"]["recipient"]){
  454. if (isset($config["data"]["recipient_data"])){
  455. foreach ($config["data"]["recipient_data"] as $email => $name){
  456. /* Set a user as a recipient */
  457. if ( isset($form_data[$email]) ){
  458. if ( isset($form_data[$name]) ){
  459. $mail->AddBCC($form_data[$email], $form_data[$name]);
  460. continue;
  461. }
  462. $mail->AddBCC($form_data[$email]);
  463. /* Use data from config */
  464. } else {
  465. $mail->AddBCC($email, $name);
  466. }
  467. }
  468. }
  469. }
  470. /* If error occurs while letter sending */
  471. if (!$mail->send()) {
  472. if ($config["debug"]){
  473. debugger( array(MAILER_ERROR_MESSAGE, $mail->ErrorInfo) );
  474. exit;
  475. }
  476. debugger( array(DEBUG_GENERAL_MESSAGE) );
  477. exit;
  478. }
  479. /* Autoresponse */
  480. if (isset($config["data"]["autoresponse"]) && $config["data"]["autoresponse"]) {
  481. if (isset($config["data"]["autoresponse_data"])) {
  482. /* Create autoresponse data */
  483. foreach ($config["data"]["autoresponse_data"] as $email => $name){
  484. /* Set a user as a autoresponse recipient */
  485. if ( isset($form_data[$email]) ){
  486. if ( isset($form_data[$name]) ){
  487. $autores_email = $form_data[$email];
  488. $autores_name = $form_data[$name];
  489. continue;
  490. }
  491. $autores_email = $form_data[$email];
  492. $autores_name = "Anonymous User";
  493. /* Use data from config */
  494. } else {
  495. $autores_email = $email;
  496. $autores_name = $name;
  497. }
  498. }
  499. require_once dirname(__FILE__)."/template_autoresponse.php";
  500. /* Send letter using sendmail or mail function */
  501. if ($config["data"]["method"]["sendmail"] || $config["data"]["method"]["mail"]) {
  502. $response = new PHPMailer;
  503. if (!$config["data"]["method"]["mail"]){
  504. $response->isSendmail();
  505. }
  506. $response->IsHTML(true);
  507. $response->CharSet = "UTF-8";
  508. $response->From = $config["your_email"];
  509. $response->FromName = $config["your_name"];
  510. $response->Encoding = "base64";
  511. $response->ContentType = "text/html";
  512. $response->addAddress($autores_email, $autores_name);
  513. $response->Subject = $config["your_subject"];
  514. $response->Body = $autoresponse;
  515. $response->AltBody = "Use an HTML compatible email client";
  516. }
  517. /* Send letter using smtp function */
  518. if ($config["data"]["method"]["smtp"]["use_smtp"]){
  519. $response = new PHPMailer;
  520. $response->isSMTP();
  521. $response->Host = $config["data"]["method"]["smtp"]["host"];
  522. $response->SMTPAuth = $config["data"]["method"]["smtp"]["auth"];
  523. $response->Username = $config["data"]["method"]["smtp"]["username"];
  524. $response->Password = $config["data"]["method"]["smtp"]["password"];
  525. $response->SMTPSecure = $config["data"]["method"]["smtp"]["secure"];
  526. $response->Port = $config["data"]["method"]["smtp"]["port"];
  527. $response->IsHTML(true);
  528. $response->From = $config["your_email"];
  529. $response->CharSet = "UTF-8";
  530. $response->FromName = $config["your_name"];
  531. $response->Encoding = "base64";
  532. $response->Timeout = 200;
  533. $response->SMTPDebug = $config["data"]["method"]["smtp"]["debug"];
  534. $response->ContentType = "text/html";
  535. $response->addAddress($autores_email, $autores_name);
  536. $response->Subject = $config["your_subject"];
  537. $response->Body = $autoresponse;
  538. $response->AltBody = "Use an HTML compatible email client";
  539. }
  540. /* Sending form files as an attachments */
  541. if (isset($config["data"]["autoresponse_attachment"])){
  542. $autores_files = $config["data"]["autoresponse_attachment"];
  543. }
  544. if ( isset($autores_files) && is_array($autores_files) ){
  545. foreach ($autores_files as $file) {
  546. if ( isset($form_data["_"]["files"][$file]) && is_file($form_data["_"]["files"][$file]) ){
  547. $response->AddAttachment($form_data["_"]["files"][$file]);
  548. continue;
  549. }
  550. if ( isset($form_data["_"][$file]) && is_file($form_data["_"][$file]) ){
  551. $response->AddAttachment($form_data["_"][$file]);
  552. continue;
  553. }
  554. $path_file = get_file(ROOT, $file);
  555. if ($path_file){
  556. $response->AddAttachment($path_file);
  557. continue;
  558. }
  559. }
  560. }
  561. /* If error occurs while letter sending */
  562. if (!$response->send()) {
  563. if ($config["debug"]){
  564. debugger( array(AUTORESPONSE_ERROR_MESSAGE, $response->ErrorInfo) );
  565. exit;
  566. }
  567. debugger( array(DEBUG_GENERAL_MESSAGE) );
  568. exit;
  569. }
  570. }
  571. }
  572. /* end Autoresponse */
  573. }
  574. /* end Send letter */
  575. }
  576. /************************************************/
  577. /* Success message */
  578. /************************************************/
  579. echo json_encode(array("success" => SUCCESS_MESSAGE));
  580. /************************************************/
  581. /* File processing */
  582. /************************************************/
  583. /* Delete form files */
  584. if (isset($config["file"])){
  585. foreach ($config["file"] as $file => $rules) {
  586. if ($file === "directory"){
  587. continue;
  588. }
  589. foreach ($rules as $rule => $value) {
  590. if ($rule === "delete" && $value === true) {
  591. if ( is_file($form_data["_"]["files"][$file]) ){
  592. unlink($form_data["_"]["files"][$file]);
  593. }
  594. }
  595. }
  596. }
  597. }
  598. /* Delete CSV file */
  599. if (isset($config["csv"])){
  600. if ($config["csv"]["delete"]) {
  601. if ( is_file($form_data["_"]["csv"]) ){
  602. unlink($form_data["_"]["csv"]);
  603. }
  604. }
  605. }
  606. /* Delete PDF file */
  607. if (isset($config["pdf"])){
  608. if ($config["pdf"]["delete"]) {
  609. if ( is_file($form_data["_"]["pdf"]) ){
  610. unlink($form_data["_"]["pdf"]);
  611. }
  612. }
  613. }
  614. ?>