Welcome Guest, Not a member yet? Register   Sign In
Help revive codeigniter 2.x project
#1

Hi there CI members.

As the thread subject says,,
long story short,, after about 6 years and a lot of $ poorer thanks to an dishonest developer I now sit with an incomplete community project.

After setting it up on my localhost I figured it out that it was built with an early version of CI 2.x.

It's up and running now on localhost and xxxxx.db imported to phpMyadmin but as I explained, it's in someways incomplete.

The project is an member community with:
dual language, depending on country on registration,
member registration page,
personal user page with users messages, latest visitors, contacts, adds, diary posts, events and image gallery.
member search page,
friends/contacts page,
private messaging/conversation page,
shoutbox/public message page,
classified add page where users can view/search and post add,
event calender page where users can view/search and post events,

and an administrator page.

Most pages and functions work, but some in wrong order and the administrator page exists in the CI htdocs folder but are not accessible in any way I have tried yet, not through localhost/administrator or through login since the developer has forgotten the admin account login information.

So since it's built with CI this is the only forum I could think of to ask and beg for help/tips/advice on how to get the project up and running again.

The basic plans is to:
get the Admin page to work and be able to login to it, to manage all the content,
make the edit userinformation on the user page to work correctly,
create dependet subcategories in the classified adds page when creating an add,
update the Ci framwork to 3.x.x

I'm no developer or coder myself but a very fast learner, so if there is anyone who can spare some time to help me with tips, guidance, help to interpret some of the coding I would be very very grateful.

/Ricke
Reply
#2

I would start by upgrading to Codeigniter 3 and take it from there.
https://www.codeigniter.com/userguide3/i...ading.html
Reply
#3

jreklundI would start by upgrading to Codeigniter 3 and take it from there.
https://www.codeigniter.com/userguide3/i...ading.html

Hi, thanks for your reply.
I've done an upgraded test version of the install in an copy of the original folder, but there seemed to become more errors since the project is started to be written in 2011 and there seems to be some code that has to be updated in controllers and models to get it to work flawless, so I feel I have to be more comfortable with the installation as it is right now and get the Administrator part of it to work to see what is working there and what's not.

According to the developer it should work but she had "forgotten" the log in, and have not heard from her in over a year.
So I'd like to get that part figured out, there is administrator_model.php and administrator.php controller in the aplication folder, and an folder with linked administrator views in an application/administrator folder called old_views, but not in the current application/views folder.
So I'm trying to figure out how and what she has been up to with a couple of folders here and there with the prefix old_.

/Ricke
Reply
#4

(This post was last modified: 02-25-2018, 12:21 PM by Ricke.)

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Administrator extends CI_Controller {

    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->helper('url');
        
$this->load->helper('date');
        
$this->load->model('location_model''location');
        
$this->load->model('state_model''state');
        
$this->load->model('province_model''province');
        
$this->load->model('member_model''member');
        
$this->load->model('administrator_model''admin');
        
$this->load->model('shout_model''shout');
        
$this->load->model('message_model''message');
        
$this->load->model('event_model''event');
        
$this->load->model('image_model''image');
        
$this->load->model('diary_model''diary');
        
$this->load->model('advertisement_model''ad');
        
$this->load->model('visit_model''visit');
        
$this->load->model('friend_model''friend');
        
$this->load->helper('language');
        
$this->lang->load('useful_words''swedish');
        
    }


    public function 
_remap($function$params)
    {
        if (
$this->session->userdata('admin') == false) {
            
$this->index();
        }
        
        
$member $this->session->userdata('member');
        
        
// user profile
        
if (intval($function) > 0) {
            
$id $function;
            if (isset(
$params[1])) {
                
$this->$params[1]($id);
            } else {
                
$this->index($id);
            }
            
            if (
$member !== false) {
                if (
$id != ($member->id) {
                    
$this->visit->add($id, ($member->id);
                }
            }
        
//REMEMBER if blocked (members_modell) then not show
        
        // own profile
        
} elseif ($member != false) {
            
$this->$function($member->id);
        } elseif (
$function == 'login') {
            
$this->login();
        } else {
            
redirect('home');
        }
    }
    
    private function 
login() {
        
$username $this->input->post('username');
        
$password $this->input->post('password');
        
        
$admin $this->admin->login($username$password);
        
        if (
is_object($admin)) {
            
$admin_data = array(
                
'id' => $admin->account_id,
                
'user' => $admin->username,
                
'pass' => $admin->password
            
);
            
$this->session->set_userdata('admin'$admin_data);
            
$this->session->unset_userdata('failed_admin_login');
        } else {
            
$this->session->unset_userdata('admin');
            
$this->session->set_userdata('failed_admin_login'true);
        }
        
        
redirect('administrator');
    }
    
    private function 
logout() {
        
$this->session->unset_userdata('admin');
        
        
redirect('home');
    }
    
    private function 
load_header()
    {
        
$header['leftside' true;
        
$header['rightside'] = true;
        
$header['shouts'] = $this->shout->get_list();
        
$member $this->session->userdata('member');
        if(
$member != false){
            
$header['messages'] = $this->message->getUnread($member->id);
            
        }
        
        
$this->load->view('header'$header);
    }
    
    private function 
load_footer()
    {
        
$footer['rightside'] = true;
        
$footer['shouts'] = $this->shout->get_list();
        
        
$this->load->view('footer'$footer);
    }

    public function 
index($id 0)
    {
        
$data = array();
        
        
/*design*/
        
$this->load_header();
        
$this->load->view('administrator/menu');
        
$this->load->view('administrator/home'$data);
        
$this->load_footer();
        
    }
    
    private function 
places($id)
    {
        
$data['countries'] = $this->admin->get_countries();
        
$data['states'] = $this->admin->get_states();
        
$data['provinces'] = $this->admin->get_provinces();
        
        
/*design*/
        
$this->load_header();
        
$this->load->view('administrator/menu');
        
$this->load->view('administrator/places'$data);
        
$this->load_footer();
    }
    
    public function 
members($id)
    {
        
$letter  $this->uri->segment(3);
        
$data['members'] = $this->admin->get_members($letter);
        
/*design*/
        
$this->load_header();
        
$this->load->view('administrator/menu');
        
$this->load->view('administrator/members'$data);
        
$this->load_footer();
    }
    
    public function 
reports($id)
    {
        
$data['reports'] = $this->admin->get_reports();
        
$data['users'] = $this->member->get_list();
        
/*design*/
        
$this->load_header();
        
$this->load->view('administrator/menu');
        
$this->load->view('administrator/reports'$data);
        
$this->load_footer();
        
//its read now
        
$read = array(
            
'read' => 1
                
);
        
$this->admin->read_report($read);
    }
    
    public function 
text($id)
    {
        
$data['text'] = $this->admin->get_text('1');
        
$data['text_no'] = $this->admin->get_text('2');
        
/*design*/
        
$this->load_header();
        
$this->load->view('administrator/menu');
        
$this->load->view('administrator/text'$data);
        
$this->load_footer();    
    }
    
    public function 
save_text($id)
    {
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
            
$text=array("content" => $this->input->post('text_swe'));
            
$this->admin->edit_text(1$text);
            
$text=array("content" => $this->input->post('text_no'));
            
$this->admin->edit_text(2$text);
        }

        
redirect('administrator/text');
    }
    
    public function 
add_country($id)
    {
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {            
            if (isset(
$_POST['country']) && !empty($_POST['country'])) {
                
$country = array(
                    
'country_name' => $_POST['country']
                );                
                
$this->admin->add_country($country);
            }
        }
    }
    
    public function 
add_state($id)
    {        
        
$state_id 0;
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
            
            if (isset(
$_POST['country']) && !empty($_POST['country'])) {
                
$state = array(
                    
'state_name' => $_POST['state'],
                    
'country_id' => $_POST['country']                    
                );
                
                
$state_id $this->admin->add_state($state);
            }    
        }
        echo 
$state_id;
    }
    public function 
update_state($id)
    {        
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
            
                
$state = array(
                    
'state_name' => $_POST['state'],
                    
'country_id' => $_POST['country']                    
                );
                
                
$this->admin->update_state($state$_POST['stateid']);
        }
        echo 
0;
    }
    public function 
add_province($id)
    {        
        
$province_id 0;
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
            
            if (isset(
$_POST['province']) && !empty($_POST['province'])) {
                
$province = array(
                    
'province_name' => $_POST['province'],
                    
'state_id' => $_POST['state']                
                );
                
                
$province_id $this->admin->add_province($province);
                
            }    
        }
        
        echo 
$province_id;
    }
    public function 
update_province($id)
    {        
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
            
                
$province = array(
                    
'province_name' => $_POST['province'],
                    
'state_id' => $_POST['state']                
                );
                
                
$this->admin->update_province($province$_POST['provinceid']);
        }
        echo 
0;
    }
    public function 
delete_member($id){
        
/*REMEMBER 
         * ARE YOU SURE? 
         */
        
$delete_id  = (int) $this->uri->segment(3);
        
$this->member->delete($delete_id);
        
        
redirect('administrator/members');
    }
    public function 
update_member($id){
        if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
            
            
$update_id $_POST['update_id'];
            
$member= array(
                
'membership_id' => $_POST['membership']
            );
            
$this->member->update($update_id$member);
            
            
//var_export($update_id.$_POST['membership']);
        
}
    }
}


/* End of file home.php */
/* Location: ./application/controllers/home.php */ 


I get this message from this Administrator.php controller:

Severity: Parsing Error
Message: syntax error, unexpected '{'
Filename: controllers/Administrator.php
Line Number: 47



// user profile
if (intval($function) > 0) {
$id = $function;
if (isset($params[1])) {
$this->$params[1]($id);
} else {
$this->index($id);
}

if ($member !== false) {
if ($id != ($member->id) { <---------------- Error points to this line
$this->visit->add($id, ($member->id);
}
}


But I can't find any faults with an PHP Editor that there is any wrong syntax.

Can the problem lie in the code language?

I've now updatet the CI to v3.1.7 and still the same error when I'm trying to access C:/localhost/projectfolder/administrator.
Reply
#5

These two works. It's not getting closed.
Get an editor with syntax highlight and place your cursor at the line, you will see where it "lights up" or lack of.
if ($id != ($member->id)) {
if ($id != $member->id) {
Reply
#6

Made the change in that line, noticed it when you pointed it out Smile

But got a new error message now for the next line:

Message: syntax error, unexpected ';'
Filename: controllers/Administrator.php
Line Number: 48

So I sorted that one out and get yet another error message:

First
Message: Undefined property: Administrator::$session

Second
Message: Call to a member function userdata() on null

So found that session could be added in autoload.php or as
Code:
$this->load->library('session');

in Administrator.php.

So I did that modification and now I just get directed to [::1]/Website/home if I try to get to localhost/Website/administrator.

Still no luck to reach the administratorpage,, or if it is supposed to load only if I log in through the orinary login with a admin user and pass, which I dont have, and there is no separate Admin backend.
Reply
#7

You need to set your $config['base_url'] in application\config\config.php.
Now it's trying to guess your url and returning ipv6 localhost address instead.

You need to be logged in, there are two redirect('home') in that file you posted.

_remap points to the private login() function. So you must have a form that triggers the _remap function with login passed as argument. Look for a url: _remap/login/

For finding out the encryption of the password, you will need to look at the admin module:
$this->admin->login($username, $password);

And reset it in the database.
Reply
#8

$config['base_url'] in application\config\config.php solved that problem, was blank, seems to be many many many overlooked things in this project.

Feels like I'm quite cheated  on 20k+ since that was for a functional page that would take about a year, and then 4 years later when nothing more happened than what I have today I withdraw my project.

I didn't quite understand:
_remap points to the private login() function. So you must have a form that triggers the _remap function with login passed as argument. Look for a url: _remap/login/

I see that there is a code that searches for 'admin' information in the DB, but I cant figure out in which table it searches.

There is an table "members" where members get registred, but the 'admin' is registred in an table called "account" that have the "rights 100"

I have created a new member with the password "abcdef".
In phpMyadmin I opened the newly ceated member in edit mode, copied the encrypted password and pasted it in the 'admin' table,, so it should have $username 'admin' and $password 'abcdef', but no luck, just get cleared loginform fields and stays on the landing page.

The site starts with a landing page where there is login fields, register new member and try as demo.
When I regiter a new member I can login to my member-home page, when I use the name admin and pass abcdef it just stay on the landing page.
Reply
#9

Great.

Sure did. I have made cheaper web application with more functionality. So sorry about my fellow countrymen, I guess you are Swedish too. At least it says swedish in the sourcecode.

Sorry about that, I had it all wrong too. _remap are a hidden function that can't be trigged in the URL: localhost/administrator/_remap/login/ so some other function or class need to call it. But the problem is that that function want's to trigger login by passing it an argument _remap('login'). If you search in all your project files after _remap you sure will find it.
Don't manually scan thought, use an editor for that. (Notepad++ for Windows)

Post the login function inside your administrator_model.

See above.

It depends on what encryption are being used. Can't tell you that one yet. Need the model.

Dunno, can't tell you without the code.
Reply
#10

(This post was last modified: 02-26-2018, 04:17 PM by Ricke.)

Yes, one step further, but yet another problem richer.

Yepp, I'm from Sweden, thought you might be Swedish to because of the jrEklund name Smile

Well, I'm being cheated 2 times, first of $2,5K which was handwritten code that would be more expensive to get sorted than build it from scratch, so I fell in the trap again and let another one do it from scratch, so about $20k + $3K design later I'm left with this unfinished project and has no funds to be able to pay that amount again, that's why I'm trying to sort it out myself as far as I'm able to.
Even thinking about go an development education, but you have to start somewhere Smile

I always had notepad++ on my PC, and got a trial PHPStorm just to get started with this project again after it been in an folder on my desktop about a year.

Although, I changed back to the CI 2.x project again, the updated CI 3.1.7 project just throws db duplicated errors, so have to take a look at that one later on, if I get this one to work I can just make a copy of the entire project, update it to 3.1.7 and go from there with an working backup.


I noticed that she has copied models since the bottom lines aren't changed to the right "xxxx_model" it's in.

PHP Code:
/* End of file event_model.php */
/* Location: ./application/models/event_model.php */ 


Here's the admin_model code:


PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Administrator_model extends CI_Model {

 
   public function __construct()
    {
        
// Call the Model constructor
        
parent::__construct();
    }
    
    function 
login($username$password)
    {
        
$this->db->where('username'$username);
        
$this->db->from('accounts');
        
$this->db->limit(1);
        
$query $this->db->get();
        
$admin $query->row();
        
        if (
is_object($admin) && $admin->password == sha1($this->config->item('member_salt') . $password)) {
            return 
$admin;
        } else {
            return 
false;
        }
    }
    
    function 
get_countries($country FALSE)
    {
        
$this->db->from('countries');
        
$query $this->db->get();
        return 
$query;
    }
    
    function 
get_states()
    {
        
$this->db->from('states');
        
$this->db->join('countries''countries.country_id=states.country_id''left');
        
$this->db->order_by('countries.country_name','asc');
        
$this->db->order_by('states.state_name''asc');
        
$query $this->db->get();
        return 
$query;
    }
    
    function 
get_provinces()
    {
        
$this->db->from('provinces');
        
$this->db->join('states''states.state_id=provinces.state_id''left');
        
$this->db->join('countries''countries.country_id=states.country_id''left');
        
$this->db->order_by('countries.country_name','asc');
        
$this->db->order_by('states.state_name''asc');
        
$this->db->order_by('provinces.province_name''asc');
        
$query $this->db->get();
        return 
$query;
    }
    
    function 
get_members($letter){
        
$this->db->like('username',$letter'after');
        
$this->db->from('members');
        
$this->db->join('provinces''provinces.province_id=members.location_id''left');
        
$this->db->join('states''states.state_id=provinces.state_id''left');
        
$this->db->join('countries''countries.country_id=states.country_id''left');
        
$this->db->join('memberships''memberships.membership_id=members.membership_id''left');
        
$query $this->db->get();
        return 
$query;
        
    }
    
    
// add a country to the DB
    
function add_country($country)
    {
        
// add the $country object/array to the DB
        
$this->db->insert('countries'$country);
        
        
// fetch the inserted id (auto incremented value of country_id) and return it
        
return $this->db->insert_id();
    }
    function 
add_state($state)
    {    
        
// add the $country object/array to the DB
        
$this->db->insert('states'$state);
        
        
// fetch the inserted id (auto incremented value of country_id) and return it
        
return $this->db->insert_id();
    }
    function 
update_state($state$state_id)
    {    
        
// add the $country object/array to the DB
        
$this->db->where('state_id'$state_id);
        
$this->db->update('states'$state);
    }
    function 
add_province($province)
    {    
        
// add the $country object/array to the DB
        
$this->db->insert('provinces'$province);
        
        
// fetch the inserted id (auto incremented value of country_id) and return it
        
return $this->db->insert_id();
    }
    function 
update_province($province$province_id)
    {    
        
// add the $country object/array to the DB
        
$this->db->where('province_id'$province_id);
        
$this->db->update('provinces'$province);
    }
    
    function 
get_reports(){
        
$this->db->from('reports');
        
$this->db->join('members''members.member_id = reports.reported_member_id''left');
        
        
$query $this->db->get();
        return 
$query;    
    }
    function 
read_report($read)
    {    
        
// add the $country object/array to the DB
        
$this->db->where('read'0);
        
$this->db->update('reports'$read);
        
        
// fetch the inserted id (auto incremented value of country_id) and return it
        
return $this->db->insert_id();
    }
    
    function 
get_text($id)
    {
        
$this->db->where('id'$id);
        
$this->db->from('texts');
        
$query $this->db->get();
        return 
$query->row();
    }
    
    function 
edit_text($id$text)
    {    
        
$this->db->where('id'$id);
        
$this->db->update('texts'$text);
    }

    
}
/* End of file event_model.php */
/* Location: ./application/models/event_model.php */ 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB