Merge pull request #4252 from civicrm/4.4
[civicrm-core.git] / CRM / Event / Cart / Page / CheckoutAJAX.php
1 <?php
2
3 /**
4 * Class CRM_Event_Cart_Page_CheckoutAJAX
5 */
6 class CRM_Event_Cart_Page_CheckoutAJAX {
7 function add_participant_to_cart() {
8 require 'CRM/Core/Transaction.php';
9 $transaction = new CRM_Core_Transaction();
10 $cart_id = $_GET['cart_id'];
11 $event_id = $_GET['event_id'];
12
13 $cart = CRM_Event_Cart_BAO_Cart::find_by_id($_GET['cart_id']);
14
15 $params_array = array('cart_id' => $cart->id, 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(), 'event_id' => $event_id);
16
17 //XXX security?
18 $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array);
19 $participant->save();
20
21 $form = new CRM_Core_Form();
22 $pform = new CRM_Event_Cart_Form_MerParticipant($participant);
23 $pform->appendQuickForm($form);
24
25 $renderer = $form->getRenderer();
26
27 $config = CRM_Core_Config::singleton();
28 $templateDir = $config->templateDir;
29 if (is_array($templateDir)) {
30 $templateDir = array_pop($templateDir);
31 }
32 $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
33 $renderer->setRequiredTemplate($requiredTemplate);
34
35 $form->accept($renderer);
36 $template = CRM_Core_Smarty::singleton();
37 $template->assign('form', $renderer->toArray());
38 $template->assign('participant', $participant);
39 $output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl");
40 $transaction->commit();
41 echo $output;
42 CRM_Utils_System::civiExit();
43 }
44
45 function remove_participant_from_cart() {
46 $participant = CRM_Event_Cart_BAO_MerParticipant::get_by_id($_GET['id']);
47 $participant->delete();
48
49 CRM_Utils_System::civiExit();
50 }
51 }
52