Created
May 8, 2014 07:41
-
-
Save clouddueling/577e56b3487e6c8e2768 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Record_Controller extends Base_Controller | |
{ | |
public function get_print($id) | |
{ | |
$record = Record::find($id); | |
has_access($record); | |
$account = Auth::user()->account(); | |
$record->created_at = Date::timezone($record->created_at, "UTC", $account->timezone); | |
if (! $record->card) { | |
return Redirect::to("profile")->with('error', "Could not find form."); | |
} | |
return View::make('record.print', [ | |
'record' => $record, | |
'i' => 0 | |
]); | |
} | |
public function post_create() | |
{ | |
$s = Api::inputs([ | |
'values' => [], | |
'tracker_ids' => [], | |
'contact_id' => 0, | |
'account_user_id' => 0, | |
'card_id' => 0, | |
'serie_id' => 0, | |
'back' => false, | |
]); | |
ini_set('max_execution_time', 300); | |
$card = Card::find($s['card_id']); | |
if (! $card) { | |
throw new Exception('Sorry, there was an error saving your entry.'); | |
} | |
$contact = false; | |
if ($s['contact_id'] != 0) { | |
$contact = Contact::find($s['contact_id']); | |
} | |
if ($card->create_contact == 1 && $s['contact_id'] == 0) { | |
$contact = Contact::create(array( | |
'account_user_id' => $s['account_user_id'], | |
)); | |
$s['contact_id'] = $contact->id; | |
} | |
if ($contact) { | |
$contact->update_with_values($s['values'], $card); | |
} | |
$record = Record::create(array( | |
'user_id' => Auth::guest() ? 0 : Auth::user()->id, | |
'account_user_id' => $s['account_user_id'], | |
'card_id' => $card->id, | |
'serie_id' => $s['serie_id'], | |
'contact_id' => $s['contact_id'], | |
'type' => 'forms', | |
)); | |
$record->create_values($s['values']); | |
$note = Note::create([ | |
'user_id' => Auth::guest() ? 0 : Auth::user()->id, | |
'account_user_id' => $s['account_user_id'], | |
'contact_id' => $s['contact_id'], | |
'card_id' => $card->id, | |
'record_id' => $record->id, | |
'action' => 'created', | |
'type' => 'form' | |
]); | |
$card->send_notifications($record, $s['account_user_id']); | |
if ($card->contactgroup && $contact) { | |
if (! $card->contactgroup->has_contact($contact->id)) { | |
$contact->contactgroups()->attach($card->contactgroup_id); | |
} | |
} | |
if ($s['back']) { | |
return Redirect::back()->with('success', "Form successfully submitted!"); | |
} | |
switch($card->after_action) { | |
case 'form' : | |
$redirect_card = Card::find($card->redirect_card_id); | |
if ($card->redirect_card_id != 0 && $redirect_card != null) { | |
if (! $redirect_card->deleted) { | |
return Redirect::to("/card/view?card_id={$card->redirect_card_id}&contact_id={$s['contact_id']}&account_user_id={$s['account_user_id']}"); | |
} | |
} | |
return Redirect::to("/card/confirm?card_id={$card->id}&contact_id={$s['contact_id']}&account_user_id={$s['account_user_id']}"); | |
case 'redirect' : | |
$url = format_url($card->redirect_url); | |
return Redirect::to($url); | |
break; | |
default : | |
return Redirect::to("/card/confirm?card_id={$card->id}&contact_id={$s['contact_id']}&account_user_id={$s['account_user_id']}"); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment