/** * Announces this module's details to those in the know. * * @access static * @param none * @return void **/ static function announce() { if (!module_is_enabled('shop')) { return FALSE; } // -------------------------------------------------------------------------- $d = new stdClass(); // -------------------------------------------------------------------------- // Configurations $d->name = 'Shop'; // Display name. // -------------------------------------------------------------------------- // Navigation options $d->funcs = array(); $d->funcs['inventory'] = 'Manage Inventory'; // Sub-nav function. $d->funcs['orders'] = 'Manage Orders'; // Sub-nav function. $d->funcs['vouchers'] = 'Manage Vouchers'; // Sub-nav function. $d->funcs['sales'] = 'Manage Sales'; // Sub-nav function. $d->funcs['manage'] = 'Other Managers'; // Sub-nav function. $d->funcs['reports'] = 'Generate Reports'; // Sub-nav function. // -------------------------------------------------------------------------- // Only announce the controller if the user has permission to know about it return self::_can_access($d, __FILE__); }
/** * Announces this module's details to those in the know. * * @access static * @param none * @return void **/ static function announce() { if (!module_is_enabled('blog')) { return FALSE; } // -------------------------------------------------------------------------- $d = new stdClass(); // -------------------------------------------------------------------------- // Configurations $d->name = 'Blog'; // Display name. // -------------------------------------------------------------------------- // Navigation options $d->funcs = array(); $d->funcs['index'] = 'Manage Posts'; // Sub-nav function. $d->funcs['create'] = 'Create New Post'; // Sub-nav function. get_instance()->load->helper('blog_helper'); if (app_setting('categories_enabled', 'blog')) { $d->funcs['manage/categories'] = 'Manage Categories'; // Sub-nav function. } if (app_setting('tags_enabled', 'blog')) { $d->funcs['manage/tags'] = 'Manage Tags'; // Sub-nav function. } // -------------------------------------------------------------------------- // Only announce the controller if the user has permission to know about it return self::_can_access($d, __FILE__); }
/** * Announces this module's details to those in the know. * * @access static * @param none * @return void **/ static function announce() { if (!module_is_enabled('cms')) { return FALSE; } // -------------------------------------------------------------------------- $d = new stdClass(); // -------------------------------------------------------------------------- // Configurations $d->name = 'Content Management'; // Display name. // -------------------------------------------------------------------------- // Navigation options $d->funcs = array(); $d->funcs['menus'] = 'Manage Menus'; // Sub-nav function. $d->funcs['pages'] = 'Manage Pages'; // Sub-nav function. $d->funcs['blocks'] = 'Manage Blocks'; // Sub-nav function. $d->funcs['sliders'] = 'Manage Sliders'; // Sub-nav function. // -------------------------------------------------------------------------- // Only announce the controller if the user has permission to know about it return self::_can_access($d, __FILE__); }
public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- // Default export sources $_acl = active_user('acl'); $this->_export_sources = array(); if ($this->user_model->is_superuser() || isset($_acl['admin']['accounts']['index'])) { $this->_export_sources[] = array('Members: All', 'Export a list of all the site\'s registered users and their meta data.', 'users_all'); } if (module_is_enabled('shop')) { if ($this->user_model->is_superuser() || isset($_acl['admin']['shop']['inventory'])) { $this->_export_sources[] = array('Shop: Inventory', 'Export a list of the shop\'s inventory.', 'shop_inventory'); } if ($this->user_model->is_superuser() || isset($_acl['admin']['shop']['orders'])) { $this->_export_sources[] = array('Shop: Orders', 'Export a list of all shop orders and their products.', 'shop_orders'); } if ($this->user_model->is_superuser() || isset($_acl['admin']['shop']['vouchers'])) { $this->_export_sources[] = array('Shop: Vouchers', 'Export a list of all shop vouchers.', 'shop_vouchers'); } } // -------------------------------------------------------------------------- // Default export formats $this->_export_formats = array(); $this->_export_formats[] = array('CSV', 'Easily imports to many software packages, including Microsoft Excel.', 'csv'); $this->_export_formats[] = array('HTML', 'Produces an HTML table containing the data', 'html'); $this->_export_formats[] = array('PHP Serialize', 'Export as an object serialized using PHP\'s serialize() function', 'serialize'); $this->_export_formats[] = array('JSON', 'Export as a JSON array', 'json'); }
/** * Constructor * * @access public * @return void * **/ public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- // Check this module is enabled in settings if (!module_is_enabled('shop')) { // Cancel execution, module isn't enabled $this->_method_not_found($this->uri->segment(2)); } }
public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- // Check this module is enabled in settings if (!module_is_enabled('cms')) { // Cancel execution, module isn't enabled show_404(); } // -------------------------------------------------------------------------- // Load language file $this->lang->load('cms'); }
public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- // Enabled? if (!module_is_enabled('sitemap')) { show_404(); } // -------------------------------------------------------------------------- $this->load->model('sitemap/sitemap_model'); $this->_filename_json = $this->sitemap_model->get_filename_json(); $this->_filename_xml = $this->sitemap_model->get_filename_xml(); }
public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- // Check this module is enabled in settings if (!module_is_enabled('shop')) { // Cancel execution, module isn't enabled show_404(); } // -------------------------------------------------------------------------- // Load language file $this->lang->load('shop'); // -------------------------------------------------------------------------- // Load the models $this->load->model('shop/shop_model'); $this->load->model('shop/shop_basket_model'); $this->load->model('shop/shop_brand_model'); $this->load->model('shop/shop_category_model'); $this->load->model('shop/shop_collection_model'); $this->load->model('shop/shop_currency_model'); $this->load->model('shop/shop_order_model'); $this->load->model('shop/shop_product_model'); $this->load->model('shop/shop_product_type_model'); $this->load->model('shop/shop_range_model'); $this->load->model('shop/shop_shipping_model'); $this->load->model('shop/shop_sale_model'); $this->load->model('shop/shop_tag_model'); $this->load->model('shop/shop_voucher_model'); $this->load->model('shop/shop_skin_model'); // -------------------------------------------------------------------------- // Load up the shop's skin $_skin = app_setting('skin', 'shop') ? app_setting('skin', 'shop') : 'getting-started'; $this->_skin = $this->shop_skin_model->get($_skin); if (!$this->_skin) { show_fatal_error('Failed to load shop skin "' . $_skin . '"', 'Shop skin "' . $_skin . '" failed to load at ' . APP_NAME . ', the following reason was given: ' . $this->shop_skin_model->last_error()); } // -------------------------------------------------------------------------- // Pass to $this->data, for the views $this->data['skin'] = $this->_skin; // -------------------------------------------------------------------------- // Shop's name $this->_shop_name = app_setting('name', 'shop') ? app_setting('name', 'shop') : 'Shop'; }
public function daily() { $this->_start('maintenance', 'daily', 'Daily Maintenance Tasks'); // -------------------------------------------------------------------------- // Daily Tasks // Shop related tasks if (module_is_enabled('shop')) { _LOG('Shop Module Enabled. Beginning Shop Tasks.'); // -------------------------------------------------------------------------- // Load models $this->load->model('shop/shop_model'); $this->load->model('shop/shop_currency_model'); // -------------------------------------------------------------------------- // Sync Currencies _LOG('... Synching Currencies'); if (!$this->shop_currency_model->sync()) { _LOG('... ... FAILED: ' . $this->shop_currency_model->last_error()); } // -------------------------------------------------------------------------- _LOG('Finished Shop Tasks'); } // Site map related tasks, makes sense for this one to come last in case any of // the previous have an impact if (module_is_enabled('sitemap')) { _LOG('Sitemap Module Enabled. Beginning Sitemap Tasks.'); // -------------------------------------------------------------------------- // Load models $this->load->model('sitemap/sitemap_model'); // -------------------------------------------------------------------------- // Generate sitemap _LOG('... Generating Sitemap data'); if (!$this->sitemap_model->generate()) { _LOG('... ... FAILED: ' . $this->sitemap_model->last_error()); } // -------------------------------------------------------------------------- _LOG('Finished Site Tasks'); } // -------------------------------------------------------------------------- $this->_end(); }
public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- // Check this module is enabled in settings if (!module_is_enabled('blog')) { // Cancel execution, module isn't enabled show_404(); } // -------------------------------------------------------------------------- // Load language file $this->lang->load('blog/blog'); // -------------------------------------------------------------------------- // Load the models $this->load->model('blog/blog_model'); $this->load->model('blog/blog_post_model'); $this->load->model('blog/blog_widget_model'); $this->load->model('blog/blog_skin_model'); // -------------------------------------------------------------------------- if (app_setting('categories_enabled', 'blog')) { $this->load->model('blog/blog_category_model'); } if (app_setting('tags_enabled', 'blog')) { $this->load->model('blog/blog_tag_model'); } // -------------------------------------------------------------------------- // Load up the blog's skin $_skin = app_setting('skin', 'blog') ? app_setting('skin', 'blog') : 'getting-started'; $this->_skin = $this->blog_skin_model->get($_skin); if (!$this->_skin) { show_fatal_error('Failed to load blog skin "' . $_skin . '"', 'Blog skin "' . $_skin . '" failed to load at ' . APP_NAME . ', the following reason was given: ' . $this->blog_skin_model->last_error()); } // -------------------------------------------------------------------------- // Pass to $this->data, for the views $this->data['skin'] = $this->_skin; // -------------------------------------------------------------------------- // Blog name $this->_blog_name = app_setting('name', 'blog') ? app_setting('name', 'blog') : 'Blog'; }
/** * Constructor * * @access public * @return void * **/ public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- $this->_authorised = TRUE; $this->_error = ''; // -------------------------------------------------------------------------- if (!module_is_enabled('cms')) { // Cancel execution, module isn't enabled show_404(); } // -------------------------------------------------------------------------- // Only logged in users if (!$this->user_model->is_logged_in()) { $this->_authorised = FALSE; $this->_error = lang('auth_require_session'); } // -------------------------------------------------------------------------- // Only admins if (!$this->user_model->is_admin()) { $this->_authorised = FALSE; $this->_error = lang('auth_require_administrator'); } }
protected function _test_shop() { // Reset result $this->_result->pass = TRUE; $this->_result->errors = array(); // -------------------------------------------------------------------------- $_buckets = array(); $_buckets[] = 'shop-product-images'; $_buckets[] = 'shop-brand-logos'; $_buckets[] = 'shop-download'; // -------------------------------------------------------------------------- // CDN Enabled? if (!module_is_enabled('cdn')) { $this->_result->pass = FALSE; $this->_result->errors[] = 'CDN is not enabled.'; return $this->_result; } else { $this->load->library('cdn'); } // -------------------------------------------------------------------------- // Execute test foreach ($_buckets as $bucket) { $this->db->where('slug', $bucket); $_bucket = $this->db->get(NAILS_DB_PREFIX . 'cdn_bucket'); if (!$_bucket) { // Attempt to create if (!$this->cdn->bucket_create($bucket)) { $this->_result->pass = FALSE; $this->_result->errors[] = '"' . $bucket . '" does not exist and is required, could not crete bucket (' . $this->cdn->last_error() . ').'; continue; } } } // -------------------------------------------------------------------------- return $this->_result; }
protected function _get_meta_columns($prefix = '', $cols = array()) { // Module: shop if (module_is_enabled('shop')) { $cols[] = 'shop_basket'; $cols[] = 'shop_currency'; } // -------------------------------------------------------------------------- // Clean up $cols = array_unique($cols); $cols = array_filter($cols); // -------------------------------------------------------------------------- // Prefix all the values, if needed if ($prefix) { foreach ($cols as $key => &$value) { $value = $prefix . '.' . $value; } } // -------------------------------------------------------------------------- return $cols; }
public function delete($id) { $_page = $this->get_by_id($id); if (!$_page) { $this->_set_error('Invalid page ID'); return FALSE; } // -------------------------------------------------------------------------- $this->db->trans_begin(); $this->db->where('id', $id); $this->db->set('is_deleted', TRUE); $this->db->set('modified', 'NOW()', FALSE); if ($this->user_model->is_logged_in()) { $this->db->set('modified_by', active_user('id')); } if ($this->db->update($this->_table)) { // Success, update children $_children = $this->get_ids_of_children($id); if ($_children) { $this->db->where_in('id', $_children); $this->db->set('is_deleted', TRUE); $this->db->set('modified', 'NOW()', FALSE); if ($this->user_model->is_logged_in()) { $this->db->set('modified_by', active_user('id')); } if (!$this->db->update($this->_table)) { $this->_set_error('Unable to delete children pages'); $this->db->trans_rollback(); return FALSE; } } // -------------------------------------------------------------------------- // Rewrite routes $this->load->model('system/routes_model'); $this->routes_model->update('cms'); // -------------------------------------------------------------------------- // Regenerate sitemap if (module_is_enabled('sitemap')) { $this->load->model('sitemap/sitemap_model'); $this->sitemap_model->generate(); } // -------------------------------------------------------------------------- $this->db->trans_commit(); return TRUE; } else { // Failed $this->db->trans_rollback(); return FALSE; } }
/** * Manage evcents * * @access public * @param none * @return void **/ public function index() { // Page Title $this->data['page']->title = lang('notification_index_title'); // -------------------------------------------------------------------------- if ($this->input->post()) { $_notification = $this->input->post('notification'); if (is_array($_notification)) { $this->load->helper('email'); $_set = array(); foreach ($_notification as $grouping => $options) { $_set[$grouping] = array(); foreach ($options as $key => $emails) { $emails = explode(',', $emails); $emails = array_filter($emails); $emails = array_unique($emails); foreach ($emails as &$email) { $email = trim($email); if (!valid_email($email)) { $_error = '"<strong>' . $email . '</strong>" is not a valid email.'; break 3; } } $_set[$grouping][$key] = $emails; } } if (empty($_error)) { foreach ($_set as $grouping => $options) { $this->app_notification_model->set($options, $grouping); } $this->data['success'] = '<strong>Success!</strong> Notifications were updated successfully.'; } else { $this->data['error'] = $_error; } } } // -------------------------------------------------------------------------- // Conditionally set this as this method may be overridden by the app to add // custom notification types if (empty($this->data['notifications'])) { $this->data['notifications'] = array(); } // Generic Site notifications // $this->data['notifications']['app'] = new stdClass(); // $this->data['notifications']['app']->label = 'Site'; // $this->data['notifications']['app']->description = 'General site notifications.'; // $this->data['notifications']['app']->options = array(); // $this->data['notifications']['app']->options['foo'] = 'Bar'; if (module_is_enabled('shop')) { $this->data['notifications']['shop'] = new stdClass(); $this->data['notifications']['shop']->label = 'Shop'; $this->data['notifications']['shop']->description = 'Shop related notifications.'; $this->data['notifications']['shop']->options = array(); $this->data['notifications']['shop']->options['notify_order'] = 'Order Notifications'; } // -------------------------------------------------------------------------- // Load views $this->load->view('structure/header', $this->data); $this->load->view('admin/notification/index', $this->data); $this->load->view('structure/footer', $this->data); }
protected function _routes_blog() { $_routes = array(); if (module_is_enabled('blog')) { $_settings = app_setting(NULL, 'blog'); $_routes['//BEGIN BLOG'] = ''; // Blog front page route $_routes[substr($_settings['url'], 0, -1) . '(/(:any)?/?)?'] = 'blog/$2'; $_routes['//END BLOG'] = ''; } return $_routes; }
protected function _autoload_items() { $_packages = array(); $_packages[] = NAILS_PATH; foreach ($_packages as $package) { $this->load->add_package_path($package); } // -------------------------------------------------------------------------- $_libraries = array(); // Test that $_SERVER is available, the session library needs this // Generally not available when running on the command line. If it's // not available then load up the faux session which has the same methods // as the session library, but behave as if logged out - comprende? if ($this->input->server('REMOTE_ADDR')) { $_libraries[] = 'session'; } else { $_libraries[] = array('faux_session', 'session'); } // -------------------------------------------------------------------------- // STOP! Before we load the session library, we need to check if we're using // the database. If we are then check if `sess_table_name` is "nails_session". // If it is, and NAILS_DB_PREFIX != nails_ then replace 'nails_' with NAILS_DB_PREFIX $_sess_table_name = $this->config->item('sess_table_name'); if ($_sess_table_name === 'nails_session' && NAILS_DB_PREFIX !== 'nails_') { $_sess_table_name = str_replace('nails_', NAILS_DB_PREFIX, $_sess_table_name); $this->config->set_item('sess_table_name', $_sess_table_name); } // -------------------------------------------------------------------------- $_libraries[] = 'encrypt'; $_libraries[] = 'asset'; $_libraries[] = 'logger'; foreach ($_libraries as $library) { if (is_array($library)) { $this->load->library($library[0], array(), $library[1]); } else { $this->load->library($library); } } // -------------------------------------------------------------------------- // Load the system & user helper $this->load->helper('system'); $this->load->helper('user'); // -------------------------------------------------------------------------- $_helpers = array(); $_helpers[] = 'app_setting'; $_helpers[] = 'app_notification'; $_helpers[] = 'datetime'; $_helpers[] = 'url'; $_helpers[] = 'cookie'; $_helpers[] = 'form'; $_helpers[] = 'html'; $_helpers[] = 'tools'; $_helpers[] = 'debug'; $_helpers[] = 'language'; $_helpers[] = 'text'; $_helpers[] = 'exception'; $_helpers[] = 'typography'; $_helpers[] = 'event'; $_helpers[] = 'log'; // Module specific helpers // CDN if (module_is_enabled('cdn')) { $_helpers[] = 'cdn'; } // Shop if (module_is_enabled('shop')) { $_helpers[] = 'shop'; } // Blog if (module_is_enabled('blog')) { $_helpers[] = 'blog'; } // CMS if (module_is_enabled('cms')) { $_helpers[] = 'cms'; } // Load... foreach ($_helpers as $helper) { $this->load->helper($helper); } // -------------------------------------------------------------------------- $_models = array(); $_models[] = 'system/app_setting_model'; $_models[] = 'system/user_model'; $_models[] = 'system/user_group_model'; $_models[] = 'system/user_password_model'; $_models[] = 'system/datetime_model'; $_models[] = 'system/language_model'; foreach ($_models as $model) { $this->load->model($model); } }
/** * Construct the class; set defaults * * @access public * @return void * **/ public function __construct() { parent::__construct(); // -------------------------------------------------------------------------- // Module enabled? if (!module_is_enabled('cdn')) { show_404(); } // -------------------------------------------------------------------------- // Determine if browsing/uploading is permitted $this->data['enabled'] = $this->user_model->is_logged_in() ? TRUE : FALSE; $this->data['enabled'] = TRUE; // -------------------------------------------------------------------------- // Load CDN library $this->load->library('cdn'); // -------------------------------------------------------------------------- if ($this->data['enabled']) { // Define the directory, if a bucket has been specified use that, if not // then use the user's upload directory if ($this->input->get('bucket') && $this->input->get('hash')) { // Decrypt the bucket and cross reference with the hash. Doing this so // That users can't casually specify a bucket and upload willy nilly. $_bucket = $this->input->get('bucket'); $_hash = $this->input->get('hash'); $_decrypted = $this->encrypt->decode($_bucket, APP_PRIVATE_KEY); if ($_decrypted) { $_bucket = explode('|', $_decrypted); if ($_bucket[0] && isset($_bucket[1])) { // Bucket and nonce set, cross-check if (md5($_bucket[0] . '|' . $_bucket[1] . '|' . APP_PRIVATE_KEY) === $_hash) { $this->data['bucket'] = $this->cdn->get_bucket($_bucket[0], TRUE, $this->input->get('filter-tag')); if ($this->data['bucket']) { $_test_ok = TRUE; } else { // Bucket doesn't exist - attempt to create it if ($this->cdn->bucket_create($_bucket[0])) { $_test_ok = TRUE; $this->data['bucket'] = $this->cdn->get_bucket($_bucket[0], TRUE, $this->input->get('filter-tag')); } else { $_test_ok = FALSE; $_error = 'Bucket <strong>"' . $_bucket[0] . '"</strong> does not exist'; $_error .= '<small>Additionally, the following error occured while attempting to create the bucket:<br />' . $this->cdn->last_error() . '</small>'; } } } else { $_test_ok = FALSE; $_error = 'Could not verify bucket hash'; } } else { $_test_ok = FALSE; $_error = 'Incomplete bucket hash'; } } else { $_test_ok = FALSE; $_error = 'Could not decrypt bucket hash'; } // -------------------------------------------------------------------------- if (!$_test_ok) { $this->data['enabled'] = FALSE; $this->data['bad_bucket'] = $_error; } } else { // No bucket specified, use the user's upload bucket $_slug = 'user-' . active_user('id'); $_label = 'User Upload Directory'; // -------------------------------------------------------------------------- // Test bucket, if it doesn't exist, create it $this->data['bucket'] = $this->cdn->get_bucket($_slug, TRUE, $this->input->get('filter-tag')); if (!$this->data['bucket']) { $_bucket_id = $this->cdn->bucket_create($_slug, $_label); if (!$_bucket_id) { $this->data['enabled'] = FALSE; $this->data['bad_bucket'] = 'Unable to create upload bucket: ' . $this->cdn->last_error(); } else { $this->data['bucket'] = $this->cdn->get_bucket($_bucket_id, TRUE, $this->input->get('filter-tag')); } } } } }
/** * Configure the shop * * @access public * @param none * @return void **/ public function shop() { if (!module_is_enabled('shop')) { show_404(); } // -------------------------------------------------------------------------- // Set method info $this->data['page']->title = lang('settings_shop_title'); // -------------------------------------------------------------------------- // Load models $this->load->model('shop/shop_model'); $this->load->model('shop/shop_currency_model'); $this->load->model('shop/shop_shipping_model'); $this->load->model('shop/shop_payment_gateway_model'); $this->load->model('shop/shop_tax_rate_model'); $this->load->model('shop/shop_skin_model'); $this->load->model('system/country_model'); // -------------------------------------------------------------------------- // Process POST if ($this->input->post()) { $_method = $this->input->post('update'); if (method_exists($this, '_shop_update_' . $_method)) { $this->{'_shop_update_' . $_method}(); } else { $this->data['error'] = '<strong>Sorry,</strong> I can\'t determine what type of update you are trying to perform.'; } } // -------------------------------------------------------------------------- // Get data $this->data['settings'] = app_setting(NULL, 'shop', TRUE); $this->data['payment_gateways'] = $this->shop_payment_gateway_model->get_available(); $this->data['shipping_modules'] = $this->shop_shipping_model->get_available(); $this->data['skins'] = $this->shop_skin_model->get_available(); $this->data['currencies'] = $this->shop_currency_model->get_all(); $this->data['tax_rates'] = $this->shop_tax_rate_model->get_all(); $this->data['tax_rates_flat'] = $this->shop_tax_rate_model->get_all_flat(); $this->data['countries_flat'] = $this->country_model->get_all_flat(); $this->data['continents_flat'] = $this->country_model->get_all_continents_flat(); array_unshift($this->data['tax_rates_flat'], 'No Tax'); // -------------------------------------------------------------------------- // Load assets $this->asset->load('nails.admin.shop.settings.min.js', TRUE); $this->asset->load('mustache.js/mustache.js', 'BOWER'); $this->asset->inline('<script>_nails_settings = new NAILS_Admin_Shop_Settings();</script>'); // -------------------------------------------------------------------------- // Load views $this->load->view('structure/header', $this->data); $this->load->view('admin/settings/shop', $this->data); $this->load->view('structure/footer', $this->data); }
protected function _generator_shop() { if (module_is_enabled('shop')) { // TODO: all shop product/category/tag/sale routes etc } }
/** * Edit an existing user account * * @access public * @param none * @return void **/ public function edit() { // Get the user's data; loaded early because it's required for the user_meta_cols // (we need to know the group of the user so we can pull up the correct cols/rules) $_user = $this->user_model->get_by_id($this->uri->segment(4)); if (!$_user) { $this->session->set_flashdata('error', lang('accounts_edit_error_unknown_id')); redirect($this->input->get('return_to')); return; } // Non-superusers editing superusers is not cool if (!$this->user_model->is_superuser() && user_has_permission('superuser', $_user)) { $this->session->set_flashdata('error', lang('accounts_edit_error_noteditable')); $_return_to = $this->input->get('return_to') ? $this->input->get('return_to') : 'admin/dashboard'; redirect($_return_to); return; } // Is this user editing someone other than themselves? If so, do they have permission? if (active_user('id') != $_user->id && !user_has_permission('admin.accounts.can_edit_others')) { $this->session->set_flashdata('error', lang('accounts_edit_error_noteditable')); $_return_to = $this->input->get('return_to') ? $this->input->get('return_to') : 'admin/dashboard'; redirect($_return_to); return; } // -------------------------------------------------------------------------- // Load helpers $this->load->helper('date'); // -------------------------------------------------------------------------- // Load the user_meta_cols; loaded here because it's needed for both the view // and the form validation $_user_meta_cols = $this->config->item('user_meta_cols'); $_group_id = $this->input->post('group_id') ? $this->input->post('group_id') : $_user->group_id; if (isset($_user_meta_cols[$_group_id])) { $this->data['user_meta_cols'] = $_user_meta_cols[$_user->group_id]; } else { $this->data['user_meta_cols'] = NULL; } // Set fields to ignore by default $this->data['ignored_fields'] = array(); $this->data['ignored_fields'][] = 'id'; $this->data['ignored_fields'][] = 'user_id'; // If no cols were found, DESCRIBE the user_meta table - where possible // you should manually set columns, including datatypes if (NULL === $this->data['user_meta_cols']) { $_describe = $this->db->query('DESCRIBE `' . NAILS_DB_PREFIX . 'user_meta`')->result(); $this->data['user_meta_cols'] = array(); foreach ($_describe as $col) { // Always ignore some fields if (array_search($col->Field, $this->data['ignored_fields']) !== FALSE) { continue; } // -------------------------------------------------------------------------- // Attempt to detect datatype $_datatype = 'string'; $_type = 'text'; switch (strtolower($col->Type)) { case 'text': $_type = 'textarea'; break; case 'date': $_datatype = 'date'; break; case 'tinyint(1) unsigned': $_datatype = 'bool'; break; } // -------------------------------------------------------------------------- $this->data['user_meta_cols'][$col->Field] = array('datatype' => $_datatype, 'type' => $_type, 'label' => ucwords(str_replace('_', ' ', $col->Field))); } } // -------------------------------------------------------------------------- // Validate if we're saving, otherwise get the data and display the edit form if ($this->input->post()) { // Load validation library $this->load->library('form_validation'); // -------------------------------------------------------------------------- // Define user table rules $this->form_validation->set_rules('username', '', 'xss_clean|alpha_dash|min_length[2]|unique_if_diff[' . NAILS_DB_PREFIX . 'user.username.' . $this->input->post('username_orig') . ']'); $this->form_validation->set_rules('first_name', '', 'xss_clean|required'); $this->form_validation->set_rules('last_name', '', 'xss_clean|required'); $this->form_validation->set_rules('gender', '', 'xss_clean|required'); $this->form_validation->set_rules('timezone', '', 'xss_clean|required'); $this->form_validation->set_rules('datetime_format_date', '', 'xss_clean|required'); $this->form_validation->set_rules('datetime_format_time', '', 'xss_clean|required'); $this->form_validation->set_rules('language', '', 'xss_clean|required'); $this->form_validation->set_rules('password', '', 'xss_clean'); $this->form_validation->set_rules('temp_pw', '', 'xss_clean'); $this->form_validation->set_rules('reset_security_questions', '', 'xss_clean'); // -------------------------------------------------------------------------- // Define user_meta table rules foreach ($this->data['user_meta_cols'] as $col => $value) { $_datatype = isset($value['datatype']) ? $value['datatype'] : 'string'; $_label = isset($value['label']) ? $value['label'] : ucwords(str_replace('_', ' ', $col)); // Some data types require different handling switch ($_datatype) { case 'date': // Dates must validate if (isset($value['validation'])) { $this->form_validation->set_rules($col, $_label, 'xss_clean|' . $value['validation'] . '|valid_date[' . $col . ']'); } else { $this->form_validation->set_rules($col, $_label, 'xss_clean|valid_date[' . $col . ']'); } break; // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- case 'file': case 'upload': case 'string': default: if (isset($value['validation'])) { $this->form_validation->set_rules($col, $_label, 'xss_clean|' . $value['validation']); } else { $this->form_validation->set_rules($col, $_label, 'xss_clean'); } break; } } // -------------------------------------------------------------------------- // Set messages $this->form_validation->set_message('required', lang('fv_required')); $this->form_validation->set_message('is_natural_no_zero', lang('fv_required')); $this->form_validation->set_message('valid_date', lang('fv_valid_date')); $this->form_validation->set_message('valid_datetime', lang('fv_valid_datetime')); // -------------------------------------------------------------------------- // Data is valid; ALL GOOD :] if ($this->form_validation->run($this)) { // Define the data var $_data = array(); // -------------------------------------------------------------------------- // If we have a profile image, attempt to upload it if (isset($_FILES['profile_img']) && $_FILES['profile_img']['error'] != 4) { $_object = $this->cdn->object_replace($_user->profile_img, 'profile-images', 'profile_img'); if ($_object) { $_data['profile_img'] = $_object->id; } else { $this->data['upload_error'] = $this->cdn->get_errors(); $this->data['error'] = lang('accounts_edit_error_profile_img'); } } // -------------------------------------------------------------------------- if (!isset($this->data['upload_error'])) { // Set basic data $_data['temp_pw'] = string_to_boolean($this->input->post('temp_pw')); $_data['reset_security_questions'] = string_to_boolean($this->input->post('reset_security_questions')); $_data['first_name'] = $this->input->post('first_name'); $_data['last_name'] = $this->input->post('last_name'); $_data['username'] = $this->input->post('username'); $_data['gender'] = $this->input->post('gender'); $_data['timezone'] = $this->input->post('timezone'); $_data['datetime_format_date'] = $this->input->post('datetime_format_date'); $_data['datetime_format_time'] = $this->input->post('datetime_format_time'); $_data['language'] = $this->input->post('language'); if ($this->input->post('password')) { $_data['password'] = $this->input->post('password'); } // Set meta data foreach ($this->data['user_meta_cols'] as $col => $value) { switch ($value['datatype']) { case 'bool': case 'boolean': // Convert all to boolean from string $_data[$col] = string_to_boolean($this->input->post($col)); break; // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- default: $_data[$col] = $this->input->post($col); break; } } // -------------------------------------------------------------------------- // Update account if ($this->user_model->update($this->input->post('id'), $_data)) { $_name = $this->input->post('first_name') . ' ' . $this->input->post('last_name'); $this->data['success'] = lang('accounts_edit_ok', array(title_case($_name))); // -------------------------------------------------------------------------- // Set Admin changelogs $_name = '#' . number_format($this->input->post('id')); if ($_data['first_name']) { $_name .= ' ' . $_data['first_name']; } if ($_data['last_name']) { $_name .= ' ' . $_data['last_name']; } foreach ($_data as $field => $value) { if (isset($_user->{$field})) { _ADMIN_CHANGE_ADD('updated', 'a', 'user', $this->input->post('id'), $_name, 'admin/accounts/edit/' . $this->input->post('id'), $field, $_user->{$field}, $value, FALSE); } } // -------------------------------------------------------------------------- // refresh the user object $_user = $this->user_model->get_by_id($this->input->post('id')); // The account failed to update, feedback to user } else { $this->data['error'] = lang('accounts_edit_fail', implode(', ', $this->user_model->get_errors())); } } // Update failed for another reason } else { $this->data['error'] = lang('fv_there_were_errors'); } } // End POST() check // -------------------------------------------------------------------------- // Get the user's meta data if ($this->data['user_meta_cols']) { $this->db->select(implode(',', array_keys($this->data['user_meta_cols']))); $this->db->where('user_id', $_user->id); $_user_meta = $this->db->get(NAILS_DB_PREFIX . 'user_meta')->row(); } else { $_user_meta = array(); } // -------------------------------------------------------------------------- // Get the user's email addresses $this->data['user_emails'] = $this->user_model->get_emails_for_user($_user->id); // -------------------------------------------------------------------------- $this->data['user_edit'] = $_user; $this->data['user_meta'] = $_user_meta; // Page Title $this->data['page']->title = lang('accounts_edit_title', title_case($_user->first_name . ' ' . $_user->last_name)); // Get the groups, timezones and languages $this->data['groups'] = $this->user_group_model->get_all(); $this->data['timezones'] = $this->datetime_model->get_all_timezone_flat(); $this->data['date_formats'] = $this->datetime_model->get_all_date_format(); $this->data['time_formats'] = $this->datetime_model->get_all_time_format(); $this->data['languages'] = $this->language_model->get_all_enabled_flat(); // Fetch any user uploads if (module_is_enabled('cdn')) { $this->data['user_uploads'] = $this->cdn->get_objects_for_user($_user->id); } // -------------------------------------------------------------------------- if (active_user('id') == $_user->id) { switch (active_user('gender')) { case 'male': $this->data['notice'] = lang('accounts_edit_editing_self_m'); break; case 'female': $this->data['notice'] = lang('accounts_edit_editing_self_f'); break; default: $this->data['notice'] = lang('accounts_edit_editing_self_u'); break; } } // -------------------------------------------------------------------------- // Load views if ($this->input->get('inline') || $this->input->get('is_fancybox')) { $this->data['header_override'] = 'structure/header/blank'; $this->data['footer_override'] = 'structure/footer/blank'; } $this->load->view('structure/header', $this->data); $this->load->view('admin/accounts/edit/index', $this->data); $this->load->view('structure/footer', $this->data); }
<?php if (module_is_enabled('cdn')) { ?> <fieldset id="edit-user-uploads" class="uploads"> <legend><?php echo lang('accounts_edit_upload_legend'); ?> </legend> <p> <?php echo '<ul>'; if ($user_uploads) { foreach ($user_uploads as $file) { echo '<li class="file">'; switch ($file->mime) { case 'image/jpg': case 'image/jpeg': case 'image/gif': case 'image/png': echo '<a href="' . cdn_serve($file->id) . '" class="fancybox image">'; echo img(cdn_thumb($file->id, 35, 35)); echo $file->filename_display; echo '<small>Bucket: ' . $file->bucket->slug . '</small>'; echo '</a>'; break; // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- default: echo anchor(cdn_serve($file->id) . '?dl=1', $file->filename_display . '<small>Bucket: ' . $file->bucket->slug . '</small>'); break;