public function register() { $this->auth->force_authentication(); $user_nick = $this->auth->get_user(); $errors = []; $user_details = $this->model->is_registered_for_ttt($user_nick); if (!$user_details && $_SERVER['REQUEST_METHOD'] === 'POST') { required_post_params(['contact_number'], $errors); if (!empty($_POST['contact_number']) && !is_valid_phone_number($_POST['contact_number'])) { $errors['contact_number'] = 'Please enter a valid phone number'; } if (!$errors) { $success = $this->model->register_for_ttt($user_nick, $_POST['contact_number']); if ($success) { $redirect_url = $this->get_ttt_payment_url($user_nick, $_POST['contact_number']); $this->load_library('http_lib', 'http'); $this->http->redirect($redirect_url); } else { $errors['common'] = 'Some unexpected error occured'; } } } $payment_url = $this->get_ttt_payment_url($user_nick, $user_details['contact_number']); $this->load_view('skeleton_template/header', ['title' => __('Register') . ' · ' . __('Terribly Tiny Tales Workshop'), 'is_authenticated' => true, 'user_nick' => $user_nick]); $this->load_view('contest/ttt_workshop', ['user_nick' => $user_nick, 'user_details' => $user_details, 'payment_url' => $payment_url, 'errors' => $errors]); $this->load_view('skeleton_template/footer'); }
public function setValue($name, $value) { if (!isset($this->fields[$name])) { trigger_error('Cannot set value for field ' . ents($name) . ' - field does not exist', E_USER_WARNING); return FALSE; } if (array_get($this->fields[$name], 'readonly')) { trigger_error('Cannot set value for readonly field "' . $name . '"', E_USER_WARNING); return; } if (array_get($this->fields[$name], 'initial_cap')) { $value = ucfirst($value); } if (array_get($this->fields[$name], 'trim')) { $value = trim($value, ",;. \t\n\r\v"); } if ($this->fields[$name]['type'] == 'select') { if (!isset($this->fields[$name]['options'][$value]) && !(array_get($this->fields[$name], 'allow_empty', 1) && empty($value))) { trigger_error(ents($value) . ' is not a valid value for field "' . $name . '", and has not been set', E_USER_NOTICE); return; } } if ($this->fields[$name]['type'] == 'phone' && $value != '') { if (!is_valid_phone_number($value, $this->fields[$name]['formats'])) { trigger_error(ents($value) . ' is not a valid phone number for field "' . $name . '", and has not been set', E_USER_NOTICE); return; } $value = clean_phone_number($value); } if (!empty($this->fields[$name]['maxlength']) && strlen($value) > $this->fields[$name]['maxlength']) { $value = substr($value, 0, $this->fields[$name]['maxlength']); } if ($this->fields[$name]['type'] == 'int') { if (!array_get($this->fields[$name], 'allow_empty', true) || $value !== '') { $strval = (string) $value; for ($i = 0; $i < strlen($strval); $i++) { $char = $strval[$i]; if ((int) $char != $char) { trigger_error(ents($value) . ' is not a valid value for integer field "' . $name . '" and has not been set', E_USER_NOTICE); return; } } } } if (array_key_exists($name, $this->values) && $this->values[$name] != $value && !isset($this->_old_values[$name])) { $this->_old_values[$name] = $this->values[$name]; } $this->values[$name] = $value; }
function process_widget($name, $params) { $value = null; switch ($params['type']) { case 'phone': if (array_get($params, 'allow_empty', TRUE) && empty($_REQUEST[$name])) { $value = ''; } else { if (!is_valid_phone_number($_REQUEST[$name], $params['formats'])) { trigger_error('The phone number "' . $_REQUEST[$name] . '" is not valid and has not been set', E_USER_NOTICE); $value = NULL; } else { $value = clean_phone_number($_REQUEST[$name]); } } break; case 'date': if (isset($_REQUEST[$name])) { // might have an ISO8601 date if (preg_match('/^(\\d\\d\\d\\d-\\d\\d-\\d\\d)$/', $_REQUEST[$name])) { return $_REQUEST[$name]; } } if (FALSE === strpos($name, '[')) { $subindex = NULL; } else { $subindex = substr($name, strpos($name, '[') + 1, strpos($name, ']') - strpos($name, '[') - 1); $name = substr($name, 0, strpos($name, '[')); } if (!isset($_REQUEST[$name . '_d'])) { return NULL; } if (!is_null($subindex) && !isset($_REQUEST[$name . '_d'][$subindex])) { return NULL; } foreach (array('y', 'm', 'd') as $comp) { $comp_vals[$comp] = array_get($_REQUEST, $name . '_' . $comp, 0); if (!is_null($subindex)) { $comp_vals[$comp] = $comp_vals[$comp][$subindex]; } } $value = sprintf('%04d-%02d-%02d', $comp_vals['y'], $comp_vals['m'], $comp_vals['d']); if ($value == '0000-00-00') { return NULL; } if ($value == '0000-01-00') { return NULL; } if (array_get($params, 'allow_blank_year') && !(int) $comp_vals['y']) { $value = substr($value, 4); if (date('-m-d', strtotime('2000' . $value)) != $value) { trigger_error('The date "' . $value . '" is not valid and has not been set', E_USER_NOTICE); $value = NULL; } } else { if (date('Y-m-d', strtotime($value)) != $value) { trigger_error('The date "' . $value . '" is not valid and has not been set', E_USER_NOTICE); $value = NULL; } } break; case 'bibleref': if (!empty($_REQUEST[$name])) { require_once 'bible_ref.class.php'; $br = new bible_ref($_REQUEST[$name]); if ($br->book) { $value = $br->toCode(); } } break; case 'bitmask': // value is the bitwise-or of all submitted values $value = 0; if (isset($_REQUEST[$name])) { if (isset($_REQUEST[$name])) { foreach ($_REQUEST[$name] as $i) { $value = $value | (int) $i; } } } break; case 'html': if (isset($_REQUEST[$name])) { require_once 'htmLawed.php'; $value = htmLawed($_REQUEST[$name], array('deny_attribute' => '* -href', 'safe' => 1)); } break; default: $value = array_get($_REQUEST, $name); if (!empty($params['regex']) && !empty($value) && !preg_match($params['regex'] . 'i', $value)) { trigger_error($value . ' is not a valid value for ' . array_get($params, 'label', ucfirst($name))); $value = NULL; } break; } return $value; }
public function webdev_workshop() { $user_nick = $this->auth->get_user(); $user_details = $this->model->is_registered_for_webdev($user_nick); if ($user_details) { $this->go_to_webdev_workshop_payment($user_details); } else { $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { required_post_params(['contact_number', 'stream', 'year', 'experience', 'why_join'], $errors); if (!empty($_POST['contact_number']) && !is_valid_phone_number($_POST['contact_number'])) { $errors['contact_number'] = 'Please enter a valid phone number'; } if (!$errors) { $user_details = ['nick' => $user_nick, 'contact_number' => $_POST['contact_number'], 'stream' => $_POST['stream'], 'year' => $_POST['year'], 'experience' => $_POST['experience'], 'why_join' => $_POST['why_join']]; if ($this->model->register_for_webdev($user_details)) { $this->go_to_webdev_workshop_payment($user_details); } else { $errors['common'] = __('Some unexpected error occurred'); } } } $this->load_view('skeleton_template/header', ['title' => __('Register') . ' · ' . __('Web development Workshop'), 'is_authenticated' => true, 'user_nick' => $user_nick]); $this->load_view('contest/webdev_workshop', ['user_nick' => $user_nick, 'errors' => $errors]); $this->load_view('skeleton_template/footer'); } }