PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/form-maker/admin/models/FMModelGenerete_xml.php

https://gitlab.com/ezgonzalez/integral
PHP | 276 lines | 246 code | 15 blank | 15 comment | 41 complexity | e1102b185e7f66e8effdab885e2fdd42 MD5 | raw file
  1. <?php
  2. class FMModelGenerete_xml {
  3. ////////////////////////////////////////////////////////////////////////////////////////
  4. // Events //
  5. ////////////////////////////////////////////////////////////////////////////////////////
  6. ////////////////////////////////////////////////////////////////////////////////////////
  7. // Constants //
  8. ////////////////////////////////////////////////////////////////////////////////////////
  9. ////////////////////////////////////////////////////////////////////////////////////////
  10. // Variables //
  11. ////////////////////////////////////////////////////////////////////////////////////////
  12. ////////////////////////////////////////////////////////////////////////////////////////
  13. // Constructor & Destructor //
  14. ////////////////////////////////////////////////////////////////////////////////////////
  15. public function __construct() {
  16. }
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. // Public Methods //
  19. ////////////////////////////////////////////////////////////////////////////////////////
  20. public function get_data() {
  21. global $wpdb;
  22. $is_paypal_info = FALSE;
  23. $params = array();
  24. $group_id_s = array();
  25. $form_id = (int)$_REQUEST['form_id'];
  26. $limitstart = (int)$_REQUEST['limitstart'];
  27. $paypal_info_fields = array('currency', 'ord_last_modified', 'status', 'full_name', 'fax', 'mobile_phone', 'email', 'phone', 'address', 'paypal_info', 'ipn', 'tax', 'shipping');
  28. $paypal_info_labels = array( 'Currency', 'Last modified', 'Status', 'Full Name', 'Fax', 'Mobile phone', 'Email', 'Phone', 'Address', 'Paypal info', 'IPN', 'Tax', 'Shipping');
  29. $query = $wpdb->prepare("SELECT distinct group_id FROM " . $wpdb->prefix . "formmaker_submits where form_id=%d", $form_id);
  30. $group_id_s = $wpdb->get_col($query);
  31. $query = $wpdb->prepare("SELECT distinct element_label FROM " . $wpdb->prefix . "formmaker_submits where form_id=%d",$form_id);
  32. $labels = $wpdb->get_col($query);
  33. $query_lable = $wpdb->prepare("SELECT label_order,title FROM " . $wpdb->prefix . "formmaker where id=%d", $form_id);
  34. $rows_lable = $wpdb->get_results($query_lable);
  35. $ptn = "/[^a-zA-Z0-9_]/";
  36. $rpltxt = "";
  37. $title = isset($rows_lable[0]) ? preg_replace($ptn, $rpltxt, $rows_lable[0]->title) : '';
  38. $sorted_labels_id = array();
  39. $sorted_labels = array();
  40. $label_titles = array();
  41. $label_id = array();
  42. $label_order = array();
  43. $label_order_original = array();
  44. $label_type = array();
  45. if ($labels) {
  46. $label_all = explode('#****#', $rows_lable[0]->label_order);
  47. $label_all = array_slice($label_all, 0, count($label_all) - 1);
  48. foreach ($label_all as $key => $label_each) {
  49. $label_id_each = explode('#**id**#', $label_each);
  50. array_push($label_id, $label_id_each[0]);
  51. $label_oder_each = explode('#**label**#', $label_id_each[1]);
  52. array_push($label_order_original, $label_oder_each[0]);
  53. $label_temp = preg_replace($ptn, $rpltxt, $label_oder_each[0]);
  54. array_push($label_order, $label_temp);
  55. array_push($label_type, $label_oder_each[1]);
  56. }
  57. foreach ($label_id as $key => $label) {
  58. if (in_array($label, $labels) && $label_type[$key] !='type_arithmetic_captcha') {
  59. array_push($sorted_labels, $label_order[$key]);
  60. array_push($sorted_labels_id, $label);
  61. array_push($label_titles, stripslashes($label_order_original[$key]));
  62. }
  63. }
  64. }
  65. $m = count($sorted_labels);
  66. $query = $wpdb->prepare("SELECT group_id, ip, date, user_id_wd, GROUP_CONCAT( element_label SEPARATOR ',') as element_label, GROUP_CONCAT( element_value SEPARATOR '*:*el_value*:*') as element_value FROM " . $wpdb->prefix . "formmaker_submits where form_id= %d GROUP BY group_id ORDER BY date ASC limit %d, %d", $form_id, $limitstart, 1000);
  67. $rows = $wpdb->get_results($query, OBJECT_K);
  68. $data = array();
  69. $group_id_s_count = $limitstart + 1000 < count($group_id_s) ? $limitstart + 1000 : count($group_id_s);
  70. for ($www = $limitstart; $www < $group_id_s_count; $www++) {
  71. $i = $group_id_s[$www];
  72. $field_key = array_search($i, $label_id);
  73. if($label_type[$field_key] != 'type_arithmetic_captcha') {
  74. $data_temp = array();
  75. $tt = $rows[$i];
  76. $date = $tt->date;
  77. $ip = $tt->ip;
  78. $user_id = get_userdata($tt->user_id_wd);
  79. $username = $user_id ? $user_id->display_name : "";
  80. $useremail = $user_id ? $user_id->user_email : "";
  81. $data_temp['Submit date'] = $date;
  82. $data_temp['Ip']=$ip;
  83. $data_temp['Submitter\'s Username']=$username;
  84. $data_temp['Submitter\'s Email Address']=$useremail;
  85. $element_labels = explode(',', $tt->element_label);
  86. $element_values = explode('*:*el_value*:*', $tt->element_value);
  87. for ($h = 0; $h < $m; $h++) {
  88. if(isset($data_temp[$label_titles[$h]]))
  89. $label_titles[$h] .= '(1)';
  90. if(in_array($sorted_labels_id[$h], $element_labels)) {
  91. $element_value = $element_values[array_search($sorted_labels_id[$h], $element_labels)];
  92. if (strpos($element_value, "*@@url@@*")) {
  93. $file_names = '';
  94. $new_files = explode("*@@url@@*", $element_value);
  95. foreach ($new_files as $new_file) {
  96. if ($new_file) {
  97. $file_names .= $new_file . ", ";
  98. }
  99. }
  100. $data_temp[stripslashes($label_titles[$h])] = $file_names;
  101. }
  102. elseif (strpos($element_value, "***br***")) {
  103. $element_value = str_replace("***br***", ', ', $element_value);
  104. if (strpos($element_value, "***quantity***")) {
  105. $element_value = str_replace("***quantity***", '', $element_value);
  106. }
  107. if (strpos($element_value, "***property***")) {
  108. $element_value = str_replace("***property***", '', $element_value);
  109. }
  110. if(substr($element_value, -2) == ', ') {
  111. $data_temp[stripslashes($label_titles[$h])]= substr($element_value, 0, -2);
  112. }
  113. else {
  114. $data_temp[stripslashes($label_titles[$h])]= $element_value;
  115. }
  116. }
  117. elseif (strpos($element_value, "***map***")) {
  118. $data_temp[stripslashes($label_titles[$h])] = 'Longitude:' . str_replace("***map***", ', Latitude:', $element_value);
  119. }
  120. elseif (strpos($element_value, "***star_rating***")) {
  121. $element = str_replace("***star_rating***", '', $element_value);
  122. $element = explode("***", $element);
  123. $data_temp[stripslashes($label_titles[$h])] = ' ' . $element[1] . '/' . $element[0];
  124. }
  125. elseif (strpos($element_value, "@@@") || $element_value == "@@@" || $element_value == "@@@@@@@@@") {
  126. $data_temp[stripslashes($label_titles[$h])] = str_replace("@@@", ' ', $element_value);
  127. }
  128. elseif (strpos($element_value, "***grading***")) {
  129. $element = str_replace("***grading***", '', $element_value);
  130. $grading = explode(":", $element);
  131. $items_count = sizeof($grading) - 1;
  132. $items = "";
  133. $total = "";
  134. for ($k = 0; $k < $items_count / 2; $k++) {
  135. $items .= $grading[$items_count / 2 + $k] . ": " . $grading[$k] . ", ";
  136. $total += $grading[$k];
  137. }
  138. $items .= "Total: " . $total;
  139. $data_temp[stripslashes($label_titles[$h])] = $items;
  140. }
  141. elseif (strpos($element_value, "***matrix***")) {
  142. $element = str_replace("***matrix***", '', $element_value);
  143. $matrix_value = explode('***', $element);
  144. $matrix_value = array_slice($matrix_value, 0, count($matrix_value) - 1);
  145. $mat_rows = $matrix_value[0];
  146. $mat_columns = $matrix_value[$mat_rows + 1];
  147. $matrix = "";
  148. $aaa = array();
  149. $var_checkbox = 1;
  150. $selected_value = "";
  151. $selected_value_yes = "";
  152. $selected_value_no = "";
  153. for ($k = 1; $k <= $mat_rows; $k++) {
  154. if ($matrix_value[$mat_rows + $mat_columns + 2] == "radio") {
  155. if ($matrix_value[$mat_rows + $mat_columns + 2 + $k] == 0) {
  156. $checked = "0";
  157. $aaa[1] = "";
  158. }
  159. else {
  160. $aaa = explode("_", $matrix_value[$mat_rows + $mat_columns + 2 + $k]);
  161. }
  162. for ($l = 1; $l <= $mat_columns; $l++) {
  163. $checked = $aaa[1] == $l ? '1' : '0';
  164. $matrix .= '['.$matrix_value[$k].','.$matrix_value[$mat_rows+1+$l].']='.$checked."; ";
  165. }
  166. }
  167. else {
  168. if ($matrix_value[$mat_rows+$mat_columns + 2] == "checkbox") {
  169. for ($l = 1; $l <= $mat_columns; $l++) {
  170. $checked = $matrix_value[$mat_rows+$mat_columns + 2 + $var_checkbox] == 1 ? '1' : '0';
  171. $matrix .= '['.$matrix_value[$k].','.$matrix_value[$mat_rows+1+$l].']='.$checked."; ";
  172. $var_checkbox++;
  173. }
  174. }
  175. else {
  176. if ($matrix_value[$mat_rows+$mat_columns + 2] == "text") {
  177. for ($l = 1; $l <= $mat_columns; $l++) {
  178. $text_value = $matrix_value[$mat_rows+$mat_columns+2+$var_checkbox];
  179. $matrix .='['.$matrix_value[$k].','.$matrix_value[$mat_rows+1+$l].']='.$text_value."; ";
  180. $var_checkbox++;
  181. }
  182. }
  183. else {
  184. for ($l = 1; $l <= $mat_columns; $l++) {
  185. $selected_text = $matrix_value[$mat_rows+$mat_columns + 2 + $var_checkbox];
  186. $matrix .= '['.$matrix_value[$k].','.$matrix_value[$mat_rows + 1 + $l].']='.$selected_text."; ";
  187. $var_checkbox++;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. $data_temp[stripslashes($label_titles[$h])] = $matrix;
  194. }
  195. else {
  196. $val = htmlspecialchars_decode($element_value);
  197. $val = stripslashes(str_replace('&#039;', "'", $val));
  198. $data_temp[stripslashes($label_titles[$h])] = ($element_value ? $val : '');
  199. }
  200. }
  201. else
  202. $data_temp[stripslashes($label_titles[$h])] = '';
  203. }
  204. $item_total = $wpdb->get_var($wpdb->prepare("SELECT `element_value` FROM " . $wpdb->prefix . "formmaker_submits where group_id=%d AND element_label=%s",$i,'item_total'));
  205. $total = $wpdb->get_var($wpdb->prepare("SELECT `element_value` FROM " . $wpdb->prefix . "formmaker_submits where group_id=%d AND element_label=%s",$i,'total'));
  206. $payment_status = $wpdb->get_var($wpdb->prepare("SELECT `element_value` FROM " . $wpdb->prefix . "formmaker_submits where group_id=%d AND element_label=%s",$i,'0'));
  207. if($item_total)
  208. $data_temp['Item Total'] = $item_total;
  209. if($total)
  210. $data_temp['Total'] = $total;
  211. if($payment_status)
  212. $data_temp['Payment Status'] = $payment_status;
  213. $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "formmaker_sessions where group_id= %d", $i);
  214. $paypal_info = $wpdb->get_results($query);
  215. if ($paypal_info) {
  216. $is_paypal_info = TRUE;
  217. }
  218. if ($is_paypal_info) {
  219. foreach ($paypal_info_fields as $key=>$paypal_info_field) {
  220. if ($paypal_info) {
  221. $data_temp['PAYPAL_' . $paypal_info_labels[$key]] = $paypal_info[0]->$paypal_info_field;
  222. }
  223. else {
  224. $data_temp['PAYPAL_' . $paypal_info_labels[$key]] = '';
  225. }
  226. }
  227. }
  228. $data[$i] = $data_temp;
  229. }
  230. }
  231. array_push($params, $data);
  232. array_push($params, $title);
  233. array_push($params, $is_paypal_info);
  234. return $params;
  235. }
  236. ////////////////////////////////////////////////////////////////////////////////////////
  237. // Getters & Setters //
  238. ////////////////////////////////////////////////////////////////////////////////////////
  239. ////////////////////////////////////////////////////////////////////////////////////////
  240. // Private Methods //
  241. ////////////////////////////////////////////////////////////////////////////////////////
  242. ////////////////////////////////////////////////////////////////////////////////////////
  243. // Listeners //
  244. ////////////////////////////////////////////////////////////////////////////////////////
  245. }