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

/src/site/components/com_chronocontact/plugins/cf_multi_page.php

https://bitbucket.org/manchas/jrobotz
PHP | 279 lines | 263 code | 5 blank | 11 comment | 1 complexity | 7af11f8299e359ad4b1b035089d087f2 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * CHRONOFORMS version 3.0
  4. * Copyright (c) 2008 Chrono_Man, ChronoEngine.com. All rights reserved.
  5. * Author: Chrono_Man
  6. * License : GPL
  7. * Visit http://www.ChronoEngine.com for regular update and information.
  8. **/
  9. defined('_JEXEC') or die('Restricted access');
  10. global $mainframe;
  11. require_once( $mainframe->getPath( 'class', 'com_chronocontact' ) );
  12. // the class name must be the same as the file name without the .php at the end
  13. class cf_multi_page
  14. {
  15. //the next 3 fields must be defined for every plugin
  16. var $result_TITLE = "Multi Page";
  17. var $result_TOOLTIP = "Create Multi page forms easily, use this plugin with a mother form which will control all other child forms which will run in a chain";
  18. var $plugin_name = "cf_multi_page"; // must be the same as the class name
  19. var $event = "ONLOADONSUBMIT"; // must be defined and in Uppercase, should be ONSUBMIT or ONLOAD or ONLOADONSUBMIT, the last one is for v3.1 RC3 and up only
  20. var $plugin_keys ='';
  21. // the next function must exist and will have the backend config code
  22. function show_conf($row, $id, $form_id, $option)
  23. {
  24. global $mainframe;
  25. require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'plugin.php');
  26. $helper = new ChronoContactHelperPlugin();
  27. // identify and initialise the parameters used in this plugin
  28. $params_array = array(
  29. 'debugging' => '0',
  30. 'onsubmit' => 'before_email',
  31. 'stepscount' => '',
  32. 'formsnames' => '',
  33. 'stepsnavigation' => '0');
  34. $params = $helper->loadParams($row, $params_array);
  35. $messages[] = '$params: '.print_r($params, true);
  36. if ( $params->get('debugging') ) {
  37. $helper->showPluginDebugMessages($messages);
  38. }
  39. ?>
  40. <form action="index2.php" method="post" name="adminForm" id="adminForm" class="adminForm">
  41. <?php
  42. echo $pane->startPane("multipage");
  43. echo $pane->startPanel( 'Multi Page settings', "settings" );
  44. ?>
  45. <table border="0" cellpadding="3" cellspacing="0" class='cf_table' >
  46. <?php
  47. $input = $helper->createHeaderTD('Configure the plugin', '',
  48. true, array('colspan' => '4', 'class' => 'cf_header'));
  49. echo $helper->wrapTR($input);
  50. foreach ( range(1, 20) as $v ) {
  51. $option_array[$v] = JHTML::_('select.option', $v, JText::_($v));
  52. }
  53. $tooltip = "Please select the number of separate form steps.<br />
  54. Don't count the last thank your page, a confimation page, or the onsubmit routine.";
  55. $input = $helper->createSelectTD("Number of Steps", "params[stepscount]",
  56. $option_array, $params->get('stepscount'), $attribs['select'], $tooltip );
  57. echo $helper->wrapTR($input, array('class' => 'cf_config'));
  58. $tooltip = "Enter the forms names for each step separated by a comma, with no spaces.<br />
  59. There must be the same number of forms as the Number of steps above";
  60. $input = $helper->createInputTD("Step form names",
  61. "params[formsnames]", $params->get('formsnames'), '', $attribs['input'], $tooltip);
  62. echo $helper->wrapTR($input, array('class' => 'cf_config'));
  63. $tooltip = "Enter the name of the submit button which when clicked will terminate the navigation chain";
  64. $input = $helper->createInputTD("Finalize button name",
  65. "params[finalbuttonname]", $params->get('finalbuttonname'), '', $attribs['input'], $tooltip);
  66. echo $helper->wrapTR($input, array('class' => 'cf_config'));
  67. $tooltip = "Enable navigating between step using urls with &cfformstep=n";
  68. $input = $helper->createYesNoTD("Enable Steps navigation", "params[stepsnavigation]", '',
  69. $params->get('stepsnavigation'), '', $tooltip);
  70. echo $helper->wrapTR($input, array('class' => 'cf_config'));
  71. $tooltip = "Show debug information on Submit?";
  72. $input = $helper->createYesNoTD("Debugging", "params[debugging]", '',
  73. $params->get('debugging'), '', $tooltip);
  74. echo $helper->wrapTR($input, array('class' => 'cf_config'));
  75. ?>
  76. </table>
  77. <?php
  78. echo $pane->endPanel();
  79. echo $pane->startPanel( "Help", 'Legend3' );
  80. ?>
  81. <table border="0" cellpadding="3" cellspacing="0" class='cf_table' >
  82. <?php
  83. $input = $helper->createHeaderTD('How to use the Multi page plugin', '',
  84. true, array('colspan' => '4', 'class' => 'cf_header'));
  85. echo $helper->wrapTR($input);
  86. ?>
  87. <tr>
  88. <td colspan='4' style='border:1px solid silver; padding:6px;'>
  89. <div>The plugin allows you to link several ChronoForms together into a sequence.</div>
  90. <ul><li>Decide on the number of steps you want in your form sequence and create a form for each step.</li>
  91. <li>Put the number of form steps in the Configuration tab</li>
  92. <li>List the names of the forms in the input box: form_1,form_2,. . .</li>
  93. <li>Select Steps Navigation if you want to be able to navigate directly to form steps using
  94. urls with the &cfformstep parameter
  95. e.g. <span style='color:blue;'>index.php?option=com_chronocontact&chronoformname=test_form_8&cfformstep=2</span></li>
  96. </ul>
  97. </td>
  98. </tr>
  99. </table>
  100. <?php
  101. echo $pane->endPanel();
  102. echo $pane->endPane();
  103. $hidden_array = array (
  104. 'id' => $id,
  105. 'form_id' => $form_id,
  106. 'name' => $this->plugin_name,
  107. 'event' => $this->event,
  108. 'option' => $option,
  109. 'task' => 'save_conf');
  110. $hidden_array['params[onsubmit]'] = 'before_email';
  111. echo $helper->createHiddenArray( $hidden_array );
  112. ?>
  113. </form>
  114. <?php
  115. }
  116. // this function must exist and may not be changed unless you need to customize something
  117. function save_conf( $option )
  118. {
  119. global $mainframe;
  120. require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_chronocontact'
  121. .DS.'helpers'.DS.'plugin.php');
  122. $helper = new ChronoContactHelperPlugin();
  123. $helper->save_conf($option);
  124. }
  125. function onload( $option, $row, $params, $html_string )
  126. {
  127. global $mainframe;
  128. require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_chronocontact'
  129. .DS.'helpers'.DS.'plugin.php');
  130. $helper = new ChronoContactHelperPlugin();
  131. $messages[] = '$params: '.print_r($params, true);
  132. //$my = JFactory::getUser();
  133. $session =& JFactory::getSession();
  134. //$formname = JRequest::getVar('chronoformname');
  135. if($row->form_id){
  136. $formname = CFChronoForm::getFormName($row->form_id);
  137. }else{
  138. $formname = JRequest::getVar('chronoformname');
  139. }
  140. $messages[] = 'formname: '.$formname;
  141. $MyForm =& CFChronoForm::getInstance($formname);
  142. $pages = explode(",", $params->get('formsnames'));
  143. $messages[] = 'Pages: '.print_r($pages, true);
  144. //$CF_PATH = ($mainframe->isSite()) ? JURI::Base() : $mainframe->getSiteURL();
  145. $current_step = 0;
  146. if ( $params->get('stepsnavigation') ) {
  147. $current_step = JRequest::getInt('cfformstep', '0');
  148. }
  149. if ( $current_step == 0 ) {
  150. $session->clear('chrono_formpages_data_'.$formname, md5('chrono'));
  151. $current_step = 1;
  152. }
  153. $posted = array();
  154. if ( $session->get('chrono_formpages_data_'.$formname, array(), md5('chrono')) ) {
  155. $posted = $session->get('chrono_formpages_data_'.$formname, array(), md5('chrono'));
  156. }
  157. $messages[] = 'Current step: '.$current_step;
  158. $messages[] = 'Session data: '.print_r($posted, true);
  159. if ( $params->get('debugging') ) {
  160. $helper->showPluginDebugMessages($messages);
  161. }
  162. if ( $current_step && ( $current_step <= (int)$params->get('stepscount') ) ) {
  163. $newForm =& CFChronoForm::getInstance(trim($pages[$current_step - 1]));
  164. $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name);
  165. $session->set('chrono_step_'.$formname, (int)$current_step, md5('chrono'));
  166. $newForm->showForm($newForm->formrow->name, $posted);
  167. } else {
  168. $newForm =& CFChronoForm::getInstance(trim($pages[0]));
  169. $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name);
  170. $session->set('chrono_step_'.$formname, 1, md5('chrono'));
  171. $newForm->showForm($newForm->formrow->name, $posted);
  172. }
  173. $html_string = '';
  174. $MyForm->stoploading = true;
  175. return $html_string ;
  176. }
  177. function onsubmit( $option, $params , $row )
  178. {
  179. global $mainframe;
  180. //echo "XXX";
  181. require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_chronocontact'
  182. .DS.'helpers'.DS.'plugin.php');
  183. $helper = new ChronoContactHelperPlugin();
  184. if($row->form_id){
  185. $formname = CFChronoForm::getFormName($row->form_id);
  186. }else{
  187. $formname = JRequest::getVar('chronoformname');
  188. }
  189. $MyForm =& CFChronoForm::getInstance($formname);
  190. $MyUploads =& CFUploads::getInstance($MyForm->formrow->id);
  191. $session =& JFactory::getSession();
  192. $pluginrow = $row;
  193. $newposted = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
  194. $oldposted = array();
  195. if ( $session->get('chrono_formpages_data_'.$formname, array(), md5('chrono')) ) {
  196. $oldposted = $session->get('chrono_formpages_data_'.$formname, array(), md5('chrono'));
  197. }
  198. if ( $session->get('chrono_formpages_files_'.$formname, array(), md5('chrono')) ) {
  199. $MyUploads->attachments = $session->get('chrono_formpages_files_'.$formname, array(), md5('chrono'));
  200. }
  201. $posted = array_merge($oldposted, $newposted);
  202. $messages[] = 'Posted: '.print_r($posted, true);
  203. $messages[] = 'Files: '.print_r($MyUploads->attachments, true);
  204. JRequest::set($posted, 'post');
  205. $session->set('chrono_formpages_data_'.$formname, $posted, md5('chrono'));
  206. $pages = explode(",", $params->get('formsnames'));
  207. $current_step = $session->get('chrono_step_'.$formname, '', md5('chrono'));
  208. $messages[] = 'Current step: '.print_r($current_step, true);
  209. if ( $params->get('debugging') ) {
  210. $helper->showPluginDebugMessages($messages);
  211. }
  212. if(JRequest::getVar($params->get('finalbuttonname'))){
  213. $current_step = 'end';
  214. }
  215. if ( $current_step != 'end' ) {
  216. if ( $current_step ) {
  217. $newForm =& CFChronoForm::getInstance(trim($pages[$current_step - 1]));
  218. $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name);
  219. $newForm->formrow->html = $newForm->formrow->html.'<input type="hidden" name="cfformstep" value="'.$current_step.'" />';
  220. $newForm->submitForm($newForm->formrow->name, $posted);
  221. $newUploads =& CFUploads::getInstance($newForm->formrow->id);
  222. $MyUploads->attachments = array_merge($MyUploads->attachments, $newUploads->attachments);
  223. $session->set('chrono_formpages_files_'.$formname, $MyUploads->attachments, md5('chrono'));
  224. //check if the previous form submission completed successfully
  225. if ( $newForm->submission_complete ) {
  226. if ( $current_step == (int)$params->get('stepscount') ) {
  227. $session->set('chrono_step_'.$formname, 'end', md5('chrono'));
  228. //$MyForm->submitForm($MyForm->formrow->name);
  229. return;
  230. }
  231. $nextForm =& CFChronoForm::getInstance(trim($pages[$current_step]));
  232. $nextForm->formrow->submiturl = $nextForm->getAction($MyForm->formrow->name);
  233. $nextForm->formrow->html = $nextForm->formrow->html.'<input type="hidden" name="cfformstep" value="'.$current_step.'" />';
  234. $session->set('chrono_step_'.$formname, $current_step + 1, md5('chrono'));
  235. $nextForm->showForm($nextForm->formrow->name, $posted);
  236. }
  237. } else {
  238. $newForm =& CFChronoForm::getInstance(trim($pages[0]));
  239. $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name);
  240. $session->set('chrono_step_'.$formname, 1, md5('chrono'));
  241. $newForm->showForm($newForm->formrow->name, $posted);
  242. }
  243. //exit the form routine
  244. $MyForm->stoprunning = true;
  245. return;
  246. }
  247. }
  248. }
  249. ?>