From d13c4c0677784a357698263eea52285948ed2fd1 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Sun, 9 Sep 2012 16:48:50 +0100 Subject: [PATCH] dos2unix, i.e. normalize line endings, using gitattributes Git core is binary-safe. However, multiple committers are understandably not using line-ending agnostic environments like KDE. (Personally, my editor works that way, but I could still do without the ugly ^Ms in git-diff). .gitattributes recommended by Github [1] Conversion commands suggested by updated Stack Overflow answer [2] $ rm .git/index # Remove the index to force git to $ git reset # re-scan the working directory $ git status # Show files that will be normalized $ git add -u [1] https://help.github.com/articles/dealing-with-line-endings#platform-all [2] http://stackoverflow.com/a/4683783/799204 --- .gitattributes | 27 + bonfire/application/core/MY_Loader.php | 12 +- bonfire/application/core/MY_Router.php | 10 +- .../emailer/libraries/emailer.php | 738 +++---- .../emailer/views/settings/index.php | 258 +-- .../core_modules/roles/models/role_model.php | 744 +++---- .../roles/views/settings/matrix.php | 102 +- .../users/controllers/settings.php | 1512 +++++++------- .../core_modules/users/controllers/users.php | 1778 ++++++++-------- .../core_modules/users/models/user_model.php | 1786 ++++++++--------- .../users/views/settings/index.php | 270 +-- .../users/views/settings/user_form.php | 374 ++-- .../core/003_Permission_system_upgrade.php | 282 +-- .../core/006_Country_state_upgrade.php | 918 ++++----- .../core/007_Add_permission_descriptions.php | 106 +- .../language/english/application_lang.php | 470 ++--- bonfire/application/third_party/MX/Base.php | 118 +- bonfire/application/third_party/MX/Ci.php | 124 +- bonfire/application/third_party/MX/Config.php | 140 +- bonfire/application/third_party/MX/Lang.php | 138 +- bonfire/application/third_party/MX/Loader.php | 784 ++++---- .../views/permission_upgrade/index.php | 2 +- bonfire/themes/default/index.php | 22 +- install/controllers/install.php | 1276 ++++++------ install/language/english/install_lang.php | 138 +- install/views/install/success.php | 22 +- 26 files changed, 6089 insertions(+), 6062 deletions(-) diff --git a/.gitattributes b/.gitattributes index 461090b7e..d0bd14187 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,28 @@ +# For anything we don't specify, git will guess whether to normalize +# line endings. You already rely on it guessing when it shows diffs +# (and you look at diffs when you commit, right?) +* text=auto + +# diff will parse PHP instead of C, and tell us which function we're in *.php diff=php + +# These should always be text files +*.php text +*.css text +*.js text +*.htaccess text +*.html text +*.markdown text +*.txt text + +# Avoid unreadable diffs for generated text files +# (e.g. minified JS) +*.min.* binary + +# These should always be binaries +*.ico binary +*.gif binary +*.png binary +*.jpg binary +*.ttf binary +*.psd binary diff --git a/bonfire/application/core/MY_Loader.php b/bonfire/application/core/MY_Loader.php index 02ec6d1f9..bb5f7a956 100644 --- a/bonfire/application/core/MY_Loader.php +++ b/bonfire/application/core/MY_Loader.php @@ -1,6 +1,6 @@ -ci =& get_instance(); - } - - //-------------------------------------------------------------------- - - /** - * Handles sending the emails and routing to the appropriate methods - * for queueing or sending. - * - * Information about the email should be sent in the $data - * array. It looks like: - * - * $data = array( - * 'to' => '', // either string or array - * 'subject' => '', // string - * 'message' => '', // string - * 'alt_message' => '' // optional (text alt to html email) - * ); - * - * @access public - * - * @param array $data An array of required information need to send the email. - * @param bool $queue_override (optional) Overrides the value of $queue_emails. - * - * @return bool TRUE/FALSE Whether the operation was successful or not. - */ - public function send($data=array(), $queue_override=null) - { - // Make sure we have the information we need. - $to = isset($data['to']) ? $data['to'] : FALSE; - $from = settings_item('sender_email'); - $subject = isset($data['subject']) ? $data['subject'] : FALSE; - $message = isset($data['message']) ? $data['message'] : FALSE; - $alt_message = isset($data['alt_message']) ? $data['alt_message'] : FALSE; - - // If we don't have everything, return FALSE. - if ($to == FALSE || $subject == FALSE || $message == FALSE) - { - $this->errors[] = lang('em_missing_data'); - return FALSE; - } - - // Wrap the $message in the email template. - $mailtype = settings_item('mailtype'); - $templated = $message; - if ($mailtype == 'html') - { - $templated = $this->ci->load->view('emailer/email/_header', null, TRUE); - $templated .= $message; - $templated .= $this->ci->load->view('emailer/email/_footer', null, TRUE); - } - - // Should we put it in the queue? - if ($queue_override === TRUE || ($queue_override !== FALSE && $this->queue_emails == TRUE)) - { - return $this->queue_email($to, $from, $subject, $templated, $alt_message); - } - // Otherwise, we're sending it right now. - else - { - return $this->send_email($to, $from, $subject, $templated, $alt_message); - } - - }//end send() - - //-------------------------------------------------------------------- - - /** - * Add the email to the database to be sent out during a cron job. - * - * @access private - * - * @param string $to The email to send the message to - * @param string $from The from email (Ignored in this method, but kept for consistency with the send_email method. - * @param string $subject The subject line of the email - * @param string $message The text to be inserted into the template for HTML emails. - * @param string $alt_message An optional, text-only version of the message to be sent with HTML emails. - * - * @return bool TRUE/FALSE Whether it was successful or not. - */ - private function queue_email($to=null, $from=null, $subject=null, $message=null, $alt_message=FALSE) - { - $this->ci->db->set('to_email', $to); - $this->ci->db->set('subject', $subject); - $this->ci->db->set('message', $message); - - if ($alt_message) - { - $this->ci->db->set('alt_message', $alt_message); - } - - $result['success'] = $this->ci->db->insert('email_queue'); - - if ($this->debug) - { - $result['debug'] = lang('em_no_debug'); - } - - return $result; - - }//end queue_email - - //-------------------------------------------------------------------- - - /** - * Sends the email immediately. - * - * @access private - * - * @param string $to The email to send the message to - * @param string $from The from email. - * @param string $subject The subject line of the email - * @param string $message The text to be inserted into the template for HTML emails. - * @param string $alt_message An optional, text-only version of the message to be sent with HTML emails. - * - * @return bool TRUE/FALSE Whether it was successful or not. - */ - private function send_email($to=null, $from=null, $subject=null, $message=null, $alt_message=FALSE) - { - $this->ci->load->library('email'); - $this->ci->load->model('settings/settings_model', 'settings_model'); - $this->ci->email->initialize($this->ci->settings_model->select('name,value')->find_all_by('module', 'email')); - - $this->ci->email->set_newline("\r\n"); - $this->ci->email->to($to); - $this->ci->email->from($from, settings_item('site.title')); - $this->ci->email->subject($subject); - $this->ci->email->message($message); - - if ($alt_message) - { - $this->ci->email->set_alt_message($alt_message); - } - - if ((defined('ENVIRONMENT') && ENVIRONMENT == 'development') && $this->ci->config->item('emailer.write_to_file') === TRUE) { - if (!function_exists('write_file')) { - $this->ci->load->helper('file'); - } - write_file($this->ci->config->item('log_path').str_replace(" ","_",strtolower($subject)).substr(md5($to.time()),0,8).".html",$message); - $result['success'] = TRUE; - } - else - { - $result['success'] = $this->ci->email->send(); - } - - if ($this->debug) - { - $result['debug'] = $this->ci->email->print_debugger(); - } - - return $result; - - }//end send_email() - - //-------------------------------------------------------------------- - - /** - * Process the email queue in chunks. - * - * Defaults to 33 which, if processed every 5 minutes, equals 400/hour - * And should keep you safe with most ISP's. Always check your ISP's - * terms of service to verify, though. - * - * @access public - * - * @param int $limit An int specifying how many emails to process at once. - * - * @return bool TRUE/FALSE Whether the method was successful or not. - */ - public function process_queue($limit=33) - { - //$limit = 33; // 33 emails every 5 minutes = 400 emails/hour. - $this->ci->load->library('email'); - - $config_settings = $this->ci->settings_model->select('name,value')->find_all_by('module', 'email'); - - // Grab records where success = 0 - $this->ci->db->limit($limit); - $this->ci->db->where('success', 0); - $query = $this->ci->db->get('email_queue'); - - if ($query->num_rows() > 0) - { - $emails = $query->result(); - } - else - { - return TRUE; - } - - foreach($emails as $email) - { - echo '.'; - - $this->ci->email->clear(); - $this->ci->email->initialize($config_settings); - - $this->ci->email->from(settings_item('sender_email'), settings_item('site.title')); - $this->ci->email->to($email->to_email); - - $this->ci->email->subject($email->subject); - $this->ci->email->message($email->message); - $this->ci->email->set_newline("\r\n"); - - if ($email->alt_message) - { - $this->ci->email->set_alt_message($email->alt_message); - } - - $prefix = $this->ci->db->dbprefix; - - if ($this->ci->email->send() === TRUE) - { - // Email was successfully sent - $sql = "UPDATE {$prefix}email_queue SET success=1, attempts=attempts+1, last_attempt = NOW(), date_sent = NOW() WHERE id = " .$email->id; - $this->ci->db->query($sql); - } - else - { - // Error sending email - $sql = "UPDATE {$prefix}email_queue SET attempts = attempts+1, last_attempt=NOW() WHERE id=". $email->id; - $this->ci->db->query($sql); - - if (class_exists('CI_Session')) - { - $result = $this->ci->email->print_debugger(); - $this->ci->session->set_userdata('email_debug', $result); - } - - } - }//end foreach - - return TRUE; - - }//end process_queue() - - //-------------------------------------------------------------------- - - /** - * Tells the emailer lib to show or hide the debugger string. - * - * @access public - * - * @param bool $show_debug TRUE/FALSE - enable/disable debugging messages - */ - public function enable_debug($show_debug) - { - $this->debug = $show_debug; - - }//end enable_debug() - - //-------------------------------------------------------------------- - - /** - * Specifies whether to queue emails in the send() method. - * - * @param bool $queue Queue emails instead of sending them directly. - * - * @return void - */ - public function queue_emails($queue) - { - if ($queue !== TRUE && $queue !== FALSE) - { - return; - } - - $this->queue_emails = $queue; - - }//end queue_emails() - - //-------------------------------------------------------------------- - -}//end class - -/* End of file emailer.php */ -/* Location: ./application/core_modules/emailer/libraries/emailer.php */ +ci =& get_instance(); + } + + //-------------------------------------------------------------------- + + /** + * Handles sending the emails and routing to the appropriate methods + * for queueing or sending. + * + * Information about the email should be sent in the $data + * array. It looks like: + * + * $data = array( + * 'to' => '', // either string or array + * 'subject' => '', // string + * 'message' => '', // string + * 'alt_message' => '' // optional (text alt to html email) + * ); + * + * @access public + * + * @param array $data An array of required information need to send the email. + * @param bool $queue_override (optional) Overrides the value of $queue_emails. + * + * @return bool TRUE/FALSE Whether the operation was successful or not. + */ + public function send($data=array(), $queue_override=null) + { + // Make sure we have the information we need. + $to = isset($data['to']) ? $data['to'] : FALSE; + $from = settings_item('sender_email'); + $subject = isset($data['subject']) ? $data['subject'] : FALSE; + $message = isset($data['message']) ? $data['message'] : FALSE; + $alt_message = isset($data['alt_message']) ? $data['alt_message'] : FALSE; + + // If we don't have everything, return FALSE. + if ($to == FALSE || $subject == FALSE || $message == FALSE) + { + $this->errors[] = lang('em_missing_data'); + return FALSE; + } + + // Wrap the $message in the email template. + $mailtype = settings_item('mailtype'); + $templated = $message; + if ($mailtype == 'html') + { + $templated = $this->ci->load->view('emailer/email/_header', null, TRUE); + $templated .= $message; + $templated .= $this->ci->load->view('emailer/email/_footer', null, TRUE); + } + + // Should we put it in the queue? + if ($queue_override === TRUE || ($queue_override !== FALSE && $this->queue_emails == TRUE)) + { + return $this->queue_email($to, $from, $subject, $templated, $alt_message); + } + // Otherwise, we're sending it right now. + else + { + return $this->send_email($to, $from, $subject, $templated, $alt_message); + } + + }//end send() + + //-------------------------------------------------------------------- + + /** + * Add the email to the database to be sent out during a cron job. + * + * @access private + * + * @param string $to The email to send the message to + * @param string $from The from email (Ignored in this method, but kept for consistency with the send_email method. + * @param string $subject The subject line of the email + * @param string $message The text to be inserted into the template for HTML emails. + * @param string $alt_message An optional, text-only version of the message to be sent with HTML emails. + * + * @return bool TRUE/FALSE Whether it was successful or not. + */ + private function queue_email($to=null, $from=null, $subject=null, $message=null, $alt_message=FALSE) + { + $this->ci->db->set('to_email', $to); + $this->ci->db->set('subject', $subject); + $this->ci->db->set('message', $message); + + if ($alt_message) + { + $this->ci->db->set('alt_message', $alt_message); + } + + $result['success'] = $this->ci->db->insert('email_queue'); + + if ($this->debug) + { + $result['debug'] = lang('em_no_debug'); + } + + return $result; + + }//end queue_email + + //-------------------------------------------------------------------- + + /** + * Sends the email immediately. + * + * @access private + * + * @param string $to The email to send the message to + * @param string $from The from email. + * @param string $subject The subject line of the email + * @param string $message The text to be inserted into the template for HTML emails. + * @param string $alt_message An optional, text-only version of the message to be sent with HTML emails. + * + * @return bool TRUE/FALSE Whether it was successful or not. + */ + private function send_email($to=null, $from=null, $subject=null, $message=null, $alt_message=FALSE) + { + $this->ci->load->library('email'); + $this->ci->load->model('settings/settings_model', 'settings_model'); + $this->ci->email->initialize($this->ci->settings_model->select('name,value')->find_all_by('module', 'email')); + + $this->ci->email->set_newline("\r\n"); + $this->ci->email->to($to); + $this->ci->email->from($from, settings_item('site.title')); + $this->ci->email->subject($subject); + $this->ci->email->message($message); + + if ($alt_message) + { + $this->ci->email->set_alt_message($alt_message); + } + + if ((defined('ENVIRONMENT') && ENVIRONMENT == 'development') && $this->ci->config->item('emailer.write_to_file') === TRUE) { + if (!function_exists('write_file')) { + $this->ci->load->helper('file'); + } + write_file($this->ci->config->item('log_path').str_replace(" ","_",strtolower($subject)).substr(md5($to.time()),0,8).".html",$message); + $result['success'] = TRUE; + } + else + { + $result['success'] = $this->ci->email->send(); + } + + if ($this->debug) + { + $result['debug'] = $this->ci->email->print_debugger(); + } + + return $result; + + }//end send_email() + + //-------------------------------------------------------------------- + + /** + * Process the email queue in chunks. + * + * Defaults to 33 which, if processed every 5 minutes, equals 400/hour + * And should keep you safe with most ISP's. Always check your ISP's + * terms of service to verify, though. + * + * @access public + * + * @param int $limit An int specifying how many emails to process at once. + * + * @return bool TRUE/FALSE Whether the method was successful or not. + */ + public function process_queue($limit=33) + { + //$limit = 33; // 33 emails every 5 minutes = 400 emails/hour. + $this->ci->load->library('email'); + + $config_settings = $this->ci->settings_model->select('name,value')->find_all_by('module', 'email'); + + // Grab records where success = 0 + $this->ci->db->limit($limit); + $this->ci->db->where('success', 0); + $query = $this->ci->db->get('email_queue'); + + if ($query->num_rows() > 0) + { + $emails = $query->result(); + } + else + { + return TRUE; + } + + foreach($emails as $email) + { + echo '.'; + + $this->ci->email->clear(); + $this->ci->email->initialize($config_settings); + + $this->ci->email->from(settings_item('sender_email'), settings_item('site.title')); + $this->ci->email->to($email->to_email); + + $this->ci->email->subject($email->subject); + $this->ci->email->message($email->message); + $this->ci->email->set_newline("\r\n"); + + if ($email->alt_message) + { + $this->ci->email->set_alt_message($email->alt_message); + } + + $prefix = $this->ci->db->dbprefix; + + if ($this->ci->email->send() === TRUE) + { + // Email was successfully sent + $sql = "UPDATE {$prefix}email_queue SET success=1, attempts=attempts+1, last_attempt = NOW(), date_sent = NOW() WHERE id = " .$email->id; + $this->ci->db->query($sql); + } + else + { + // Error sending email + $sql = "UPDATE {$prefix}email_queue SET attempts = attempts+1, last_attempt=NOW() WHERE id=". $email->id; + $this->ci->db->query($sql); + + if (class_exists('CI_Session')) + { + $result = $this->ci->email->print_debugger(); + $this->ci->session->set_userdata('email_debug', $result); + } + + } + }//end foreach + + return TRUE; + + }//end process_queue() + + //-------------------------------------------------------------------- + + /** + * Tells the emailer lib to show or hide the debugger string. + * + * @access public + * + * @param bool $show_debug TRUE/FALSE - enable/disable debugging messages + */ + public function enable_debug($show_debug) + { + $this->debug = $show_debug; + + }//end enable_debug() + + //-------------------------------------------------------------------- + + /** + * Specifies whether to queue emails in the send() method. + * + * @param bool $queue Queue emails instead of sending them directly. + * + * @return void + */ + public function queue_emails($queue) + { + if ($queue !== TRUE && $queue !== FALSE) + { + return; + } + + $this->queue_emails = $queue; + + }//end queue_emails() + + //-------------------------------------------------------------------- + +}//end class + +/* End of file emailer.php */ +/* Location: ./application/core_modules/emailer/libraries/emailer.php */ diff --git a/bonfire/application/core_modules/emailer/views/settings/index.php b/bonfire/application/core_modules/emailer/views/settings/index.php index 0b8da09a0..3558f6cff 100644 --- a/bonfire/application/core_modules/emailer/views/settings/index.php +++ b/bonfire/application/core_modules/emailer/views/settings/index.php @@ -1,129 +1,129 @@ -
-

- - - -
- General Settings - -
- -
- - '. form_error('sender_email') .''; ?> -

-
-
- -
- -
- -
-
- -
- -
- - -
-
-
- -
- - -
-

-
- - -
- -
- - -
-
- - -
- -
- -
- - -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
-
-
- -
- -
- - -
- - -
-

- - 'form-horizontal', 'id'=>'test-form')); ?> -
- - -
-

- -
-
- -
- - -
-
-
- -
- - -
+
+

+ + + +
+ General Settings + +
+ +
+ + '. form_error('sender_email') .''; ?> +

+
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+
+ +
+ + +
+

+
+ + +
+ +
+ + +
+
+ + +
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ + +
+ + +
+

+ + 'form-horizontal', 'id'=>'test-form')); ?> +
+ + +
+

+ +
+
+ +
+ + +
+
+
+ +
+ + +
diff --git a/bonfire/application/core_modules/roles/models/role_model.php b/bonfire/application/core_modules/roles/models/role_model.php index 862b362cc..dee071abd 100644 --- a/bonfire/application/core_modules/roles/models/role_model.php +++ b/bonfire/application/core_modules/roles/models/role_model.php @@ -1,372 +1,372 @@ -load->model('permissions/permission_model'); - } - - }//end __construct() - - //-------------------------------------------------------------------- - - /** - * Returns a single role, with an array of permissions. - * - * @access public - * - * @param int $id An int that matches the role_id of the role in question. - * - * @return array An array of information about the role, along with a sub-array that contains the role's applicable permissions. - */ - public function find($id=NULL) - { - if (empty($id) || !is_integer($id)) - { - return FALSE; - } - - $role = parent::find($id); - - if ($role == FALSE) - { - return FALSE; - } - - $this->get_role_permissions($role); - - return $role; - - }//end find() - - //-------------------------------------------------------------------- - - /** - * Locates a role based on the role name. Case doesn't matter. - * - * @access public - * - * @param string $name A string with the name of the role. - * - * @return object An object with the role and it's permissions. - */ - public function find_by_name($name=NULL) - { - if (empty($name)) - { - return FALSE; - } - - $role = $this->find_by('role_name', $name); - - $this->get_role_permissions($role); - - return $role; - - }//end find_by_name() - - //-------------------------------------------------------------------- - - - /** - * A simple update of the role. This does, however, clean things up - * when setting this role as the default role for new users. - * - * @access public - * - * @param int $id An int, being the role_id - * @param array $data An array of key/value pairs to update the db with. - * - * @return bool TRUE/FALSE - */ - public function update($id=NULL, $data=NULL) - { - // If this one is set to default, then we need to - // reset all others to NOT be default - if (isset($data['default']) && $data['default'] == 1) - { - $this->db->set('default', 0); - $this->db->update($this->table); - } - - return parent::update($id, $data); - - }//end update() - - //-------------------------------------------------------------------- - - /** - * Verifies that a role can be deleted. - * - * @param int $role_id The role to verify. - * - * @return bool TRUE/FALSE - */ - public function can_delete_role($role_id=0) - { - $this->db->select('role_id, can_delete'); - $delete_role = parent::find($role_id); - - if ($delete_role->can_delete == 1) - { - return TRUE; - } - - return FALSE; - - }//end can_delete_role() - - //-------------------------------------------------------------------- - - /** - * Deletes a role. By default, it will perform a soft_delete and - * leave the permissions untouched. However, if $purge == TRUE, then - * all permissions related to this role are also deleted. - * - * @access public - * - * @param int $id An integer with the role_id to delete. - * @param bool $purge If FALSE, will perform a soft_delete. If TRUE, will remove the role and related permissions from db. - * - * @return bool TRUE/FALSE - */ - function delete($id=0, $purge=FALSE) - { - if ($purge === TRUE) - { - // temporarily set the soft_deletes to TRUE. - $this->soft_deletes = FALSE; - } - - // We might not be allowed to delete this role. - if ($this->can_delete_role($id) == FALSE) - { - $this->error = 'This role can not be deleted.'; - return FALSE; - } - - // get the name for management deletion later - $role = $this->role_model->find($id); - - // delete the record - $deleted = parent::delete($id); - - if ($deleted === TRUE) - { - // Now update the users to the default role - if (!class_exists('User_model')) - { - $this->load->model('users/User_model','user_model'); - } - - $this->user_model->set_to_default_role($id); - - // now delete the role_permissions for this permission - $this->role_permission_model->delete_for_role($id); - - // now delete the manage permission for this role - $prefix = $this->db->dbprefix; - - if (!class_exists('Permission_model')) - { - $this->load->model('permissions/permission_model'); - } - - $perm = $this->permission_model->find_by('name','Permissions.'.ucwords($role->role_name).'.Manage'); - if ($perm) - { - // remove the role_permissions for this permission - $this->db->query("DELETE FROM {$prefix}role_permissions WHERE permission_id='".$perm->permission_id."';"); - - if ($deleted === TRUE && $purge === TRUE) - { - $this->db->query("DELETE FROM {$prefix}permissions WHERE (name = 'Permissions.".ucwords($role->role_name).".Manage')"); - } - else - { - $this->db->query("UPDATE {$prefix}permissions SET status = 'inactive' WHERE (name = 'Permissions.".ucwords($role->role_name).".Manage')"); - } - } - }//end if - - return $deleted; - - }//end delete() - - //-------------------------------------------------------------------- - - /** - * Returns the id of the default role. - * - * @access public - * - * @return mixed ID of the default role or FALSE - */ - public function default_role_id() - { - $this->db->where('default', 1); - $query = $this->db->get($this->table); - - if ($query->num_rows() == 1) - { - return (int)$query->row()->role_id; - } - - return FALSE; - - }//end default_role_id() - - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - // !PRIVATE METHODS - //-------------------------------------------------------------------- - - /** - * Finds the permissions and role_permissions array for a single role. - * - * @access public - * - * @param int $role A reference to an existing role object. This object is modified directly. - * - * @return void - */ - public function get_role_permissions(&$role) - { - if (!is_object($role)) - { - return; - } - - $permission_array = array(); - - // Grab our permissions for the role. - $permissions = $this->permission_model->find_all_by('status','active'); - - // Permissions - foreach($permissions as $key => $permission) - { - $permission_array[$permission->name] = $permission; - } - - $role->permissions = $permission_array; - - if (!class_exists('Role_permission_model')) - { - $this->load->model('roles/role_permission_model'); - } - - // Role Permissions - $permission_array = array(); - $role_permissions = $this->role_permission_model->find_for_role($role->role_id); - - if (is_array($role_permissions) && count($role_permissions)) - { - foreach($role_permissions as $key => $permission) - { - $permission_array[$permission->permission_id] = 1; - } - } - - $role->role_permissions = $permission_array; - unset($permission_array); - - }//end get_role_permissions() - - //-------------------------------------------------------------------- - -}//end Role_model +load->model('permissions/permission_model'); + } + + }//end __construct() + + //-------------------------------------------------------------------- + + /** + * Returns a single role, with an array of permissions. + * + * @access public + * + * @param int $id An int that matches the role_id of the role in question. + * + * @return array An array of information about the role, along with a sub-array that contains the role's applicable permissions. + */ + public function find($id=NULL) + { + if (empty($id) || !is_integer($id)) + { + return FALSE; + } + + $role = parent::find($id); + + if ($role == FALSE) + { + return FALSE; + } + + $this->get_role_permissions($role); + + return $role; + + }//end find() + + //-------------------------------------------------------------------- + + /** + * Locates a role based on the role name. Case doesn't matter. + * + * @access public + * + * @param string $name A string with the name of the role. + * + * @return object An object with the role and it's permissions. + */ + public function find_by_name($name=NULL) + { + if (empty($name)) + { + return FALSE; + } + + $role = $this->find_by('role_name', $name); + + $this->get_role_permissions($role); + + return $role; + + }//end find_by_name() + + //-------------------------------------------------------------------- + + + /** + * A simple update of the role. This does, however, clean things up + * when setting this role as the default role for new users. + * + * @access public + * + * @param int $id An int, being the role_id + * @param array $data An array of key/value pairs to update the db with. + * + * @return bool TRUE/FALSE + */ + public function update($id=NULL, $data=NULL) + { + // If this one is set to default, then we need to + // reset all others to NOT be default + if (isset($data['default']) && $data['default'] == 1) + { + $this->db->set('default', 0); + $this->db->update($this->table); + } + + return parent::update($id, $data); + + }//end update() + + //-------------------------------------------------------------------- + + /** + * Verifies that a role can be deleted. + * + * @param int $role_id The role to verify. + * + * @return bool TRUE/FALSE + */ + public function can_delete_role($role_id=0) + { + $this->db->select('role_id, can_delete'); + $delete_role = parent::find($role_id); + + if ($delete_role->can_delete == 1) + { + return TRUE; + } + + return FALSE; + + }//end can_delete_role() + + //-------------------------------------------------------------------- + + /** + * Deletes a role. By default, it will perform a soft_delete and + * leave the permissions untouched. However, if $purge == TRUE, then + * all permissions related to this role are also deleted. + * + * @access public + * + * @param int $id An integer with the role_id to delete. + * @param bool $purge If FALSE, will perform a soft_delete. If TRUE, will remove the role and related permissions from db. + * + * @return bool TRUE/FALSE + */ + function delete($id=0, $purge=FALSE) + { + if ($purge === TRUE) + { + // temporarily set the soft_deletes to TRUE. + $this->soft_deletes = FALSE; + } + + // We might not be allowed to delete this role. + if ($this->can_delete_role($id) == FALSE) + { + $this->error = 'This role can not be deleted.'; + return FALSE; + } + + // get the name for management deletion later + $role = $this->role_model->find($id); + + // delete the record + $deleted = parent::delete($id); + + if ($deleted === TRUE) + { + // Now update the users to the default role + if (!class_exists('User_model')) + { + $this->load->model('users/User_model','user_model'); + } + + $this->user_model->set_to_default_role($id); + + // now delete the role_permissions for this permission + $this->role_permission_model->delete_for_role($id); + + // now delete the manage permission for this role + $prefix = $this->db->dbprefix; + + if (!class_exists('Permission_model')) + { + $this->load->model('permissions/permission_model'); + } + + $perm = $this->permission_model->find_by('name','Permissions.'.ucwords($role->role_name).'.Manage'); + if ($perm) + { + // remove the role_permissions for this permission + $this->db->query("DELETE FROM {$prefix}role_permissions WHERE permission_id='".$perm->permission_id."';"); + + if ($deleted === TRUE && $purge === TRUE) + { + $this->db->query("DELETE FROM {$prefix}permissions WHERE (name = 'Permissions.".ucwords($role->role_name).".Manage')"); + } + else + { + $this->db->query("UPDATE {$prefix}permissions SET status = 'inactive' WHERE (name = 'Permissions.".ucwords($role->role_name).".Manage')"); + } + } + }//end if + + return $deleted; + + }//end delete() + + //-------------------------------------------------------------------- + + /** + * Returns the id of the default role. + * + * @access public + * + * @return mixed ID of the default role or FALSE + */ + public function default_role_id() + { + $this->db->where('default', 1); + $query = $this->db->get($this->table); + + if ($query->num_rows() == 1) + { + return (int)$query->row()->role_id; + } + + return FALSE; + + }//end default_role_id() + + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // !PRIVATE METHODS + //-------------------------------------------------------------------- + + /** + * Finds the permissions and role_permissions array for a single role. + * + * @access public + * + * @param int $role A reference to an existing role object. This object is modified directly. + * + * @return void + */ + public function get_role_permissions(&$role) + { + if (!is_object($role)) + { + return; + } + + $permission_array = array(); + + // Grab our permissions for the role. + $permissions = $this->permission_model->find_all_by('status','active'); + + // Permissions + foreach($permissions as $key => $permission) + { + $permission_array[$permission->name] = $permission; + } + + $role->permissions = $permission_array; + + if (!class_exists('Role_permission_model')) + { + $this->load->model('roles/role_permission_model'); + } + + // Role Permissions + $permission_array = array(); + $role_permissions = $this->role_permission_model->find_for_role($role->role_id); + + if (is_array($role_permissions) && count($role_permissions)) + { + foreach($role_permissions as $key => $permission) + { + $permission_array[$permission->permission_id] = 1; + } + } + + $role->role_permissions = $permission_array; + unset($permission_array); + + }//end get_role_permissions() + + //-------------------------------------------------------------------- + +}//end Role_model diff --git a/bonfire/application/core_modules/roles/views/settings/matrix.php b/bonfire/application/core_modules/roles/views/settings/matrix.php index ffec030ad..9a4089c5d 100644 --- a/bonfire/application/core_modules/roles/views/settings/matrix.php +++ b/bonfire/application/core_modules/roles/views/settings/matrix.php @@ -1,51 +1,51 @@ - - - $fields) : ?> - - - - - - - - - - - $field_actions) : ?> - - - - - - - - - - -
- -
- - - - /> - - - -
-
- - - - -
- - + + + $fields) : ?> + + + + + + + + + + + $field_actions) : ?> + + + + + + + + + + +
+ +
+ + + + /> + + + +
+
+ + + + +
+ + diff --git a/bonfire/application/core_modules/users/controllers/settings.php b/bonfire/application/core_modules/users/controllers/settings.php index 918366f78..5227cece4 100644 --- a/bonfire/application/core_modules/users/controllers/settings.php +++ b/bonfire/application/core_modules/users/controllers/settings.php @@ -1,756 +1,756 @@ -auth->restrict('Bonfire.Users.View'); - - $this->load->model('roles/role_model'); - - $this->lang->load('users'); - - Template::set_block('sub_nav', 'settings/_sub_nav'); - - }//end __construct() - - //-------------------------------------------------------------------- - - /* - * Display the user list and manage the user deletions/banning/purge - * - * @access public - * - * @return void - */ - public function index($offset=0) - { - $this->auth->restrict('Bonfire.Users.Manage'); - - $roles = $this->role_model->select('role_id, role_name')->where('deleted', 0)->find_all(); - $ordered_roles = array(); - foreach ($roles as $role) - { - $ordered_roles[$role->role_id] = $role; - } - Template::set('roles', $ordered_roles); - - // Do we have any actions? - $action = $this->input->post('submit').$this->input->post('delete').$this->input->post('purge').$this->input->post('restore').$this->input->post('activate').$this->input->post('deactivate'); - - if (!empty($action)) - { - $checked = $this->input->post('checked'); - - if (!empty($checked)) - { - foreach($checked as $user_id) - { - switch(strtolower($action)) - { - case 'activate': - $this->_activate($user_id); - break; - case 'deactivate': - $this->_deactivate($user_id); - break; - case 'ban': - $this->_ban($user_id); - break; - case 'delete': - $this->_delete($user_id); - break; - case 'purge': - $this->_purge($user_id); - break; - case 'restore': - $this->_restore($user_id); - break; - } - } - } - else - { - Template::set_message(lang('us_empty_id'), 'error'); - } - } - - $where = array(); - $show_deleted = FALSE; - - // Filters - $filter = $this->input->get('filter'); - switch($filter) - { - case 'inactive': - $where['users.active'] = 0; - break; - case 'banned': - $where['users.banned'] = 1; - break; - case 'deleted': - $where['users.deleted'] = 1; - $show_deleted = TRUE; - break; - case 'role': - $role_id = (int)$this->input->get('role_id'); - $where['users.role_id'] = $role_id; - - foreach ($roles as $role) - { - if ($role->role_id == $role_id) - { - Template::set('filter_role', $role->role_name); - break; - } - } - break; - - default: - $where['users.deleted'] = 0; - $this->user_model->where('users.deleted', 0); - break; - } - - // First Letter - $first_letter = $this->input->get('firstletter'); - if (!empty($first_letter)) - { - $where['SUBSTRING( LOWER(username), 1, 1)='] = $first_letter; - } - - $this->load->helper('ui/ui'); - - $this->user_model->limit($this->limit, $offset)->where($where); - $this->user_model->select('users.id, users.role_id, username, display_name, email, last_login, banned, active, users.deleted, role_name'); - - Template::set('users', $this->user_model->find_all($show_deleted)); - - // Pagination - $this->load->library('pagination'); - - $this->user_model->where($where); - $total_users = $this->user_model->count_all(); - - - $this->pager['base_url'] = site_url(SITE_AREA .'/settings/users/index'); - $this->pager['total_rows'] = $total_users; - $this->pager['per_page'] = $this->limit; - $this->pager['uri_segment'] = 5; - - $this->pagination->initialize($this->pager); - - Template::set('current_url', current_url()); - Template::set('filter', $filter); - - Template::set('toolbar_title', lang('us_user_management')); - Template::render(); - - }//end index() - - //-------------------------------------------------------------------- - - /** - * Manage creating a new user - * - * @access public - * - * @return void - */ - public function create() - { - $this->auth->restrict('Bonfire.Users.Add'); - - $this->load->config('address'); - $this->load->helper('address'); - $this->load->helper('date'); - - - $this->load->config('user_meta'); - $meta_fields = config_item('user_meta_fields'); - Template::set('meta_fields', $meta_fields); - - if ($this->input->post('submit')) - { - if ($id = $this->save_user('insert', NULL, $meta_fields)) - { - - $meta_data = array(); - foreach ($meta_fields as $field) - { - if (!isset($field['admin_only']) || $field['admin_only'] === FALSE - || (isset($field['admin_only']) && $field['admin_only'] === TRUE - && isset($this->current_user) && $this->current_user->role_id == 1)) - { - $meta_data[$field['name']] = $this->input->post($field['name']); - } - } - - // now add the meta is there is meta data - $this->user_model->save_meta_for($id, $meta_data); - - $user = $this->user_model->find($id); - $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); - $this->activity_model->log_activity($this->current_user->id, lang('us_log_create').' '. $user->role_name . ': '.$log_name, 'users'); - - Template::set_message(lang('us_user_created_success'), 'success'); - Template::redirect(SITE_AREA .'/settings/users'); - } - } - - $settings = $this->settings_lib->find_all(); - if ($settings['auth.password_show_labels'] == 1) { - Assets::add_module_js('users','password_strength.js'); - Assets::add_module_js('users','jquery.strength.js'); - Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); - } - Template::set('roles', $this->role_model->select('role_id, role_name, default')->where('deleted', 0)->find_all()); - Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); - - Template::set('toolbar_title', lang('us_create_user')); - Template::set_view('settings/user_form'); - Template::render(); - - }//end create() - - //-------------------------------------------------------------------- - - /** - * Edit a user - * - * @access public - * - * @return void - */ - public function edit($user_id='') - { - $this->load->config('address'); - $this->load->helper('address'); - $this->load->helper('date'); - - // if there is no id passed in edit the current user - // this is so we don't have to pass the user id in the url for editing the current users profile - if (empty($user_id)) - { - $user_id = $this->current_user->id; - } - - if (empty($user_id)) - { - Template::set_message(lang('us_empty_id'), 'error'); - redirect(SITE_AREA .'/settings/users'); - } - - if ($user_id != $this->current_user->id) - { - $this->auth->restrict('Bonfire.Users.Manage'); - } - - - $this->load->config('user_meta'); - $meta_fields = config_item('user_meta_fields'); - Template::set('meta_fields', $meta_fields); - - $user = $this->user_model->find_user_and_meta($user_id); - - if ($this->input->post('submit')) - { - if ($this->save_user('update', $user_id, $meta_fields, $user->role_name)) - { - - $meta_data = array(); - foreach ($meta_fields as $field) - { - if (!isset($field['admin_only']) || $field['admin_only'] === FALSE - || (isset($field['admin_only']) && $field['admin_only'] === TRUE - && isset($this->current_user) && $this->current_user->role_id == 1)) - { - $meta_data[$field['name']] = $this->input->post($field['name']); - } - } - - // now add the meta is there is meta data - $this->user_model->save_meta_for($user_id, $meta_data); - - - $user = $this->user_model->find_user_and_meta($user_id); - $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); - $this->activity_model->log_activity($this->current_user->id, lang('us_log_edit') .': '.$log_name, 'users'); - - Template::set_message(lang('us_user_update_success'), 'success'); - - // redirect back to the edit page to make sure that a users password change - // forces a login check - Template::redirect($this->uri->uri_string()); - } - } - - if (isset($user)) - { - Template::set('roles', $this->role_model->select('role_id, role_name, default')->where('deleted', 0)->find_all()); - Template::set('user', $user); - Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); - } - else - { - Template::set_message(sprintf(lang('us_unauthorized'),$user->role_name), 'error'); - redirect(SITE_AREA .'/settings/users'); - } - - $settings = $this->settings_lib->find_all(); - if ($settings['auth.password_show_labels'] == 1) { - Assets::add_module_js('users','password_strength.js'); - Assets::add_module_js('users','jquery.strength.js'); - Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); - } - - Template::set('toolbar_title', lang('us_edit_user')); - - Template::set_view('settings/user_form'); - - Template::render(); - - }//end edit() - - //-------------------------------------------------------------------- - - /** - * Ban a user or group of users - * - * @access private - * - * @param int $user_id User to ban - * @param string $ban_message Set a message for the user as the reason for banning them - * - * @return void - */ - private function _ban($user_id, $ban_message='') - { - $data = array( - 'banned' => 1, - 'ban_message' => $ban_message - ); - - $this->user_model->update($user_id, $data); - - }//end _ban() - - //-------------------------------------------------------------------- - - /** - * Delete a user or group of users - * - * @access private - * - * @param int $id User to delete - * - * @return void - */ - private function _delete($id) - { - $user = $this->user_model->find($id); - - if (isset($user) && has_permission('Permissions.'.$user->role_name.'.Manage') && $user->id != $this->current_user->id) - { - if ($this->user_model->delete($id)) - { - - $user = $this->user_model->find($id); - $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); - $this->activity_model->log_activity($this->current_user->id, lang('us_log_delete') . ': '.$log_name, 'users'); - Template::set_message(lang('us_action_deleted'), 'success'); - } - else - { - Template::set_message(lang('us_action_not_deleted'). $this->user_model->error, 'error'); - } - } - else - { - if ($user->id == $this->current_user->id) - { - Template::set_message(lang('us_self_delete'), 'error'); - } - else - { - Template::set_message(sprintf(lang('us_unauthorized'),$user->role_name), 'error'); - } - }//end if - - }//end _delete() - - //-------------------------------------------------------------------- - - /** - * Purge the selected users which are already marked as deleted - * - * @access private - * - * @param int $id User to purge - * - * @return void - */ - private function _purge($id) - { - $this->user_model->delete($id, TRUE); - Template::set_message(lang('us_action_purged'), 'success'); - - }//end _purge() - - //-------------------------------------------------------------------- - - /** - * Restore the deleted user - * - * @access private - * - * @return void - */ - private function _restore($id) - { - if ($this->user_model->update($id, array('users.deleted'=>0))) - { - Template::set_message(lang('us_user_restored_success'), 'success'); - } - else - { - Template::set_message(lang('us_user_restored_error'). $this->user_model->error, 'error'); - } - - }//end restore() - - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - // !HMVC METHODS - //-------------------------------------------------------------------- - - /** - * Show the access logs - * - * @access public - * - * @param int $limit Limit the number of logs to show at a time - * - * @return string Show the access logs - */ - public function access_logs($limit=15) - { - $logs = $this->user_model->get_access_logs($limit); - - return $this->load->view('settings/access_logs', array('access_logs' => $logs), TRUE); - - }//end access_logs() - - //-------------------------------------------------------------------- - - - - //-------------------------------------------------------------------- - // !PRIVATE METHODS - //-------------------------------------------------------------------- - - /** - * Save the user - * - * @access private - * - * @param string $type The type of operation (insert or edit) - * @param int $id The id of the user in the case of an edit operation - * @param array $meta_fields Array of meta fields fur the user - * @param string $cur_role_name The current role for the user being edited - * - * @return bool - */ - private function save_user($type='insert', $id=0, $meta_fields=array(), $cur_role_name = '') - { - - if ($type == 'insert') - { - $this->form_validation->set_rules('email', lang('bf_email'), 'required|trim|unique[users.email]|valid_email|max_length[120]|xss_clean'); - $this->form_validation->set_rules('password', lang('bf_password'), 'required|trim|strip_tags|min_length[8]|max_length[120]|valid_password|xss_clean'); - $this->form_validation->set_rules('pass_confirm', lang('bf_password_confirm'), 'required|trim|strip_tags|matches[password]|xss_clean'); - } - else - { - $_POST['id'] = $id; - $this->form_validation->set_rules('email', lang('bf_email'), 'required|trim|unique[users.email,users.id]|valid_email|max_length[120]|xss_clean'); - $this->form_validation->set_rules('password', lang('bf_password'), 'trim|strip_tags|min_length[8]|max_length[120]|valid_password|matches[pass_confirm]|xss_clean'); - $this->form_validation->set_rules('pass_confirm', lang('bf_password_confirm'), 'trim|strip_tags|xss_clean'); - } - - $use_usernames = $this->settings_lib->item('auth.use_usernames'); - - if ($use_usernames) - { - $extra_unique_rule = $type == 'update' ? ',users.id' : ''; - - $this->form_validation->set_rules('username', lang('bf_username'), 'required|trim|strip_tags|max_length[30]|unique[users.username'.$extra_unique_rule.']|xss_clean'); - } - - $this->form_validation->set_rules('display_name', lang('bf_display_name'), 'trim|strip_tags|max_length[255]|xss_clean'); - - $this->form_validation->set_rules('language', lang('bf_language'), 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('timezones', lang('bf_timezone'), 'required|trim|strip_tags|max_length[4]|xss_clean'); - - if (has_permission('Bonfire.Roles.Manage') && has_permission('Permissions.'.$cur_role_name.'.Manage')) - { - $this->form_validation->set_rules('role_id', lang('us_role'), 'required|trim|strip_tags|max_length[2]|is_numeric|xss_clean'); - } - - $meta_data = array(); - - foreach ($meta_fields as $field) - { - if (!isset($field['admin_only']) || $field['admin_only'] === FALSE - || (isset($field['admin_only']) && $field['admin_only'] === TRUE - && isset($this->current_user) && $this->current_user->role_id == 1)) - { - $this->form_validation->set_rules($field['name'], $field['label'], $field['rules']); - - $meta_data[$field['name']] = $this->input->post($field['name']); - } - } - - if ($this->form_validation->run($this) === FALSE) - { - return FALSE; - } - - // Compile our core user elements to save. - $data = array( - 'email' => $this->input->post('email'), - 'username' => $this->input->post('username'), - 'language' => $this->input->post('language'), - 'timezone' => $this->input->post('timezones'), - ); - - if ($this->input->post('password')) - { - $data['password'] = $this->input->post('password'); - } - - if ($this->input->post('pass_confirm')) - { - $data['pass_confirm'] = $this->input->post('pass_confirm'); - } - - if ($this->input->post('role_id')) - { - $data['role_id'] = $this->input->post('role_id'); - } - - if ($this->input->post('restore')) - { - $data['deleted'] = 0; - } - - if ($this->input->post('unban')) - { - $data['banned'] = 0; - } - - if ($this->input->post('display_name')) - { - $data['display_name'] = $this->input->post('display_name'); - } - - // Activation - if ($this->input->post('activate')) - { - $data['active'] = 1; - } - else if ($this->input->post('deactivate')) - { - $data['active'] = 0; - } - - if ($type == 'insert') - { - $activation_method = $this->settings_lib->item('auth.user_activation_method'); - - // No activation method - if ($activation_method == 0) - { - // Activate the user automatically - $data['active'] = 1; - } - - $return = $this->user_model->insert($data); - } - else // Update - { - $return = $this->user_model->update($id, $data); - } - - // Any modules needing to save data? - Events::trigger('save_user', $this->input->post()); - - return $return; - - }//end save_user() - - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - // ACTIVATION METHODS - //-------------------------------------------------------------------- - /** - * Activates selected users accounts. - * - * @access private - * - * @param int $user_id - * - * @return void - */ - private function _activate($user_id) - { - $this->user_status($user_id,1,0); - - }//end _activate() - - //-------------------------------------------------------------------- - /** - * Deactivates selected users accounts. - * - * @access private - * - * @param int $user_id - * - * @return void - */ - private function _deactivate($user_id) - { - $this->user_status($user_id,0,0); - - }//end _deactivate() - - //-------------------------------------------------------------------- - - /** - * Activates or deavtivates a user from the users dashboard. - * Redirects to /settings/users on completion. - * - * @access private - * - * @param int $user_id User ID int - * @param int $status 1 = Activate, -1 = Deactivate - * @param int $supress_email 1 = Supress, All others = send email - * - * @return void - */ - private function user_status($user_id = false, $status = 1, $supress_email = 0) - { - $supress_email = (isset($supress_email) && $supress_email == 1 ? true : false); - - if ($user_id !== false && $user_id != -1) - { - $result = false; - $type = ''; - if ($status == 1) - { - $result = $this->user_model->admin_activation($user_id); - $type = lang('bf_action_activate'); - } - else - { - $result = $this->user_model->admin_deactivation($user_id); - $type = lang('bf_action_deactivate'); - } - - $user = $this->user_model->find($user_id); - $log_name = $this->settings_lib->item('auth.use_own_names') ? $this->current_user->username : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); - if (!isset($this->activity_model)) - { - $this->load->model('activities/activity_model'); - } - - $this->activity_model->log_activity($this->current_user->id, lang('us_log_status_change') . ': '.$log_name . ' : '.$type."ed", 'users'); - if ($result) - { - $message = lang('us_active_status_changed'); - if (!$supress_email) - { - // Now send the email - $this->load->library('emailer/emailer'); - - $settings = $this->settings_lib->find_by('name','site.title'); - - $data = array - ( - 'to' => $this->user_model->find($user_id)->email, - 'subject' => lang('us_account_active'), - 'message' => $this->load->view('_emails/activated', array('link'=>site_url(),'title'=>$settings->value), true) - ); - - if ($this->emailer->send($data)) - { - $message = lang('us_active_email_sent'); - } - else - { - $message=lang('us_err_no_email'). $this->emailer->errors; - } - } - Template::set_message($message, 'success'); - } - else - { - Template::set_message(lang('us_err_status_error').$this->user_model->error,'error'); - }//end if - } - else - { - Template::set_message(lang('us_err_no_id'),'error'); - }//end if - - Template::redirect(SITE_AREA.'/settings/users'); - - }//end user_status() - - //-------------------------------------------------------------------- - -}//end Settings - -// End of Admin User Controller -/* End of file settings.php */ -/* Location: ./application/core_modules/controllers/settings.php */ +auth->restrict('Bonfire.Users.View'); + + $this->load->model('roles/role_model'); + + $this->lang->load('users'); + + Template::set_block('sub_nav', 'settings/_sub_nav'); + + }//end __construct() + + //-------------------------------------------------------------------- + + /* + * Display the user list and manage the user deletions/banning/purge + * + * @access public + * + * @return void + */ + public function index($offset=0) + { + $this->auth->restrict('Bonfire.Users.Manage'); + + $roles = $this->role_model->select('role_id, role_name')->where('deleted', 0)->find_all(); + $ordered_roles = array(); + foreach ($roles as $role) + { + $ordered_roles[$role->role_id] = $role; + } + Template::set('roles', $ordered_roles); + + // Do we have any actions? + $action = $this->input->post('submit').$this->input->post('delete').$this->input->post('purge').$this->input->post('restore').$this->input->post('activate').$this->input->post('deactivate'); + + if (!empty($action)) + { + $checked = $this->input->post('checked'); + + if (!empty($checked)) + { + foreach($checked as $user_id) + { + switch(strtolower($action)) + { + case 'activate': + $this->_activate($user_id); + break; + case 'deactivate': + $this->_deactivate($user_id); + break; + case 'ban': + $this->_ban($user_id); + break; + case 'delete': + $this->_delete($user_id); + break; + case 'purge': + $this->_purge($user_id); + break; + case 'restore': + $this->_restore($user_id); + break; + } + } + } + else + { + Template::set_message(lang('us_empty_id'), 'error'); + } + } + + $where = array(); + $show_deleted = FALSE; + + // Filters + $filter = $this->input->get('filter'); + switch($filter) + { + case 'inactive': + $where['users.active'] = 0; + break; + case 'banned': + $where['users.banned'] = 1; + break; + case 'deleted': + $where['users.deleted'] = 1; + $show_deleted = TRUE; + break; + case 'role': + $role_id = (int)$this->input->get('role_id'); + $where['users.role_id'] = $role_id; + + foreach ($roles as $role) + { + if ($role->role_id == $role_id) + { + Template::set('filter_role', $role->role_name); + break; + } + } + break; + + default: + $where['users.deleted'] = 0; + $this->user_model->where('users.deleted', 0); + break; + } + + // First Letter + $first_letter = $this->input->get('firstletter'); + if (!empty($first_letter)) + { + $where['SUBSTRING( LOWER(username), 1, 1)='] = $first_letter; + } + + $this->load->helper('ui/ui'); + + $this->user_model->limit($this->limit, $offset)->where($where); + $this->user_model->select('users.id, users.role_id, username, display_name, email, last_login, banned, active, users.deleted, role_name'); + + Template::set('users', $this->user_model->find_all($show_deleted)); + + // Pagination + $this->load->library('pagination'); + + $this->user_model->where($where); + $total_users = $this->user_model->count_all(); + + + $this->pager['base_url'] = site_url(SITE_AREA .'/settings/users/index'); + $this->pager['total_rows'] = $total_users; + $this->pager['per_page'] = $this->limit; + $this->pager['uri_segment'] = 5; + + $this->pagination->initialize($this->pager); + + Template::set('current_url', current_url()); + Template::set('filter', $filter); + + Template::set('toolbar_title', lang('us_user_management')); + Template::render(); + + }//end index() + + //-------------------------------------------------------------------- + + /** + * Manage creating a new user + * + * @access public + * + * @return void + */ + public function create() + { + $this->auth->restrict('Bonfire.Users.Add'); + + $this->load->config('address'); + $this->load->helper('address'); + $this->load->helper('date'); + + + $this->load->config('user_meta'); + $meta_fields = config_item('user_meta_fields'); + Template::set('meta_fields', $meta_fields); + + if ($this->input->post('submit')) + { + if ($id = $this->save_user('insert', NULL, $meta_fields)) + { + + $meta_data = array(); + foreach ($meta_fields as $field) + { + if (!isset($field['admin_only']) || $field['admin_only'] === FALSE + || (isset($field['admin_only']) && $field['admin_only'] === TRUE + && isset($this->current_user) && $this->current_user->role_id == 1)) + { + $meta_data[$field['name']] = $this->input->post($field['name']); + } + } + + // now add the meta is there is meta data + $this->user_model->save_meta_for($id, $meta_data); + + $user = $this->user_model->find($id); + $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); + $this->activity_model->log_activity($this->current_user->id, lang('us_log_create').' '. $user->role_name . ': '.$log_name, 'users'); + + Template::set_message(lang('us_user_created_success'), 'success'); + Template::redirect(SITE_AREA .'/settings/users'); + } + } + + $settings = $this->settings_lib->find_all(); + if ($settings['auth.password_show_labels'] == 1) { + Assets::add_module_js('users','password_strength.js'); + Assets::add_module_js('users','jquery.strength.js'); + Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); + } + Template::set('roles', $this->role_model->select('role_id, role_name, default')->where('deleted', 0)->find_all()); + Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); + + Template::set('toolbar_title', lang('us_create_user')); + Template::set_view('settings/user_form'); + Template::render(); + + }//end create() + + //-------------------------------------------------------------------- + + /** + * Edit a user + * + * @access public + * + * @return void + */ + public function edit($user_id='') + { + $this->load->config('address'); + $this->load->helper('address'); + $this->load->helper('date'); + + // if there is no id passed in edit the current user + // this is so we don't have to pass the user id in the url for editing the current users profile + if (empty($user_id)) + { + $user_id = $this->current_user->id; + } + + if (empty($user_id)) + { + Template::set_message(lang('us_empty_id'), 'error'); + redirect(SITE_AREA .'/settings/users'); + } + + if ($user_id != $this->current_user->id) + { + $this->auth->restrict('Bonfire.Users.Manage'); + } + + + $this->load->config('user_meta'); + $meta_fields = config_item('user_meta_fields'); + Template::set('meta_fields', $meta_fields); + + $user = $this->user_model->find_user_and_meta($user_id); + + if ($this->input->post('submit')) + { + if ($this->save_user('update', $user_id, $meta_fields, $user->role_name)) + { + + $meta_data = array(); + foreach ($meta_fields as $field) + { + if (!isset($field['admin_only']) || $field['admin_only'] === FALSE + || (isset($field['admin_only']) && $field['admin_only'] === TRUE + && isset($this->current_user) && $this->current_user->role_id == 1)) + { + $meta_data[$field['name']] = $this->input->post($field['name']); + } + } + + // now add the meta is there is meta data + $this->user_model->save_meta_for($user_id, $meta_data); + + + $user = $this->user_model->find_user_and_meta($user_id); + $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); + $this->activity_model->log_activity($this->current_user->id, lang('us_log_edit') .': '.$log_name, 'users'); + + Template::set_message(lang('us_user_update_success'), 'success'); + + // redirect back to the edit page to make sure that a users password change + // forces a login check + Template::redirect($this->uri->uri_string()); + } + } + + if (isset($user)) + { + Template::set('roles', $this->role_model->select('role_id, role_name, default')->where('deleted', 0)->find_all()); + Template::set('user', $user); + Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); + } + else + { + Template::set_message(sprintf(lang('us_unauthorized'),$user->role_name), 'error'); + redirect(SITE_AREA .'/settings/users'); + } + + $settings = $this->settings_lib->find_all(); + if ($settings['auth.password_show_labels'] == 1) { + Assets::add_module_js('users','password_strength.js'); + Assets::add_module_js('users','jquery.strength.js'); + Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); + } + + Template::set('toolbar_title', lang('us_edit_user')); + + Template::set_view('settings/user_form'); + + Template::render(); + + }//end edit() + + //-------------------------------------------------------------------- + + /** + * Ban a user or group of users + * + * @access private + * + * @param int $user_id User to ban + * @param string $ban_message Set a message for the user as the reason for banning them + * + * @return void + */ + private function _ban($user_id, $ban_message='') + { + $data = array( + 'banned' => 1, + 'ban_message' => $ban_message + ); + + $this->user_model->update($user_id, $data); + + }//end _ban() + + //-------------------------------------------------------------------- + + /** + * Delete a user or group of users + * + * @access private + * + * @param int $id User to delete + * + * @return void + */ + private function _delete($id) + { + $user = $this->user_model->find($id); + + if (isset($user) && has_permission('Permissions.'.$user->role_name.'.Manage') && $user->id != $this->current_user->id) + { + if ($this->user_model->delete($id)) + { + + $user = $this->user_model->find($id); + $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); + $this->activity_model->log_activity($this->current_user->id, lang('us_log_delete') . ': '.$log_name, 'users'); + Template::set_message(lang('us_action_deleted'), 'success'); + } + else + { + Template::set_message(lang('us_action_not_deleted'). $this->user_model->error, 'error'); + } + } + else + { + if ($user->id == $this->current_user->id) + { + Template::set_message(lang('us_self_delete'), 'error'); + } + else + { + Template::set_message(sprintf(lang('us_unauthorized'),$user->role_name), 'error'); + } + }//end if + + }//end _delete() + + //-------------------------------------------------------------------- + + /** + * Purge the selected users which are already marked as deleted + * + * @access private + * + * @param int $id User to purge + * + * @return void + */ + private function _purge($id) + { + $this->user_model->delete($id, TRUE); + Template::set_message(lang('us_action_purged'), 'success'); + + }//end _purge() + + //-------------------------------------------------------------------- + + /** + * Restore the deleted user + * + * @access private + * + * @return void + */ + private function _restore($id) + { + if ($this->user_model->update($id, array('users.deleted'=>0))) + { + Template::set_message(lang('us_user_restored_success'), 'success'); + } + else + { + Template::set_message(lang('us_user_restored_error'). $this->user_model->error, 'error'); + } + + }//end restore() + + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + // !HMVC METHODS + //-------------------------------------------------------------------- + + /** + * Show the access logs + * + * @access public + * + * @param int $limit Limit the number of logs to show at a time + * + * @return string Show the access logs + */ + public function access_logs($limit=15) + { + $logs = $this->user_model->get_access_logs($limit); + + return $this->load->view('settings/access_logs', array('access_logs' => $logs), TRUE); + + }//end access_logs() + + //-------------------------------------------------------------------- + + + + //-------------------------------------------------------------------- + // !PRIVATE METHODS + //-------------------------------------------------------------------- + + /** + * Save the user + * + * @access private + * + * @param string $type The type of operation (insert or edit) + * @param int $id The id of the user in the case of an edit operation + * @param array $meta_fields Array of meta fields fur the user + * @param string $cur_role_name The current role for the user being edited + * + * @return bool + */ + private function save_user($type='insert', $id=0, $meta_fields=array(), $cur_role_name = '') + { + + if ($type == 'insert') + { + $this->form_validation->set_rules('email', lang('bf_email'), 'required|trim|unique[users.email]|valid_email|max_length[120]|xss_clean'); + $this->form_validation->set_rules('password', lang('bf_password'), 'required|trim|strip_tags|min_length[8]|max_length[120]|valid_password|xss_clean'); + $this->form_validation->set_rules('pass_confirm', lang('bf_password_confirm'), 'required|trim|strip_tags|matches[password]|xss_clean'); + } + else + { + $_POST['id'] = $id; + $this->form_validation->set_rules('email', lang('bf_email'), 'required|trim|unique[users.email,users.id]|valid_email|max_length[120]|xss_clean'); + $this->form_validation->set_rules('password', lang('bf_password'), 'trim|strip_tags|min_length[8]|max_length[120]|valid_password|matches[pass_confirm]|xss_clean'); + $this->form_validation->set_rules('pass_confirm', lang('bf_password_confirm'), 'trim|strip_tags|xss_clean'); + } + + $use_usernames = $this->settings_lib->item('auth.use_usernames'); + + if ($use_usernames) + { + $extra_unique_rule = $type == 'update' ? ',users.id' : ''; + + $this->form_validation->set_rules('username', lang('bf_username'), 'required|trim|strip_tags|max_length[30]|unique[users.username'.$extra_unique_rule.']|xss_clean'); + } + + $this->form_validation->set_rules('display_name', lang('bf_display_name'), 'trim|strip_tags|max_length[255]|xss_clean'); + + $this->form_validation->set_rules('language', lang('bf_language'), 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('timezones', lang('bf_timezone'), 'required|trim|strip_tags|max_length[4]|xss_clean'); + + if (has_permission('Bonfire.Roles.Manage') && has_permission('Permissions.'.$cur_role_name.'.Manage')) + { + $this->form_validation->set_rules('role_id', lang('us_role'), 'required|trim|strip_tags|max_length[2]|is_numeric|xss_clean'); + } + + $meta_data = array(); + + foreach ($meta_fields as $field) + { + if (!isset($field['admin_only']) || $field['admin_only'] === FALSE + || (isset($field['admin_only']) && $field['admin_only'] === TRUE + && isset($this->current_user) && $this->current_user->role_id == 1)) + { + $this->form_validation->set_rules($field['name'], $field['label'], $field['rules']); + + $meta_data[$field['name']] = $this->input->post($field['name']); + } + } + + if ($this->form_validation->run($this) === FALSE) + { + return FALSE; + } + + // Compile our core user elements to save. + $data = array( + 'email' => $this->input->post('email'), + 'username' => $this->input->post('username'), + 'language' => $this->input->post('language'), + 'timezone' => $this->input->post('timezones'), + ); + + if ($this->input->post('password')) + { + $data['password'] = $this->input->post('password'); + } + + if ($this->input->post('pass_confirm')) + { + $data['pass_confirm'] = $this->input->post('pass_confirm'); + } + + if ($this->input->post('role_id')) + { + $data['role_id'] = $this->input->post('role_id'); + } + + if ($this->input->post('restore')) + { + $data['deleted'] = 0; + } + + if ($this->input->post('unban')) + { + $data['banned'] = 0; + } + + if ($this->input->post('display_name')) + { + $data['display_name'] = $this->input->post('display_name'); + } + + // Activation + if ($this->input->post('activate')) + { + $data['active'] = 1; + } + else if ($this->input->post('deactivate')) + { + $data['active'] = 0; + } + + if ($type == 'insert') + { + $activation_method = $this->settings_lib->item('auth.user_activation_method'); + + // No activation method + if ($activation_method == 0) + { + // Activate the user automatically + $data['active'] = 1; + } + + $return = $this->user_model->insert($data); + } + else // Update + { + $return = $this->user_model->update($id, $data); + } + + // Any modules needing to save data? + Events::trigger('save_user', $this->input->post()); + + return $return; + + }//end save_user() + + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // ACTIVATION METHODS + //-------------------------------------------------------------------- + /** + * Activates selected users accounts. + * + * @access private + * + * @param int $user_id + * + * @return void + */ + private function _activate($user_id) + { + $this->user_status($user_id,1,0); + + }//end _activate() + + //-------------------------------------------------------------------- + /** + * Deactivates selected users accounts. + * + * @access private + * + * @param int $user_id + * + * @return void + */ + private function _deactivate($user_id) + { + $this->user_status($user_id,0,0); + + }//end _deactivate() + + //-------------------------------------------------------------------- + + /** + * Activates or deavtivates a user from the users dashboard. + * Redirects to /settings/users on completion. + * + * @access private + * + * @param int $user_id User ID int + * @param int $status 1 = Activate, -1 = Deactivate + * @param int $supress_email 1 = Supress, All others = send email + * + * @return void + */ + private function user_status($user_id = false, $status = 1, $supress_email = 0) + { + $supress_email = (isset($supress_email) && $supress_email == 1 ? true : false); + + if ($user_id !== false && $user_id != -1) + { + $result = false; + $type = ''; + if ($status == 1) + { + $result = $this->user_model->admin_activation($user_id); + $type = lang('bf_action_activate'); + } + else + { + $result = $this->user_model->admin_deactivation($user_id); + $type = lang('bf_action_deactivate'); + } + + $user = $this->user_model->find($user_id); + $log_name = $this->settings_lib->item('auth.use_own_names') ? $this->current_user->username : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); + if (!isset($this->activity_model)) + { + $this->load->model('activities/activity_model'); + } + + $this->activity_model->log_activity($this->current_user->id, lang('us_log_status_change') . ': '.$log_name . ' : '.$type."ed", 'users'); + if ($result) + { + $message = lang('us_active_status_changed'); + if (!$supress_email) + { + // Now send the email + $this->load->library('emailer/emailer'); + + $settings = $this->settings_lib->find_by('name','site.title'); + + $data = array + ( + 'to' => $this->user_model->find($user_id)->email, + 'subject' => lang('us_account_active'), + 'message' => $this->load->view('_emails/activated', array('link'=>site_url(),'title'=>$settings->value), true) + ); + + if ($this->emailer->send($data)) + { + $message = lang('us_active_email_sent'); + } + else + { + $message=lang('us_err_no_email'). $this->emailer->errors; + } + } + Template::set_message($message, 'success'); + } + else + { + Template::set_message(lang('us_err_status_error').$this->user_model->error,'error'); + }//end if + } + else + { + Template::set_message(lang('us_err_no_id'),'error'); + }//end if + + Template::redirect(SITE_AREA.'/settings/users'); + + }//end user_status() + + //-------------------------------------------------------------------- + +}//end Settings + +// End of Admin User Controller +/* End of file settings.php */ +/* Location: ./application/core_modules/controllers/settings.php */ diff --git a/bonfire/application/core_modules/users/controllers/users.php b/bonfire/application/core_modules/users/controllers/users.php index 4ca267004..4f320310c 100644 --- a/bonfire/application/core_modules/users/controllers/users.php +++ b/bonfire/application/core_modules/users/controllers/users.php @@ -1,889 +1,889 @@ -load->helper('form'); - $this->load->library('form_validation'); - $this->form_validation->CI =& $this; - - if (!class_exists('User_model')) - { - $this->load->model('users/User_model', 'user_model'); - } - - $this->load->database(); - - $this->load->library('users/auth'); - - $this->lang->load('users'); - - }//end __construct() - - //-------------------------------------------------------------------- - - /** - * Presents the login function and allows the user to actually login. - * - * @access public - * - * @return void - */ - public function login() - { - // if the user is not logged in continue to show the login page - if ($this->auth->is_logged_in() === FALSE) - { - if ($this->input->post('submit')) - { - $remember = $this->input->post('remember_me') == '1' ? TRUE : FALSE; - - // Try to login - if ($this->auth->login($this->input->post('login'), $this->input->post('password'), $remember) === TRUE) - { - - // Log the Activity - $this->activity_model->log_activity($this->auth->user_id(), lang('us_log_logged').': ' . $this->input->ip_address(), 'users'); - - /* - In many cases, we will have set a destination for a - particular user-role to redirect to. This is helpful for - cases where we are presenting different information to different - roles that might cause the base destination to be not available. - */ - if ($this->settings_lib->item('auth.do_login_redirect') && !empty ($this->auth->login_destination)) - { - Template::redirect($this->auth->login_destination); - } - else - { - if (!empty($this->requested_page)) - { - Template::redirect($this->requested_page); - } - else - { - Template::redirect('/'); - } - } - }//end if - }//end if - - Template::set_view('users/users/login'); - Template::set('page_title', 'Login'); - Template::render('login'); - } - else - { - - Template::redirect('/'); - }//end if - - }//end login() - - //-------------------------------------------------------------------- - - /** - * Calls the auth->logout method to destroy the session and cleanup, - * then redirects to the home page. - * - * @access public - * - * @return void - */ - public function logout() - { - // Log the Activity - $this->activity_model->log_activity($this->current_user->id, lang('us_log_logged_out').': ' . $this->input->ip_address(), 'users'); - - $this->auth->logout(); - - redirect('/'); - - }//end logout() - - //-------------------------------------------------------------------- - - /** - * Allows a user to start the process of resetting their password. - * An email is allowed with a special temporary link that is only valid - * for 24 hours. This link takes them to reset_password(). - * - * @access public - * - * @return void - */ - public function forgot_password() - { - - // if the user is not logged in continue to show the login page - if ($this->auth->is_logged_in() === FALSE) - { - if (isset($_POST['submit'])) - { - $this->form_validation->set_rules('email', 'lang:bf_email', 'required|trim|strip_tags|valid_email|xss_clean'); - - if ($this->form_validation->run() === FALSE) - { - Template::set_message(lang('us_invalid_email'), 'error'); - } - else - { - // We validated. Does the user actually exist? - $user = $this->user_model->find_by('email', $_POST['email']); - - if ($user !== FALSE) - { - // User exists, so create a temp password. - $this->load->helpers(array('string', 'security')); - - $pass_code = random_string('alnum', 40); - - $hash = do_hash($pass_code . $user->salt . $_POST['email']); - - // Save the hash to the db so we can confirm it later. - $this->user_model->update_where('email', $_POST['email'], array('reset_hash' => $hash, 'reset_by' => strtotime("+24 hours") )); - - // Create the link to reset the password - $pass_link = site_url('reset_password/'. str_replace('@', ':', $_POST['email']) .'/'. $hash); - - // Now send the email - $this->load->library('emailer/emailer'); - - $data = array( - 'to' => $_POST['email'], - 'subject' => lang('us_reset_pass_subject'), - 'message' => $this->load->view('_emails/forgot_password', array('link' => $pass_link), TRUE) - ); - - if ($this->emailer->send($data)) - { - Template::set_message(lang('us_reset_pass_message'), 'success'); - } - else - { - Template::set_message(lang('us_reset_pass_error'). $this->emailer->errors, 'error'); - } - }//end if - }//end if - }//end if - - Template::set_view('users/users/forgot_password'); - Template::set('page_title', 'Password Reset'); - Template::render(); - } - else - { - - Template::redirect('/'); - }//end if - - }//end forgot_password() - - //-------------------------------------------------------------------- - - /** - * Allows a user to edit their own profile information. - * - * @access public - * - * @return void - */ - public function profile() - { - - if ($this->auth->is_logged_in() === FALSE) - { - $this->auth->logout(); - redirect('login'); - } - - $this->load->helper('date'); - - $this->load->config('address'); - $this->load->helper('address'); - - $this->load->config('user_meta'); - $meta_fields = config_item('user_meta_fields'); - - Template::set('meta_fields', $meta_fields); - - if ($this->input->post('submit')) - { - - $user_id = $this->current_user->id; - if ($this->save_user($user_id, $meta_fields)) - { - - $meta_data = array(); - foreach ($meta_fields as $field) - { - if ((!isset($field['admin_only']) || $field['admin_only'] === FALSE - || (isset($field['admin_only']) && $field['admin_only'] === TRUE - && isset($this->current_user) && $this->current_user->role_id == 1)) - && (!isset($field['frontend']) || $field['frontend'] === TRUE)) - { - $meta_data[$field['name']] = $this->input->post($field['name']); - } - } - - // now add the meta is there is meta data - $this->user_model->save_meta_for($user_id, $meta_data); - - // Log the Activity - - $user = $this->user_model->find($user_id); - $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); - $this->activity_model->log_activity($this->current_user->id, lang('us_log_edit_profile') .': '.$log_name, 'users'); - - Template::set_message(lang('us_profile_updated_success'), 'success'); - - // redirect to make sure any language changes are picked up - Template::redirect('/users/profile'); - exit; - } - else - { - Template::set_message(lang('us_profile_updated_error'), 'error'); - }//end if - }//end if - - // get the current user information - $user = $this->user_model->find_user_and_meta($this->current_user->id); - - $settings = $this->settings_lib->find_all(); - if ($settings['auth.password_show_labels'] == 1) { - Assets::add_module_js('users','password_strength.js'); - Assets::add_module_js('users','jquery.strength.js'); - Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); - } - // Generate password hint messages. - $this->user_model->password_hints(); - - Template::set('user', $user); - Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); - - Template::set_view('users/users/profile'); - Template::render(); - - }//end profile() - - //-------------------------------------------------------------------- - - /** - * Allows the user to create a new password for their account. At the moment, - * the only way to get here is to go through the forgot_password() process, - * which creates a unique code that is only valid for 24 hours. - * - * @access public - * - * @param string $email The email address to check against. - * @param string $code A randomly generated alphanumeric code. (Generated by forgot_password() ). - * - * @return void - */ - public function reset_password($email='', $code='') - { - // if the user is not logged in continue to show the login page - if ($this->auth->is_logged_in() === FALSE) - { - // If there is no code, then it's not a valid request. - if (empty($code) || empty($email)) - { - Template::set_message(lang('us_reset_invalid_email'), 'error'); - Template::redirect('/login'); - } - - // Handle the form - if ($this->input->post('submit')) - { - $this->form_validation->set_rules('password', 'lang:bf_password', 'required|trim|strip_tags|min_length[8]|max_length[120]|valid_password'); - $this->form_validation->set_rules('pass_confirm', 'lang:bf_password_confirm', 'required|trim|strip_tags|matches[password]'); - - if ($this->form_validation->run() !== FALSE) - { - // The user model will create the password hash for us. - $data = array('password' => $this->input->post('password'), - 'pass_confirm' => $this->input->post('pass_confirm'), - 'reset_by' => 0, - 'reset_hash' => ''); - - if ($this->user_model->update($this->input->post('user_id'), $data)) - { - // Log the Activity - - $this->activity_model->log_activity($this->input->post('user_id'), lang('us_log_reset') , 'users'); - Template::set_message(lang('us_reset_password_success'), 'success'); - Template::redirect('/login'); - } - else - { - Template::set_message(lang('us_reset_password_error'). $this->user_model->error, 'error'); - - } - } - }//end if - - // Check the code against the database - $email = str_replace(':', '@', $email); - $user = $this->user_model->find_by(array( - 'email' => $email, - 'reset_hash' => $code, - 'reset_by >=' => time() - )); - - // It will be an Object if a single result was returned. - if (!is_object($user)) - { - Template::set_message( lang('us_reset_invalid_email'), 'error'); - Template::redirect('/login'); - } - - $settings = $this->settings_lib->find_all(); - if ($settings['auth.password_show_labels'] == 1) { - Assets::add_module_js('users','password_strength.js'); - Assets::add_module_js('users','jquery.strength.js'); - Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); - } - // If we're here, then it is a valid request.... - Template::set('user', $user); - - Template::set_view('users/users/reset_password'); - Template::render(); - } - else - { - - Template::redirect('/'); - }//end if - - }//end reset_password() - - //-------------------------------------------------------------------- - - /** - * Display the registration form for the user and manage the registration process - * - * @access public - * - * @return void - */ - public function register() - { - // Are users even allowed to register? - if (!$this->settings_lib->item('auth.allow_register')) - { - Template::set_message(lang('us_register_disabled'), 'error'); - Template::redirect('/'); - } - - $this->load->model('roles/role_model'); - $this->load->helper('date'); - - $this->load->config('address'); - $this->load->helper('address'); - - $this->load->config('user_meta'); - $meta_fields = config_item('user_meta_fields'); - Template::set('meta_fields', $meta_fields); - - if ($this->input->post('submit')) - { - // Validate input - $this->form_validation->set_rules('email', 'lang:bf_email', 'required|trim|strip_tags|valid_email|max_length[120]|unique[users.email]|xss_clean'); - - if ($this->settings_lib->item('auth.use_usernames')) - { - $this->form_validation->set_rules('username', 'lang:bf_username', 'required|trim|strip_tags|max_length[30]|unique[users.username]|xss_clean'); - } - - $this->form_validation->set_rules('password', 'lang:bf_password', 'required|trim|strip_tags|min_length[8]|max_length[120]|valid_password'); - $this->form_validation->set_rules('pass_confirm', 'lang:bf_password_confirm', 'required|trim|strip_tags|matches[password]'); - - $this->form_validation->set_rules('language', 'lang:bf_language', 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('timezones', 'lang:bf_timezone', 'required|trim|strip_tags|max_length[4]|xss_clean'); - $this->form_validation->set_rules('display_name', 'lang:bf_display_name', 'trim|strip_tags|max_length[255]|xss_clean'); - - - $meta_data = array(); - foreach ($meta_fields as $field) - { - if ((!isset($field['admin_only']) || $field['admin_only'] === FALSE - || (isset($field['admin_only']) && $field['admin_only'] === TRUE - && isset($this->current_user) && $this->current_user->role_id == 1)) - && (!isset($field['frontend']) || $field['frontend'] === TRUE)) - { - $this->form_validation->set_rules($field['name'], $field['label'], $field['rules']); - - $meta_data[$field['name']] = $this->input->post($field['name']); - } - } - - if ($this->form_validation->run($this) !== FALSE) - { - // Time to save the user... - $data = array( - 'email' => $_POST['email'], - 'username' => isset($_POST['username']) ? $_POST['username'] : '', - 'password' => $_POST['password'], - 'language' => $this->input->post('language'), - 'timezone' => $this->input->post('timezones'), - ); - - // User activation method - $activation_method = $this->settings_lib->item('auth.user_activation_method'); - - // No activation method - if ($activation_method == 0) - { - // Activate the user automatically - $data['active'] = 1; - } - - if ($user_id = $this->user_model->insert($data)) - { - // now add the meta is there is meta data - $this->user_model->save_meta_for($user_id, $meta_data); - - /* - * USER ACTIVATIONS ENHANCEMENT - */ - - // Prepare user messaging vars - $subject = ''; - $email_mess = ''; - $message = lang('us_email_thank_you'); - $type = 'success'; - $site_title = $this->settings_lib->item('site.title'); - $error = false; - - switch ($activation_method) - { - case 0: - // No activation required. Activate the user and send confirmation email - $subject = str_replace('[SITE_TITLE]',$this->settings_lib->item('site.title'),lang('us_account_reg_complete')); - $email_mess = $this->load->view('_emails/activated', array('title'=>$site_title,'link' => site_url()), true); - $message .= lang('us_account_active_login'); - break; - case 1: - // Email Activiation. - // Create the link to activate membership - // Run the account deactivate to assure everything is set correctly - // Switch on the login type to test the correct field - $login_type = $this->settings_lib->item('auth.login_type'); - switch ($login_type) - { - case 'username': - if ($this->settings_lib->item('auth.use_usernames')) - { - $id_val = $_POST['username']; - } - else - { - $id_val = $_POST['email']; - $login_type = 'email'; - } - break; - case 'email': - case 'both': - default: - $id_val = $_POST['email']; - $login_type = 'email'; - break; - } // END switch - - $activation_code = $this->user_model->deactivate($id_val, $login_type); - $activate_link = site_url('activate/'. str_replace('@', ':', $_POST['email']) .'/'. $activation_code); - $subject = lang('us_email_subj_activate'); - - $email_message_data = array( - 'title' => $site_title, - 'code' => $activation_code, - 'link' => $activate_link - ); - $email_mess = $this->load->view('_emails/activate', $email_message_data, true); - $message .= lang('us_check_activate_email'); - break; - case 2: - // Admin Activation - // Clear hash but leave user inactive - $subject = lang('us_email_subj_pending'); - $email_mess = $this->load->view('_emails/pending', array('title'=>$site_title), true); - $message .= lang('us_admin_approval_pending'); - break; - }//end switch - - // Now send the email - $this->load->library('emailer/emailer'); - $data = array( - 'to' => $_POST['email'], - 'subject' => $subject, - 'message' => $email_mess - ); - - if (!$this->emailer->send($data)) - { - $message .= lang('us_err_no_email'). $this->emailer->errors; - $error = true; - } - - if ($error) - { - $type = 'error'; - } - else - { - $type = 'success'; - } - - Template::set_message($message, $type); - - // Log the Activity - - $this->activity_model->log_activity($user_id, lang('us_log_register') , 'users'); - Template::redirect('login'); - } - else - { - Template::set_message(lang('us_registration_fail'), 'error'); - redirect('/register'); - }//end if - }//end if - }//end if - - $settings = $this->settings_lib->find_all(); - if ($settings['auth.password_show_labels'] == 1) { - Assets::add_module_js('users','password_strength.js'); - Assets::add_module_js('users','jquery.strength.js'); - Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); - } - - // Generate password hint messages. - $this->user_model->password_hints(); - - Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); - - Template::set_view('users/users/register'); - Template::set('page_title', 'Register'); - Template::render(); - - }//end register() - - //-------------------------------------------------------------------- - - /** - * Save the user - * - * @access private - * - * @param int $id The id of the user in the case of an edit operation - * @param array $meta_fields Array of meta fields fur the user - * - * @return bool - */ - private function save_user($id=0, $meta_fields=array()) - { - - if ( $id == 0 ) - { - $id = $this->current_user->id; /* ( $this->input->post('id') > 0 ) ? $this->input->post('id') : */ - } - - $_POST['id'] = $id; - - // Simple check to make the posted id is equal to the current user's id, minor security check - if ( $_POST['id'] != $this->current_user->id ) - { - $this->form_validation->set_message('email', 'lang:us_invalid_userid'); - return FALSE; - } - - // Setting the payload for Events system. - $payload = array ( 'user_id' => $id, 'data' => $this->input->post() ); - - - $this->form_validation->set_rules('email', 'lang:bf_email', 'required|trim|valid_email|max_length[120]|unique[users.email,users.id]|xss_clean'); - $this->form_validation->set_rules('password', 'lang:bf_password', 'trim|strip_tags|min_length[8]|max_length[120]|valid_password'); - - // check if a value has been entered for the password - if so then the pass_confirm is required - // if you don't set it as "required" the pass_confirm field could be left blank and the form validation would still pass - $extra_rules = !empty($_POST['password']) ? 'required|' : ''; - $this->form_validation->set_rules('pass_confirm', 'lang:bf_password_confirm', 'trim|strip_tags|'.$extra_rules.'matches[password]'); - - if ($this->settings_lib->item('auth.use_usernames')) - { - $this->form_validation->set_rules('username', 'lang:bf_username', 'required|trim|strip_tags|max_length[30]|unique[users.username,users.id]|xss_clean'); - } - - $this->form_validation->set_rules('language', 'lang:bf_language', 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('timezones', 'lang:bf_timezone', 'required|trim|strip_tags|max_length[4]|xss_clean'); - $this->form_validation->set_rules('display_name', 'lang:bf_display_name', 'trim|strip_tags|max_length[255]|xss_clean'); - - // Added Event "before_user_validation" to run before the form validation - Events::trigger('before_user_validation', $payload ); - - - foreach ($meta_fields as $field) - { - if ((!isset($field['admin_only']) || $field['admin_only'] === FALSE - || (isset($field['admin_only']) && $field['admin_only'] === TRUE - && isset($this->current_user) && $this->current_user->role_id == 1)) - && (!isset($field['frontend']) || $field['frontend'] === TRUE)) - { - $this->form_validation->set_rules($field['name'], $field['label'], $field['rules']); - } - } - - - if ($this->form_validation->run($this) === FALSE) - { - return FALSE; - } - - // Compile our core user elements to save. - $data = array( - 'email' => $this->input->post('email'), - 'language' => $this->input->post('language'), - 'timezone' => $this->input->post('timezones'), - ); - - if ($this->input->post('password')) - { - $data['password'] = $this->input->post('password'); - } - - if ($this->input->post('pass_confirm')) - { - $data['pass_confirm'] = $this->input->post('pass_confirm'); - } - - if ($this->input->post('display_name')) - { - $data['display_name'] = $this->input->post('display_name'); - } - - if ($this->settings_lib->item('auth.use_usernames')) - { - if ($this->input->post('username')) - { - $data['username'] = $this->input->post('username'); - } - } - - // Any modules needing to save data? - // Event to run after saving a user - Events::trigger('save_user', $payload ); - - return $this->user_model->update($id, $data); - - }//end save_user() - - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - // ACTIVATION METHODS - //-------------------------------------------------------------------- - /* - Activate user. - - Checks a passed activation code and if verified, enables the user - account. If the code fails, an error is generated and returned. - - */ - public function activate($email = FALSE, $code = FALSE) - { - - if ($this->input->post('submit')) { - $this->form_validation->set_rules('code', 'Verification Code', 'required|trim|xss_clean'); - if ($this->form_validation->run() == TRUE) { - $code = $this->input->post('code'); - } - } else { - if ($email === FALSE) - { - $email = $this->uri->segment(2); - } - if ($code === FALSE) - { - $code = $this->uri->segment(3); - } - } - - // fix up the email - if (!empty($email)) - { - $email = str_replace(":", "@", $email); - } - - - if (!empty($code)) - { - $activated = $this->user_model->activate($email, $code); - if ($activated) - { - // Now send the email - $this->load->library('emailer/emailer'); - - $site_title = $this->settings_lib->item('site.title'); - - $email_message_data = array( - 'title' => $site_title, - 'link' => site_url('login') - ); - $data = array - ( - 'to' => $this->user_model->find($activated)->email, - 'subject' => lang('us_account_active'), - 'message' => $this->load->view('_emails/activated', $email_message_data, TRUE) - ); - - if ($this->emailer->send($data)) - { - Template::set_message(lang('us_account_active'), 'success'); - } - else - { - Template::set_message(lang('us_err_no_email'). $this->emailer->errors, 'error'); - } - Template::redirect('/'); - } - else - { - Template::set_message(lang('us_activate_error_msg').$this->user_model->error.'. '. lang('us_err_activate_code'), 'error'); - } - } - Template::set_view('users/users/activate'); - Template::set('page_title', 'Account Activation'); - Template::render(); - } - - //-------------------------------------------------------------------- - - /* - Method: resend_activation - - Allows a user to request that their activation code be resent to their - account's email address. If a matching email is found, the code is resent. - */ - public function resend_activation() - { - if (isset($_POST['submit'])) - { - $this->form_validation->set_rules('email', 'Email', 'required|trim|strip_tags|valid_email|xss_clean'); - - if ($this->form_validation->run() === FALSE) - { - Template::set_message('Cannot find that email in our records.', 'error'); - } - else - { - // We validated. Does the user actually exist? - $user = $this->user_model->find_by('email', $_POST['email']); - - if ($user !== FALSE) - { - // User exists, so create a temp password. - $this->load->helpers(array('string', 'security')); - - $pass_code = random_string('alnum', 40); - - $activation_code = do_hash($pass_code . $user->salt . $_POST['email']); - - $site_title = $this->settings_lib->item('site.title'); - - // Save the hash to the db so we can confirm it later. - $this->user_model->update_where('email', $_POST['email'], array('activate_hash' => $activation_code )); - - // Create the link to reset the password - $activate_link = site_url('activate/'. str_replace('@', ':', $_POST['email']) .'/'. $activation_code); - - // Now send the email - $this->load->library('emailer/emailer'); - - $email_message_data = array( - 'title' => $site_title, - 'code' => $activation_code, - 'link' => $activate_link - ); - - $data = array - ( - 'to' => $_POST['email'], - 'subject' => 'Activation Code', - 'message' => $this->load->view('_emails/activate', $email_message_data, TRUE) - ); - $this->emailer->enable_debug(true); - if ($this->emailer->send($data)) - { - Template::set_message(lang('us_check_activate_email'), 'success'); - } - else - { - if (isset($this->emailer->errors)) - { - $errors = ''; - if (is_array($this->emailer->errors)) - { - foreach ($this->emailer->errors as $error) - { - $errors .= $error."
"; - } - } - else - { - $errors = $this->emailer->errors; - } - Template::set_message(lang('us_err_no_email').$errors.", ".$this->emailer->debug, 'error'); - } - } - } - } - } - Template::set_view('users/users/resend_activation'); - Template::set('page_title', 'Activate Account'); - Template::render(); - } - -}//end Users - -/* Front-end Users Controller */ -/* End of file users.php */ -/* Location: ./application/core_modules/users/controllers/users.php */ +load->helper('form'); + $this->load->library('form_validation'); + $this->form_validation->CI =& $this; + + if (!class_exists('User_model')) + { + $this->load->model('users/User_model', 'user_model'); + } + + $this->load->database(); + + $this->load->library('users/auth'); + + $this->lang->load('users'); + + }//end __construct() + + //-------------------------------------------------------------------- + + /** + * Presents the login function and allows the user to actually login. + * + * @access public + * + * @return void + */ + public function login() + { + // if the user is not logged in continue to show the login page + if ($this->auth->is_logged_in() === FALSE) + { + if ($this->input->post('submit')) + { + $remember = $this->input->post('remember_me') == '1' ? TRUE : FALSE; + + // Try to login + if ($this->auth->login($this->input->post('login'), $this->input->post('password'), $remember) === TRUE) + { + + // Log the Activity + $this->activity_model->log_activity($this->auth->user_id(), lang('us_log_logged').': ' . $this->input->ip_address(), 'users'); + + /* + In many cases, we will have set a destination for a + particular user-role to redirect to. This is helpful for + cases where we are presenting different information to different + roles that might cause the base destination to be not available. + */ + if ($this->settings_lib->item('auth.do_login_redirect') && !empty ($this->auth->login_destination)) + { + Template::redirect($this->auth->login_destination); + } + else + { + if (!empty($this->requested_page)) + { + Template::redirect($this->requested_page); + } + else + { + Template::redirect('/'); + } + } + }//end if + }//end if + + Template::set_view('users/users/login'); + Template::set('page_title', 'Login'); + Template::render('login'); + } + else + { + + Template::redirect('/'); + }//end if + + }//end login() + + //-------------------------------------------------------------------- + + /** + * Calls the auth->logout method to destroy the session and cleanup, + * then redirects to the home page. + * + * @access public + * + * @return void + */ + public function logout() + { + // Log the Activity + $this->activity_model->log_activity($this->current_user->id, lang('us_log_logged_out').': ' . $this->input->ip_address(), 'users'); + + $this->auth->logout(); + + redirect('/'); + + }//end logout() + + //-------------------------------------------------------------------- + + /** + * Allows a user to start the process of resetting their password. + * An email is allowed with a special temporary link that is only valid + * for 24 hours. This link takes them to reset_password(). + * + * @access public + * + * @return void + */ + public function forgot_password() + { + + // if the user is not logged in continue to show the login page + if ($this->auth->is_logged_in() === FALSE) + { + if (isset($_POST['submit'])) + { + $this->form_validation->set_rules('email', 'lang:bf_email', 'required|trim|strip_tags|valid_email|xss_clean'); + + if ($this->form_validation->run() === FALSE) + { + Template::set_message(lang('us_invalid_email'), 'error'); + } + else + { + // We validated. Does the user actually exist? + $user = $this->user_model->find_by('email', $_POST['email']); + + if ($user !== FALSE) + { + // User exists, so create a temp password. + $this->load->helpers(array('string', 'security')); + + $pass_code = random_string('alnum', 40); + + $hash = do_hash($pass_code . $user->salt . $_POST['email']); + + // Save the hash to the db so we can confirm it later. + $this->user_model->update_where('email', $_POST['email'], array('reset_hash' => $hash, 'reset_by' => strtotime("+24 hours") )); + + // Create the link to reset the password + $pass_link = site_url('reset_password/'. str_replace('@', ':', $_POST['email']) .'/'. $hash); + + // Now send the email + $this->load->library('emailer/emailer'); + + $data = array( + 'to' => $_POST['email'], + 'subject' => lang('us_reset_pass_subject'), + 'message' => $this->load->view('_emails/forgot_password', array('link' => $pass_link), TRUE) + ); + + if ($this->emailer->send($data)) + { + Template::set_message(lang('us_reset_pass_message'), 'success'); + } + else + { + Template::set_message(lang('us_reset_pass_error'). $this->emailer->errors, 'error'); + } + }//end if + }//end if + }//end if + + Template::set_view('users/users/forgot_password'); + Template::set('page_title', 'Password Reset'); + Template::render(); + } + else + { + + Template::redirect('/'); + }//end if + + }//end forgot_password() + + //-------------------------------------------------------------------- + + /** + * Allows a user to edit their own profile information. + * + * @access public + * + * @return void + */ + public function profile() + { + + if ($this->auth->is_logged_in() === FALSE) + { + $this->auth->logout(); + redirect('login'); + } + + $this->load->helper('date'); + + $this->load->config('address'); + $this->load->helper('address'); + + $this->load->config('user_meta'); + $meta_fields = config_item('user_meta_fields'); + + Template::set('meta_fields', $meta_fields); + + if ($this->input->post('submit')) + { + + $user_id = $this->current_user->id; + if ($this->save_user($user_id, $meta_fields)) + { + + $meta_data = array(); + foreach ($meta_fields as $field) + { + if ((!isset($field['admin_only']) || $field['admin_only'] === FALSE + || (isset($field['admin_only']) && $field['admin_only'] === TRUE + && isset($this->current_user) && $this->current_user->role_id == 1)) + && (!isset($field['frontend']) || $field['frontend'] === TRUE)) + { + $meta_data[$field['name']] = $this->input->post($field['name']); + } + } + + // now add the meta is there is meta data + $this->user_model->save_meta_for($user_id, $meta_data); + + // Log the Activity + + $user = $this->user_model->find($user_id); + $log_name = (isset($user->display_name) && !empty($user->display_name)) ? $user->display_name : ($this->settings_lib->item('auth.use_usernames') ? $user->username : $user->email); + $this->activity_model->log_activity($this->current_user->id, lang('us_log_edit_profile') .': '.$log_name, 'users'); + + Template::set_message(lang('us_profile_updated_success'), 'success'); + + // redirect to make sure any language changes are picked up + Template::redirect('/users/profile'); + exit; + } + else + { + Template::set_message(lang('us_profile_updated_error'), 'error'); + }//end if + }//end if + + // get the current user information + $user = $this->user_model->find_user_and_meta($this->current_user->id); + + $settings = $this->settings_lib->find_all(); + if ($settings['auth.password_show_labels'] == 1) { + Assets::add_module_js('users','password_strength.js'); + Assets::add_module_js('users','jquery.strength.js'); + Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); + } + // Generate password hint messages. + $this->user_model->password_hints(); + + Template::set('user', $user); + Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); + + Template::set_view('users/users/profile'); + Template::render(); + + }//end profile() + + //-------------------------------------------------------------------- + + /** + * Allows the user to create a new password for their account. At the moment, + * the only way to get here is to go through the forgot_password() process, + * which creates a unique code that is only valid for 24 hours. + * + * @access public + * + * @param string $email The email address to check against. + * @param string $code A randomly generated alphanumeric code. (Generated by forgot_password() ). + * + * @return void + */ + public function reset_password($email='', $code='') + { + // if the user is not logged in continue to show the login page + if ($this->auth->is_logged_in() === FALSE) + { + // If there is no code, then it's not a valid request. + if (empty($code) || empty($email)) + { + Template::set_message(lang('us_reset_invalid_email'), 'error'); + Template::redirect('/login'); + } + + // Handle the form + if ($this->input->post('submit')) + { + $this->form_validation->set_rules('password', 'lang:bf_password', 'required|trim|strip_tags|min_length[8]|max_length[120]|valid_password'); + $this->form_validation->set_rules('pass_confirm', 'lang:bf_password_confirm', 'required|trim|strip_tags|matches[password]'); + + if ($this->form_validation->run() !== FALSE) + { + // The user model will create the password hash for us. + $data = array('password' => $this->input->post('password'), + 'pass_confirm' => $this->input->post('pass_confirm'), + 'reset_by' => 0, + 'reset_hash' => ''); + + if ($this->user_model->update($this->input->post('user_id'), $data)) + { + // Log the Activity + + $this->activity_model->log_activity($this->input->post('user_id'), lang('us_log_reset') , 'users'); + Template::set_message(lang('us_reset_password_success'), 'success'); + Template::redirect('/login'); + } + else + { + Template::set_message(lang('us_reset_password_error'). $this->user_model->error, 'error'); + + } + } + }//end if + + // Check the code against the database + $email = str_replace(':', '@', $email); + $user = $this->user_model->find_by(array( + 'email' => $email, + 'reset_hash' => $code, + 'reset_by >=' => time() + )); + + // It will be an Object if a single result was returned. + if (!is_object($user)) + { + Template::set_message( lang('us_reset_invalid_email'), 'error'); + Template::redirect('/login'); + } + + $settings = $this->settings_lib->find_all(); + if ($settings['auth.password_show_labels'] == 1) { + Assets::add_module_js('users','password_strength.js'); + Assets::add_module_js('users','jquery.strength.js'); + Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); + } + // If we're here, then it is a valid request.... + Template::set('user', $user); + + Template::set_view('users/users/reset_password'); + Template::render(); + } + else + { + + Template::redirect('/'); + }//end if + + }//end reset_password() + + //-------------------------------------------------------------------- + + /** + * Display the registration form for the user and manage the registration process + * + * @access public + * + * @return void + */ + public function register() + { + // Are users even allowed to register? + if (!$this->settings_lib->item('auth.allow_register')) + { + Template::set_message(lang('us_register_disabled'), 'error'); + Template::redirect('/'); + } + + $this->load->model('roles/role_model'); + $this->load->helper('date'); + + $this->load->config('address'); + $this->load->helper('address'); + + $this->load->config('user_meta'); + $meta_fields = config_item('user_meta_fields'); + Template::set('meta_fields', $meta_fields); + + if ($this->input->post('submit')) + { + // Validate input + $this->form_validation->set_rules('email', 'lang:bf_email', 'required|trim|strip_tags|valid_email|max_length[120]|unique[users.email]|xss_clean'); + + if ($this->settings_lib->item('auth.use_usernames')) + { + $this->form_validation->set_rules('username', 'lang:bf_username', 'required|trim|strip_tags|max_length[30]|unique[users.username]|xss_clean'); + } + + $this->form_validation->set_rules('password', 'lang:bf_password', 'required|trim|strip_tags|min_length[8]|max_length[120]|valid_password'); + $this->form_validation->set_rules('pass_confirm', 'lang:bf_password_confirm', 'required|trim|strip_tags|matches[password]'); + + $this->form_validation->set_rules('language', 'lang:bf_language', 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('timezones', 'lang:bf_timezone', 'required|trim|strip_tags|max_length[4]|xss_clean'); + $this->form_validation->set_rules('display_name', 'lang:bf_display_name', 'trim|strip_tags|max_length[255]|xss_clean'); + + + $meta_data = array(); + foreach ($meta_fields as $field) + { + if ((!isset($field['admin_only']) || $field['admin_only'] === FALSE + || (isset($field['admin_only']) && $field['admin_only'] === TRUE + && isset($this->current_user) && $this->current_user->role_id == 1)) + && (!isset($field['frontend']) || $field['frontend'] === TRUE)) + { + $this->form_validation->set_rules($field['name'], $field['label'], $field['rules']); + + $meta_data[$field['name']] = $this->input->post($field['name']); + } + } + + if ($this->form_validation->run($this) !== FALSE) + { + // Time to save the user... + $data = array( + 'email' => $_POST['email'], + 'username' => isset($_POST['username']) ? $_POST['username'] : '', + 'password' => $_POST['password'], + 'language' => $this->input->post('language'), + 'timezone' => $this->input->post('timezones'), + ); + + // User activation method + $activation_method = $this->settings_lib->item('auth.user_activation_method'); + + // No activation method + if ($activation_method == 0) + { + // Activate the user automatically + $data['active'] = 1; + } + + if ($user_id = $this->user_model->insert($data)) + { + // now add the meta is there is meta data + $this->user_model->save_meta_for($user_id, $meta_data); + + /* + * USER ACTIVATIONS ENHANCEMENT + */ + + // Prepare user messaging vars + $subject = ''; + $email_mess = ''; + $message = lang('us_email_thank_you'); + $type = 'success'; + $site_title = $this->settings_lib->item('site.title'); + $error = false; + + switch ($activation_method) + { + case 0: + // No activation required. Activate the user and send confirmation email + $subject = str_replace('[SITE_TITLE]',$this->settings_lib->item('site.title'),lang('us_account_reg_complete')); + $email_mess = $this->load->view('_emails/activated', array('title'=>$site_title,'link' => site_url()), true); + $message .= lang('us_account_active_login'); + break; + case 1: + // Email Activiation. + // Create the link to activate membership + // Run the account deactivate to assure everything is set correctly + // Switch on the login type to test the correct field + $login_type = $this->settings_lib->item('auth.login_type'); + switch ($login_type) + { + case 'username': + if ($this->settings_lib->item('auth.use_usernames')) + { + $id_val = $_POST['username']; + } + else + { + $id_val = $_POST['email']; + $login_type = 'email'; + } + break; + case 'email': + case 'both': + default: + $id_val = $_POST['email']; + $login_type = 'email'; + break; + } // END switch + + $activation_code = $this->user_model->deactivate($id_val, $login_type); + $activate_link = site_url('activate/'. str_replace('@', ':', $_POST['email']) .'/'. $activation_code); + $subject = lang('us_email_subj_activate'); + + $email_message_data = array( + 'title' => $site_title, + 'code' => $activation_code, + 'link' => $activate_link + ); + $email_mess = $this->load->view('_emails/activate', $email_message_data, true); + $message .= lang('us_check_activate_email'); + break; + case 2: + // Admin Activation + // Clear hash but leave user inactive + $subject = lang('us_email_subj_pending'); + $email_mess = $this->load->view('_emails/pending', array('title'=>$site_title), true); + $message .= lang('us_admin_approval_pending'); + break; + }//end switch + + // Now send the email + $this->load->library('emailer/emailer'); + $data = array( + 'to' => $_POST['email'], + 'subject' => $subject, + 'message' => $email_mess + ); + + if (!$this->emailer->send($data)) + { + $message .= lang('us_err_no_email'). $this->emailer->errors; + $error = true; + } + + if ($error) + { + $type = 'error'; + } + else + { + $type = 'success'; + } + + Template::set_message($message, $type); + + // Log the Activity + + $this->activity_model->log_activity($user_id, lang('us_log_register') , 'users'); + Template::redirect('login'); + } + else + { + Template::set_message(lang('us_registration_fail'), 'error'); + redirect('/register'); + }//end if + }//end if + }//end if + + $settings = $this->settings_lib->find_all(); + if ($settings['auth.password_show_labels'] == 1) { + Assets::add_module_js('users','password_strength.js'); + Assets::add_module_js('users','jquery.strength.js'); + Assets::add_js($this->load->view('users_js', array('settings'=>$settings), true), 'inline'); + } + + // Generate password hint messages. + $this->user_model->password_hints(); + + Template::set('languages', unserialize($this->settings_lib->item('site.languages'))); + + Template::set_view('users/users/register'); + Template::set('page_title', 'Register'); + Template::render(); + + }//end register() + + //-------------------------------------------------------------------- + + /** + * Save the user + * + * @access private + * + * @param int $id The id of the user in the case of an edit operation + * @param array $meta_fields Array of meta fields fur the user + * + * @return bool + */ + private function save_user($id=0, $meta_fields=array()) + { + + if ( $id == 0 ) + { + $id = $this->current_user->id; /* ( $this->input->post('id') > 0 ) ? $this->input->post('id') : */ + } + + $_POST['id'] = $id; + + // Simple check to make the posted id is equal to the current user's id, minor security check + if ( $_POST['id'] != $this->current_user->id ) + { + $this->form_validation->set_message('email', 'lang:us_invalid_userid'); + return FALSE; + } + + // Setting the payload for Events system. + $payload = array ( 'user_id' => $id, 'data' => $this->input->post() ); + + + $this->form_validation->set_rules('email', 'lang:bf_email', 'required|trim|valid_email|max_length[120]|unique[users.email,users.id]|xss_clean'); + $this->form_validation->set_rules('password', 'lang:bf_password', 'trim|strip_tags|min_length[8]|max_length[120]|valid_password'); + + // check if a value has been entered for the password - if so then the pass_confirm is required + // if you don't set it as "required" the pass_confirm field could be left blank and the form validation would still pass + $extra_rules = !empty($_POST['password']) ? 'required|' : ''; + $this->form_validation->set_rules('pass_confirm', 'lang:bf_password_confirm', 'trim|strip_tags|'.$extra_rules.'matches[password]'); + + if ($this->settings_lib->item('auth.use_usernames')) + { + $this->form_validation->set_rules('username', 'lang:bf_username', 'required|trim|strip_tags|max_length[30]|unique[users.username,users.id]|xss_clean'); + } + + $this->form_validation->set_rules('language', 'lang:bf_language', 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('timezones', 'lang:bf_timezone', 'required|trim|strip_tags|max_length[4]|xss_clean'); + $this->form_validation->set_rules('display_name', 'lang:bf_display_name', 'trim|strip_tags|max_length[255]|xss_clean'); + + // Added Event "before_user_validation" to run before the form validation + Events::trigger('before_user_validation', $payload ); + + + foreach ($meta_fields as $field) + { + if ((!isset($field['admin_only']) || $field['admin_only'] === FALSE + || (isset($field['admin_only']) && $field['admin_only'] === TRUE + && isset($this->current_user) && $this->current_user->role_id == 1)) + && (!isset($field['frontend']) || $field['frontend'] === TRUE)) + { + $this->form_validation->set_rules($field['name'], $field['label'], $field['rules']); + } + } + + + if ($this->form_validation->run($this) === FALSE) + { + return FALSE; + } + + // Compile our core user elements to save. + $data = array( + 'email' => $this->input->post('email'), + 'language' => $this->input->post('language'), + 'timezone' => $this->input->post('timezones'), + ); + + if ($this->input->post('password')) + { + $data['password'] = $this->input->post('password'); + } + + if ($this->input->post('pass_confirm')) + { + $data['pass_confirm'] = $this->input->post('pass_confirm'); + } + + if ($this->input->post('display_name')) + { + $data['display_name'] = $this->input->post('display_name'); + } + + if ($this->settings_lib->item('auth.use_usernames')) + { + if ($this->input->post('username')) + { + $data['username'] = $this->input->post('username'); + } + } + + // Any modules needing to save data? + // Event to run after saving a user + Events::trigger('save_user', $payload ); + + return $this->user_model->update($id, $data); + + }//end save_user() + + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // ACTIVATION METHODS + //-------------------------------------------------------------------- + /* + Activate user. + + Checks a passed activation code and if verified, enables the user + account. If the code fails, an error is generated and returned. + + */ + public function activate($email = FALSE, $code = FALSE) + { + + if ($this->input->post('submit')) { + $this->form_validation->set_rules('code', 'Verification Code', 'required|trim|xss_clean'); + if ($this->form_validation->run() == TRUE) { + $code = $this->input->post('code'); + } + } else { + if ($email === FALSE) + { + $email = $this->uri->segment(2); + } + if ($code === FALSE) + { + $code = $this->uri->segment(3); + } + } + + // fix up the email + if (!empty($email)) + { + $email = str_replace(":", "@", $email); + } + + + if (!empty($code)) + { + $activated = $this->user_model->activate($email, $code); + if ($activated) + { + // Now send the email + $this->load->library('emailer/emailer'); + + $site_title = $this->settings_lib->item('site.title'); + + $email_message_data = array( + 'title' => $site_title, + 'link' => site_url('login') + ); + $data = array + ( + 'to' => $this->user_model->find($activated)->email, + 'subject' => lang('us_account_active'), + 'message' => $this->load->view('_emails/activated', $email_message_data, TRUE) + ); + + if ($this->emailer->send($data)) + { + Template::set_message(lang('us_account_active'), 'success'); + } + else + { + Template::set_message(lang('us_err_no_email'). $this->emailer->errors, 'error'); + } + Template::redirect('/'); + } + else + { + Template::set_message(lang('us_activate_error_msg').$this->user_model->error.'. '. lang('us_err_activate_code'), 'error'); + } + } + Template::set_view('users/users/activate'); + Template::set('page_title', 'Account Activation'); + Template::render(); + } + + //-------------------------------------------------------------------- + + /* + Method: resend_activation + + Allows a user to request that their activation code be resent to their + account's email address. If a matching email is found, the code is resent. + */ + public function resend_activation() + { + if (isset($_POST['submit'])) + { + $this->form_validation->set_rules('email', 'Email', 'required|trim|strip_tags|valid_email|xss_clean'); + + if ($this->form_validation->run() === FALSE) + { + Template::set_message('Cannot find that email in our records.', 'error'); + } + else + { + // We validated. Does the user actually exist? + $user = $this->user_model->find_by('email', $_POST['email']); + + if ($user !== FALSE) + { + // User exists, so create a temp password. + $this->load->helpers(array('string', 'security')); + + $pass_code = random_string('alnum', 40); + + $activation_code = do_hash($pass_code . $user->salt . $_POST['email']); + + $site_title = $this->settings_lib->item('site.title'); + + // Save the hash to the db so we can confirm it later. + $this->user_model->update_where('email', $_POST['email'], array('activate_hash' => $activation_code )); + + // Create the link to reset the password + $activate_link = site_url('activate/'. str_replace('@', ':', $_POST['email']) .'/'. $activation_code); + + // Now send the email + $this->load->library('emailer/emailer'); + + $email_message_data = array( + 'title' => $site_title, + 'code' => $activation_code, + 'link' => $activate_link + ); + + $data = array + ( + 'to' => $_POST['email'], + 'subject' => 'Activation Code', + 'message' => $this->load->view('_emails/activate', $email_message_data, TRUE) + ); + $this->emailer->enable_debug(true); + if ($this->emailer->send($data)) + { + Template::set_message(lang('us_check_activate_email'), 'success'); + } + else + { + if (isset($this->emailer->errors)) + { + $errors = ''; + if (is_array($this->emailer->errors)) + { + foreach ($this->emailer->errors as $error) + { + $errors .= $error."
"; + } + } + else + { + $errors = $this->emailer->errors; + } + Template::set_message(lang('us_err_no_email').$errors.", ".$this->emailer->debug, 'error'); + } + } + } + } + } + Template::set_view('users/users/resend_activation'); + Template::set('page_title', 'Activate Account'); + Template::render(); + } + +}//end Users + +/* Front-end Users Controller */ +/* End of file users.php */ +/* Location: ./application/core_modules/users/controllers/users.php */ diff --git a/bonfire/application/core_modules/users/models/user_model.php b/bonfire/application/core_modules/users/models/user_model.php index 8df0f6250..14fe92104 100644 --- a/bonfire/application/core_modules/users/models/user_model.php +++ b/bonfire/application/core_modules/users/models/user_model.php @@ -1,893 +1,893 @@ -settings_lib->item('auth.password_min_length'); - - $message = sprintf( lang('bf_password_min_length_help'), $min_length ); - - - if ( $this->settings_lib->item('auth.password_force_numbers') == 1 ) - { - $message .= '
' . lang('bf_password_number_required_help'); - } - - if ( $this->settings_lib->item('auth.password_force_symbols') == 1 ) - { - $message .= '
' . lang('bf_password_symbols_required_help'); - } - - if ( $this->settings_lib->item('auth.password_force_mixed_case') == 1 ) - { - $message .= '
' . lang('bf_password_caps_required_help'); - } - - Template::set('password_hints', $message); - - unset ($min_length, $message); - - }//end password_hints() - - //-------------------------------------------------------------------- - - /** - * Creates a new user in the database. - * - * Required parameters sent in the $data array: - * * password - * * A unique email address - * - * If no _role_id_ is passed in the $data array, it will assign the default role from model. - * - * @access public - * - * @param array $data An array of user information. - * - * @return bool|int The ID of the new user. - */ - public function insert($data=array()) - { - if (!$this->_function_check(FALSE, $data)) - { - return FALSE; - } - - if (!isset($data['password']) || empty($data['password'])) - { - $this->error = lang('us_no_password'); - return FALSE; - } - - if (!isset($data['email']) || empty($data['email'])) - { - $this->error = lang('us_no_email'); - return FALSE; - } - - // Is this a unique email? - if ($this->is_unique('email', $data['email']) == FALSE) - { - $this->error = lang('us_email_taken'); - return FALSE; - } - - if (empty($data['username'])) - { - unset($data['username']); - } - - // Display Name - if (!isset($data['display_name']) || (isset($data['display_name']) && empty($data['display_name']))) - { - if ($this->settings_lib->item('auth.use_usernames') == 1 && !empty($data['username'])) - { - $data['display_name'] = $data['username']; - } - else - { - $data['display_name'] = $data['email']; - } - } - - list($password, $salt) = $this->hash_password($data['password']); - - unset($data['password'], $data['pass_confirm'], $data['submit']); - - $data['password_hash'] = $password; - $data['salt'] = $salt; - - // What's the default role? - if (!isset($data['role_id'])) - { - // We better have a guardian here - if (!class_exists('Role_model')) - { - $this->load->model('roles/Role_model','role_model'); - } - - $data['role_id'] = $this->role_model->default_role_id(); - } - - $id = parent::insert($data); - - Events::trigger('after_create_user', $id); - - return $id; - - }//end insert() - - //-------------------------------------------------------------------- - - /** - * Updates an existing user. Before saving, it will: - * * generate a new password/salt combo if both password and pass_confirm are passed in. - * * store the country code - * - * @access public - * - * @param int $id An INT with the user's ID. - * @param array $data An array of key/value pairs to update for the user. - * - * @return bool TRUE/FALSE - */ - public function update($id=null, $data=array()) - { - if ($id) - { - $trigger_data = array('user_id'=>$id, 'data'=>$data); - Events::trigger('before_user_update', $trigger_data); - } - - if (empty($data['pass_confirm']) && isset($data['password'])) - { - unset($data['pass_confirm'], $data['password']); - } - else if (!empty($data['password']) && !empty($data['pass_confirm']) && $data['password'] == $data['pass_confirm']) - { - list($password, $salt) = $this->hash_password($data['password']); - - unset($data['password'], $data['pass_confirm']); - - $data['password_hash'] = $password; - $data['salt'] = $salt; - } - - // Handle the country - if (isset($data['iso'])) - { - $data['country_iso'] = $data['iso']; - unset($data['iso']); - } - - $return = parent::update($id, $data); - - if ($return) - { - $trigger_data = array('user_id'=>$id, 'data'=>$data); - Events::trigger('after_user_update', $trigger_data); - } - - return $return; - - }//end update() - - - /** - * Returns the number of users that belong to each role. - * - * @access public - * - * @return bool|array An array of objects representing the number in each role. - */ - public function set_to_default_role($current_role) - { - $prefix = $this->db->dbprefix; - - if (!is_int($current_role)) { - return FALSE; - } - - // We better have a guardian here - if (!class_exists('Role_model')) - { - $this->load->model('roles/Role_model','role_model'); - } - - $data = array(); - $data['role_id'] = $this->role_model->default_role_id(); - - $query = $this->db->where('role_id', $current_role) - ->update($this->table, $data); - - if ($query) - { - return TRUE; - } - - return FALSE; - - }//end set_to_default_role() - - - //-------------------------------------------------------------------- - - /** - * Finds an individual user record. Also returns role information for the user. - * - * @access public - * - * @param int $id An INT with the user's ID. - * - * @return bool|object An object with the user's information. - */ - public function find($id=null) - { - if (empty($this->selects)) - { - $this->select($this->table .'.*, role_name'); - } - - $this->db->join('roles', 'roles.role_id = users.role_id', 'left'); - - return parent::find($id); - - }//end find() - - //-------------------------------------------------------------------- - - /** - * Returns all user records, and their associated role information. - * - * @access public - * - * @param bool $show_deleted If FALSE, will only return non-deleted users. If TRUE, will return both deleted and non-deleted users. - * - * @return bool An array of objects with each user's information. - */ - public function find_all($show_deleted=FALSE) - { - if (empty($this->selects)) - { - $this->select($this->table .'.*, role_name'); - } - - if ($show_deleted === FALSE) - { - $this->db->where('users.deleted', 0); - } - - $this->db->join('roles', 'roles.role_id = users.role_id', 'left'); - - return parent::find_all(); - - }//end find_all() - - //-------------------------------------------------------------------- - - /** - * Locates a single user based on a field/value match, with their role information. - * If the $field string is 'both', then it will attempt to find the user - * where their $value field matches either the username or email on record. - * - * @access public - * - * @param string $field A string with the field to match. - * @param string $value A string with the value to search for. - * - * @return bool|object An object with the user's info, or FALSE on failure. - */ - public function find_by($field=null, $value=null) - { - $this->db->join('roles', 'roles.role_id = users.role_id', 'left'); - - if (empty($this->selects)) - { - $this->select($this->table .'.*, role_name'); - } - - if ($field == 'both') - { - $field = array( - 'username' => $value, - 'email' => $value - ); - - return parent::find_by($field, null, 'or'); - } - - return parent::find_by($field, $value); - - }//end find_by() - - //-------------------------------------------------------------------- - - /** - * Returns the number of users that belong to each role. - * - * @access public - * - * @return bool|array An array of objects representing the number in each role. - */ - public function count_by_roles() - { - $prefix = $this->db->dbprefix; - - $sql = "SELECT role_name, COUNT(1) as count - FROM {$prefix}users, {$prefix}roles - WHERE {$prefix}users.role_id = {$prefix}roles.role_id - GROUP BY {$prefix}users.role_id"; - - $query = $this->db->query($sql); - - if ($query->num_rows()) - { - return $query->result(); - } - - return FALSE; - - }//end count_by_roles() - - //-------------------------------------------------------------------- - - /** - * Counts all users in the system. - * - * @access public - * - * @param bool $get_deleted If FALSE, will only return active users. If TRUE, will return both deleted and active users. - * - * @return int An INT with the number of users found. - */ - public function count_all($get_deleted = FALSE) - { - if ($get_deleted) - { - // Get only the deleted users - $this->db->where('users.deleted !=', 0); - } - else - { - $this->db->where('users.deleted', 0); - } - - return $this->db->count_all_results('users'); - - }//end count_all() - - //-------------------------------------------------------------------- - - /** - * Performs a standard delete, but also allows for purging of a record. - * - * @access public - * - * @param int $id An INT with the record ID to delete. - * @param bool $purge If FALSE, will perform a soft-delete. If TRUE, will permanently delete the record. - * - * @return bool TRUE/FALSE - */ - public function delete($id=0, $purge=FALSE) - { - if ($purge === TRUE) - { - // temporarily set the soft_deletes to TRUE. - $this->soft_deletes = FALSE; - } - - return parent::delete($id); - - }//end delete() - - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - // !AUTH HELPER METHODS - //-------------------------------------------------------------------- - - /** - * Generates a new salt and password hash for the given password. - * - * @access public - * - * @param string $old The password to hash. - * - * @return array An array with the hashed password and new salt. - */ - public function hash_password($old='') - { - if (!function_exists('do_hash')) - { - $this->load->helper('security'); - } - - $salt = $this->generate_salt(); - $pass = do_hash($salt . $old); - - return array($pass, $salt); - - }//end hash_password() - - //-------------------------------------------------------------------- - - /** - * Create a salt to be used for the passwords - * - * @access private - * - * @return string A random string of 7 characters - */ - private function generate_salt() - { - if (!function_exists('random_string')) - { - $this->load->helper('string'); - } - - return random_string('alnum', 7); - - }//end generate_salt() - - //-------------------------------------------------------------------- - - - //-------------------------------------------------------------------- - // !HMVC METHOD HELPERS - //-------------------------------------------------------------------- - - /** - * Returns the most recent login attempts and their description. - * - * @access public - * - * @param int $limit An INT which is the number of results to return. - * - * @return bool|array An array of objects with the login information. - */ - public function get_login_attempts($limit=15) - { - $this->db->limit($limit); - $this->db->order_by('login', 'desc'); - $query = $this->db->get('login_attempts'); - - if ($query->num_rows()) - { - return $query->result(); - } - - return FALSE; - - }//end get_login_attempts() - - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - // !META METHODS - //-------------------------------------------------------------------- - - /** - * Saves one or more key/value pairs of additional meta information for a user. - * - * @access public - * @example - * $data = array( - * 'location' => 'That City, Katmandu', - * 'interests' => 'My interests' - * ); - * $this->user_model->save_meta_for($user_id, $data); - * - * @param int $user_id The ID of the user to save the meta for. - * @param array $data An array of key/value pairs to save. - * - * @return void - */ - public function save_meta_for($user_id=null, $data=array()) - { - if (!is_numeric($user_id)) - { - $this->error = lang('us_invalid_user_id'); - } - - $this->table = 'user_meta'; - $this->key = 'meta_id'; - - foreach ($data as $key => $value) - { - $this->db->where('user_id', $user_id); - $this->db->where('meta_key', $key); - $query = $this->db->get('user_meta'); - - $obj = array( - 'user_id' => $user_id, - 'meta_key' => $key, - 'meta_value' => $value - ); - - if ($query->num_rows() == 0 && !empty($value)) - { - // Insert - $this->db->insert('user_meta', $obj); - } - // Update - else if ($query->num_rows() > 0) - { - $row = $query->row(); - $meta_id = $row->meta_id; - - $this->db->where('user_id', $user_id); - $this->db->where('meta_key', $key); - $this->db->set('meta_value', $value); - $this->db->update('user_meta', $obj); - }//end if - }//end foreach - - - // Reset our table info - $this->table = 'users'; - $this->key = 'id'; - }//end save_meta_for() - - //-------------------------------------------------------------------- - - /** - * Retrieves all meta values defined for a user. - * - * @access public - * - * @param int $user_id An INT with the user's ID to find the meta for. - * @param array $fields An array of meta_key names to retrieve. - * - * @return null A stdObject with the key/value pairs, or NULL. - */ - public function find_meta_for($user_id=null, $fields=null) - { - if (!is_numeric($user_id)) - { - $this->error = lang('us_invalid_user_id'); - } - - $this->table = 'user_meta'; - $this->key = 'meta_id'; - - // Limiting to certain fields? - if (is_array($fields)) - { - $this->db->where_in('meta_key', $fields); - } - - $this->db->where('user_id', $user_id); - $query = $this->db->get('user_meta'); - - if ($query->num_rows()) - { - $rows = $query->result(); - - $result = null; - foreach ($rows as $row) - { - $key = $row->meta_key; - $result->$key = $row->meta_value; - } - } - else - { - $result = null; - } - - // Reset our table info - $this->table = 'users'; - $this->key = 'id'; - - return $result; - - }//end find_meta_for() - - //-------------------------------------------------------------------- - - /** - * Locates a single user and joins there meta information based on a the user id match. - * - * @access public - * - * @param int $user_id Integer of User ID to fetch - * - * @return bool|object An object with the user's info and meta information, or FALSE on failure. - */ - public function find_user_and_meta($user_id=null) - { - if (!is_numeric($user_id)) - { - $this->error = lang('us_invalid_user_id'); - } - - $result = $this->find( $user_id ); - - $this->db->where('user_id', $user_id); - $query = $this->db->get('user_meta'); - - if ($query->num_rows()) - { - $rows = $query->result(); - - foreach ($rows as $row) - { - $key = $row->meta_key; - $result->$key = $row->meta_value; - } - } - - $query->free_result(); - return $result; - - }//end find_user_and_meta() - - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - // !ACTIVATION - //-------------------------------------------------------------------- - - /** - * Count Inactive users. - * - * @access public - * - * @return int Inactive user count. - */ - public function count_inactive_users() - { - $this->db->where('active',-1); - return $this->count_all(FALSE); - - }//end count_inactive_users() - - - /** - * Accepts an activation code and validates is against a matching entry int eh database. - * - * There are some instances where we want to remove the activation hash yet leave the user - * inactive (Admin Activation scenario), so leave_inactive handles this use case. - * - * @access public - * - * @param string $email The email address to be verified - * @param string $code The activation code to be verified - * @param bool $leave_inactive Flag whether to remove the activate hash value, but leave active = 0 - * - * @return int User Id on success, FALSE on error - */ - public function activate($email = FALSE, $code = FALSE, $leave_inactive = FALSE) - { - - if ($code === FALSE) - { - $this->error = lang('us_err_no_activate_code'); - return FALSE; - } - - if (!empty($email)) - { - $this->db->where('email', $email); - } - - $query = $this->db->select('id') - ->where('activate_hash', $code) - ->limit(1) - ->get($this->table); - - if ($query->num_rows() !== 1) - { - $this->error = lang('us_err_no_matching_code'); - return FALSE; - } - - $result = $query->row(); - $active = ($leave_inactive === FALSE) ? 1 : 0; - if ($this->update($result->id, array('activate_hash' => '','active' => $active))) - { - return $result->id; - } - - }//end activate() - - - /** - * This function is triggered during account set up to assure user is not active and, - * if not supressed, generate an activation hash code. This function can be used to - * deactivate accounts based on public view events. - * - * @param int $user_id The username or email to match to deactivate - * @param string $login_type Login Method - * @param bool $make_hash Create a hash - * - * @return mixed $activate_hash on success, FALSE on error - */ - public function deactivate($user_id = FALSE, $login_type = 'email', $make_hash = TRUE) - { - if ($user_id === FALSE) - { - return FALSE; - } - - // create a temp activation code. - $activate_hash = ''; - if ($make_hash === true) - { - $this->load->helpers(array('string', 'security')); - $activate_hash = do_hash(random_string('alnum', 40) . time()); - } - - $this->db->update($this->table, array('active'=>0,'activate_hash' => $activate_hash), array($login_type => $user_id)); - - return ($this->db->affected_rows() == 1) ? $activate_hash : FALSE; - - }//end deactivate() - - - /** - * Admin specific activation function for admin approvals or re-activation. - * - * @access public - * - * @param int $user_id The user ID to activate - * - * @return bool TRUE on success, FALSE on error - */ - public function admin_activation($user_id = FALSE) - { - - if ($user_id === FALSE) - { - $this->error = lang('us_err_no_id'); - return FALSE; - } - - $query = $this->db->select('id') - ->where('id', $user_id) - ->limit(1) - ->get($this->table); - - if ($query->num_rows() !== 1) - { - $this->error = lang('us_err_no_matching_id'); - return FALSE; - } - - $result = $query->row(); - $this->update($result->id, array('activate_hash' => '','active' => 1)); - - if ($this->db->affected_rows() > 0) - { - return $result->id; - } - else - { - $this->error = lang('us_err_user_is_active'); - return FALSE; - } - - }//end admin_activation() - - - /** - * Admin only deactivation function. - * - * @access public - * - * @param int $user_id The user ID to deactivate - * - * @return bool TRUE on success, FALSE on error - */ - public function admin_deactivation($user_id = FALSE) - { - if ($user_id === FALSE) - { - $this->error = lang('us_err_no_id'); - return FALSE; - } - - if ($this->deactivate($user_id, 'id', FALSE)) - { - return $user_id; - } - else - { - $this->error = lang('us_err_user_is_inactive'); - return FALSE; - } - - }//end admin_deactivation() - - //-------------------------------------------------------------------- - -}//end User_model +settings_lib->item('auth.password_min_length'); + + $message = sprintf( lang('bf_password_min_length_help'), $min_length ); + + + if ( $this->settings_lib->item('auth.password_force_numbers') == 1 ) + { + $message .= '
' . lang('bf_password_number_required_help'); + } + + if ( $this->settings_lib->item('auth.password_force_symbols') == 1 ) + { + $message .= '
' . lang('bf_password_symbols_required_help'); + } + + if ( $this->settings_lib->item('auth.password_force_mixed_case') == 1 ) + { + $message .= '
' . lang('bf_password_caps_required_help'); + } + + Template::set('password_hints', $message); + + unset ($min_length, $message); + + }//end password_hints() + + //-------------------------------------------------------------------- + + /** + * Creates a new user in the database. + * + * Required parameters sent in the $data array: + * * password + * * A unique email address + * + * If no _role_id_ is passed in the $data array, it will assign the default role from model. + * + * @access public + * + * @param array $data An array of user information. + * + * @return bool|int The ID of the new user. + */ + public function insert($data=array()) + { + if (!$this->_function_check(FALSE, $data)) + { + return FALSE; + } + + if (!isset($data['password']) || empty($data['password'])) + { + $this->error = lang('us_no_password'); + return FALSE; + } + + if (!isset($data['email']) || empty($data['email'])) + { + $this->error = lang('us_no_email'); + return FALSE; + } + + // Is this a unique email? + if ($this->is_unique('email', $data['email']) == FALSE) + { + $this->error = lang('us_email_taken'); + return FALSE; + } + + if (empty($data['username'])) + { + unset($data['username']); + } + + // Display Name + if (!isset($data['display_name']) || (isset($data['display_name']) && empty($data['display_name']))) + { + if ($this->settings_lib->item('auth.use_usernames') == 1 && !empty($data['username'])) + { + $data['display_name'] = $data['username']; + } + else + { + $data['display_name'] = $data['email']; + } + } + + list($password, $salt) = $this->hash_password($data['password']); + + unset($data['password'], $data['pass_confirm'], $data['submit']); + + $data['password_hash'] = $password; + $data['salt'] = $salt; + + // What's the default role? + if (!isset($data['role_id'])) + { + // We better have a guardian here + if (!class_exists('Role_model')) + { + $this->load->model('roles/Role_model','role_model'); + } + + $data['role_id'] = $this->role_model->default_role_id(); + } + + $id = parent::insert($data); + + Events::trigger('after_create_user', $id); + + return $id; + + }//end insert() + + //-------------------------------------------------------------------- + + /** + * Updates an existing user. Before saving, it will: + * * generate a new password/salt combo if both password and pass_confirm are passed in. + * * store the country code + * + * @access public + * + * @param int $id An INT with the user's ID. + * @param array $data An array of key/value pairs to update for the user. + * + * @return bool TRUE/FALSE + */ + public function update($id=null, $data=array()) + { + if ($id) + { + $trigger_data = array('user_id'=>$id, 'data'=>$data); + Events::trigger('before_user_update', $trigger_data); + } + + if (empty($data['pass_confirm']) && isset($data['password'])) + { + unset($data['pass_confirm'], $data['password']); + } + else if (!empty($data['password']) && !empty($data['pass_confirm']) && $data['password'] == $data['pass_confirm']) + { + list($password, $salt) = $this->hash_password($data['password']); + + unset($data['password'], $data['pass_confirm']); + + $data['password_hash'] = $password; + $data['salt'] = $salt; + } + + // Handle the country + if (isset($data['iso'])) + { + $data['country_iso'] = $data['iso']; + unset($data['iso']); + } + + $return = parent::update($id, $data); + + if ($return) + { + $trigger_data = array('user_id'=>$id, 'data'=>$data); + Events::trigger('after_user_update', $trigger_data); + } + + return $return; + + }//end update() + + + /** + * Returns the number of users that belong to each role. + * + * @access public + * + * @return bool|array An array of objects representing the number in each role. + */ + public function set_to_default_role($current_role) + { + $prefix = $this->db->dbprefix; + + if (!is_int($current_role)) { + return FALSE; + } + + // We better have a guardian here + if (!class_exists('Role_model')) + { + $this->load->model('roles/Role_model','role_model'); + } + + $data = array(); + $data['role_id'] = $this->role_model->default_role_id(); + + $query = $this->db->where('role_id', $current_role) + ->update($this->table, $data); + + if ($query) + { + return TRUE; + } + + return FALSE; + + }//end set_to_default_role() + + + //-------------------------------------------------------------------- + + /** + * Finds an individual user record. Also returns role information for the user. + * + * @access public + * + * @param int $id An INT with the user's ID. + * + * @return bool|object An object with the user's information. + */ + public function find($id=null) + { + if (empty($this->selects)) + { + $this->select($this->table .'.*, role_name'); + } + + $this->db->join('roles', 'roles.role_id = users.role_id', 'left'); + + return parent::find($id); + + }//end find() + + //-------------------------------------------------------------------- + + /** + * Returns all user records, and their associated role information. + * + * @access public + * + * @param bool $show_deleted If FALSE, will only return non-deleted users. If TRUE, will return both deleted and non-deleted users. + * + * @return bool An array of objects with each user's information. + */ + public function find_all($show_deleted=FALSE) + { + if (empty($this->selects)) + { + $this->select($this->table .'.*, role_name'); + } + + if ($show_deleted === FALSE) + { + $this->db->where('users.deleted', 0); + } + + $this->db->join('roles', 'roles.role_id = users.role_id', 'left'); + + return parent::find_all(); + + }//end find_all() + + //-------------------------------------------------------------------- + + /** + * Locates a single user based on a field/value match, with their role information. + * If the $field string is 'both', then it will attempt to find the user + * where their $value field matches either the username or email on record. + * + * @access public + * + * @param string $field A string with the field to match. + * @param string $value A string with the value to search for. + * + * @return bool|object An object with the user's info, or FALSE on failure. + */ + public function find_by($field=null, $value=null) + { + $this->db->join('roles', 'roles.role_id = users.role_id', 'left'); + + if (empty($this->selects)) + { + $this->select($this->table .'.*, role_name'); + } + + if ($field == 'both') + { + $field = array( + 'username' => $value, + 'email' => $value + ); + + return parent::find_by($field, null, 'or'); + } + + return parent::find_by($field, $value); + + }//end find_by() + + //-------------------------------------------------------------------- + + /** + * Returns the number of users that belong to each role. + * + * @access public + * + * @return bool|array An array of objects representing the number in each role. + */ + public function count_by_roles() + { + $prefix = $this->db->dbprefix; + + $sql = "SELECT role_name, COUNT(1) as count + FROM {$prefix}users, {$prefix}roles + WHERE {$prefix}users.role_id = {$prefix}roles.role_id + GROUP BY {$prefix}users.role_id"; + + $query = $this->db->query($sql); + + if ($query->num_rows()) + { + return $query->result(); + } + + return FALSE; + + }//end count_by_roles() + + //-------------------------------------------------------------------- + + /** + * Counts all users in the system. + * + * @access public + * + * @param bool $get_deleted If FALSE, will only return active users. If TRUE, will return both deleted and active users. + * + * @return int An INT with the number of users found. + */ + public function count_all($get_deleted = FALSE) + { + if ($get_deleted) + { + // Get only the deleted users + $this->db->where('users.deleted !=', 0); + } + else + { + $this->db->where('users.deleted', 0); + } + + return $this->db->count_all_results('users'); + + }//end count_all() + + //-------------------------------------------------------------------- + + /** + * Performs a standard delete, but also allows for purging of a record. + * + * @access public + * + * @param int $id An INT with the record ID to delete. + * @param bool $purge If FALSE, will perform a soft-delete. If TRUE, will permanently delete the record. + * + * @return bool TRUE/FALSE + */ + public function delete($id=0, $purge=FALSE) + { + if ($purge === TRUE) + { + // temporarily set the soft_deletes to TRUE. + $this->soft_deletes = FALSE; + } + + return parent::delete($id); + + }//end delete() + + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + // !AUTH HELPER METHODS + //-------------------------------------------------------------------- + + /** + * Generates a new salt and password hash for the given password. + * + * @access public + * + * @param string $old The password to hash. + * + * @return array An array with the hashed password and new salt. + */ + public function hash_password($old='') + { + if (!function_exists('do_hash')) + { + $this->load->helper('security'); + } + + $salt = $this->generate_salt(); + $pass = do_hash($salt . $old); + + return array($pass, $salt); + + }//end hash_password() + + //-------------------------------------------------------------------- + + /** + * Create a salt to be used for the passwords + * + * @access private + * + * @return string A random string of 7 characters + */ + private function generate_salt() + { + if (!function_exists('random_string')) + { + $this->load->helper('string'); + } + + return random_string('alnum', 7); + + }//end generate_salt() + + //-------------------------------------------------------------------- + + + //-------------------------------------------------------------------- + // !HMVC METHOD HELPERS + //-------------------------------------------------------------------- + + /** + * Returns the most recent login attempts and their description. + * + * @access public + * + * @param int $limit An INT which is the number of results to return. + * + * @return bool|array An array of objects with the login information. + */ + public function get_login_attempts($limit=15) + { + $this->db->limit($limit); + $this->db->order_by('login', 'desc'); + $query = $this->db->get('login_attempts'); + + if ($query->num_rows()) + { + return $query->result(); + } + + return FALSE; + + }//end get_login_attempts() + + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // !META METHODS + //-------------------------------------------------------------------- + + /** + * Saves one or more key/value pairs of additional meta information for a user. + * + * @access public + * @example + * $data = array( + * 'location' => 'That City, Katmandu', + * 'interests' => 'My interests' + * ); + * $this->user_model->save_meta_for($user_id, $data); + * + * @param int $user_id The ID of the user to save the meta for. + * @param array $data An array of key/value pairs to save. + * + * @return void + */ + public function save_meta_for($user_id=null, $data=array()) + { + if (!is_numeric($user_id)) + { + $this->error = lang('us_invalid_user_id'); + } + + $this->table = 'user_meta'; + $this->key = 'meta_id'; + + foreach ($data as $key => $value) + { + $this->db->where('user_id', $user_id); + $this->db->where('meta_key', $key); + $query = $this->db->get('user_meta'); + + $obj = array( + 'user_id' => $user_id, + 'meta_key' => $key, + 'meta_value' => $value + ); + + if ($query->num_rows() == 0 && !empty($value)) + { + // Insert + $this->db->insert('user_meta', $obj); + } + // Update + else if ($query->num_rows() > 0) + { + $row = $query->row(); + $meta_id = $row->meta_id; + + $this->db->where('user_id', $user_id); + $this->db->where('meta_key', $key); + $this->db->set('meta_value', $value); + $this->db->update('user_meta', $obj); + }//end if + }//end foreach + + + // Reset our table info + $this->table = 'users'; + $this->key = 'id'; + }//end save_meta_for() + + //-------------------------------------------------------------------- + + /** + * Retrieves all meta values defined for a user. + * + * @access public + * + * @param int $user_id An INT with the user's ID to find the meta for. + * @param array $fields An array of meta_key names to retrieve. + * + * @return null A stdObject with the key/value pairs, or NULL. + */ + public function find_meta_for($user_id=null, $fields=null) + { + if (!is_numeric($user_id)) + { + $this->error = lang('us_invalid_user_id'); + } + + $this->table = 'user_meta'; + $this->key = 'meta_id'; + + // Limiting to certain fields? + if (is_array($fields)) + { + $this->db->where_in('meta_key', $fields); + } + + $this->db->where('user_id', $user_id); + $query = $this->db->get('user_meta'); + + if ($query->num_rows()) + { + $rows = $query->result(); + + $result = null; + foreach ($rows as $row) + { + $key = $row->meta_key; + $result->$key = $row->meta_value; + } + } + else + { + $result = null; + } + + // Reset our table info + $this->table = 'users'; + $this->key = 'id'; + + return $result; + + }//end find_meta_for() + + //-------------------------------------------------------------------- + + /** + * Locates a single user and joins there meta information based on a the user id match. + * + * @access public + * + * @param int $user_id Integer of User ID to fetch + * + * @return bool|object An object with the user's info and meta information, or FALSE on failure. + */ + public function find_user_and_meta($user_id=null) + { + if (!is_numeric($user_id)) + { + $this->error = lang('us_invalid_user_id'); + } + + $result = $this->find( $user_id ); + + $this->db->where('user_id', $user_id); + $query = $this->db->get('user_meta'); + + if ($query->num_rows()) + { + $rows = $query->result(); + + foreach ($rows as $row) + { + $key = $row->meta_key; + $result->$key = $row->meta_value; + } + } + + $query->free_result(); + return $result; + + }//end find_user_and_meta() + + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // !ACTIVATION + //-------------------------------------------------------------------- + + /** + * Count Inactive users. + * + * @access public + * + * @return int Inactive user count. + */ + public function count_inactive_users() + { + $this->db->where('active',-1); + return $this->count_all(FALSE); + + }//end count_inactive_users() + + + /** + * Accepts an activation code and validates is against a matching entry int eh database. + * + * There are some instances where we want to remove the activation hash yet leave the user + * inactive (Admin Activation scenario), so leave_inactive handles this use case. + * + * @access public + * + * @param string $email The email address to be verified + * @param string $code The activation code to be verified + * @param bool $leave_inactive Flag whether to remove the activate hash value, but leave active = 0 + * + * @return int User Id on success, FALSE on error + */ + public function activate($email = FALSE, $code = FALSE, $leave_inactive = FALSE) + { + + if ($code === FALSE) + { + $this->error = lang('us_err_no_activate_code'); + return FALSE; + } + + if (!empty($email)) + { + $this->db->where('email', $email); + } + + $query = $this->db->select('id') + ->where('activate_hash', $code) + ->limit(1) + ->get($this->table); + + if ($query->num_rows() !== 1) + { + $this->error = lang('us_err_no_matching_code'); + return FALSE; + } + + $result = $query->row(); + $active = ($leave_inactive === FALSE) ? 1 : 0; + if ($this->update($result->id, array('activate_hash' => '','active' => $active))) + { + return $result->id; + } + + }//end activate() + + + /** + * This function is triggered during account set up to assure user is not active and, + * if not supressed, generate an activation hash code. This function can be used to + * deactivate accounts based on public view events. + * + * @param int $user_id The username or email to match to deactivate + * @param string $login_type Login Method + * @param bool $make_hash Create a hash + * + * @return mixed $activate_hash on success, FALSE on error + */ + public function deactivate($user_id = FALSE, $login_type = 'email', $make_hash = TRUE) + { + if ($user_id === FALSE) + { + return FALSE; + } + + // create a temp activation code. + $activate_hash = ''; + if ($make_hash === true) + { + $this->load->helpers(array('string', 'security')); + $activate_hash = do_hash(random_string('alnum', 40) . time()); + } + + $this->db->update($this->table, array('active'=>0,'activate_hash' => $activate_hash), array($login_type => $user_id)); + + return ($this->db->affected_rows() == 1) ? $activate_hash : FALSE; + + }//end deactivate() + + + /** + * Admin specific activation function for admin approvals or re-activation. + * + * @access public + * + * @param int $user_id The user ID to activate + * + * @return bool TRUE on success, FALSE on error + */ + public function admin_activation($user_id = FALSE) + { + + if ($user_id === FALSE) + { + $this->error = lang('us_err_no_id'); + return FALSE; + } + + $query = $this->db->select('id') + ->where('id', $user_id) + ->limit(1) + ->get($this->table); + + if ($query->num_rows() !== 1) + { + $this->error = lang('us_err_no_matching_id'); + return FALSE; + } + + $result = $query->row(); + $this->update($result->id, array('activate_hash' => '','active' => 1)); + + if ($this->db->affected_rows() > 0) + { + return $result->id; + } + else + { + $this->error = lang('us_err_user_is_active'); + return FALSE; + } + + }//end admin_activation() + + + /** + * Admin only deactivation function. + * + * @access public + * + * @param int $user_id The user ID to deactivate + * + * @return bool TRUE on success, FALSE on error + */ + public function admin_deactivation($user_id = FALSE) + { + if ($user_id === FALSE) + { + $this->error = lang('us_err_no_id'); + return FALSE; + } + + if ($this->deactivate($user_id, 'id', FALSE)) + { + return $user_id; + } + else + { + $this->error = lang('us_err_user_is_inactive'); + return FALSE; + } + + }//end admin_deactivation() + + //-------------------------------------------------------------------- + +}//end User_model diff --git a/bonfire/application/core_modules/users/views/settings/index.php b/bonfire/application/core_modules/users/views/settings/index.php index 90b12f70d..81b4ef14d 100644 --- a/bonfire/application/core_modules/users/views/settings/index.php +++ b/bonfire/application/core_modules/users/views/settings/index.php @@ -1,135 +1,135 @@ -
- -
- -
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - id ?> - username; ?> - banned) echo 'Banned'; ?> - display_name ?> - email ?> - - role_id]->role_name ?> - - last_login != '0000-00-00 00:00:00') - { - echo date('M j, y g:i A', strtotime($user->last_login)); - } - else - { - echo '---'; - } - ?> - active) - { - case 1: - $class = " label-success"; - break; - case 0: - default: - $class = " label-warning"; - break; - - } - ?> - - active == 1) - { - echo(lang('us_active')); - } - else - { - echo(lang('us_inactive')); - } - ?> - -
No users found that match your selection.
- - - pagination->create_links(); ?> - -
+
+ +
+ +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + id ?> + username; ?> + banned) echo 'Banned'; ?> + display_name ?> + email ?> + + role_id]->role_name ?> + + last_login != '0000-00-00 00:00:00') + { + echo date('M j, y g:i A', strtotime($user->last_login)); + } + else + { + echo '---'; + } + ?> + active) + { + case 1: + $class = " label-success"; + break; + case 0: + default: + $class = " label-warning"; + break; + + } + ?> + + active == 1) + { + echo(lang('us_active')); + } + else + { + echo(lang('us_inactive')); + } + ?> + +
No users found that match your selection.
+ + + pagination->create_links(); ?> + +
diff --git a/bonfire/application/core_modules/users/views/settings/user_form.php b/bonfire/application/core_modules/users/views/settings/user_form.php index 03272f822..ee3e05674 100644 --- a/bonfire/application/core_modules/users/views/settings/user_form.php +++ b/bonfire/application/core_modules/users/views/settings/user_form.php @@ -1,187 +1,187 @@ -banned) : ?> -
-

-
- - -
-
-
- × -

- -
-
-
- -
- -

- - uri->uri_string(), 'class="form-horizontal" autocomplete="off"'); ?> - -
- - -
- -
- - '. form_error('email') .''; ?> -
-
- -
- -
- - '. form_error('username') .''; ?> -
-
- -
- -
- - '. form_error('display_name') .''; ?> -
-
- -
- -
- - '. form_error('password') .''; ?> -
-
- -
- -
- - '. form_error('pass_confirm') .''; ?> -
-
- -
- -
- - '. form_error('language') .''; ?> -
-
- -
- -
- timezone : $current_user->timezone)); ?> - '. form_error('timezones') .''; ?> -
-
-
- - role_name.'.Manage') && isset($roles) ) :?> -
- - -
- -
- -
-
-
- - - - - - - load->view('users/user_meta');?> - - - - role_name).'.Manage') && $user->id != $this->auth->user_id() && ($user->banned || $user->deleted)) : ?> -
- - - active) : - $field = 'de'.$field; - endif; ?> -
-
- -
-
- - deleted) : ?> -
-
- -
-
- - banned) :?> -
-
- -
-
- - -
- - - -
- -   ' . lang('bf_action_cancel'), 'class="btn btn-warning"'); ?> -
- - - -
+banned) : ?> +
+

+
+ + +
+
+
+ × +

+ +
+
+
+ +
+ +

+ + uri->uri_string(), 'class="form-horizontal" autocomplete="off"'); ?> + +
+ + +
+ +
+ + '. form_error('email') .''; ?> +
+
+ +
+ +
+ + '. form_error('username') .''; ?> +
+
+ +
+ +
+ + '. form_error('display_name') .''; ?> +
+
+ +
+ +
+ + '. form_error('password') .''; ?> +
+
+ +
+ +
+ + '. form_error('pass_confirm') .''; ?> +
+
+ +
+ +
+ + '. form_error('language') .''; ?> +
+
+ +
+ +
+ timezone : $current_user->timezone)); ?> + '. form_error('timezones') .''; ?> +
+
+
+ + role_name.'.Manage') && isset($roles) ) :?> +
+ + +
+ +
+ +
+
+
+ + + + + + + load->view('users/user_meta');?> + + + + role_name).'.Manage') && $user->id != $this->auth->user_id() && ($user->banned || $user->deleted)) : ?> +
+ + + active) : + $field = 'de'.$field; + endif; ?> +
+
+ +
+
+ + deleted) : ?> +
+
+ +
+
+ + banned) :?> +
+
+ +
+
+ + +
+ + + +
+ +   ' . lang('bf_action_cancel'), 'class="btn btn-warning"'); ?> +
+ + + +
diff --git a/bonfire/application/db/migrations/core/003_Permission_system_upgrade.php b/bonfire/application/db/migrations/core/003_Permission_system_upgrade.php index 105c0289d..7ea245866 100644 --- a/bonfire/application/db/migrations/core/003_Permission_system_upgrade.php +++ b/bonfire/application/db/migrations/core/003_Permission_system_upgrade.php @@ -1,142 +1,142 @@ -db->dbprefix; - - /* - Take care of a few preliminaries before updating: - - - Add new Site.Signin.Offline permission - - Rename Site.Statistics.View to Site.Reports.View - - Remove Site.Appearance.View - - Then the rest of the update script handles transferring them - to the new tables. - */ - $sql = "ALTER TABLE {$prefix}permissions ADD `Site.Signin.Offline` TINYINT(1) DEFAULT 0 NOT NULL"; - $this->db->query($sql); - $this->db->query("UPDATE {$prefix}permissions SET `Site.Signin.Offline`=1 WHERE `role_id`=1"); - - $sql = "ALTER TABLE {$prefix}permissions CHANGE `Site.Statistics.View` `Site.Reports.View` TINYINT(1) DEFAULT 0 NOT NULL"; - $this->db->query($sql); - - $sql = "ALTER TABLE {$prefix}permissions DROP COLUMN `Site.Appearance.View`"; - $this->db->query($sql); - - /* - Do the actual update. - */ - // get the field names in the current bf_permissions table - $permissions_fields = $this->db->list_fields('permissions'); - - // get the current permissions assigned to each role - $sql = "SELECT * FROM {$prefix}permissions"; - $permission_query = $this->db->query($sql); - - $old_permissions_array = array(); - foreach ($permission_query->result_array() as $row) - { - $role_id = $row['role_id']; - $old_permissions_array[$role_id] = $row; - } - - // modify the permissions table - $this->dbforge->rename_table('permissions', 'permissions_old'); - - $fields = array( - 'permission_id' => array( - 'type' => 'INT', - 'constraint' => 11, - 'null' => FALSE, - 'auto_increment' => TRUE - ), - 'name' => array( - 'type' => 'VARCHAR', - 'constraint' => '30', - ), - 'description' => array( - 'type' =>'VARCHAR', - 'constraint' => '100', - ), - 'status' => array( - 'type' => 'ENUM', - 'constraint' => "'active','inactive','deleted'", - 'null' => TRUE, - 'default' => 'active' - ), - ); - $this->dbforge->add_field($fields); - $this->dbforge->add_key('permission_id', TRUE); - $this->dbforge->create_table('permissions'); - // add records for each of the old permissions - foreach ($permissions_fields as $field) - { - if($field != 'role_id' && $field != 'permission_id') - { - $this->db->query("INSERT INTO {$prefix}permissions VALUES (0,'{$field}','','active');"); - } - } - $this->db->query("INSERT INTO {$prefix}permissions VALUES (0,'Permissions.Settings.View','Allow access to view the Permissions menu unders Settings Context','active');"); - $this->db->query("INSERT INTO {$prefix}permissions VALUES (0,'Permissions.Settings.Manage','Allow access to manage the Permissions in the system','active');"); - - - // create the new bf_role_permissions table - $this->dbforge->add_field("role_id int(11) NOT NULL"); - $this->dbforge->add_field("permission_id int(11) NOT NULL "); - $this->dbforge->add_key('role_id', TRUE); - $this->dbforge->add_key('permission_id', TRUE); - $this->dbforge->create_table('role_permissions'); - - // add records to allow access to the permissions by the roles - adding records to bf_role_permissions - // get the current list of permissions - $sql = "SELECT * FROM {$prefix}permissions"; - $new_permission_query = $this->db->query($sql); - // loop through the current permissions - foreach ($new_permission_query->result_array() as $permission_rec) - { - // loop through the old permissions - foreach($old_permissions_array as $role_id => $role_permissions) - { - // if the role had access to this permission then give it access again - if(isset($role_permissions[$permission_rec['name']]) && $role_permissions[$permission_rec['name']] == 1) - { - $this->db->query("INSERT INTO {$prefix}role_permissions VALUES ({$role_id},{$permission_rec['permission_id']});"); - } - - // specific case for the administrator to get access to - Bonfire.Permissions.Manage - if($role_id == 1 AND $permission_rec['name'] == 'Bonfire.Permissions.Manage') - { - $this->db->query("INSERT INTO {$prefix}role_permissions VALUES ({$role_id},{$permission_rec['permission_id']});"); - } - } - - // give the administrator use access to the new "Permissions" permissions - if($permission_rec['name'] == 'Permissions.Settings.View' || $permission_rec['name'] == 'Permissions.Settings.Manage') - { - $this->db->query("INSERT INTO {$prefix}role_permissions VALUES (1,{$permission_rec['permission_id']});"); - } - - } - - } - - //-------------------------------------------------------------------- - - public function down() - { - $prefix = $this->db->dbprefix; - - // Drop our countries table - $this->dbforge->drop_table('permissions'); - $this->dbforge->drop_table('role_permissions'); - - $this->dbforge->rename_table($prefix.'permissions_old', $prefix.'permissions'); - - } - - //-------------------------------------------------------------------- - +db->dbprefix; + + /* + Take care of a few preliminaries before updating: + + - Add new Site.Signin.Offline permission + - Rename Site.Statistics.View to Site.Reports.View + - Remove Site.Appearance.View + + Then the rest of the update script handles transferring them + to the new tables. + */ + $sql = "ALTER TABLE {$prefix}permissions ADD `Site.Signin.Offline` TINYINT(1) DEFAULT 0 NOT NULL"; + $this->db->query($sql); + $this->db->query("UPDATE {$prefix}permissions SET `Site.Signin.Offline`=1 WHERE `role_id`=1"); + + $sql = "ALTER TABLE {$prefix}permissions CHANGE `Site.Statistics.View` `Site.Reports.View` TINYINT(1) DEFAULT 0 NOT NULL"; + $this->db->query($sql); + + $sql = "ALTER TABLE {$prefix}permissions DROP COLUMN `Site.Appearance.View`"; + $this->db->query($sql); + + /* + Do the actual update. + */ + // get the field names in the current bf_permissions table + $permissions_fields = $this->db->list_fields('permissions'); + + // get the current permissions assigned to each role + $sql = "SELECT * FROM {$prefix}permissions"; + $permission_query = $this->db->query($sql); + + $old_permissions_array = array(); + foreach ($permission_query->result_array() as $row) + { + $role_id = $row['role_id']; + $old_permissions_array[$role_id] = $row; + } + + // modify the permissions table + $this->dbforge->rename_table('permissions', 'permissions_old'); + + $fields = array( + 'permission_id' => array( + 'type' => 'INT', + 'constraint' => 11, + 'null' => FALSE, + 'auto_increment' => TRUE + ), + 'name' => array( + 'type' => 'VARCHAR', + 'constraint' => '30', + ), + 'description' => array( + 'type' =>'VARCHAR', + 'constraint' => '100', + ), + 'status' => array( + 'type' => 'ENUM', + 'constraint' => "'active','inactive','deleted'", + 'null' => TRUE, + 'default' => 'active' + ), + ); + $this->dbforge->add_field($fields); + $this->dbforge->add_key('permission_id', TRUE); + $this->dbforge->create_table('permissions'); + // add records for each of the old permissions + foreach ($permissions_fields as $field) + { + if($field != 'role_id' && $field != 'permission_id') + { + $this->db->query("INSERT INTO {$prefix}permissions VALUES (0,'{$field}','','active');"); + } + } + $this->db->query("INSERT INTO {$prefix}permissions VALUES (0,'Permissions.Settings.View','Allow access to view the Permissions menu unders Settings Context','active');"); + $this->db->query("INSERT INTO {$prefix}permissions VALUES (0,'Permissions.Settings.Manage','Allow access to manage the Permissions in the system','active');"); + + + // create the new bf_role_permissions table + $this->dbforge->add_field("role_id int(11) NOT NULL"); + $this->dbforge->add_field("permission_id int(11) NOT NULL "); + $this->dbforge->add_key('role_id', TRUE); + $this->dbforge->add_key('permission_id', TRUE); + $this->dbforge->create_table('role_permissions'); + + // add records to allow access to the permissions by the roles - adding records to bf_role_permissions + // get the current list of permissions + $sql = "SELECT * FROM {$prefix}permissions"; + $new_permission_query = $this->db->query($sql); + // loop through the current permissions + foreach ($new_permission_query->result_array() as $permission_rec) + { + // loop through the old permissions + foreach($old_permissions_array as $role_id => $role_permissions) + { + // if the role had access to this permission then give it access again + if(isset($role_permissions[$permission_rec['name']]) && $role_permissions[$permission_rec['name']] == 1) + { + $this->db->query("INSERT INTO {$prefix}role_permissions VALUES ({$role_id},{$permission_rec['permission_id']});"); + } + + // specific case for the administrator to get access to - Bonfire.Permissions.Manage + if($role_id == 1 AND $permission_rec['name'] == 'Bonfire.Permissions.Manage') + { + $this->db->query("INSERT INTO {$prefix}role_permissions VALUES ({$role_id},{$permission_rec['permission_id']});"); + } + } + + // give the administrator use access to the new "Permissions" permissions + if($permission_rec['name'] == 'Permissions.Settings.View' || $permission_rec['name'] == 'Permissions.Settings.Manage') + { + $this->db->query("INSERT INTO {$prefix}role_permissions VALUES (1,{$permission_rec['permission_id']});"); + } + + } + + } + + //-------------------------------------------------------------------- + + public function down() + { + $prefix = $this->db->dbprefix; + + // Drop our countries table + $this->dbforge->drop_table('permissions'); + $this->dbforge->drop_table('role_permissions'); + + $this->dbforge->rename_table($prefix.'permissions_old', $prefix.'permissions'); + + } + + //-------------------------------------------------------------------- + } \ No newline at end of file diff --git a/bonfire/application/db/migrations/core/006_Country_state_upgrade.php b/bonfire/application/db/migrations/core/006_Country_state_upgrade.php index c1246c35f..7370336d6 100644 --- a/bonfire/application/db/migrations/core/006_Country_state_upgrade.php +++ b/bonfire/application/db/migrations/core/006_Country_state_upgrade.php @@ -1,460 +1,460 @@ -db->dbprefix; - - /* - Take care of a few preliminaries before updating: - - - Add a state_code column to the user table -TODO - Map users.state_id to the correct state_code and update each user - - Remove the state_id column from the users table - - Remove the country_id column from the users table - doesn't seem to be updated anyway - - - Remove the states table - - Remove the countries table - */ - - // Add a state_code column to the user table - $this->dbforge->add_column('users', array( - 'state_code' => array( - 'type' => 'CHAR', - 'constraint' => 4, - 'null' => TRUE, - 'default' => NULL - ) - ) - ); - - // Map users.state_id to the correct state_code and update each user - $sql = "SELECT * FROM {$prefix}states"; - $old_states_query = $this->db->query($sql); - // loop through the current states - $old_states_array = array(); - foreach ($old_states_query->result_array() as $state_rec) - { - $old_states_array[$state_rec['id']] = $state_rec['abbrev']; - } - - $sql = "SELECT * FROM {$prefix}users"; - $users_query = $this->db->query($sql); - // loop through the current users - foreach ($users_query->result_array() as $user_rec) - { - - if (!empty($user_rec['state_id'])) - { - $this->db->query("UPDATE {$prefix}users SET `state_code` = '{$old_states_array[$user_rec['state_id']]}' WHERE `id` = '{$user_rec['id']}';"); - } - } - - // Remove the state_id column from the users table - $this->dbforge->drop_column('users', 'state_id'); - - // Remove the country_id column from the users table - $this->dbforge->drop_column('users', 'country_id'); - - // Remove the states table - $this->dbforge->drop_table('states'); - - // Remove the countries table - $this->dbforge->drop_table('countries'); - - } - - //-------------------------------------------------------------------- - - public function down() - { - $prefix = $this->db->dbprefix; - - /* - oh no we have to rollback ?? - really?? - please no! - - ok then. - - Reinstate the states table - - Reinstate the countries table - - Add the country_id column into the users table - - Add the state_id column into the users table -TODO - Map the state_code values to the state_id and update each user - - Remove the state_code column from the users table - */ - - // Reinstate the states table - $this->dbforge->add_field("`id` int(11) NOT NULL AUTO_INCREMENT"); - $this->dbforge->add_field("`name` char(40) NOT NULL"); - $this->dbforge->add_field("`abbrev` char(2) NOT NULL"); - $this->dbforge->add_key('id', true); - $this->dbforge->create_table('states'); - - $this->db->query("INSERT INTO {$prefix}states VALUES(1, 'Alaska', 'AK')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(2, 'Alabama', 'AL')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(3, 'American Samoa', 'AS')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(4, 'Arizona', 'AZ')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(5, 'Arkansas', 'AR')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(6, 'California', 'CA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(7, 'Colorado', 'CO')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(8, 'Connecticut', 'CT')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(9, 'Delaware', 'DE')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(10, 'District of Columbia', 'DC')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(12, 'Florida', 'FL')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(13, 'Georgia', 'GA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(14, 'Guam', 'GU')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(15, 'Hawaii', 'HI')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(16, 'Idaho', 'ID')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(17, 'Illinois', 'IL')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(18, 'Indiana', 'IN')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(19, 'Iowa', 'IA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(20, 'Kansas', 'KS')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(21, 'Kentucky', 'KY')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(22, 'Louisiana', 'LA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(23, 'Maine', 'ME')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(24, 'Marshall Islands', 'MH')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(25, 'Maryland', 'MD')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(26, 'Massachusetts', 'MA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(27, 'Michigan', 'MI')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(28, 'Minnesota', 'MN')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(29, 'Mississippi', 'MS')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(30, 'Missouri', 'MO')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(31, 'Montana', 'MT')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(32, 'Nebraska', 'NE')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(33, 'Nevada', 'NV')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(34, 'New Hampshire', 'NH')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(35, 'New Jersey', 'NJ')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(36, 'New Mexico', 'NM')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(37, 'New York', 'NY')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(38, 'North Carolina', 'NC')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(39, 'North Dakota', 'ND')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(40, 'Northern Mariana Islands', 'MP')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(41, 'Ohio', 'OH')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(42, 'Oklahoma', 'OK')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(43, 'Oregon', 'OR')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(44, 'Palau', 'PW')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(45, 'Pennsylvania', 'PA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(46, 'Puerto Rico', 'PR')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(47, 'Rhode Island', 'RI')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(48, 'South Carolina', 'SC')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(49, 'South Dakota', 'SD')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(50, 'Tennessee', 'TN')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(51, 'Texas', 'TX')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(52, 'Utah', 'UT')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(53, 'Vermont', 'VT')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(54, 'Virgin Islands', 'VI')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(55, 'Virginia', 'VA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(56, 'Washington', 'WA')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(57, 'West Virginia', 'WV')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(58, 'Wisconsin', 'WI')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(59, 'Wyoming', 'WY')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(60, 'Armed Forces Africa', 'AE')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(62, 'Armed Forces Canada', 'AE')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(63, 'Armed Forces Europe', 'AE')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(64, 'Armed Forces Middle East', 'AE')"); - $this->db->query("INSERT INTO {$prefix}states VALUES(65, 'Armed Forces Pacific', 'AP')"); - - - // Add countries table for our users. - // Source: http://27.org/isocountrylist/ - $this->dbforge->add_field("iso CHAR(2) DEFAULT 'US' NOT NULL"); - $this->dbforge->add_field("name VARCHAR(80) NOT NULL"); - $this->dbforge->add_field("printable_name VARCHAR(80) NOT NULL"); - $this->dbforge->add_field("iso3 CHAR(3)"); - $this->dbforge->add_field("numcode SMALLINT"); - $this->dbforge->add_key('iso', true); - $this->dbforge->create_table('countries'); - - // And... the countries themselves. (whew!) - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AF','AFGHANISTAN','Afghanistan','AFG','004');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AL','ALBANIA','Albania','ALB','008');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('DZ','ALGERIA','Algeria','DZA','012');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AS','AMERICAN SAMOA','American Samoa','ASM','016');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AD','ANDORRA','Andorra','AND','020');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AO','ANGOLA','Angola','AGO','024');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AI','ANGUILLA','Anguilla','AIA','660');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AQ','ANTARCTICA','Antarctica',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AG','ANTIGUA AND BARBUDA','Antigua and Barbuda','ATG','028');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AR','ARGENTINA','Argentina','ARG','032');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AM','ARMENIA','Armenia','ARM','051');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AW','ARUBA','Aruba','ABW','533');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AU','AUSTRALIA','Australia','AUS','036');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AT','AUSTRIA','Austria','AUT','040');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AZ','AZERBAIJAN','Azerbaijan','AZE','031');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BS','BAHAMAS','Bahamas','BHS','044');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BH','BAHRAIN','Bahrain','BHR','048');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BD','BANGLADESH','Bangladesh','BGD','050');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BB','BARBADOS','Barbados','BRB','052');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BY','BELARUS','Belarus','BLR','112');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BE','BELGIUM','Belgium','BEL','056');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BZ','BELIZE','Belize','BLZ','084');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BJ','BENIN','Benin','BEN','204');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BM','BERMUDA','Bermuda','BMU','060');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BT','BHUTAN','Bhutan','BTN','064');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BO','BOLIVIA','Bolivia','BOL','068');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BA','BOSNIA AND HERZEGOVINA','Bosnia and Herzegovina','BIH','070');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BW','BOTSWANA','Botswana','BWA','072');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BV','BOUVET ISLAND','Bouvet Island',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BR','BRAZIL','Brazil','BRA','076');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IO','BRITISH INDIAN OCEAN TERRITORY','British Indian Ocean Territory',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BN','BRUNEI DARUSSALAM','Brunei Darussalam','BRN','096');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BG','BULGARIA','Bulgaria','BGR','100');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BF','BURKINA FASO','Burkina Faso','BFA','854');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('BI','BURUNDI','Burundi','BDI','108');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KH','CAMBODIA','Cambodia','KHM','116');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CM','CAMEROON','Cameroon','CMR','120');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CA','CANADA','Canada','CAN','124');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CV','CAPE VERDE','Cape Verde','CPV','132');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KY','CAYMAN ISLANDS','Cayman Islands','CYM','136');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CF','CENTRAL AFRICAN REPUBLIC','Central African Republic','CAF','140');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TD','CHAD','Chad','TCD','148');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CL','CHILE','Chile','CHL','152');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CN','CHINA','China','CHN','156');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CX','CHRISTMAS ISLAND','Christmas Island',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CC','COCOS (KEELING) ISLANDS','Cocos (Keeling) Islands',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CO','COLOMBIA','Colombia','COL','170');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KM','COMOROS','Comoros','COM','174');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CG','CONGO','Congo','COG','178');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CD','CONGO, THE DEMOCRATIC REPUBLIC OF THE','Congo, the Democratic Republic of the','COD','180');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CK','COOK ISLANDS','Cook Islands','COK','184');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CR','COSTA RICA','Costa Rica','CRI','188');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CI','COTE D\'IVOIRE','Cote D\'Ivoire','CIV','384');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('HR','CROATIA','Croatia','HRV','191');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CU','CUBA','Cuba','CUB','192');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CY','CYPRUS','Cyprus','CYP','196');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CZ','CZECH REPUBLIC','Czech Republic','CZE','203');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('DK','DENMARK','Denmark','DNK','208');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('DJ','DJIBOUTI','Djibouti','DJI','262');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('DM','DOMINICA','Dominica','DMA','212');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('DO','DOMINICAN REPUBLIC','Dominican Republic','DOM','214');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('EC','ECUADOR','Ecuador','ECU','218');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('EG','EGYPT','Egypt','EGY','818');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SV','EL SALVADOR','El Salvador','SLV','222');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GQ','EQUATORIAL GUINEA','Equatorial Guinea','GNQ','226');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ER','ERITREA','Eritrea','ERI','232');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('EE','ESTONIA','Estonia','EST','233');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ET','ETHIOPIA','Ethiopia','ETH','231');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('FK','FALKLAND ISLANDS (MALVINAS)','Falkland Islands (Malvinas)','FLK','238');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('FO','FAROE ISLANDS','Faroe Islands','FRO','234');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('FJ','FIJI','Fiji','FJI','242');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('FI','FINLAND','Finland','FIN','246');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('FR','FRANCE','France','FRA','250');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GF','FRENCH GUIANA','French Guiana','GUF','254');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PF','FRENCH POLYNESIA','French Polynesia','PYF','258');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TF','FRENCH SOUTHERN TERRITORIES','French Southern Territories',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GA','GABON','Gabon','GAB','266');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GM','GAMBIA','Gambia','GMB','270');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GE','GEORGIA','Georgia','GEO','268');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('DE','GERMANY','Germany','DEU','276');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GH','GHANA','Ghana','GHA','288');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GI','GIBRALTAR','Gibraltar','GIB','292');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GR','GREECE','Greece','GRC','300');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GL','GREENLAND','Greenland','GRL','304');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GD','GRENADA','Grenada','GRD','308');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GP','GUADELOUPE','Guadeloupe','GLP','312');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GU','GUAM','Guam','GUM','316');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GT','GUATEMALA','Guatemala','GTM','320');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GN','GUINEA','Guinea','GIN','324');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GW','GUINEA-BISSAU','Guinea-Bissau','GNB','624');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GY','GUYANA','Guyana','GUY','328');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('HT','HAITI','Haiti','HTI','332');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('HM','HEARD ISLAND AND MCDONALD ISLANDS','Heard Island and Mcdonald Islands',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('VA','HOLY SEE (VATICAN CITY STATE)','Holy See (Vatican City State)','VAT','336');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('HN','HONDURAS','Honduras','HND','340');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('HK','HONG KONG','Hong Kong','HKG','344');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('HU','HUNGARY','Hungary','HUN','348');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IS','ICELAND','Iceland','ISL','352');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IN','INDIA','India','IND','356');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ID','INDONESIA','Indonesia','IDN','360');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IR','IRAN, ISLAMIC REPUBLIC OF','Iran, Islamic Republic of','IRN','364');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IQ','IRAQ','Iraq','IRQ','368');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IE','IRELAND','Ireland','IRL','372');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IL','ISRAEL','Israel','ISR','376');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('IT','ITALY','Italy','ITA','380');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('JM','JAMAICA','Jamaica','JAM','388');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('JP','JAPAN','Japan','JPN','392');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('JO','JORDAN','Jordan','JOR','400');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KZ','KAZAKHSTAN','Kazakhstan','KAZ','398');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KE','KENYA','Kenya','KEN','404');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KI','KIRIBATI','Kiribati','KIR','296');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KP','KOREA, DEMOCRATIC PEOPLE\'S REPUBLIC OF','Korea, Democratic People\'s Republic of','PRK','408');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KR','KOREA, REPUBLIC OF','Korea, Republic of','KOR','410');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KW','KUWAIT','Kuwait','KWT','414');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KG','KYRGYZSTAN','Kyrgyzstan','KGZ','417');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LA','LAO PEOPLE\'S DEMOCRATIC REPUBLIC','Lao People\'s Democratic Republic','LAO','418');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LV','LATVIA','Latvia','LVA','428');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LB','LEBANON','Lebanon','LBN','422');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LS','LESOTHO','Lesotho','LSO','426');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LR','LIBERIA','Liberia','LBR','430');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LY','LIBYAN ARAB JAMAHIRIYA','Libyan Arab Jamahiriya','LBY','434');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LI','LIECHTENSTEIN','Liechtenstein','LIE','438');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LT','LITHUANIA','Lithuania','LTU','440');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LU','LUXEMBOURG','Luxembourg','LUX','442');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MO','MACAO','Macao','MAC','446');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MK','MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF','Macedonia, the Former Yugoslav Republic of','MKD','807');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MG','MADAGASCAR','Madagascar','MDG','450');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MW','MALAWI','Malawi','MWI','454');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MY','MALAYSIA','Malaysia','MYS','458');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MV','MALDIVES','Maldives','MDV','462');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ML','MALI','Mali','MLI','466');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MT','MALTA','Malta','MLT','470');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MH','MARSHALL ISLANDS','Marshall Islands','MHL','584');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MQ','MARTINIQUE','Martinique','MTQ','474');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MR','MAURITANIA','Mauritania','MRT','478');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MU','MAURITIUS','Mauritius','MUS','480');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('YT','MAYOTTE','Mayotte',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MX','MEXICO','Mexico','MEX','484');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('FM','MICRONESIA, FEDERATED STATES OF','Micronesia, Federated States of','FSM','583');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MD','MOLDOVA, REPUBLIC OF','Moldova, Republic of','MDA','498');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MC','MONACO','Monaco','MCO','492');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MN','MONGOLIA','Mongolia','MNG','496');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MS','MONTSERRAT','Montserrat','MSR','500');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MA','MOROCCO','Morocco','MAR','504');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MZ','MOZAMBIQUE','Mozambique','MOZ','508');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MM','MYANMAR','Myanmar','MMR','104');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NA','NAMIBIA','Namibia','NAM','516');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NR','NAURU','Nauru','NRU','520');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NP','NEPAL','Nepal','NPL','524');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NL','NETHERLANDS','Netherlands','NLD','528');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AN','NETHERLANDS ANTILLES','Netherlands Antilles','ANT','530');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NC','NEW CALEDONIA','New Caledonia','NCL','540');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NZ','NEW ZEALAND','New Zealand','NZL','554');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NI','NICARAGUA','Nicaragua','NIC','558');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NE','NIGER','Niger','NER','562');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NG','NIGERIA','Nigeria','NGA','566');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NU','NIUE','Niue','NIU','570');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NF','NORFOLK ISLAND','Norfolk Island','NFK','574');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('MP','NORTHERN MARIANA ISLANDS','Northern Mariana Islands','MNP','580');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('NO','NORWAY','Norway','NOR','578');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('OM','OMAN','Oman','OMN','512');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PK','PAKISTAN','Pakistan','PAK','586');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PW','PALAU','Palau','PLW','585');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PS','PALESTINIAN TERRITORY, OCCUPIED','Palestinian Territory, Occupied',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PA','PANAMA','Panama','PAN','591');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PG','PAPUA NEW GUINEA','Papua New Guinea','PNG','598');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PY','PARAGUAY','Paraguay','PRY','600');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PE','PERU','Peru','PER','604');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PH','PHILIPPINES','Philippines','PHL','608');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PN','PITCAIRN','Pitcairn','PCN','612');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PL','POLAND','Poland','POL','616');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PT','PORTUGAL','Portugal','PRT','620');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PR','PUERTO RICO','Puerto Rico','PRI','630');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('QA','QATAR','Qatar','QAT','634');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('RE','REUNION','Reunion','REU','638');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('RO','ROMANIA','Romania','ROM','642');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('RU','RUSSIAN FEDERATION','Russian Federation','RUS','643');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('RW','RWANDA','Rwanda','RWA','646');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SH','SAINT HELENA','Saint Helena','SHN','654');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('KN','SAINT KITTS AND NEVIS','Saint Kitts and Nevis','KNA','659');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LC','SAINT LUCIA','Saint Lucia','LCA','662');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('PM','SAINT PIERRE AND MIQUELON','Saint Pierre and Miquelon','SPM','666');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('VC','SAINT VINCENT AND THE GRENADINES','Saint Vincent and the Grenadines','VCT','670');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('WS','SAMOA','Samoa','WSM','882');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SM','SAN MARINO','San Marino','SMR','674');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ST','SAO TOME AND PRINCIPE','Sao Tome and Principe','STP','678');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SA','SAUDI ARABIA','Saudi Arabia','SAU','682');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SN','SENEGAL','Senegal','SEN','686');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CS','SERBIA AND MONTENEGRO','Serbia and Montenegro',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SC','SEYCHELLES','Seychelles','SYC','690');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SL','SIERRA LEONE','Sierra Leone','SLE','694');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SG','SINGAPORE','Singapore','SGP','702');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SK','SLOVAKIA','Slovakia','SVK','703');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SI','SLOVENIA','Slovenia','SVN','705');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SB','SOLOMON ISLANDS','Solomon Islands','SLB','090');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SO','SOMALIA','Somalia','SOM','706');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ZA','SOUTH AFRICA','South Africa','ZAF','710');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GS','SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS','South Georgia and the South Sandwich Islands',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ES','SPAIN','Spain','ESP','724');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('LK','SRI LANKA','Sri Lanka','LKA','144');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SD','SUDAN','Sudan','SDN','736');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SR','SURINAME','Suriname','SUR','740');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SJ','SVALBARD AND JAN MAYEN','Svalbard and Jan Mayen','SJM','744');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SZ','SWAZILAND','Swaziland','SWZ','748');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SE','SWEDEN','Sweden','SWE','752');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('CH','SWITZERLAND','Switzerland','CHE','756');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('SY','SYRIAN ARAB REPUBLIC','Syrian Arab Republic','SYR','760');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TW','TAIWAN, PROVINCE OF CHINA','Taiwan, Province of China','TWN','158');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TJ','TAJIKISTAN','Tajikistan','TJK','762');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TZ','TANZANIA, UNITED REPUBLIC OF','Tanzania, United Republic of','TZA','834');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TH','THAILAND','Thailand','THA','764');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TL','TIMOR-LESTE','Timor-Leste',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TG','TOGO','Togo','TGO','768');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TK','TOKELAU','Tokelau','TKL','772')"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TO','TONGA','Tonga','TON','776');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TT','TRINIDAD AND TOBAGO','Trinidad and Tobago','TTO','780');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TN','TUNISIA','Tunisia','TUN','788');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TR','TURKEY','Turkey','TUR','792');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TM','TURKMENISTAN','Turkmenistan','TKM','795');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TC','TURKS AND CAICOS ISLANDS','Turks and Caicos Islands','TCA','796');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('TV','TUVALU','Tuvalu','TUV','798');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('UG','UGANDA','Uganda','UGA','800');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('UA','UKRAINE','Ukraine','UKR','804');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('AE','UNITED ARAB EMIRATES','United Arab Emirates','ARE','784');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('GB','UNITED KINGDOM','United Kingdom','GBR','826');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('US','UNITED STATES','United States','USA','840');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('UM','UNITED STATES MINOR OUTLYING ISLANDS','United States Minor Outlying Islands',NULL,NULL);"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('UY','URUGUAY','Uruguay','URY','858');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('UZ','UZBEKISTAN','Uzbekistan','UZB','860');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('VU','VANUATU','Vanuatu','VUT','548');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('VE','VENEZUELA','Venezuela','VEN','862');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('VN','VIET NAM','Viet Nam','VNM','704');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('VG','VIRGIN ISLANDS, BRITISH','Virgin Islands, British','VGB','092');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('VI','VIRGIN ISLANDS, U.S.','Virgin Islands, U.s.','VIR','850');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('WF','WALLIS AND FUTUNA','Wallis and Futuna','WLF','876');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('EH','WESTERN SAHARA','Western Sahara','ESH','732');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('YE','YEMEN','Yemen','YEM','887');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ZM','ZAMBIA','Zambia','ZMB','894');"); - $this->db->query("INSERT INTO {$prefix}countries VALUES ('ZW','ZIMBABWE','Zimbabwe','ZWE','716');"); - - - // Add the country_id column into the users table - $this->dbforge->add_column('users', array( - 'country_id' => array( - 'type' => 'INT', - 'constraint' => 11, - 'null' => TRUE - ) - ) - ); - - // Add the state_id column into the users table - $this->dbforge->add_column('users', array( - 'state_id' => array( - 'type' => 'INT', - 'constraint' => 11, - 'null' => TRUE - ) - ) - ); - - // Map the state_code values to the state_id and update each user - $sql = "SELECT * FROM {$prefix}states"; - $old_states_query = $this->db->query($sql); - // loop through the current states - $old_states_array = array(); - foreach ($old_states_query->result_array() as $state_rec) - { - $old_states_array[$state_rec['abbrev']] = $state_rec['id']; - } - - $sql = "SELECT * FROM {$prefix}users"; - $users_query = $this->db->query($sql); - // loop through the current users - foreach ($users_query->result_array() as $user_rec) - { - - if (!empty($user_rec['state_code'])) - { - $this->db->query("UPDATE {$prefix}users SET `state_id` = '{$old_states_array[$user_rec['state_code']]}' WHERE `id` = '{$user_rec['id']}';"); - } - } - - // Remove the state_code column from the users table - $this->dbforge->drop_column('users', 'state_code'); - } - - //-------------------------------------------------------------------- - +db->dbprefix; + + /* + Take care of a few preliminaries before updating: + + - Add a state_code column to the user table +TODO - Map users.state_id to the correct state_code and update each user + - Remove the state_id column from the users table + - Remove the country_id column from the users table - doesn't seem to be updated anyway + + - Remove the states table + - Remove the countries table + */ + + // Add a state_code column to the user table + $this->dbforge->add_column('users', array( + 'state_code' => array( + 'type' => 'CHAR', + 'constraint' => 4, + 'null' => TRUE, + 'default' => NULL + ) + ) + ); + + // Map users.state_id to the correct state_code and update each user + $sql = "SELECT * FROM {$prefix}states"; + $old_states_query = $this->db->query($sql); + // loop through the current states + $old_states_array = array(); + foreach ($old_states_query->result_array() as $state_rec) + { + $old_states_array[$state_rec['id']] = $state_rec['abbrev']; + } + + $sql = "SELECT * FROM {$prefix}users"; + $users_query = $this->db->query($sql); + // loop through the current users + foreach ($users_query->result_array() as $user_rec) + { + + if (!empty($user_rec['state_id'])) + { + $this->db->query("UPDATE {$prefix}users SET `state_code` = '{$old_states_array[$user_rec['state_id']]}' WHERE `id` = '{$user_rec['id']}';"); + } + } + + // Remove the state_id column from the users table + $this->dbforge->drop_column('users', 'state_id'); + + // Remove the country_id column from the users table + $this->dbforge->drop_column('users', 'country_id'); + + // Remove the states table + $this->dbforge->drop_table('states'); + + // Remove the countries table + $this->dbforge->drop_table('countries'); + + } + + //-------------------------------------------------------------------- + + public function down() + { + $prefix = $this->db->dbprefix; + + /* + oh no we have to rollback ?? + really?? + please no! + + ok then. + - Reinstate the states table + - Reinstate the countries table + - Add the country_id column into the users table + - Add the state_id column into the users table +TODO - Map the state_code values to the state_id and update each user + - Remove the state_code column from the users table + */ + + // Reinstate the states table + $this->dbforge->add_field("`id` int(11) NOT NULL AUTO_INCREMENT"); + $this->dbforge->add_field("`name` char(40) NOT NULL"); + $this->dbforge->add_field("`abbrev` char(2) NOT NULL"); + $this->dbforge->add_key('id', true); + $this->dbforge->create_table('states'); + + $this->db->query("INSERT INTO {$prefix}states VALUES(1, 'Alaska', 'AK')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(2, 'Alabama', 'AL')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(3, 'American Samoa', 'AS')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(4, 'Arizona', 'AZ')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(5, 'Arkansas', 'AR')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(6, 'California', 'CA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(7, 'Colorado', 'CO')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(8, 'Connecticut', 'CT')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(9, 'Delaware', 'DE')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(10, 'District of Columbia', 'DC')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(12, 'Florida', 'FL')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(13, 'Georgia', 'GA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(14, 'Guam', 'GU')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(15, 'Hawaii', 'HI')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(16, 'Idaho', 'ID')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(17, 'Illinois', 'IL')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(18, 'Indiana', 'IN')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(19, 'Iowa', 'IA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(20, 'Kansas', 'KS')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(21, 'Kentucky', 'KY')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(22, 'Louisiana', 'LA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(23, 'Maine', 'ME')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(24, 'Marshall Islands', 'MH')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(25, 'Maryland', 'MD')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(26, 'Massachusetts', 'MA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(27, 'Michigan', 'MI')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(28, 'Minnesota', 'MN')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(29, 'Mississippi', 'MS')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(30, 'Missouri', 'MO')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(31, 'Montana', 'MT')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(32, 'Nebraska', 'NE')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(33, 'Nevada', 'NV')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(34, 'New Hampshire', 'NH')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(35, 'New Jersey', 'NJ')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(36, 'New Mexico', 'NM')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(37, 'New York', 'NY')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(38, 'North Carolina', 'NC')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(39, 'North Dakota', 'ND')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(40, 'Northern Mariana Islands', 'MP')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(41, 'Ohio', 'OH')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(42, 'Oklahoma', 'OK')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(43, 'Oregon', 'OR')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(44, 'Palau', 'PW')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(45, 'Pennsylvania', 'PA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(46, 'Puerto Rico', 'PR')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(47, 'Rhode Island', 'RI')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(48, 'South Carolina', 'SC')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(49, 'South Dakota', 'SD')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(50, 'Tennessee', 'TN')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(51, 'Texas', 'TX')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(52, 'Utah', 'UT')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(53, 'Vermont', 'VT')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(54, 'Virgin Islands', 'VI')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(55, 'Virginia', 'VA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(56, 'Washington', 'WA')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(57, 'West Virginia', 'WV')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(58, 'Wisconsin', 'WI')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(59, 'Wyoming', 'WY')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(60, 'Armed Forces Africa', 'AE')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(62, 'Armed Forces Canada', 'AE')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(63, 'Armed Forces Europe', 'AE')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(64, 'Armed Forces Middle East', 'AE')"); + $this->db->query("INSERT INTO {$prefix}states VALUES(65, 'Armed Forces Pacific', 'AP')"); + + + // Add countries table for our users. + // Source: http://27.org/isocountrylist/ + $this->dbforge->add_field("iso CHAR(2) DEFAULT 'US' NOT NULL"); + $this->dbforge->add_field("name VARCHAR(80) NOT NULL"); + $this->dbforge->add_field("printable_name VARCHAR(80) NOT NULL"); + $this->dbforge->add_field("iso3 CHAR(3)"); + $this->dbforge->add_field("numcode SMALLINT"); + $this->dbforge->add_key('iso', true); + $this->dbforge->create_table('countries'); + + // And... the countries themselves. (whew!) + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AF','AFGHANISTAN','Afghanistan','AFG','004');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AL','ALBANIA','Albania','ALB','008');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('DZ','ALGERIA','Algeria','DZA','012');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AS','AMERICAN SAMOA','American Samoa','ASM','016');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AD','ANDORRA','Andorra','AND','020');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AO','ANGOLA','Angola','AGO','024');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AI','ANGUILLA','Anguilla','AIA','660');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AQ','ANTARCTICA','Antarctica',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AG','ANTIGUA AND BARBUDA','Antigua and Barbuda','ATG','028');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AR','ARGENTINA','Argentina','ARG','032');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AM','ARMENIA','Armenia','ARM','051');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AW','ARUBA','Aruba','ABW','533');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AU','AUSTRALIA','Australia','AUS','036');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AT','AUSTRIA','Austria','AUT','040');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AZ','AZERBAIJAN','Azerbaijan','AZE','031');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BS','BAHAMAS','Bahamas','BHS','044');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BH','BAHRAIN','Bahrain','BHR','048');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BD','BANGLADESH','Bangladesh','BGD','050');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BB','BARBADOS','Barbados','BRB','052');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BY','BELARUS','Belarus','BLR','112');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BE','BELGIUM','Belgium','BEL','056');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BZ','BELIZE','Belize','BLZ','084');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BJ','BENIN','Benin','BEN','204');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BM','BERMUDA','Bermuda','BMU','060');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BT','BHUTAN','Bhutan','BTN','064');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BO','BOLIVIA','Bolivia','BOL','068');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BA','BOSNIA AND HERZEGOVINA','Bosnia and Herzegovina','BIH','070');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BW','BOTSWANA','Botswana','BWA','072');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BV','BOUVET ISLAND','Bouvet Island',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BR','BRAZIL','Brazil','BRA','076');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IO','BRITISH INDIAN OCEAN TERRITORY','British Indian Ocean Territory',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BN','BRUNEI DARUSSALAM','Brunei Darussalam','BRN','096');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BG','BULGARIA','Bulgaria','BGR','100');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BF','BURKINA FASO','Burkina Faso','BFA','854');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('BI','BURUNDI','Burundi','BDI','108');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KH','CAMBODIA','Cambodia','KHM','116');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CM','CAMEROON','Cameroon','CMR','120');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CA','CANADA','Canada','CAN','124');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CV','CAPE VERDE','Cape Verde','CPV','132');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KY','CAYMAN ISLANDS','Cayman Islands','CYM','136');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CF','CENTRAL AFRICAN REPUBLIC','Central African Republic','CAF','140');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TD','CHAD','Chad','TCD','148');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CL','CHILE','Chile','CHL','152');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CN','CHINA','China','CHN','156');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CX','CHRISTMAS ISLAND','Christmas Island',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CC','COCOS (KEELING) ISLANDS','Cocos (Keeling) Islands',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CO','COLOMBIA','Colombia','COL','170');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KM','COMOROS','Comoros','COM','174');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CG','CONGO','Congo','COG','178');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CD','CONGO, THE DEMOCRATIC REPUBLIC OF THE','Congo, the Democratic Republic of the','COD','180');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CK','COOK ISLANDS','Cook Islands','COK','184');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CR','COSTA RICA','Costa Rica','CRI','188');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CI','COTE D\'IVOIRE','Cote D\'Ivoire','CIV','384');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('HR','CROATIA','Croatia','HRV','191');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CU','CUBA','Cuba','CUB','192');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CY','CYPRUS','Cyprus','CYP','196');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CZ','CZECH REPUBLIC','Czech Republic','CZE','203');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('DK','DENMARK','Denmark','DNK','208');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('DJ','DJIBOUTI','Djibouti','DJI','262');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('DM','DOMINICA','Dominica','DMA','212');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('DO','DOMINICAN REPUBLIC','Dominican Republic','DOM','214');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('EC','ECUADOR','Ecuador','ECU','218');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('EG','EGYPT','Egypt','EGY','818');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SV','EL SALVADOR','El Salvador','SLV','222');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GQ','EQUATORIAL GUINEA','Equatorial Guinea','GNQ','226');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ER','ERITREA','Eritrea','ERI','232');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('EE','ESTONIA','Estonia','EST','233');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ET','ETHIOPIA','Ethiopia','ETH','231');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('FK','FALKLAND ISLANDS (MALVINAS)','Falkland Islands (Malvinas)','FLK','238');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('FO','FAROE ISLANDS','Faroe Islands','FRO','234');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('FJ','FIJI','Fiji','FJI','242');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('FI','FINLAND','Finland','FIN','246');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('FR','FRANCE','France','FRA','250');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GF','FRENCH GUIANA','French Guiana','GUF','254');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PF','FRENCH POLYNESIA','French Polynesia','PYF','258');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TF','FRENCH SOUTHERN TERRITORIES','French Southern Territories',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GA','GABON','Gabon','GAB','266');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GM','GAMBIA','Gambia','GMB','270');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GE','GEORGIA','Georgia','GEO','268');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('DE','GERMANY','Germany','DEU','276');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GH','GHANA','Ghana','GHA','288');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GI','GIBRALTAR','Gibraltar','GIB','292');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GR','GREECE','Greece','GRC','300');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GL','GREENLAND','Greenland','GRL','304');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GD','GRENADA','Grenada','GRD','308');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GP','GUADELOUPE','Guadeloupe','GLP','312');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GU','GUAM','Guam','GUM','316');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GT','GUATEMALA','Guatemala','GTM','320');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GN','GUINEA','Guinea','GIN','324');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GW','GUINEA-BISSAU','Guinea-Bissau','GNB','624');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GY','GUYANA','Guyana','GUY','328');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('HT','HAITI','Haiti','HTI','332');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('HM','HEARD ISLAND AND MCDONALD ISLANDS','Heard Island and Mcdonald Islands',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('VA','HOLY SEE (VATICAN CITY STATE)','Holy See (Vatican City State)','VAT','336');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('HN','HONDURAS','Honduras','HND','340');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('HK','HONG KONG','Hong Kong','HKG','344');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('HU','HUNGARY','Hungary','HUN','348');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IS','ICELAND','Iceland','ISL','352');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IN','INDIA','India','IND','356');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ID','INDONESIA','Indonesia','IDN','360');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IR','IRAN, ISLAMIC REPUBLIC OF','Iran, Islamic Republic of','IRN','364');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IQ','IRAQ','Iraq','IRQ','368');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IE','IRELAND','Ireland','IRL','372');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IL','ISRAEL','Israel','ISR','376');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('IT','ITALY','Italy','ITA','380');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('JM','JAMAICA','Jamaica','JAM','388');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('JP','JAPAN','Japan','JPN','392');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('JO','JORDAN','Jordan','JOR','400');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KZ','KAZAKHSTAN','Kazakhstan','KAZ','398');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KE','KENYA','Kenya','KEN','404');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KI','KIRIBATI','Kiribati','KIR','296');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KP','KOREA, DEMOCRATIC PEOPLE\'S REPUBLIC OF','Korea, Democratic People\'s Republic of','PRK','408');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KR','KOREA, REPUBLIC OF','Korea, Republic of','KOR','410');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KW','KUWAIT','Kuwait','KWT','414');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KG','KYRGYZSTAN','Kyrgyzstan','KGZ','417');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LA','LAO PEOPLE\'S DEMOCRATIC REPUBLIC','Lao People\'s Democratic Republic','LAO','418');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LV','LATVIA','Latvia','LVA','428');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LB','LEBANON','Lebanon','LBN','422');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LS','LESOTHO','Lesotho','LSO','426');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LR','LIBERIA','Liberia','LBR','430');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LY','LIBYAN ARAB JAMAHIRIYA','Libyan Arab Jamahiriya','LBY','434');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LI','LIECHTENSTEIN','Liechtenstein','LIE','438');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LT','LITHUANIA','Lithuania','LTU','440');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LU','LUXEMBOURG','Luxembourg','LUX','442');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MO','MACAO','Macao','MAC','446');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MK','MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF','Macedonia, the Former Yugoslav Republic of','MKD','807');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MG','MADAGASCAR','Madagascar','MDG','450');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MW','MALAWI','Malawi','MWI','454');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MY','MALAYSIA','Malaysia','MYS','458');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MV','MALDIVES','Maldives','MDV','462');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ML','MALI','Mali','MLI','466');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MT','MALTA','Malta','MLT','470');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MH','MARSHALL ISLANDS','Marshall Islands','MHL','584');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MQ','MARTINIQUE','Martinique','MTQ','474');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MR','MAURITANIA','Mauritania','MRT','478');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MU','MAURITIUS','Mauritius','MUS','480');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('YT','MAYOTTE','Mayotte',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MX','MEXICO','Mexico','MEX','484');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('FM','MICRONESIA, FEDERATED STATES OF','Micronesia, Federated States of','FSM','583');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MD','MOLDOVA, REPUBLIC OF','Moldova, Republic of','MDA','498');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MC','MONACO','Monaco','MCO','492');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MN','MONGOLIA','Mongolia','MNG','496');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MS','MONTSERRAT','Montserrat','MSR','500');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MA','MOROCCO','Morocco','MAR','504');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MZ','MOZAMBIQUE','Mozambique','MOZ','508');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MM','MYANMAR','Myanmar','MMR','104');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NA','NAMIBIA','Namibia','NAM','516');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NR','NAURU','Nauru','NRU','520');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NP','NEPAL','Nepal','NPL','524');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NL','NETHERLANDS','Netherlands','NLD','528');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AN','NETHERLANDS ANTILLES','Netherlands Antilles','ANT','530');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NC','NEW CALEDONIA','New Caledonia','NCL','540');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NZ','NEW ZEALAND','New Zealand','NZL','554');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NI','NICARAGUA','Nicaragua','NIC','558');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NE','NIGER','Niger','NER','562');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NG','NIGERIA','Nigeria','NGA','566');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NU','NIUE','Niue','NIU','570');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NF','NORFOLK ISLAND','Norfolk Island','NFK','574');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('MP','NORTHERN MARIANA ISLANDS','Northern Mariana Islands','MNP','580');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('NO','NORWAY','Norway','NOR','578');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('OM','OMAN','Oman','OMN','512');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PK','PAKISTAN','Pakistan','PAK','586');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PW','PALAU','Palau','PLW','585');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PS','PALESTINIAN TERRITORY, OCCUPIED','Palestinian Territory, Occupied',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PA','PANAMA','Panama','PAN','591');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PG','PAPUA NEW GUINEA','Papua New Guinea','PNG','598');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PY','PARAGUAY','Paraguay','PRY','600');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PE','PERU','Peru','PER','604');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PH','PHILIPPINES','Philippines','PHL','608');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PN','PITCAIRN','Pitcairn','PCN','612');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PL','POLAND','Poland','POL','616');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PT','PORTUGAL','Portugal','PRT','620');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PR','PUERTO RICO','Puerto Rico','PRI','630');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('QA','QATAR','Qatar','QAT','634');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('RE','REUNION','Reunion','REU','638');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('RO','ROMANIA','Romania','ROM','642');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('RU','RUSSIAN FEDERATION','Russian Federation','RUS','643');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('RW','RWANDA','Rwanda','RWA','646');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SH','SAINT HELENA','Saint Helena','SHN','654');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('KN','SAINT KITTS AND NEVIS','Saint Kitts and Nevis','KNA','659');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LC','SAINT LUCIA','Saint Lucia','LCA','662');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('PM','SAINT PIERRE AND MIQUELON','Saint Pierre and Miquelon','SPM','666');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('VC','SAINT VINCENT AND THE GRENADINES','Saint Vincent and the Grenadines','VCT','670');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('WS','SAMOA','Samoa','WSM','882');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SM','SAN MARINO','San Marino','SMR','674');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ST','SAO TOME AND PRINCIPE','Sao Tome and Principe','STP','678');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SA','SAUDI ARABIA','Saudi Arabia','SAU','682');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SN','SENEGAL','Senegal','SEN','686');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CS','SERBIA AND MONTENEGRO','Serbia and Montenegro',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SC','SEYCHELLES','Seychelles','SYC','690');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SL','SIERRA LEONE','Sierra Leone','SLE','694');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SG','SINGAPORE','Singapore','SGP','702');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SK','SLOVAKIA','Slovakia','SVK','703');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SI','SLOVENIA','Slovenia','SVN','705');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SB','SOLOMON ISLANDS','Solomon Islands','SLB','090');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SO','SOMALIA','Somalia','SOM','706');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ZA','SOUTH AFRICA','South Africa','ZAF','710');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GS','SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS','South Georgia and the South Sandwich Islands',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ES','SPAIN','Spain','ESP','724');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('LK','SRI LANKA','Sri Lanka','LKA','144');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SD','SUDAN','Sudan','SDN','736');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SR','SURINAME','Suriname','SUR','740');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SJ','SVALBARD AND JAN MAYEN','Svalbard and Jan Mayen','SJM','744');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SZ','SWAZILAND','Swaziland','SWZ','748');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SE','SWEDEN','Sweden','SWE','752');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('CH','SWITZERLAND','Switzerland','CHE','756');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('SY','SYRIAN ARAB REPUBLIC','Syrian Arab Republic','SYR','760');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TW','TAIWAN, PROVINCE OF CHINA','Taiwan, Province of China','TWN','158');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TJ','TAJIKISTAN','Tajikistan','TJK','762');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TZ','TANZANIA, UNITED REPUBLIC OF','Tanzania, United Republic of','TZA','834');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TH','THAILAND','Thailand','THA','764');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TL','TIMOR-LESTE','Timor-Leste',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TG','TOGO','Togo','TGO','768');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TK','TOKELAU','Tokelau','TKL','772')"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TO','TONGA','Tonga','TON','776');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TT','TRINIDAD AND TOBAGO','Trinidad and Tobago','TTO','780');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TN','TUNISIA','Tunisia','TUN','788');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TR','TURKEY','Turkey','TUR','792');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TM','TURKMENISTAN','Turkmenistan','TKM','795');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TC','TURKS AND CAICOS ISLANDS','Turks and Caicos Islands','TCA','796');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('TV','TUVALU','Tuvalu','TUV','798');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('UG','UGANDA','Uganda','UGA','800');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('UA','UKRAINE','Ukraine','UKR','804');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('AE','UNITED ARAB EMIRATES','United Arab Emirates','ARE','784');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('GB','UNITED KINGDOM','United Kingdom','GBR','826');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('US','UNITED STATES','United States','USA','840');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('UM','UNITED STATES MINOR OUTLYING ISLANDS','United States Minor Outlying Islands',NULL,NULL);"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('UY','URUGUAY','Uruguay','URY','858');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('UZ','UZBEKISTAN','Uzbekistan','UZB','860');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('VU','VANUATU','Vanuatu','VUT','548');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('VE','VENEZUELA','Venezuela','VEN','862');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('VN','VIET NAM','Viet Nam','VNM','704');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('VG','VIRGIN ISLANDS, BRITISH','Virgin Islands, British','VGB','092');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('VI','VIRGIN ISLANDS, U.S.','Virgin Islands, U.s.','VIR','850');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('WF','WALLIS AND FUTUNA','Wallis and Futuna','WLF','876');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('EH','WESTERN SAHARA','Western Sahara','ESH','732');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('YE','YEMEN','Yemen','YEM','887');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ZM','ZAMBIA','Zambia','ZMB','894');"); + $this->db->query("INSERT INTO {$prefix}countries VALUES ('ZW','ZIMBABWE','Zimbabwe','ZWE','716');"); + + + // Add the country_id column into the users table + $this->dbforge->add_column('users', array( + 'country_id' => array( + 'type' => 'INT', + 'constraint' => 11, + 'null' => TRUE + ) + ) + ); + + // Add the state_id column into the users table + $this->dbforge->add_column('users', array( + 'state_id' => array( + 'type' => 'INT', + 'constraint' => 11, + 'null' => TRUE + ) + ) + ); + + // Map the state_code values to the state_id and update each user + $sql = "SELECT * FROM {$prefix}states"; + $old_states_query = $this->db->query($sql); + // loop through the current states + $old_states_array = array(); + foreach ($old_states_query->result_array() as $state_rec) + { + $old_states_array[$state_rec['abbrev']] = $state_rec['id']; + } + + $sql = "SELECT * FROM {$prefix}users"; + $users_query = $this->db->query($sql); + // loop through the current users + foreach ($users_query->result_array() as $user_rec) + { + + if (!empty($user_rec['state_code'])) + { + $this->db->query("UPDATE {$prefix}users SET `state_id` = '{$old_states_array[$user_rec['state_code']]}' WHERE `id` = '{$user_rec['id']}';"); + } + } + + // Remove the state_code column from the users table + $this->dbforge->drop_column('users', 'state_code'); + } + + //-------------------------------------------------------------------- + } \ No newline at end of file diff --git a/bonfire/application/db/migrations/core/007_Add_permission_descriptions.php b/bonfire/application/db/migrations/core/007_Add_permission_descriptions.php index 9a5afc249..82464b78f 100644 --- a/bonfire/application/db/migrations/core/007_Add_permission_descriptions.php +++ b/bonfire/application/db/migrations/core/007_Add_permission_descriptions.php @@ -1,54 +1,54 @@ -db->dbprefix; - - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to login to the site' WHERE `name` = 'Site.Signin.Allow';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to login to the site when the site is offline' WHERE `name` = 'Site.Signin.Offline';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Content Context' WHERE `name` = 'Site.Content.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Reports Context' WHERE `name` = 'Site.Reports.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Settings Context' WHERE `name` = 'Site.Settings.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Developer Context' WHERE `name` = 'Site.Developer.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the user Roles' WHERE `name` = 'Bonfire.Roles.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to delete user Roles' WHERE `name` = 'Bonfire.Roles.Delete';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the site Users' WHERE `name` = 'Bonfire.Users.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users access to the User Settings' WHERE `name` = 'Bonfire.Users.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to add new Users' WHERE `name` = 'Bonfire.Users.Add';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the Database settings' WHERE `name` = 'Bonfire.Database.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users access to the Emailer settings' WHERE `name` = 'Bonfire.Emailer.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the Emailer settings' WHERE `name` = 'Bonfire.Emailer.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users access to the Log details' WHERE `name` = 'Bonfire.Logs.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the Log files' WHERE `name` = 'Bonfire.Logs.Manage';"); - - } - - //-------------------------------------------------------------------- - - public function down() - { - $prefix = $this->db->dbprefix; - - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Signin.Allow';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Signin.Offline';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Content.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Reports.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Settings.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Developer.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Roles.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Roles.Delete';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Users.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Users.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Users.Add';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Database.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Emailer.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Emailer.Manage';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Logs.View';"); - $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Logs.Manage';"); - } - - //-------------------------------------------------------------------- - +db->dbprefix; + + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to login to the site' WHERE `name` = 'Site.Signin.Allow';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to login to the site when the site is offline' WHERE `name` = 'Site.Signin.Offline';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Content Context' WHERE `name` = 'Site.Content.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Reports Context' WHERE `name` = 'Site.Reports.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Settings Context' WHERE `name` = 'Site.Settings.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to view the Developer Context' WHERE `name` = 'Site.Developer.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the user Roles' WHERE `name` = 'Bonfire.Roles.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to delete user Roles' WHERE `name` = 'Bonfire.Roles.Delete';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the site Users' WHERE `name` = 'Bonfire.Users.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users access to the User Settings' WHERE `name` = 'Bonfire.Users.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to add new Users' WHERE `name` = 'Bonfire.Users.Add';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the Database settings' WHERE `name` = 'Bonfire.Database.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users access to the Emailer settings' WHERE `name` = 'Bonfire.Emailer.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the Emailer settings' WHERE `name` = 'Bonfire.Emailer.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users access to the Log details' WHERE `name` = 'Bonfire.Logs.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = 'Allow users to manage the Log files' WHERE `name` = 'Bonfire.Logs.Manage';"); + + } + + //-------------------------------------------------------------------- + + public function down() + { + $prefix = $this->db->dbprefix; + + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Signin.Allow';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Signin.Offline';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Content.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Reports.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Settings.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Site.Developer.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Roles.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Roles.Delete';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Users.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Users.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Users.Add';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Database.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Emailer.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Emailer.Manage';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Logs.View';"); + $this->db->query("UPDATE {$prefix}permissions SET `description` = '' WHERE `name` = 'Bonfire.Logs.Manage';"); + } + + //-------------------------------------------------------------------- + } \ No newline at end of file diff --git a/bonfire/application/language/english/application_lang.php b/bonfire/application/language/english/application_lang.php index 9d0d92b01..7790a1904 100644 --- a/bonfire/application/language/english/application_lang.php +++ b/bonfire/application/language/english/application_lang.php @@ -1,235 +1,235 @@ -per page:'; -$lang['bf_top_number_help'] = 'When viewing reports, how many items should be listed at a time?'; -$lang['bf_home'] = 'Home'; -$lang['bf_site_information'] = 'Site Information'; -$lang['bf_timezone'] = 'Timezone'; -$lang['bf_language'] = 'Language'; -$lang['bf_language_help'] = 'Choose the languages available to the user.'; - -//-------------------------------------------------------------------- -// ! AUTH SETTINGS -//-------------------------------------------------------------------- - -$lang['bf_security'] = 'Security'; -$lang['bf_login_type'] = 'Login Type'; -$lang['bf_login_type_email'] = 'Email Only'; -$lang['bf_login_type_username'] = 'Username Only'; -$lang['bf_allow_register'] = 'Allow User Registrations?'; -$lang['bf_login_type_both'] = 'Email or Username'; -$lang['bf_use_usernames'] = 'User display across bonfire:'; -$lang['bf_use_own_name'] = 'Use Own Name'; -$lang['bf_allow_remember'] = 'Allow \'Remember Me\'?'; -$lang['bf_remember_time'] = 'Remember Users For'; -$lang['bf_week'] = 'Week'; -$lang['bf_weeks'] = 'Weeks'; -$lang['bf_days'] = 'Days'; -$lang['bf_username'] = 'Username'; -$lang['bf_password'] = 'Password'; -$lang['bf_password_confirm'] = 'Password (again)'; -$lang['bf_display_name'] = 'Display Name'; - -//-------------------------------------------------------------------- -// ! CRUD SETTINGS -//-------------------------------------------------------------------- - -$lang['bf_home_page'] = 'Home Page'; -$lang['bf_pages'] = 'Pages'; -$lang['bf_enable_rte'] = 'Enable RTE for pages?'; -$lang['bf_rte_type'] = 'RTE Type'; -$lang['bf_searchable_default'] = 'Searchable by default?'; -$lang['bf_cacheable_default'] = 'Cacheable by default?'; -$lang['bf_track_hits'] = 'Track Page Hits?'; - -$lang['bf_action_save'] = 'Save'; -$lang['bf_action_delete'] = 'Delete'; -$lang['bf_action_cancel'] = 'Cancel'; -$lang['bf_action_download'] = 'Download'; -$lang['bf_action_preview'] = 'Preview'; -$lang['bf_action_search'] = 'Search'; -$lang['bf_action_purge'] = 'Purge'; -$lang['bf_action_restore'] = 'Restore'; -$lang['bf_action_show'] = 'Show'; -$lang['bf_action_login'] = 'Sign In'; -$lang['bf_action_logout'] = 'Sign Out'; -$lang['bf_actions'] = 'Actions'; -$lang['bf_clear'] = 'Clear'; -$lang['bf_action_list'] = 'List'; -$lang['bf_action_create'] = 'Create'; -$lang['bf_action_ban'] = 'Ban'; - -//-------------------------------------------------------------------- -// ! SETTINGS LIB -//-------------------------------------------------------------------- - -$lang['bf_do_check'] = 'Check for updates?'; -$lang['bf_do_check_edge'] = 'Must be enabled to see bleeding edge updates as well.'; - -$lang['bf_update_show_edge'] = 'View bleeding edge updates?'; -$lang['bf_update_info_edge'] = 'Leave unchecked to only check for new tagged updates. Check to see any new commits to the official repository.'; - -$lang['bf_ext_profile_show'] = 'Does User accounts have extended profile?'; -$lang['bf_ext_profile_info'] = 'Check "Extended Profiles" to have extra profile meta-data available option(wip), omiting some default bonfire fields (eg: address).'; - -$lang['bf_yes'] = 'Yes'; -$lang['bf_no'] = 'No'; -$lang['bf_none'] = 'None'; -$lang['bf_id'] = 'ID'; - -$lang['bf_or'] = 'or'; -$lang['bf_size'] = 'Size'; -$lang['bf_files'] = 'Files'; -$lang['bf_file'] = 'File'; - -$lang['bf_with_selected'] = 'With selected'; - -$lang['bf_env_dev'] = 'Development'; -$lang['bf_env_test'] = 'Testing'; -$lang['bf_env_prod'] = 'Production'; - -$lang['bf_show_profiler'] = 'Show Admin Profiler?'; -$lang['bf_show_front_profiler'] = 'Show Front End Profiler?'; - -$lang['bf_cache_not_writable'] = 'The application cache folder is not writable'; - -$lang['bf_password_strength'] = 'Password Strength Settings'; -$lang['bf_password_length_help'] = 'Minimum password length e.g. 8'; -$lang['bf_password_force_numbers'] = 'Should password force numbers?'; -$lang['bf_password_force_symbols'] = 'Should password force symbols?'; -$lang['bf_password_force_mixed_case'] = 'Should password force mixed case?'; -$lang['bf_password_show_labels'] = 'Display password validation labels'; - -//-------------------------------------------------------------------- -// ! USER/PROFILE -//-------------------------------------------------------------------- - -$lang['bf_user'] = 'User'; -$lang['bf_users'] = 'Users'; -$lang['bf_username'] = 'Username'; -$lang['bf_description'] = 'Description'; -$lang['bf_email'] = 'Email'; -$lang['bf_user_settings'] = 'My Profile'; - -//-------------------------------------------------------------------- -// ! -//-------------------------------------------------------------------- - -$lang['bf_both'] = 'both'; -$lang['bf_go_back'] = 'Go Back'; -$lang['bf_new'] = 'New'; -$lang['bf_required_note'] = 'Required fields are in bold.'; -$lang['bf_form_label_required'] = '*'; - -//-------------------------------------------------------------------- -// MY_Model -//-------------------------------------------------------------------- -$lang['bf_model_db_error'] = 'DB Error: '; -$lang['bf_model_no_data'] = 'No data available.'; -$lang['bf_model_invalid_id'] = 'Invalid ID passed to model.'; -$lang['bf_model_no_table'] = 'Model has unspecified database table.'; -$lang['bf_model_fetch_error'] = 'Not enough information to fetch field.'; -$lang['bf_model_count_error'] = 'Not enough information to count results.'; -$lang['bf_model_unique_error'] = 'Not enough information to check uniqueness.'; -$lang['bf_model_find_error'] = 'Not enough information to find by.'; -$lang['bf_model_bad_select'] = 'Invalid selection.'; - -//-------------------------------------------------------------------- -// Contexts -//-------------------------------------------------------------------- -$lang['bf_no_contexts'] = 'The contexts array is not properly setup. Check your application config file.'; -$lang['bf_context_content'] = 'Content'; -$lang['bf_context_reports'] = 'Reports'; -$lang['bf_context_settings'] = 'Settings'; -$lang['bf_context_developer'] = 'Developer'; - -//-------------------------------------------------------------------- -// Activities -//-------------------------------------------------------------------- -$lang['bf_act_settings_saved'] = 'App settings saved from'; -$lang['bf_unauthorized_attempt']= 'unsuccessfully attempted to access a page which required the following permission "%s" from '; - -$lang['bf_keyboard_shortcuts'] = 'Available keyboard shortcuts:'; -$lang['bf_keyboard_shortcuts_none'] = 'There are no keyboard shortcuts assigned.'; -$lang['bf_keyboard_shortcuts_edit'] = 'Update the keyboard shortcuts'; - -//-------------------------------------------------------------------- -// Common -//-------------------------------------------------------------------- -$lang['bf_question_mark'] = '?'; -$lang['bf_language_direction'] = 'ltr'; -$lang['log_intro'] = 'These are your log messages'; - -//-------------------------------------------------------------------- -// Login -//-------------------------------------------------------------------- -$lang['bf_action_register'] = 'Sign Up'; -$lang['bf_forgot_password'] = 'Forgot your password?'; -$lang['bf_remember_me'] = 'Remember me'; - -//-------------------------------------------------------------------- -// Password Help Fields to be used as a warning on register -//-------------------------------------------------------------------- -$lang['bf_password_number_required_help'] = 'Password must contain at least 1 punctuation mark.'; -$lang['bf_password_caps_required_help'] = 'Password must contain at least 1 capital letter.'; -$lang['bf_password_symbols_required_help'] = 'Password must contain at least 1 symbol.'; - -$lang['bf_password_min_length_help'] = 'Password must be at least %s characters long.'; -$lang['bf_password_length'] = 'Password Length'; - -//-------------------------------------------------------------------- -// User Meta examples -//-------------------------------------------------------------------- - -$lang['user_meta_street_name'] = 'Street Name'; -$lang['user_meta_type'] = 'Type'; -$lang['user_meta_country'] = 'Country'; -$lang['user_meta_state'] = 'State'; - -// Activation -//-------------------------------------------------------------------- -$lang['bf_activate_method'] = 'Activation Method'; -$lang['bf_activate_none'] = 'None'; -$lang['bf_activate_email'] = 'Email'; -$lang['bf_activate_admin'] = 'Admin'; -$lang['bf_activate'] = 'Activate'; -$lang['bf_activate_resend'] = 'Resend Activation'; - -$lang['bf_reg_complete_error'] = 'An error occurred completing your registration. Please try again or contact the site administrator for help.'; -$lang['bf_reg_activate_email'] = 'An email containing your activation code has been sent to [EMAIL].'; -$lang['bf_reg_activate_admin'] = 'You will be notified when the site administrator has approved your membership.'; -$lang['bf_reg_activate_none'] = 'Please login to begin using the site.'; -$lang['bf_user_not_active'] = 'User account is not active.'; -$lang['bf_login_activate_title'] = 'Need to activate your account?'; -$lang['bf_login_activate_email'] = 'Have an activation code to enter to activate your membership? Enter it on the [ACCOUNT_ACTIVATE_URL] page.

Need your code again? Request it again on the [ACTIVATE_RESEND_URL] page.'; +per page:'; +$lang['bf_top_number_help'] = 'When viewing reports, how many items should be listed at a time?'; +$lang['bf_home'] = 'Home'; +$lang['bf_site_information'] = 'Site Information'; +$lang['bf_timezone'] = 'Timezone'; +$lang['bf_language'] = 'Language'; +$lang['bf_language_help'] = 'Choose the languages available to the user.'; + +//-------------------------------------------------------------------- +// ! AUTH SETTINGS +//-------------------------------------------------------------------- + +$lang['bf_security'] = 'Security'; +$lang['bf_login_type'] = 'Login Type'; +$lang['bf_login_type_email'] = 'Email Only'; +$lang['bf_login_type_username'] = 'Username Only'; +$lang['bf_allow_register'] = 'Allow User Registrations?'; +$lang['bf_login_type_both'] = 'Email or Username'; +$lang['bf_use_usernames'] = 'User display across bonfire:'; +$lang['bf_use_own_name'] = 'Use Own Name'; +$lang['bf_allow_remember'] = 'Allow \'Remember Me\'?'; +$lang['bf_remember_time'] = 'Remember Users For'; +$lang['bf_week'] = 'Week'; +$lang['bf_weeks'] = 'Weeks'; +$lang['bf_days'] = 'Days'; +$lang['bf_username'] = 'Username'; +$lang['bf_password'] = 'Password'; +$lang['bf_password_confirm'] = 'Password (again)'; +$lang['bf_display_name'] = 'Display Name'; + +//-------------------------------------------------------------------- +// ! CRUD SETTINGS +//-------------------------------------------------------------------- + +$lang['bf_home_page'] = 'Home Page'; +$lang['bf_pages'] = 'Pages'; +$lang['bf_enable_rte'] = 'Enable RTE for pages?'; +$lang['bf_rte_type'] = 'RTE Type'; +$lang['bf_searchable_default'] = 'Searchable by default?'; +$lang['bf_cacheable_default'] = 'Cacheable by default?'; +$lang['bf_track_hits'] = 'Track Page Hits?'; + +$lang['bf_action_save'] = 'Save'; +$lang['bf_action_delete'] = 'Delete'; +$lang['bf_action_cancel'] = 'Cancel'; +$lang['bf_action_download'] = 'Download'; +$lang['bf_action_preview'] = 'Preview'; +$lang['bf_action_search'] = 'Search'; +$lang['bf_action_purge'] = 'Purge'; +$lang['bf_action_restore'] = 'Restore'; +$lang['bf_action_show'] = 'Show'; +$lang['bf_action_login'] = 'Sign In'; +$lang['bf_action_logout'] = 'Sign Out'; +$lang['bf_actions'] = 'Actions'; +$lang['bf_clear'] = 'Clear'; +$lang['bf_action_list'] = 'List'; +$lang['bf_action_create'] = 'Create'; +$lang['bf_action_ban'] = 'Ban'; + +//-------------------------------------------------------------------- +// ! SETTINGS LIB +//-------------------------------------------------------------------- + +$lang['bf_do_check'] = 'Check for updates?'; +$lang['bf_do_check_edge'] = 'Must be enabled to see bleeding edge updates as well.'; + +$lang['bf_update_show_edge'] = 'View bleeding edge updates?'; +$lang['bf_update_info_edge'] = 'Leave unchecked to only check for new tagged updates. Check to see any new commits to the official repository.'; + +$lang['bf_ext_profile_show'] = 'Does User accounts have extended profile?'; +$lang['bf_ext_profile_info'] = 'Check "Extended Profiles" to have extra profile meta-data available option(wip), omiting some default bonfire fields (eg: address).'; + +$lang['bf_yes'] = 'Yes'; +$lang['bf_no'] = 'No'; +$lang['bf_none'] = 'None'; +$lang['bf_id'] = 'ID'; + +$lang['bf_or'] = 'or'; +$lang['bf_size'] = 'Size'; +$lang['bf_files'] = 'Files'; +$lang['bf_file'] = 'File'; + +$lang['bf_with_selected'] = 'With selected'; + +$lang['bf_env_dev'] = 'Development'; +$lang['bf_env_test'] = 'Testing'; +$lang['bf_env_prod'] = 'Production'; + +$lang['bf_show_profiler'] = 'Show Admin Profiler?'; +$lang['bf_show_front_profiler'] = 'Show Front End Profiler?'; + +$lang['bf_cache_not_writable'] = 'The application cache folder is not writable'; + +$lang['bf_password_strength'] = 'Password Strength Settings'; +$lang['bf_password_length_help'] = 'Minimum password length e.g. 8'; +$lang['bf_password_force_numbers'] = 'Should password force numbers?'; +$lang['bf_password_force_symbols'] = 'Should password force symbols?'; +$lang['bf_password_force_mixed_case'] = 'Should password force mixed case?'; +$lang['bf_password_show_labels'] = 'Display password validation labels'; + +//-------------------------------------------------------------------- +// ! USER/PROFILE +//-------------------------------------------------------------------- + +$lang['bf_user'] = 'User'; +$lang['bf_users'] = 'Users'; +$lang['bf_username'] = 'Username'; +$lang['bf_description'] = 'Description'; +$lang['bf_email'] = 'Email'; +$lang['bf_user_settings'] = 'My Profile'; + +//-------------------------------------------------------------------- +// ! +//-------------------------------------------------------------------- + +$lang['bf_both'] = 'both'; +$lang['bf_go_back'] = 'Go Back'; +$lang['bf_new'] = 'New'; +$lang['bf_required_note'] = 'Required fields are in bold.'; +$lang['bf_form_label_required'] = '*'; + +//-------------------------------------------------------------------- +// MY_Model +//-------------------------------------------------------------------- +$lang['bf_model_db_error'] = 'DB Error: '; +$lang['bf_model_no_data'] = 'No data available.'; +$lang['bf_model_invalid_id'] = 'Invalid ID passed to model.'; +$lang['bf_model_no_table'] = 'Model has unspecified database table.'; +$lang['bf_model_fetch_error'] = 'Not enough information to fetch field.'; +$lang['bf_model_count_error'] = 'Not enough information to count results.'; +$lang['bf_model_unique_error'] = 'Not enough information to check uniqueness.'; +$lang['bf_model_find_error'] = 'Not enough information to find by.'; +$lang['bf_model_bad_select'] = 'Invalid selection.'; + +//-------------------------------------------------------------------- +// Contexts +//-------------------------------------------------------------------- +$lang['bf_no_contexts'] = 'The contexts array is not properly setup. Check your application config file.'; +$lang['bf_context_content'] = 'Content'; +$lang['bf_context_reports'] = 'Reports'; +$lang['bf_context_settings'] = 'Settings'; +$lang['bf_context_developer'] = 'Developer'; + +//-------------------------------------------------------------------- +// Activities +//-------------------------------------------------------------------- +$lang['bf_act_settings_saved'] = 'App settings saved from'; +$lang['bf_unauthorized_attempt']= 'unsuccessfully attempted to access a page which required the following permission "%s" from '; + +$lang['bf_keyboard_shortcuts'] = 'Available keyboard shortcuts:'; +$lang['bf_keyboard_shortcuts_none'] = 'There are no keyboard shortcuts assigned.'; +$lang['bf_keyboard_shortcuts_edit'] = 'Update the keyboard shortcuts'; + +//-------------------------------------------------------------------- +// Common +//-------------------------------------------------------------------- +$lang['bf_question_mark'] = '?'; +$lang['bf_language_direction'] = 'ltr'; +$lang['log_intro'] = 'These are your log messages'; + +//-------------------------------------------------------------------- +// Login +//-------------------------------------------------------------------- +$lang['bf_action_register'] = 'Sign Up'; +$lang['bf_forgot_password'] = 'Forgot your password?'; +$lang['bf_remember_me'] = 'Remember me'; + +//-------------------------------------------------------------------- +// Password Help Fields to be used as a warning on register +//-------------------------------------------------------------------- +$lang['bf_password_number_required_help'] = 'Password must contain at least 1 punctuation mark.'; +$lang['bf_password_caps_required_help'] = 'Password must contain at least 1 capital letter.'; +$lang['bf_password_symbols_required_help'] = 'Password must contain at least 1 symbol.'; + +$lang['bf_password_min_length_help'] = 'Password must be at least %s characters long.'; +$lang['bf_password_length'] = 'Password Length'; + +//-------------------------------------------------------------------- +// User Meta examples +//-------------------------------------------------------------------- + +$lang['user_meta_street_name'] = 'Street Name'; +$lang['user_meta_type'] = 'Type'; +$lang['user_meta_country'] = 'Country'; +$lang['user_meta_state'] = 'State'; + +// Activation +//-------------------------------------------------------------------- +$lang['bf_activate_method'] = 'Activation Method'; +$lang['bf_activate_none'] = 'None'; +$lang['bf_activate_email'] = 'Email'; +$lang['bf_activate_admin'] = 'Admin'; +$lang['bf_activate'] = 'Activate'; +$lang['bf_activate_resend'] = 'Resend Activation'; + +$lang['bf_reg_complete_error'] = 'An error occurred completing your registration. Please try again or contact the site administrator for help.'; +$lang['bf_reg_activate_email'] = 'An email containing your activation code has been sent to [EMAIL].'; +$lang['bf_reg_activate_admin'] = 'You will be notified when the site administrator has approved your membership.'; +$lang['bf_reg_activate_none'] = 'Please login to begin using the site.'; +$lang['bf_user_not_active'] = 'User account is not active.'; +$lang['bf_login_activate_title'] = 'Need to activate your account?'; +$lang['bf_login_activate_email'] = 'Have an activation code to enter to activate your membership? Enter it on the [ACCOUNT_ACTIVATE_URL] page.

Need your code again? Request it again on the [ACTIVATE_RESEND_URL] page.'; diff --git a/bonfire/application/third_party/MX/Base.php b/bonfire/application/third_party/MX/Base.php index 8c8033dca..08e5c8a1e 100644 --- a/bonfire/application/third_party/MX/Base.php +++ b/bonfire/application/third_party/MX/Base.php @@ -1,60 +1,60 @@ -load = new MX_Loader; - - /* autoload module items */ - self::$APP->load->_autoloader(array()); - } -} - -/* create the application object */ +load = new MX_Loader; + + /* autoload module items */ + self::$APP->load->_autoloader(array()); + } +} + +/* create the application object */ new CI; \ No newline at end of file diff --git a/bonfire/application/third_party/MX/Config.php b/bonfire/application/third_party/MX/Config.php index 54d79cfc1..c1eb6b346 100644 --- a/bonfire/application/third_party/MX/Config.php +++ b/bonfire/application/third_party/MX/Config.php @@ -1,71 +1,71 @@ -is_loaded, TRUE)) return $this->item($file); - - $_module OR $_module = CI::$APP->router->fetch_module(); - list($path, $file) = Modules::find($file, $_module, 'config/'); - - if ($path === FALSE) { - parent::load($file, $use_sections, $fail_gracefully); - return $this->item($file); - } - - if ($config = Modules::load_file($file, $path, 'config')) { - - /* reference to the config array */ - $current_config =& $this->config; - - if ($use_sections === TRUE) { - - if (isset($current_config[$file])) { - $current_config[$file] = array_merge($current_config[$file], $config); - } else { - $current_config[$file] = $config; - } - - } else { - $current_config = array_merge($current_config, $config); - } - $this->is_loaded[] = $file; - unset($config); - return $this->item($file); - } - } +is_loaded, TRUE)) return $this->item($file); + + $_module OR $_module = CI::$APP->router->fetch_module(); + list($path, $file) = Modules::find($file, $_module, 'config/'); + + if ($path === FALSE) { + parent::load($file, $use_sections, $fail_gracefully); + return $this->item($file); + } + + if ($config = Modules::load_file($file, $path, 'config')) { + + /* reference to the config array */ + $current_config =& $this->config; + + if ($use_sections === TRUE) { + + if (isset($current_config[$file])) { + $current_config[$file] = array_merge($current_config[$file], $config); + } else { + $current_config[$file] = $config; + } + + } else { + $current_config = array_merge($current_config, $config); + } + $this->is_loaded[] = $file; + unset($config); + return $this->item($file); + } + } } \ No newline at end of file diff --git a/bonfire/application/third_party/MX/Lang.php b/bonfire/application/third_party/MX/Lang.php index a5086301b..209766dc5 100644 --- a/bonfire/application/third_party/MX/Lang.php +++ b/bonfire/application/third_party/MX/Lang.php @@ -1,70 +1,70 @@ -load($_lang); - return $this->language; - } - - $deft_lang = CI::$APP->config->item('language'); - $idiom = ($lang == '') ? $deft_lang : $lang; - - if (in_array($langfile.'_lang'.EXT, $this->is_loaded, TRUE)) - return $this->language; - - $_module OR $_module = CI::$APP->router->fetch_module(); - list($path, $_langfile) = Modules::find($langfile.'_lang', $_module, 'language/'.$idiom.'/'); - - if ($path === FALSE) { - - if ($lang = parent::load($langfile, $lang, $return, $add_suffix, $alt_path)) return $lang; - - } else { - - if($lang = Modules::load_file($_langfile, $path, 'lang')) { - if ($return) return $lang; - $this->language = array_merge($this->language, $lang); - $this->is_loaded[] = $langfile.'_lang'.EXT; - unset($lang); - } - } - - return $this->language; - } +load($_lang); + return $this->language; + } + + $deft_lang = CI::$APP->config->item('language'); + $idiom = ($lang == '') ? $deft_lang : $lang; + + if (in_array($langfile.'_lang'.EXT, $this->is_loaded, TRUE)) + return $this->language; + + $_module OR $_module = CI::$APP->router->fetch_module(); + list($path, $_langfile) = Modules::find($langfile.'_lang', $_module, 'language/'.$idiom.'/'); + + if ($path === FALSE) { + + if ($lang = parent::load($langfile, $lang, $return, $add_suffix, $alt_path)) return $lang; + + } else { + + if($lang = Modules::load_file($_langfile, $path, 'lang')) { + if ($return) return $lang; + $this->language = array_merge($this->language, $lang); + $this->is_loaded[] = $langfile.'_lang'.EXT; + unset($lang); + } + } + + return $this->language; + } } \ No newline at end of file diff --git a/bonfire/application/third_party/MX/Loader.php b/bonfire/application/third_party/MX/Loader.php index 369d0efba..379d38b2a 100644 --- a/bonfire/application/third_party/MX/Loader.php +++ b/bonfire/application/third_party/MX/Loader.php @@ -1,393 +1,393 @@ -_module = CI::$APP->router->fetch_module(); - - /* add this module path to the loader variables */ - $this->_add_module_paths($this->_module); - } - - /** Initialize the module **/ - public function _init($controller) { - - /* references to ci loader variables */ - foreach (get_class_vars('CI_Loader') as $var => $val) { - if ($var != '_ci_ob_level') $this->$var =& CI::$APP->load->$var; - } - - /* set a reference to the module controller */ - $this->controller = $controller; - $this->__construct(); - } - - /** Add a module path loader variables **/ - public function _add_module_paths($module = '') { - - if (empty($module)) return; - - foreach (Modules::$locations as $location => $offset) { - - /* only add a module path if it exists */ - if (is_dir($module_path = $location.$module.'/')) { - array_unshift($this->_ci_model_paths, $module_path); - } - } - } - - /** Load a module config file **/ - public function config($file = 'config', $use_sections = FALSE, $fail_gracefully = FALSE) { - return CI::$APP->config->load($file, $use_sections, $fail_gracefully, $this->_module); - } - - /** Load the database drivers **/ - public function database($params = '', $return = FALSE, $active_record = NULL) { - - if (class_exists('CI_DB', FALSE) AND $return == FALSE AND $active_record == NULL AND isset(CI::$APP->db) AND is_object(CI::$APP->db)) - return; - - require_once BASEPATH.'database/DB'.EXT; - - if ($return === TRUE) return DB($params, $active_record); - - CI::$APP->db = DB($params, $active_record); - - return CI::$APP->db; - } - - /** Load a module helper **/ - public function helper($helper) { - - if (is_array($helper)) return $this->helpers($helper); - - if (isset($this->_ci_helpers[$helper])) return; - - list($path, $_helper) = Modules::find($helper.'_helper', $this->_module, 'helpers/'); - - if ($path === FALSE) return parent::helper($helper); - - Modules::load_file($_helper, $path); - $this->_ci_helpers[$_helper] = TRUE; - } - - /** Load an array of helpers **/ - public function helpers($helpers) { - foreach ($helpers as $_helper) $this->helper($_helper); - } - - /** Load a module language file **/ - public function language($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') { - return CI::$APP->lang->load($langfile, $idiom, $return, $add_suffix, $alt_path, $this->_module); - } - - public function languages($languages) { - foreach($languages as $_language) $this->language($language); - } - - /** Load a module library **/ - public function library($library, $params = NULL, $object_name = NULL) { - - if (is_array($library)) return $this->libraries($library); - - $class = strtolower(basename($library)); - - if (isset($this->_ci_classes[$class]) AND $_alias = $this->_ci_classes[$class]) - return CI::$APP->$_alias; - - ($_alias = strtolower($object_name)) OR $_alias = $class; - - list($path, $_library) = Modules::find($library, $this->_module, 'libraries/'); - - /* load library config file as params */ - if ($params == NULL) { - list($path2, $file) = Modules::find($_alias, $this->_module, 'config/'); - ($path2) AND $params = Modules::load_file($file, $path2, 'config'); - } - - if ($path === FALSE) { - - $this->_ci_load_class($library, $params, $object_name); - $_alias = $this->_ci_classes[$class]; - - } else { - - Modules::load_file($_library, $path); - - $library = ucfirst($_library); - CI::$APP->$_alias = new $library($params); - - $this->_ci_classes[$class] = $_alias; - } - - return CI::$APP->$_alias; - } - - /** Load an array of libraries **/ - public function libraries($libraries) { - foreach ($libraries as $_library) $this->library($_library); - } - - /** Load a module model **/ - public function model($model, $object_name = NULL, $connect = FALSE) { - - if (is_array($model)) return $this->models($model); - - ($_alias = $object_name) OR $_alias = basename($model); - - if (in_array($_alias, $this->_ci_models, TRUE)) - return CI::$APP->$_alias; - - /* check module */ - list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/'); - - if ($path == FALSE) { - - /* check application & packages */ - parent::model($model, $object_name); - - } else { - - class_exists('CI_Model', FALSE) OR load_class('Model', 'core'); - - if ($connect !== FALSE AND ! class_exists('CI_DB', FALSE)) { - if ($connect === TRUE) $connect = ''; - $this->database($connect, FALSE, TRUE); - } - - Modules::load_file($_model, $path); - - $model = ucfirst($_model); - CI::$APP->$_alias = new $model(); - - $this->_ci_models[] = $_alias; - } - - return CI::$APP->$_alias; - } - - /** Load an array of models **/ - public function models($models) { - foreach ($models as $_model) $this->model($_model); - } - - /** Load a module controller **/ - public function module($module, $params = NULL) { - - if (is_array($module)) return $this->modules($module); - - $_alias = strtolower(basename($module)); - CI::$APP->$_alias = Modules::load(array($module => $params)); - return CI::$APP->$_alias; - } - - /** Load an array of controllers **/ - public function modules($modules) { - foreach ($modules as $_module) $this->module($_module); - } - - /** Load a module plugin **/ - public function plugin($plugin) { - - if (is_array($plugin)) return $this->plugins($plugin); - - if (isset($this->_ci_plugins[$plugin])) - return; - - list($path, $_plugin) = Modules::find($plugin.'_pi', $this->_module, 'plugins/'); - - if ($path === FALSE) return; - - Modules::load_file($_plugin, $path); - $this->_ci_plugins[$plugin] = TRUE; - } - - /** Load an array of plugins **/ - public function plugins($plugins) { - foreach ($plugins as $_plugin) $this->plugin($_plugin); - } - - /** Load a module view **/ - public function view($view, $vars = array(), $return = FALSE) { - list($path, $view) = Modules::find($view, $this->_module, 'views/'); - $this->_ci_view_path = $path; - return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); - } - - public function _ci_is_instance() {} - - public function _ci_get_component($component) { - return CI::$APP->$component; - } - - public function __get($class) { - return (isset($this->controller)) ? $this->controller->$class : CI::$APP->$class; - } - - public function _ci_load($_ci_data) { - - foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) { - $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; - } - - if ($_ci_path == '') { - $_ci_file = strpos($_ci_view, '.') ? $_ci_view : $_ci_view.EXT; - $_ci_path = $this->_ci_view_path.$_ci_file; - } else { - $_ci_file = basename($_ci_path); - } - - if ( ! file_exists($_ci_path)) - show_error('Unable to load the requested file: '.$_ci_file); - - if (is_array($_ci_vars)) - $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); - - extract($this->_ci_cached_vars); - - ob_start(); - - if ((bool) @ini_get('short_open_tag') === FALSE AND CI::$APP->config->item('rewrite_short_tags') == TRUE) { - echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' $this->_ci_ob_level + 1) { - ob_end_flush(); - } else { - CI::$APP->output->append_output(ob_get_clean()); - } - } - - /** Autoload module items **/ - public function _autoloader($autoload) { - - $path = FALSE; - - if ($this->_module) { - - list($path, $file) = Modules::find('constants', $this->_module, 'config/'); - - /* module constants file */ - if ($path != FALSE) { - include_once $path.$file.EXT; - } - - list($path, $file) = Modules::find('autoload', $this->_module, 'config/'); - - /* module autoload file */ - if ($path != FALSE) { - $autoload = array_merge(Modules::load_file($file, $path, 'autoload'), $autoload); - } - } - - /* nothing to do */ - if (count($autoload) == 0) return; - - /* autoload package paths */ - if (isset($autoload['packages'])) { - foreach ($autoload['packages'] as $package_path) { - $this->add_package_path($package_path); - } - } - - /* autoload config */ - if (isset($autoload['config'])) { - foreach ($autoload['config'] as $config) { - $this->config($config); - } - } - - /* autoload helpers, plugins, languages */ - foreach (array('helper', 'plugin', 'language') as $type) { - if (isset($autoload[$type])){ - foreach ($autoload[$type] as $item) { - $this->$type($item); - } - } - } - - /* autoload database & libraries */ - if (isset($autoload['libraries'])) { - if (in_array('database', $autoload['libraries'])) { - /* autoload database */ - if ( ! $db = CI::$APP->config->item('database')) { - $db['params'] = 'default'; - $db['active_record'] = TRUE; - } - $this->database($db['params'], FALSE, $db['active_record']); - $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); - } - - /* autoload libraries */ - foreach ($autoload['libraries'] as $library) { - $this->library($library); - } - } - - /* autoload models */ - if (isset($autoload['model'])) { - foreach ($autoload['model'] as $model => $alias) { - (is_numeric($model)) ? $this->model($alias) : $this->model($model, $alias); - } - } - - /* autoload module controllers */ - if (isset($autoload['modules'])) { - foreach ($autoload['modules'] as $controller) { - ($controller != $this->_module) AND $this->module($controller); - } - } - } -} - -/** load the CI class for Modular Separation **/ +_module = CI::$APP->router->fetch_module(); + + /* add this module path to the loader variables */ + $this->_add_module_paths($this->_module); + } + + /** Initialize the module **/ + public function _init($controller) { + + /* references to ci loader variables */ + foreach (get_class_vars('CI_Loader') as $var => $val) { + if ($var != '_ci_ob_level') $this->$var =& CI::$APP->load->$var; + } + + /* set a reference to the module controller */ + $this->controller = $controller; + $this->__construct(); + } + + /** Add a module path loader variables **/ + public function _add_module_paths($module = '') { + + if (empty($module)) return; + + foreach (Modules::$locations as $location => $offset) { + + /* only add a module path if it exists */ + if (is_dir($module_path = $location.$module.'/')) { + array_unshift($this->_ci_model_paths, $module_path); + } + } + } + + /** Load a module config file **/ + public function config($file = 'config', $use_sections = FALSE, $fail_gracefully = FALSE) { + return CI::$APP->config->load($file, $use_sections, $fail_gracefully, $this->_module); + } + + /** Load the database drivers **/ + public function database($params = '', $return = FALSE, $active_record = NULL) { + + if (class_exists('CI_DB', FALSE) AND $return == FALSE AND $active_record == NULL AND isset(CI::$APP->db) AND is_object(CI::$APP->db)) + return; + + require_once BASEPATH.'database/DB'.EXT; + + if ($return === TRUE) return DB($params, $active_record); + + CI::$APP->db = DB($params, $active_record); + + return CI::$APP->db; + } + + /** Load a module helper **/ + public function helper($helper) { + + if (is_array($helper)) return $this->helpers($helper); + + if (isset($this->_ci_helpers[$helper])) return; + + list($path, $_helper) = Modules::find($helper.'_helper', $this->_module, 'helpers/'); + + if ($path === FALSE) return parent::helper($helper); + + Modules::load_file($_helper, $path); + $this->_ci_helpers[$_helper] = TRUE; + } + + /** Load an array of helpers **/ + public function helpers($helpers) { + foreach ($helpers as $_helper) $this->helper($_helper); + } + + /** Load a module language file **/ + public function language($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') { + return CI::$APP->lang->load($langfile, $idiom, $return, $add_suffix, $alt_path, $this->_module); + } + + public function languages($languages) { + foreach($languages as $_language) $this->language($language); + } + + /** Load a module library **/ + public function library($library, $params = NULL, $object_name = NULL) { + + if (is_array($library)) return $this->libraries($library); + + $class = strtolower(basename($library)); + + if (isset($this->_ci_classes[$class]) AND $_alias = $this->_ci_classes[$class]) + return CI::$APP->$_alias; + + ($_alias = strtolower($object_name)) OR $_alias = $class; + + list($path, $_library) = Modules::find($library, $this->_module, 'libraries/'); + + /* load library config file as params */ + if ($params == NULL) { + list($path2, $file) = Modules::find($_alias, $this->_module, 'config/'); + ($path2) AND $params = Modules::load_file($file, $path2, 'config'); + } + + if ($path === FALSE) { + + $this->_ci_load_class($library, $params, $object_name); + $_alias = $this->_ci_classes[$class]; + + } else { + + Modules::load_file($_library, $path); + + $library = ucfirst($_library); + CI::$APP->$_alias = new $library($params); + + $this->_ci_classes[$class] = $_alias; + } + + return CI::$APP->$_alias; + } + + /** Load an array of libraries **/ + public function libraries($libraries) { + foreach ($libraries as $_library) $this->library($_library); + } + + /** Load a module model **/ + public function model($model, $object_name = NULL, $connect = FALSE) { + + if (is_array($model)) return $this->models($model); + + ($_alias = $object_name) OR $_alias = basename($model); + + if (in_array($_alias, $this->_ci_models, TRUE)) + return CI::$APP->$_alias; + + /* check module */ + list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/'); + + if ($path == FALSE) { + + /* check application & packages */ + parent::model($model, $object_name); + + } else { + + class_exists('CI_Model', FALSE) OR load_class('Model', 'core'); + + if ($connect !== FALSE AND ! class_exists('CI_DB', FALSE)) { + if ($connect === TRUE) $connect = ''; + $this->database($connect, FALSE, TRUE); + } + + Modules::load_file($_model, $path); + + $model = ucfirst($_model); + CI::$APP->$_alias = new $model(); + + $this->_ci_models[] = $_alias; + } + + return CI::$APP->$_alias; + } + + /** Load an array of models **/ + public function models($models) { + foreach ($models as $_model) $this->model($_model); + } + + /** Load a module controller **/ + public function module($module, $params = NULL) { + + if (is_array($module)) return $this->modules($module); + + $_alias = strtolower(basename($module)); + CI::$APP->$_alias = Modules::load(array($module => $params)); + return CI::$APP->$_alias; + } + + /** Load an array of controllers **/ + public function modules($modules) { + foreach ($modules as $_module) $this->module($_module); + } + + /** Load a module plugin **/ + public function plugin($plugin) { + + if (is_array($plugin)) return $this->plugins($plugin); + + if (isset($this->_ci_plugins[$plugin])) + return; + + list($path, $_plugin) = Modules::find($plugin.'_pi', $this->_module, 'plugins/'); + + if ($path === FALSE) return; + + Modules::load_file($_plugin, $path); + $this->_ci_plugins[$plugin] = TRUE; + } + + /** Load an array of plugins **/ + public function plugins($plugins) { + foreach ($plugins as $_plugin) $this->plugin($_plugin); + } + + /** Load a module view **/ + public function view($view, $vars = array(), $return = FALSE) { + list($path, $view) = Modules::find($view, $this->_module, 'views/'); + $this->_ci_view_path = $path; + return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); + } + + public function _ci_is_instance() {} + + public function _ci_get_component($component) { + return CI::$APP->$component; + } + + public function __get($class) { + return (isset($this->controller)) ? $this->controller->$class : CI::$APP->$class; + } + + public function _ci_load($_ci_data) { + + foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) { + $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; + } + + if ($_ci_path == '') { + $_ci_file = strpos($_ci_view, '.') ? $_ci_view : $_ci_view.EXT; + $_ci_path = $this->_ci_view_path.$_ci_file; + } else { + $_ci_file = basename($_ci_path); + } + + if ( ! file_exists($_ci_path)) + show_error('Unable to load the requested file: '.$_ci_file); + + if (is_array($_ci_vars)) + $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); + + extract($this->_ci_cached_vars); + + ob_start(); + + if ((bool) @ini_get('short_open_tag') === FALSE AND CI::$APP->config->item('rewrite_short_tags') == TRUE) { + echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace(' $this->_ci_ob_level + 1) { + ob_end_flush(); + } else { + CI::$APP->output->append_output(ob_get_clean()); + } + } + + /** Autoload module items **/ + public function _autoloader($autoload) { + + $path = FALSE; + + if ($this->_module) { + + list($path, $file) = Modules::find('constants', $this->_module, 'config/'); + + /* module constants file */ + if ($path != FALSE) { + include_once $path.$file.EXT; + } + + list($path, $file) = Modules::find('autoload', $this->_module, 'config/'); + + /* module autoload file */ + if ($path != FALSE) { + $autoload = array_merge(Modules::load_file($file, $path, 'autoload'), $autoload); + } + } + + /* nothing to do */ + if (count($autoload) == 0) return; + + /* autoload package paths */ + if (isset($autoload['packages'])) { + foreach ($autoload['packages'] as $package_path) { + $this->add_package_path($package_path); + } + } + + /* autoload config */ + if (isset($autoload['config'])) { + foreach ($autoload['config'] as $config) { + $this->config($config); + } + } + + /* autoload helpers, plugins, languages */ + foreach (array('helper', 'plugin', 'language') as $type) { + if (isset($autoload[$type])){ + foreach ($autoload[$type] as $item) { + $this->$type($item); + } + } + } + + /* autoload database & libraries */ + if (isset($autoload['libraries'])) { + if (in_array('database', $autoload['libraries'])) { + /* autoload database */ + if ( ! $db = CI::$APP->config->item('database')) { + $db['params'] = 'default'; + $db['active_record'] = TRUE; + } + $this->database($db['params'], FALSE, $db['active_record']); + $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); + } + + /* autoload libraries */ + foreach ($autoload['libraries'] as $library) { + $this->library($library); + } + } + + /* autoload models */ + if (isset($autoload['model'])) { + foreach ($autoload['model'] as $model => $alias) { + (is_numeric($model)) ? $this->model($alias) : $this->model($model, $alias); + } + } + + /* autoload module controllers */ + if (isset($autoload['modules'])) { + foreach ($autoload['modules'] as $controller) { + ($controller != $this->_module) AND $this->module($controller); + } + } + } +} + +/** load the CI class for Modular Separation **/ (class_exists('CI', FALSE)) OR require dirname(__FILE__).'/Ci.php'; \ No newline at end of file diff --git a/bonfire/application/views/permission_upgrade/index.php b/bonfire/application/views/permission_upgrade/index.php index cbe48c759..647925e6a 100644 --- a/bonfire/application/views/permission_upgrade/index.php +++ b/bonfire/application/views/permission_upgrade/index.php @@ -1 +1 @@ -

Bonfire Permissions Upgrade.

+

Bonfire Permissions Upgrade.

diff --git a/bonfire/themes/default/index.php b/bonfire/themes/default/index.php index be8e2b067..975990636 100644 --- a/bonfire/themes/default/index.php +++ b/bonfire/themes/default/index.php @@ -1,11 +1,11 @@ - - -
- - - - + + +
+ + + + diff --git a/install/controllers/install.php b/install/controllers/install.php index 79f095437..bd8e1e5bb 100644 --- a/install/controllers/install.php +++ b/install/controllers/install.php @@ -1,638 +1,638 @@ -load->helper('form'); - - $this->output->enable_profiler(false); - - $this->lang->load('application'); - $this->lang->load('install'); - - // check if the app is installed - $this->load->config('application'); - - $this->load->helper('install'); - - $this->cURL_check(); - } - - //-------------------------------------------------------------------- - - public function index() - { - if ($this->is_installed()) - { - $this->load->view('install/installed'); - } - else - { - $this->load->library('form_validation'); - $this->form_validation->set_error_delimiters('', ''); - //$this->form_validation->CI =& $this; - $this->form_validation->set_rules('environment', lang('in_environment'), 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('hostname', lang('in_host'), 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('username', lang('bf_username'), 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('database', lang('in_database'), 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('db_prefix', lang('in_prefix'), 'trim|strip_tags|xss_clean'); - - $this->startup_check(); - - if ($this->form_validation->run() !== false) - { - // Write the database config files - $this->load->helper('config_file'); - - $dbname = strip_tags($this->input->post('database')); - - // get the chosen environment - $environment = strip_tags($this->input->post('environment')); - - $data = array( - 'main' => array( - 'hostname' => strip_tags($this->input->post('hostname')), - 'username' => strip_tags($this->input->post('username')), - 'password' => strip_tags($this->input->post('password')), - 'database' => $dbname, - 'dbprefix' => strip_tags($this->input->post('db_prefix')) - ), - 'environment' => $environment, - ); - - $this->session->set_userdata('db_data', $data); - if ($this->session->userdata('db_data')) - { - // - // Make sure the database exists, otherwise create it. - // CRAP! dbutil and database_forge require a running database driver, - // which seems to require a valid database, which we don't have. To get - // past this, we'll deal only with MySQL for now and create things - // the old fashioned way. Eventually, we'll make this more generic. - // - $db = @mysql_connect(strip_tags($this->input->post('hostname')), strip_tags($this->input->post('username')), strip_tags($this->input->post('password'))); - - if (!$db) - { - $this->vdata['error'] = message(lang('in_db_no_connect').': '. mysql_error(), 'error'); - } - else - { - $db_selected = mysql_select_db($dbname, $db); - if (!$db_selected) - { - // Table doesn't exist, so create it. - if (!mysql_query("CREATE DATABASE $dbname", $db)) - { - die('Unable to create database: '. mysql_error()); - } - mysql_close($db); - } - - redirect('account'); - } - } - else - { - $this->vdata['attention'] = message(sprintf(lang('in_settings_save_error'), $environment), 'attention'); - } - } - - $this->load->view('install/index', $this->vdata); - } - } - - //-------------------------------------------------------------------- - - public function account() - { - $view = 'install/account'; - - if ($this->input->post('submit')) - { - $this->load->library('form_validation'); - $this->form_validation->set_error_delimiters('', ''); - //$this->form_validation->CI =& $this; - - $this->form_validation->set_rules('site_title', lang('in_site_title'), 'required|trim|strip_tags|min_length[1]|xss_clean'); - $this->form_validation->set_rules('username', lang('in_username'), 'required|trim|strip_tags|xss_clean'); - $this->form_validation->set_rules('password', lang('in_password'), 'required|trim|strip_tags|alpha_dash|min_length[8]|xss_clean'); - $this->form_validation->set_rules('pass_confirm', lang('in_password_again'), 'required|trim|matches[password]'); - $this->form_validation->set_rules('email', lang('in_email'), 'required|trim|strip_tags|valid_email|xss_clean'); - - if ($this->form_validation->run() !== false) - { - if ($this->setup()) - { - $this->vdata['success'] = message(lang('in_success_notification'), 'success'); - - $success_data = array(); - // check if we are running in a sub directory - $url_path = parse_url(base_url(), PHP_URL_PATH); - $base_path = preg_replace('#/install/#', '', $url_path); - if (!empty($base_path)) - { - $this->vdata['rebase'] = $base_path.'/'; - } - - $view = 'install/success'; - } - else - { - $this->vdata['error']= message(lang('in_db_setup_error').': '. $this->errors, 'error'); - } - } - } - - // if $this->curl_error = 1, show warning on "account" page of setup - $this->vdata['curl_error'] = $this->curl_error; - - $this->load->view($view, $this->vdata); - } - - //-------------------------------------------------------------------- - - public function rename_folder() - { - $folder = FCPATH; - - // This should always have the /install in it, but - // better safe than sorry. - if (strpos($folder, 'install') === false) - { - $folder .= '/install/'; - } - - $new_folder = str_replace('install/', 'install_bak', $folder); - - rename($folder, $new_folder); - - $url = str_replace('install', '', base_url()); - $url = str_replace('http://', '', $url); - $url = str_replace('//', '/', $url); - $url = 'http://'. $url; - - redirect($url); - } - - //-------------------------------------------------------------------- - - //-------------------------------------------------------------------- - // !PRIVATE METHODS - //-------------------------------------------------------------------- - - /* - Method: is_installed() - - Performs some basic checks to see if maybe, just maybe, the - user has already installed the application and just hasn't - moved the install folder.... - */ - private function is_installed() - { - // Does the database config exist? - // If not, then we definitely haven't installed yet. - if (!file_exists('../bonfire/application/config/development/database.php')) - { - return false; - } - - require('../bonfire/application/config/development/database.php'); - - // If the $db['default'] doesn't exist then we can't - // load our database. - if (!isset($db) || !isset($db['default'])) - { - return false; - } - - $this->load->database($db['default']); - - // Does the users table exist? - if (!$this->db->table_exists('users')) - { - return false; - } - - // Make sure at least one row exists in the users table. - $query = $this->db->get('users'); - - if ($query->num_rows() == 0) - { - return false; - } - - return true; - } - - //-------------------------------------------------------------------- - - /* - Method: startup_check() - - Verifies that the folders and files needed are writeable. Sets - 'startup_errors' as a string in the template if not. - */ - private function startup_check() - { - $errors = ''; - $folder_errors = ''; - $file_errors = ''; - - // Check Folders - foreach ($this->writeable_folders as $folder) - { - $full_folder = FCPATH . '..' . $folder; - - @chmod($full_folder, 0777); - if (!is_dir($full_folder) || !is_writeable($full_folder)) - { - $folder_errors .= "
  • $folder
  • "; - } - } - - if (!empty($folder_errors)) - { - $errors = '

    '.lang('in_writeable_directories_message').':

      ' . $folder_errors .'
    '; - } - - // Check files - foreach ($this->writeable_files as $file) - { - @chmod(FCPATH . '..' . $file, 0666); - if (!is_writeable(FCPATH . '..' . $file)) - { - $file_errors .= "
  • $file
  • "; - } - } - - if (!empty($file_errors)) - { - $errors .= '

    '.lang('in_writeable_files_message').':

      ' . $file_errors .'
    '; - } - - // Make it available to the template lib if there are errors - if (!empty($errors)) - { - $this->vdata['startup_errors'] = $errors; - } - - unset($errors, $folder_errors, $file_errors); - - /* - Copies generic file versions to their appropriate spots. - This provides a safe way to perform upgrades, as well - as simplifying what will need to be modified when some - sweeping changes are made. - */ - } - - //-------------------------------------------------------------------- - - - private function setup() - { - - // Save the DB details - $data = $this->session->userdata("db_data"); - $environment = $data['environment']; - unset($data['environment']); - - $this->load->helper('config_file'); - - write_db_config($data); - - if (!file_exists(FCPATH . $this->app_path . 'config/development/database.php') && is_writeable(FCPATH . $this->app_path . 'config/')) - { - // Database - copy(FCPATH . $this->app_path . 'config/database.php', FCPATH . $this->app_path . 'config/'.$environment.'/database.php'); - } - - $server = $data['main']['hostname']; - $username = $data['main']['username']; - $password = $data['main']['password']; - $database = $data['main']['database']; - $dbprefix = $data['main']['dbprefix']; - - if( !$this->db = mysql_connect($server, $username, $password) ) - { - return array('status' => FALSE, 'message' => lang('in_db_no_connect')); - } - - // use the entered Database settings to connect before calling the Migrations - $dsn = 'mysql://'.$username.':'.$password.'@'.$server.'/'.$database.'?dbprefix='.$dbprefix.'&db_debug=TRUE'; - $this->load->database($dsn); - - // - // Now install the database tables. - // - $this->load->library('Migrations'); - - if (!$this->migrations->install()) - { - $this->errors = $this->migrations->error; - return false; - } - - // get the list of custom modules in the main application - $module_list = $this->get_module_versions(); - - if (is_array($module_list) && count($module_list)) - { - foreach($module_list as $module_name => $module_detail) - { - // install the migrations for the custom modules - if (!$this->migrations->install($module_name.'_')) - { - $this->errors = $this->migrations->error; - return false; - } - } - } - - // - // Save the information to the settings table - // - - $settings = array( - 'site.title' => $this->input->post('site_title'), - 'site.system_email' => $this->input->post('email'), - 'updates.do_check' => $this->curl_update, - 'updates.bleeding_edge' => $this->curl_update - ); - - foreach ($settings as $key => $value) - { - $setting_rec = array('name' => $key, 'module' => 'core', 'value' => $value); - - $this->db->where('name', $key); - if ($this->db->update('settings', $setting_rec) == false) - { - $this->errors = lang('in_db_settings_error'); - return false; - } - } - - // update the emailer serder_email - $setting_rec = array('name' => 'sender_email', 'module' => 'email', 'value' => $this->input->post('email')); - - $this->db->where('name', 'sender_email'); - if ($this->db->update('settings', $setting_rec) == false) - { - $this->errors = lang('in_db_settings_error'); - return false; - } - - // - // Install the user in the users table so they can actually login. - // - $data = array( - 'role_id' => 1, - 'email' => $this->input->post('email'), - 'username' => $this->input->post('username'), - 'active' => 1, - ); - list($password, $salt) = $this->hash_password($this->input->post('password')); - - $data['password_hash'] = $password; - $data['salt'] = $salt; - - if ($this->db->insert('users', $data) == false) - { - $this->errors = lang('in_db_account_error'); - return false; - } - - // Create a unique encryption key - $this->load->helper('string'); - $key = random_string('unique', 40); - - $config_array = array('encryption_key' => $key); - - // check the mod_rewrite setting - $config_array['index_page'] = $this->rewrite_check() ? '' : 'index.php'; - - write_config('config', $config_array); - - // Reverse Folders - foreach ($this->reverse_writeable_folders as $folder) - { - @chmod(FCPATH . '..' . $folder, 0775); - } - - // We made it to the end, so we're good to go! - return true; - } - - //-------------------------------------------------------------------- - - /* - Method: cURL_check() - - Verifies that cURL is enabled as a PHP extension. Sets - 'curl_update' to 0 if not. - */ - private function cURL_check() - { - if (!function_exists('curl_version')) - { - $this->curl_error = 1; - $this->curl_update = 0; - } - } - - - //-------------------------------------------------------------------- - - /* - Method: rewrite_check() - - Verifies that mod_rewrite is enabled as a PHP extension. - */ - private function rewrite_check() - { - if (!function_exists('rewrite_check')) - { - ob_start(); - phpinfo(INFO_MODULES); - $contents = ob_get_clean(); - return strpos($contents, 'mod_rewrite') !== false; - } - - }//end rewrite_check() - - /* - Method: hash_password() - - Generates a new salt and password hash for the given password. - - Parameters: - $old - The password to hash. - - Returns: - An array with the hashed password and new salt. - */ - public function hash_password($old='') - { - if (!function_exists('do_hash')) - { - $this->load->helper('security'); - } - - $salt = $this->generate_salt(); - $pass = do_hash($salt . $old); - - return array($pass, $salt); - } - - //-------------------------------------------------------------------- - - private function generate_salt() - { - if (!function_exists('random_string')) - { - $this->load->helper('string'); - } - - return random_string('alnum', 7); - } - - //-------------------------------------------------------------------- - - private function get_module_versions() - { - $mod_versions = array(); - - - - $modules = module_files(null, 'migrations'); - - if ($modules === false) - { - return false; - } - - foreach ($modules as $module => $migrations) - { - $mod_versions[$module] = array( - 'installed_version' => $this->migrations->get_schema_version($module .'_'), - 'latest_version' => $this->migrations->get_latest_version($module .'_'), - 'migrations' => $migrations['migrations'] - ); - } - - return $mod_versions; - } - - - //-------------------------------------------------------------------- -} - -/* get module locations from config settings or use the default module location and offset */ -Install::$locations = array( - APPPATH.'../bonfire/modules/' => '../modules/', -); +load->helper('form'); + + $this->output->enable_profiler(false); + + $this->lang->load('application'); + $this->lang->load('install'); + + // check if the app is installed + $this->load->config('application'); + + $this->load->helper('install'); + + $this->cURL_check(); + } + + //-------------------------------------------------------------------- + + public function index() + { + if ($this->is_installed()) + { + $this->load->view('install/installed'); + } + else + { + $this->load->library('form_validation'); + $this->form_validation->set_error_delimiters('', ''); + //$this->form_validation->CI =& $this; + $this->form_validation->set_rules('environment', lang('in_environment'), 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('hostname', lang('in_host'), 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('username', lang('bf_username'), 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('database', lang('in_database'), 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('db_prefix', lang('in_prefix'), 'trim|strip_tags|xss_clean'); + + $this->startup_check(); + + if ($this->form_validation->run() !== false) + { + // Write the database config files + $this->load->helper('config_file'); + + $dbname = strip_tags($this->input->post('database')); + + // get the chosen environment + $environment = strip_tags($this->input->post('environment')); + + $data = array( + 'main' => array( + 'hostname' => strip_tags($this->input->post('hostname')), + 'username' => strip_tags($this->input->post('username')), + 'password' => strip_tags($this->input->post('password')), + 'database' => $dbname, + 'dbprefix' => strip_tags($this->input->post('db_prefix')) + ), + 'environment' => $environment, + ); + + $this->session->set_userdata('db_data', $data); + if ($this->session->userdata('db_data')) + { + // + // Make sure the database exists, otherwise create it. + // CRAP! dbutil and database_forge require a running database driver, + // which seems to require a valid database, which we don't have. To get + // past this, we'll deal only with MySQL for now and create things + // the old fashioned way. Eventually, we'll make this more generic. + // + $db = @mysql_connect(strip_tags($this->input->post('hostname')), strip_tags($this->input->post('username')), strip_tags($this->input->post('password'))); + + if (!$db) + { + $this->vdata['error'] = message(lang('in_db_no_connect').': '. mysql_error(), 'error'); + } + else + { + $db_selected = mysql_select_db($dbname, $db); + if (!$db_selected) + { + // Table doesn't exist, so create it. + if (!mysql_query("CREATE DATABASE $dbname", $db)) + { + die('Unable to create database: '. mysql_error()); + } + mysql_close($db); + } + + redirect('account'); + } + } + else + { + $this->vdata['attention'] = message(sprintf(lang('in_settings_save_error'), $environment), 'attention'); + } + } + + $this->load->view('install/index', $this->vdata); + } + } + + //-------------------------------------------------------------------- + + public function account() + { + $view = 'install/account'; + + if ($this->input->post('submit')) + { + $this->load->library('form_validation'); + $this->form_validation->set_error_delimiters('', ''); + //$this->form_validation->CI =& $this; + + $this->form_validation->set_rules('site_title', lang('in_site_title'), 'required|trim|strip_tags|min_length[1]|xss_clean'); + $this->form_validation->set_rules('username', lang('in_username'), 'required|trim|strip_tags|xss_clean'); + $this->form_validation->set_rules('password', lang('in_password'), 'required|trim|strip_tags|alpha_dash|min_length[8]|xss_clean'); + $this->form_validation->set_rules('pass_confirm', lang('in_password_again'), 'required|trim|matches[password]'); + $this->form_validation->set_rules('email', lang('in_email'), 'required|trim|strip_tags|valid_email|xss_clean'); + + if ($this->form_validation->run() !== false) + { + if ($this->setup()) + { + $this->vdata['success'] = message(lang('in_success_notification'), 'success'); + + $success_data = array(); + // check if we are running in a sub directory + $url_path = parse_url(base_url(), PHP_URL_PATH); + $base_path = preg_replace('#/install/#', '', $url_path); + if (!empty($base_path)) + { + $this->vdata['rebase'] = $base_path.'/'; + } + + $view = 'install/success'; + } + else + { + $this->vdata['error']= message(lang('in_db_setup_error').': '. $this->errors, 'error'); + } + } + } + + // if $this->curl_error = 1, show warning on "account" page of setup + $this->vdata['curl_error'] = $this->curl_error; + + $this->load->view($view, $this->vdata); + } + + //-------------------------------------------------------------------- + + public function rename_folder() + { + $folder = FCPATH; + + // This should always have the /install in it, but + // better safe than sorry. + if (strpos($folder, 'install') === false) + { + $folder .= '/install/'; + } + + $new_folder = str_replace('install/', 'install_bak', $folder); + + rename($folder, $new_folder); + + $url = str_replace('install', '', base_url()); + $url = str_replace('http://', '', $url); + $url = str_replace('//', '/', $url); + $url = 'http://'. $url; + + redirect($url); + } + + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // !PRIVATE METHODS + //-------------------------------------------------------------------- + + /* + Method: is_installed() + + Performs some basic checks to see if maybe, just maybe, the + user has already installed the application and just hasn't + moved the install folder.... + */ + private function is_installed() + { + // Does the database config exist? + // If not, then we definitely haven't installed yet. + if (!file_exists('../bonfire/application/config/development/database.php')) + { + return false; + } + + require('../bonfire/application/config/development/database.php'); + + // If the $db['default'] doesn't exist then we can't + // load our database. + if (!isset($db) || !isset($db['default'])) + { + return false; + } + + $this->load->database($db['default']); + + // Does the users table exist? + if (!$this->db->table_exists('users')) + { + return false; + } + + // Make sure at least one row exists in the users table. + $query = $this->db->get('users'); + + if ($query->num_rows() == 0) + { + return false; + } + + return true; + } + + //-------------------------------------------------------------------- + + /* + Method: startup_check() + + Verifies that the folders and files needed are writeable. Sets + 'startup_errors' as a string in the template if not. + */ + private function startup_check() + { + $errors = ''; + $folder_errors = ''; + $file_errors = ''; + + // Check Folders + foreach ($this->writeable_folders as $folder) + { + $full_folder = FCPATH . '..' . $folder; + + @chmod($full_folder, 0777); + if (!is_dir($full_folder) || !is_writeable($full_folder)) + { + $folder_errors .= "
  • $folder
  • "; + } + } + + if (!empty($folder_errors)) + { + $errors = '

    '.lang('in_writeable_directories_message').':

      ' . $folder_errors .'
    '; + } + + // Check files + foreach ($this->writeable_files as $file) + { + @chmod(FCPATH . '..' . $file, 0666); + if (!is_writeable(FCPATH . '..' . $file)) + { + $file_errors .= "
  • $file
  • "; + } + } + + if (!empty($file_errors)) + { + $errors .= '

    '.lang('in_writeable_files_message').':

      ' . $file_errors .'
    '; + } + + // Make it available to the template lib if there are errors + if (!empty($errors)) + { + $this->vdata['startup_errors'] = $errors; + } + + unset($errors, $folder_errors, $file_errors); + + /* + Copies generic file versions to their appropriate spots. + This provides a safe way to perform upgrades, as well + as simplifying what will need to be modified when some + sweeping changes are made. + */ + } + + //-------------------------------------------------------------------- + + + private function setup() + { + + // Save the DB details + $data = $this->session->userdata("db_data"); + $environment = $data['environment']; + unset($data['environment']); + + $this->load->helper('config_file'); + + write_db_config($data); + + if (!file_exists(FCPATH . $this->app_path . 'config/development/database.php') && is_writeable(FCPATH . $this->app_path . 'config/')) + { + // Database + copy(FCPATH . $this->app_path . 'config/database.php', FCPATH . $this->app_path . 'config/'.$environment.'/database.php'); + } + + $server = $data['main']['hostname']; + $username = $data['main']['username']; + $password = $data['main']['password']; + $database = $data['main']['database']; + $dbprefix = $data['main']['dbprefix']; + + if( !$this->db = mysql_connect($server, $username, $password) ) + { + return array('status' => FALSE, 'message' => lang('in_db_no_connect')); + } + + // use the entered Database settings to connect before calling the Migrations + $dsn = 'mysql://'.$username.':'.$password.'@'.$server.'/'.$database.'?dbprefix='.$dbprefix.'&db_debug=TRUE'; + $this->load->database($dsn); + + // + // Now install the database tables. + // + $this->load->library('Migrations'); + + if (!$this->migrations->install()) + { + $this->errors = $this->migrations->error; + return false; + } + + // get the list of custom modules in the main application + $module_list = $this->get_module_versions(); + + if (is_array($module_list) && count($module_list)) + { + foreach($module_list as $module_name => $module_detail) + { + // install the migrations for the custom modules + if (!$this->migrations->install($module_name.'_')) + { + $this->errors = $this->migrations->error; + return false; + } + } + } + + // + // Save the information to the settings table + // + + $settings = array( + 'site.title' => $this->input->post('site_title'), + 'site.system_email' => $this->input->post('email'), + 'updates.do_check' => $this->curl_update, + 'updates.bleeding_edge' => $this->curl_update + ); + + foreach ($settings as $key => $value) + { + $setting_rec = array('name' => $key, 'module' => 'core', 'value' => $value); + + $this->db->where('name', $key); + if ($this->db->update('settings', $setting_rec) == false) + { + $this->errors = lang('in_db_settings_error'); + return false; + } + } + + // update the emailer serder_email + $setting_rec = array('name' => 'sender_email', 'module' => 'email', 'value' => $this->input->post('email')); + + $this->db->where('name', 'sender_email'); + if ($this->db->update('settings', $setting_rec) == false) + { + $this->errors = lang('in_db_settings_error'); + return false; + } + + // + // Install the user in the users table so they can actually login. + // + $data = array( + 'role_id' => 1, + 'email' => $this->input->post('email'), + 'username' => $this->input->post('username'), + 'active' => 1, + ); + list($password, $salt) = $this->hash_password($this->input->post('password')); + + $data['password_hash'] = $password; + $data['salt'] = $salt; + + if ($this->db->insert('users', $data) == false) + { + $this->errors = lang('in_db_account_error'); + return false; + } + + // Create a unique encryption key + $this->load->helper('string'); + $key = random_string('unique', 40); + + $config_array = array('encryption_key' => $key); + + // check the mod_rewrite setting + $config_array['index_page'] = $this->rewrite_check() ? '' : 'index.php'; + + write_config('config', $config_array); + + // Reverse Folders + foreach ($this->reverse_writeable_folders as $folder) + { + @chmod(FCPATH . '..' . $folder, 0775); + } + + // We made it to the end, so we're good to go! + return true; + } + + //-------------------------------------------------------------------- + + /* + Method: cURL_check() + + Verifies that cURL is enabled as a PHP extension. Sets + 'curl_update' to 0 if not. + */ + private function cURL_check() + { + if (!function_exists('curl_version')) + { + $this->curl_error = 1; + $this->curl_update = 0; + } + } + + + //-------------------------------------------------------------------- + + /* + Method: rewrite_check() + + Verifies that mod_rewrite is enabled as a PHP extension. + */ + private function rewrite_check() + { + if (!function_exists('rewrite_check')) + { + ob_start(); + phpinfo(INFO_MODULES); + $contents = ob_get_clean(); + return strpos($contents, 'mod_rewrite') !== false; + } + + }//end rewrite_check() + + /* + Method: hash_password() + + Generates a new salt and password hash for the given password. + + Parameters: + $old - The password to hash. + + Returns: + An array with the hashed password and new salt. + */ + public function hash_password($old='') + { + if (!function_exists('do_hash')) + { + $this->load->helper('security'); + } + + $salt = $this->generate_salt(); + $pass = do_hash($salt . $old); + + return array($pass, $salt); + } + + //-------------------------------------------------------------------- + + private function generate_salt() + { + if (!function_exists('random_string')) + { + $this->load->helper('string'); + } + + return random_string('alnum', 7); + } + + //-------------------------------------------------------------------- + + private function get_module_versions() + { + $mod_versions = array(); + + + + $modules = module_files(null, 'migrations'); + + if ($modules === false) + { + return false; + } + + foreach ($modules as $module => $migrations) + { + $mod_versions[$module] = array( + 'installed_version' => $this->migrations->get_schema_version($module .'_'), + 'latest_version' => $this->migrations->get_latest_version($module .'_'), + 'migrations' => $migrations['migrations'] + ); + } + + return $mod_versions; + } + + + //-------------------------------------------------------------------- +} + +/* get module locations from config settings or use the default module location and offset */ +Install::$locations = array( + APPPATH.'../bonfire/modules/' => '../modules/', +); diff --git a/install/language/english/install_lang.php b/install/language/english/install_lang.php index b426a6f7e..e10bd5aa0 100644 --- a/install/language/english/install_lang.php +++ b/install/language/english/install_lang.php @@ -1,70 +1,70 @@ -Welcome

    Welcome to the Bonfire installation process! Just fill in the fields below, and before you know it you will be creating CodeIgniter 2.1 based web apps faster than ever.

    '; -$lang['in_not_writeable_heading'] = 'Files/Folders Not Writeable'; - -$lang['in_writeable_directories_message'] = 'Please ensure that the following directories are writeable, and try again'; -$lang['in_writeable_files_message'] = 'Please ensure that the following files are writeable, and try again'; - -$lang['in_db_settings'] = 'Database Settings'; -$lang['in_db_settings_note'] = '

    Please fill out the database information below.

    These settings will be saved to both the main config/database.php file and to the development environment (found at config/development/database.php).

    '; -$lang['in_db_no_connect'] = 'The installer could not connect to the MySQL server or the database, be sure to enter the correct information.'; -$lang['in_db_setup_error'] = 'There was an error setting up your database'; -$lang['in_db_settings_error'] = 'There was an error inserting settings into the database'; -$lang['in_db_account_error'] = 'There was an error creating your account in the database'; -$lang['in_settings_save_error'] = 'There was an error saving the settings. Please verify that your database and %s/database config files are writeable.'; - -$lang['in_environment'] = 'Environment'; -$lang['in_host'] = 'Host'; -$lang['in_database'] = 'Database'; -$lang['in_prefix'] = 'Prefix'; -$lang['in_test_db'] = 'Test Database'; - -$lang['in_account_heading'] = '

    Information Needed

    Please provide the following information.

    '; -$lang['in_site_title'] = 'Site Title'; -$lang['in_username'] = 'Username'; -$lang['in_password'] = 'Password'; -$lang['in_password_note'] = 'Minimum length: 8 characters.'; -$lang['in_password_again'] = 'Password (again)'; -$lang['in_email'] = 'Your Email'; -$lang['in_email_note'] = 'Please double-check your email before continuing.'; -$lang['in_install_button'] = 'Install Bonfire'; - -$lang['in_curl_disabled'] = '

    cURL is not presently enabled as a PHP extension. Bonfire will not be able to check for updates until it is enabled.

    '; - -$lang['in_success_notification'] = 'You are good to go! Happy coding!'; -$lang['in_success_rebase_msg'] = 'Please set the .htaccess RewriteBase setting to: RewriteBase '; -$lang['in_success_msg'] = 'Please remove the install folder and return to '; - -$lang['no_migrations_found'] = 'No migration files were found'; -$lang['multiple_migrations_version'] = 'Multiple migrations version: %d'; -$lang['multiple_migrations_name'] = 'Multiple migrations name: %s'; -$lang['migration_class_doesnt_exist'] = 'Migration class does not exist: %s'; -$lang['wrong_migration_interface'] = 'Wrong migration interface: %s'; -$lang['invalid_migration_filename'] = 'Wrong migration filename: %s - %s'; - -$lang['in_installed'] = 'Bonfire is already installed. Please delete or rename the install folder to'; -$lang['in_rename_msg'] = 'If you would like, we can simply rename it for you.'; -$lang['continue'] = 'continue'; +Welcome

    Welcome to the Bonfire installation process! Just fill in the fields below, and before you know it you will be creating CodeIgniter 2.1 based web apps faster than ever.

    '; +$lang['in_not_writeable_heading'] = 'Files/Folders Not Writeable'; + +$lang['in_writeable_directories_message'] = 'Please ensure that the following directories are writeable, and try again'; +$lang['in_writeable_files_message'] = 'Please ensure that the following files are writeable, and try again'; + +$lang['in_db_settings'] = 'Database Settings'; +$lang['in_db_settings_note'] = '

    Please fill out the database information below.

    These settings will be saved to both the main config/database.php file and to the development environment (found at config/development/database.php).

    '; +$lang['in_db_no_connect'] = 'The installer could not connect to the MySQL server or the database, be sure to enter the correct information.'; +$lang['in_db_setup_error'] = 'There was an error setting up your database'; +$lang['in_db_settings_error'] = 'There was an error inserting settings into the database'; +$lang['in_db_account_error'] = 'There was an error creating your account in the database'; +$lang['in_settings_save_error'] = 'There was an error saving the settings. Please verify that your database and %s/database config files are writeable.'; + +$lang['in_environment'] = 'Environment'; +$lang['in_host'] = 'Host'; +$lang['in_database'] = 'Database'; +$lang['in_prefix'] = 'Prefix'; +$lang['in_test_db'] = 'Test Database'; + +$lang['in_account_heading'] = '

    Information Needed

    Please provide the following information.

    '; +$lang['in_site_title'] = 'Site Title'; +$lang['in_username'] = 'Username'; +$lang['in_password'] = 'Password'; +$lang['in_password_note'] = 'Minimum length: 8 characters.'; +$lang['in_password_again'] = 'Password (again)'; +$lang['in_email'] = 'Your Email'; +$lang['in_email_note'] = 'Please double-check your email before continuing.'; +$lang['in_install_button'] = 'Install Bonfire'; + +$lang['in_curl_disabled'] = '

    cURL is not presently enabled as a PHP extension. Bonfire will not be able to check for updates until it is enabled.

    '; + +$lang['in_success_notification'] = 'You are good to go! Happy coding!'; +$lang['in_success_rebase_msg'] = 'Please set the .htaccess RewriteBase setting to: RewriteBase '; +$lang['in_success_msg'] = 'Please remove the install folder and return to '; + +$lang['no_migrations_found'] = 'No migration files were found'; +$lang['multiple_migrations_version'] = 'Multiple migrations version: %d'; +$lang['multiple_migrations_name'] = 'Multiple migrations name: %s'; +$lang['migration_class_doesnt_exist'] = 'Migration class does not exist: %s'; +$lang['wrong_migration_interface'] = 'Wrong migration interface: %s'; +$lang['invalid_migration_filename'] = 'Wrong migration filename: %s - %s'; + +$lang['in_installed'] = 'Bonfire is already installed. Please delete or rename the install folder to'; +$lang['in_rename_msg'] = 'If you would like, we can simply rename it for you.'; +$lang['continue'] = 'continue'; $lang['click'] = 'Click here'; \ No newline at end of file diff --git a/install/views/install/success.php b/install/views/install/success.php index 64f05e38c..eab07216c 100644 --- a/install/views/install/success.php +++ b/install/views/install/success.php @@ -1,11 +1,11 @@ -load->view('header'); ?> - - - - -

    - - - - -load->view('footer'); ?> +load->view('header'); ?> + + + + +

    + + + + +load->view('footer'); ?>