Created
May 8, 2014 07:42
-
-
Save clouddueling/10e7d52d0b8fa6a069bc 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 Card_Controller extends Base_Controller | |
{ | |
public function get_confirm() | |
{ | |
$s = Api::inputs([ | |
'card_id' => 0, | |
'contact_id' => 0, | |
'account_user_id' => 0, | |
]); | |
$card = Card::find($s['card_id']); | |
$data = array( | |
'card' => $card, | |
'card_id' => $s['card_id'], | |
'contact_id' => $s['contact_id'], | |
'account_user_id' => $s['account_user_id'] | |
); | |
return View::make('card.confirm', $data); | |
} | |
public function get_secure() | |
{ | |
try { | |
$s = Api::inputs([ | |
'card_id' => 0, | |
'contact_id' => 0, | |
'account_user_id' => 0, | |
]); | |
if (Auth::guest()) { | |
throw new Exception("Please sign in."); | |
} | |
$user_id = Auth::user()->id; | |
Session::put('secure_user_id', $user_id); | |
Auth::logout(); | |
return Redirect::to("card/view?card_id={$s['card_id']}&contact_id={$s['contact_id']}&account_user_id={$s['account_user_id']}") | |
->with('success', 'This form is now secure.'); | |
} catch (Exception $e) { | |
return Redirect::back() | |
->with('error', $e->getMessage()); | |
} | |
} | |
public function get_view() | |
{ | |
try { | |
$s = Api::inputs([ | |
'card_id' => 0, | |
'contact_id' => 0, | |
'serie_id' => 0, | |
'account_user_id' => 0, | |
'record_id' => 0, | |
]); | |
$card = Card::find($s['card_id']); | |
if (! $card) { | |
throw new Exception("Could not find form."); | |
} | |
if ($s['account_user_id'] == 0 && Auth::check()) { | |
$s['account_user_id'] = Auth::user()->account_user_id; | |
} | |
$account = User::find($s['account_user_id']); | |
if (! $account) { | |
throw new Exception("Could not find an account."); | |
} | |
$card_options = array( | |
'compact' => $card->compact, | |
'groups' => $card->groups, | |
'record' => $s['record_id'] > 0 && Auth::check() ? Record::find($s['record_id']) : null | |
); | |
return View::make('card.view', [ | |
'account' => $account, | |
'account_user_id' => $s['account_user_id'], | |
'card' => $card, | |
'serie_id' => $s['serie_id'], | |
'contact_id' => $s['contact_id'], | |
'form_elements' => Card::read_form_elements($card_options) | |
]); | |
} catch (Exception $e) { | |
return Redirect::home() | |
->with('error', $e->getMessage()); | |
} | |
} | |
public function get_print($id = 0) | |
{ | |
$card = Card::find($id); | |
$form_elements = Card::read_form_elements(array( | |
'compact' => $card->compact, | |
'show_submit' => false, | |
'groups' => $card->groups | |
)); | |
return View::make('card.print', array( | |
'card' => $card, | |
'form_elements' => $form_elements, | |
'to_columns' => function($dropdown) { | |
return explode("\n", $dropdown); | |
}, | |
'to_radios' => function($dropdown) { | |
$page = ""; | |
$options = explode("\n", $dropdown); | |
foreach ($options as $option) { | |
if ($option != '') { | |
$page .= " | |
<label class='radio'> | |
<input type='radio'> {$option} | |
</label> | |
"; | |
} | |
} | |
return $page; | |
} | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment