public function check_access_action($params) { $p = arr::extract($params, ['calling_date', 'shop']); $p['user_id'] = usr::id(); $c = db::exec_count($this->db, "SELECT COUNT(*) FROM i_interview_meta WHERE calling_date = :calling_date AND shop = :shop AND user_id != :user_id", $p); $this->view->render('json', !$c); }
public function action_index() { if ($_POST) { $message = html::chars((string) arr::get($_POST, 'message', '')); if ($message) { // Append user information if ($user = $this->auth->get_user()) { $message .= '<h2>Användarinfo</h2>'; $message .= '<dl>'; foreach (array('id', 'username', 'email') as $field) { $message .= sprintf('<dt>%s</dt><dd>%s</dd>', $field, html::chars($user->{$field})); } $message .= '</dl>'; } $from = arr::extract($_POST, array('e-mail', 'name')); if (!Validate::email($from['e-mail'])) { $from['name'] .= " ({$from['e-mail']})"; $from['e-mail'] = '*****@*****.**'; } $sent = Email::send('*****@*****.**', array($from['e-mail'], $from['name']), '[Änglarna Stockholm] Meddelande från kontaktsidan', $message, TRUE); if ($sent >= 1) { $this->message_add('Ditt meddelande har skickats till ' . html::mailto('*****@*****.**') . '!'); } else { $this->message_add('Något blev fel. Försök igen eller skicka ett vanligt mail till ' . html::mailto('*****@*****.**') . ' istället.', 'error'); } } else { $this->message_add('Du måste ange ett meddelande.', 'error'); } $this->request->reload(); } $this->template->title = 'Kontakta Änglarna Stockholm'; $this->template->content = View::factory('kontakt/index'); }
public function login_action($params) { $params = arr::extract($params, ['name', 'password']); $params['msg'] = "Введите своё имя и пароль"; if (arr::is_all_values_not_null($params)) { $row = db::exec_row($this->db, "SELECT id FROM i_users WHERE name = :name AND password = :password", [':name' => $params['name'], ':password' => md5($params['password'] . $this->salt)]); $params['msg'] = $row ? "complete" : "incorrect"; if ($params['msg'] == "complete") { usr::init([id => $row["id"], name => $params['name']]); header('Location: /interview.html#!start/'); } } $this->view->render('json', $params); }
/** * Loads the landing page for this controller */ public function index() { // Set the current page $this->template->this_page = "addons"; // Nexmo settings view $this->template->content = new View('admin/addons/plugin_settings'); $this->template->content->title = Kohana::lang('nexmo.settings'); $this->template->content->settings_form = new View('nexmo/admin/nexmo_settings'); // Set up the form fields $form = array('nexmo_api_key' => '', 'nexmo_api_secret' => '', 'nexmo_phone_no' => ''); // Get the current settings $nexmo = ORM::factory('nexmo', 1)->loaded ? ORM::factory('nexmo', 1) : new Nexmo_Model(); // Has the form been submitted if ($_POST) { // Extract the data to be validated $nexmo_data = arr::extract($_POST, 'nexmo_api_key', 'nexmo_api_secret', 'nexmo_phone_no'); Kohana::log('debug', Kohana::debug($nexmo_data)); // Invoke model validation on the data if ($nexmo->validate($nexmo_data)) { $nexmo->save(); } } // Check if authorization keys have been set if (empty($nexmo->delivery_receipt_key)) { // Key for authenticating delivery receipt not set, therefore generate $nexmo->delivery_receipt_key = strtoupper(text::random('alnum', 10)); // Save $nexmo->save(); } if (empty($nexmo->inbound_message_key)) { // Key for authenticating incoming messages not set, therefore generate $nexmo->inbound_message_key = strtoupper(text::random('alnum', 10)); // Save $nexmo->save(); } // Set the form data $form = array('nexmo_api_key' => $nexmo->nexmo_api_key, 'nexmo_api_secret' => $nexmo->nexmo_api_secret, 'nexmo_phone_no' => $nexmo->nexmo_phone_no); // Set the content for the view $this->template->content->settings_form->form = $form; // Set the DLR and incoming message URLs $this->template->content->settings_form->delivery_receipt_url = url::site() . 'nexmo/delivery/?key=' . $nexmo->delivery_receipt_key; $this->template->content->settings_form->inbound_message_url = url::site() . 'nexmo/inbound/?key=' . $nexmo->inbound_message_key; // Javascript header $this->template->js = new View('nexmo/admin/nexmo_settings_js'); }
public function action_index() { if (!$this->auth->logged_in()) { $this->request->redirect('/'); } else { $user = $this->auth->get_user(); if ($_POST) { $values = arr::extract($_POST, array('email', 'password'), NULL); $values = array_filter($values, create_function('$x', 'return ! empty($x);')); /** * We have huge problems here: * - $user->check() throws exception if $user->email is the same (since it is not unique) * - $user->values($values) sets values but does not rollback if update() throws exception * - clone $user does not update $user in session if update is successfull * - if $user is updated after update (using values); session user changed() array is forever set * * Solution: remove email if its’ the same as the current email (to avoid unique exception) */ if ($values['email'] === $user->email) { unset($values['email']); } try { // Update user $user->values($user->check($values))->update(); $this->message_add('Din användare har uppdaterats.'); } catch (Validate_Exception $e) { foreach ($e->array->errors('user/index') as $message) { $this->message_add($message, 'error'); } } $this->request->reload(); } $this->template->title = 'Information om ' . html::chars($user->username); $this->template->content = View::factory('user/index')->set('user', $user); } }
/** * Save newly added dynamic categories */ public function save_category() { $this->auto_render = FALSE; $this->template = ""; // Check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST fields with our own things // HT: New code for category save with parent $post = arr::extract($_POST, 'parent_id', 'category_title', 'category_description', 'category_color'); // Category instance for the operation $category = new Category_Model(); if ($category->validate($post)) { $category->save(); $form_saved = TRUE; echo json_encode(array("status" => "saved", "id" => $category->id)); } else { echo json_encode(array("status" => "error")); } } else { echo json_encode(array("status" => "error")); } }
/** * Add Edit Reporter Levels */ public function levels() { $this->template->content = new View('admin/levels'); $this->template->content->title = Kohana::lang('ui_admin.reporter_levels'); // setup and initialize form field names $form = array('level_id' => '', 'level_title' => '', 'level_description' => '', 'level_weight' => ''); // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; // Check, has the form been submitted, if so, setup validation if ($_POST) { // Level_Model instance for the opertation $level = (isset($_POST['level_id']) and Level_Model::is_valid_level($_POST['level_id'])) ? new Level_Model($_POST['level_id']) : new Level_Model(); if ($_POST['action'] == 'a') { // Manually extract the data to be validated $data = arr::extract($_POST, 'level_title', 'level_description', 'level_weight'); if ($level->validate($data)) { $level->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.added_edited')); } else { // Repopulate the form fields $form = arr::overwrite($form, $data->as_array()); // Ropulate the error fields, if any $errors = arr::overwrite($errors, $data->errors('level')); $form_error = TRUE; } } elseif ($_POST['action'] == 'd') { if ($level->loaded) { // Levels are tied to reporters, therefore nullify // @todo Reporter_Model::delink_level($level_id) $level->delete(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.deleted')); } } } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('level')->count_all())); $levels = ORM::factory('level')->orderby('level_weight', 'asc')->find_all($this->items_per_page, $pagination->sql_offset); $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->pagination = $pagination; $this->template->content->total_items = $pagination->total_items; $this->template->content->levels = $levels; }
/** * Create/Edit & Save New Form Field */ public function field_add() { $this->template = ""; $this->auto_render = FALSE; // setup and initialize form field names $form = array('field_type' => '', 'field_name' => '', 'field_default' => '', 'field_required' => '', 'field_width' => '', 'field_height' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $field_add_status = ""; $field_add_response = ""; if ($_POST) { // @todo Manually extract the data to be validated $form_field_data = arr::extract($_POST, 'form_id', 'field_type', 'field_name', 'field_default', 'field_required', 'field_width', 'field_height', 'field_isdate', 'field_ispublic_visible', 'field_ispublic_submit'); // Sanitize the default value (if provided) $form_field_data['field_default'] = $this->input->xss_clean($form_field_data['field_default']); // Form_Field_Model instance $form_field = Form_Field_Model::is_valid_form_field($_POST['field_id']) ? ORM::factory('form_field', $_POST['field_id']) : new Form_Field_Model(); // Validate the form field data if ($form_field->validate($form_field_data)) { // Validation succeeded, proceed... // Check for new form field entry $new_field = $form_field->loaded; // Save the new/modified form field entry $form_field->save(); // Get the form field id $field_id = $form_field->id; // Save optional values if (isset($_POST['field_options'])) { foreach ($_POST['field_options'] as $name => $value) { $option_exists = ORM::factory('form_field_option')->where('form_field_id', $field_id)->where('option_name', $name)->find(); $option_entry = $option_exists->loaded == TRUE ? ORM::factory('form_field_option', $option_exists->id) : new Form_Field_Option_Model(); $option_entry->form_field_id = $field_id; $option_entry->option_name = $name; $option_entry->option_value = $value; $option_entry->save(); } } // If a new field, calculate the field position if (empty($new_field)) { // Calculate the field position $field_position = ORM::factory('form_field')->where(array('form_id' => $form_field->form_id, 'id != ' => $field_id))->count_all() + 1; $form_field->field_position = $field_position; $form_field->save(); } $field_add_status = "success"; $field_add_response = rawurlencode(customforms::get_current_fields($form_field->form_id, $this->user)); } else { // Repopulate the form fields $form = arr::overwrite($form, $form_field_data->as_array()); // Populate the error fields, if any $errors = arr::overwrite($errors, $form_field_data->errors('form')); // populate the response to this post request $field_add_status = "error"; $field_add_response = ""; $field_add_response .= "<ul>"; foreach ($errors as $error_item => $error_description) { $field_add_response .= !$error_description ? '' : "<li>" . $error_description . "</li>"; } $field_add_response .= "</ul>"; } } echo json_encode(array("status" => $field_add_status, "response" => $field_add_response)); }
/** * Add Edit geometrys (KML, KMZ, GeoRSS) */ public function index() { $this->template->content = new View('densitymap/settings'); $this->template->content->title = Kohana::lang('densitymap.densitymap'); // Setup and initialize form field names $form = array('action' => '', 'geometry_id' => '', 'geometry_name' => '', 'kml_file' => '', 'label_lat' => '', 'label_long' => ''); // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; $parents_array = array(); // Check, has the form been submitted, if so, setup validation if ($_POST) { // Fetch the submitted data $post_data = array_merge($_POST, $_FILES); // geometry instance for the actions $geometry = (isset($post_data['geometry_id']) and Densitymap_geometry_Model::is_valid_geometry($post_data['geometry_id'])) ? new Densitymap_geometry_Model($post_data['geometry_id']) : new Densitymap_geometry_Model(); // Check for action if ($post_data['dm_action'] == 'a') { // Manually extract the primary geometry data $geometry_data = arr::extract($post_data, 'category_id', 'kml_file_old', 'label_lat', 'label_lon'); // Grab the geometry file to be uploaded $geometry_data['kml_file'] = isset($post_data['kml_file']['name']) ? $post_data['kml_file']['name'] : NULL; // Extract the geometry file for upload validation $other_data = arr::extract($post_data, 'kml_file'); // Set up validation for the geometry file $post = Validation::factory($other_data)->pre_filter('trim', TRUE)->add_rules('kml_file', 'upload::valid', 'upload::type[kml,kmz]'); $old_file = $geometry->kml_file; // Test to see if validation has passed if ($geometry->validate($geometry_data) and $post->validate(false)) { $geometry->kml_file = $old_file; $geometry->category_id = $geometry_data["category_id"]; $geometry->label_lat = $geometry_data["label_lat"]; $geometry->label_lon = $geometry_data["label_lon"]; // Success! SAVE $geometry->save(); $path_info = upload::save("kml_file"); if ($path_info) { $path_parts = pathinfo($path_info); $file_name = $path_parts['filename']; $file_ext = $path_parts['extension']; if (strtolower($file_ext) == "kmz") { // This is a KMZ Zip Archive, so extract $archive = new Pclzip($path_info); if (TRUE == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING))) { foreach ($archive_files as $file) { $ext_file_name = $file['filename']; } } if ($ext_file_name and $archive->extract(PCLZIP_OPT_PATH, Kohana::config('upload.directory')) == TRUE) { // Okay, so we have an extracted KML - Rename it and delete KMZ file rename($path_parts['dirname'] . "/" . $ext_file_name, $path_parts['dirname'] . "/" . $file_name . ".kml"); $file_ext = "kml"; unlink($path_info); } } $json_file_name = $this->parse_kml($file_name, $file_ext); //delete the KML file unlink(Kohana::config('upload.directory', TRUE) . $file_name . "." . $file_ext); $geometry->kml_file = $json_file_name; $geometry->save(); //delete old file if (!empty($old_file) and file_exists(Kohana::config('upload.directory', TRUE) . $old_file)) { unlink(Kohana::config('upload.directory', TRUE) . $old_file); } } $form_saved = TRUE; array_fill_keys($form, ''); $form_action = strtoupper(Kohana::lang('ui_admin.added_edited')); } else { // Validation failed // Repopulate the form fields $form = arr::overwrite($form, array_merge($geometry_data->as_array(), $post->as_array())); // Ropulate the error fields, if any $errors = arr::overwrite($errors, array_merge($geometry_data->errors('geometry'), $post->errors('geometry'))); $form_error = TRUE; } } elseif ($post_data['dm_action'] == 'd') { // Delete action if ($geometry->loaded) { // Delete KMZ file if any $kml_file = $geometry->kml_file; if (!empty($kml_file) and file_exists(Kohana::config('upload.directory', TRUE) . $kml_file)) { unlink(Kohana::config('upload.directory', TRUE) . $kml_file); } $geometry->delete(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.deleted')); } } } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('densitymap_geometry')->count_all())); $geometrys = ORM::factory('densitymap_geometry')->orderby('id', 'asc')->find_all($this->items_per_page, $pagination->sql_offset); $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->pagination = $pagination; $this->template->content->total_items = $pagination->total_items; $this->template->content->geometrys = $geometrys; //get array of categories $categories = ORM::factory("category")->where("category_visible", "1")->find_all(); $cat_array = array(); foreach ($categories as $category) { $cat_array[$category->id] = $category->category_title; } $this->template->content->cat_array = $cat_array; // Javascript Header $this->template->colorpicker_enabled = TRUE; $this->template->js = new View('densitymap/settings_js'); }
/** * Set map options * * @todo Add $options processing * @param array $options_arr * @param array $options * @return object Yamaps */ public function options($options_arr, $options = array()) { $valid_options = arr::extract($this->_options, $options_arr, NULL); foreach ($valid_options as $name => $options) { $this->options[] = array('name' => $name); } return $this; }
public function get_interviews_count_action($params) { $u = arr::extract($params, ['user_id', 'date']); $count = db::exec_count($this->db, "SELECT COUNT(*) FROM i_interview_meta WHERE user_id = :user_id AND DATE(date) = :date", $u); $this->view->render('json', $count); }
/** * JP: Edit & Save Advanced Form Field */ public function advanced_field_edit() { $this->template = ""; $this->auto_render = FALSE; // setup and initialize form field names $form = array('report_title_name' => '', 'description_name' => '', 'description_active' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $advanced_edit_status = ""; $advanced_edit_response = ""; if ($_POST) { // @todo Manually extract the data to be validated $form_data = arr::extract($_POST, 'advanced_form_id', 'advanced_form_title', 'advanced_form_description', 'advanced_form_active', 'report_title_name', 'description_name', 'description_active'); // Form Model instance $custom_form = Form_Model::is_valid_form($_POST['advanced_form_id']) ? ORM::factory('form', $_POST['advanced_form_id']) : new Form_Model(); // Validate the form data if ($custom_form->validate(Validation::factory($form_data))) { // Validation succeeded, proceed... // Save the new or modified entries // JP: The Report Title and Description fields are saved as null in the database if they match the default names or are empty. if (strcmp(trim($form_data['report_title_name']), Kohana::lang('ui_main.reports_title')) === 0 or empty(trim($form_data['report_title_name']))) { $custom_form->report_title_name = null; } else { $custom_form->report_title_name = trim($form_data['report_title_name']); } if (strcmp(trim($form_data['description_name']), Kohana::lang('ui_main.reports_description')) === 0 or empty(trim($form_data['description_name']))) { $custom_form->description_name = null; } else { $custom_form->description_name = trim($form_data['description_name']); } $custom_form->description_active = $form_data['description_active']; $custom_form->save(); $advanced_edit_status = "success"; $advanced_edit_response = rawurlencode(customforms::get_current_fields($custom_form->id, $this->user)); } else { // Repopulate the form fields $form = arr::overwrite($form, $form_data->as_array()); // Populate the error fields, if any $errors = arr::overwrite($errors, $form_data->errors('form')); // populate the response to this post request $advanced_edit_status = "error"; $advanced_edit_response = ""; $advanced_edit_response .= "<ul>"; foreach ($errors as $error_item => $error_description) { $advanced_edit_response .= !$error_description ? '' : "<li>" . $error_description . "</li>"; } $advanced_edit_response .= "</ul>"; } } echo json_encode(array("status" => $advanced_edit_status, "response" => $advanced_edit_response)); }
/** * Add Edit Layers (KML, KMZ, GeoRSS) */ public function layers() { $this->template->content = new View('admin/manage/layers/main'); $this->template->content->title = Kohana::lang('ui_admin.layers'); // Setup and initialize form field names $form = array('action' => '', 'layer_id' => '', 'layer_name' => '', 'layer_url' => '', 'layer_file' => '', 'layer_color' => ''); // Copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; $parents_array = array(); // Check, has the form been submitted, if so, setup validation if ($_POST) { // Fetch the submitted data $post_data = array_merge($_POST, $_FILES); // Layer instance for the actions $layer = (isset($post_data['layer_id']) and Layer_Model::is_valid_layer($post_data['layer_id'])) ? new Layer_Model($post_data['layer_id']) : new Layer_Model(); // Check for action if ($post_data['action'] == 'a') { // Manually extract the primary layer data $layer_data = arr::extract($post_data, 'layer_name', 'layer_color', 'layer_url', 'layer_file_old'); // Grab the layer file to be uploaded $layer_data['layer_file'] = isset($post_data['layer_file']['name']) ? $post_data['layer_file']['name'] : NULL; // Extract the layer file for upload validation $other_data = arr::extract($post_data, 'layer_file'); // Set up validation for the layer file $post = Validation::factory($other_data)->pre_filter('trim', TRUE)->add_rules('layer_file', 'upload::valid', 'upload::type[kml,kmz]'); // Test to see if validation has passed if ($layer->validate($layer_data) and $post->validate(FALSE)) { // Success! SAVE $layer->save(); $path_info = upload::save("layer_file"); if ($path_info) { $path_parts = pathinfo($path_info); $file_name = $path_parts['filename']; $file_ext = $path_parts['extension']; $layer_file = $file_name . "." . $file_ext; $layer_url = ''; if (strtolower($file_ext) == "kmz") { // This is a KMZ Zip Archive, so extract $archive = new Pclzip($path_info); if (TRUE == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING))) { foreach ($archive_files as $file) { $ext_file_name = $file['filename']; $archive_file_parts = pathinfo($ext_file_name); //because there can be more than one file in a KMZ if ($archive_file_parts['extension'] == 'kml' and $ext_file_name and $archive->extract(PCLZIP_OPT_PATH, Kohana::config('upload.directory')) == TRUE) { // Okay, so we have an extracted KML - Rename it and delete KMZ file rename($path_parts['dirname'] . "/" . $ext_file_name, $path_parts['dirname'] . "/" . $file_name . ".kml"); $file_ext = "kml"; unlink($path_info); $layer_file = $file_name . "." . $file_ext; } } } } // Upload the KML to the CDN server if configured if (Kohana::config("cdn.cdn_store_dynamic_content")) { // Upload the file to the CDN $layer_url = cdn::upload($layer_file); // We no longer need the files we created on the server. Remove them. $local_directory = rtrim(Kohana::config('upload.directory', TRUE), '/') . '/'; unlink($local_directory . $layer_file); // We no longer need to store the file name for the local file since it's gone $layer_file = ''; } // Set the final variables for the DB $layer->layer_url = $layer_url; $layer->layer_file = $layer_file; $layer->save(); } $form_saved = TRUE; array_fill_keys($form, ''); $form_action = utf8::strtoupper(Kohana::lang('ui_admin.added_edited')); } else { // Validation failed // Repopulate the form fields $form = arr::overwrite($form, array_merge($layer_data->as_array(), $post->as_array())); // Ropulate the error fields, if any $errors = arr::overwrite($errors, array_merge($layer_data->errors('layer'), $post->errors('layer'))); $form_error = TRUE; } } elseif ($post_data['action'] == 'd') { // Delete action if ($layer->loaded) { // Delete KMZ file if any $layer_file = $layer->layer_file; if (!empty($layer_file) and file_exists(Kohana::config('upload.directory', TRUE) . $layer_file)) { unlink(Kohana::config('upload.directory', TRUE) . $layer_file); } $layer->delete(); $form_saved = TRUE; $form_action = utf8::strtoupper(Kohana::lang('ui_admin.deleted')); } } elseif ($post_data['action'] == 'v') { // Show/Hide Action if ($layer->loaded == TRUE) { $layer->layer_visible = $layer->layer_visible == 1 ? 0 : 1; $layer->save(); $form_saved = TRUE; $form_action = utf8::strtoupper(Kohana::lang('ui_admin.modified')); } } elseif ($post_data['action'] == 'i') { // Delete KML/KMZ action if ($layer->loaded == TRUE) { $layer_file = $layer->layer_file; if (!empty($layer_file) and file_exists(Kohana::config('upload.directory', TRUE) . $layer_file)) { unlink(Kohana::config('upload.directory', TRUE) . $layer_file); } $layer->layer_file = null; $layer->save(); $form_saved = TRUE; $form_action = utf8::strtoupper(Kohana::lang('ui_admin.modified')); } } } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('layer')->count_all())); $layers = ORM::factory('layer')->orderby('layer_name', 'asc')->find_all($this->items_per_page, $pagination->sql_offset); $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->pagination = $pagination; $this->template->content->total_items = $pagination->total_items; $this->template->content->layers = $layers; // Javascript Header $this->themes->colorpicker_enabled = TRUE; $this->themes->js = new View('admin/manage/layers/layers_js'); }