Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14075 articles
Browse latest View live

Checking if a user has submitted an approval with if statements

$
0
0
Is a user has composed a message, other users be able to should approve the message but the message Author should only delete and edit not approve. The below if statement is supposed to work for that but its not 

    <td>
      <?php $author = array(
        $message->user_id == $this->session->userdata('id')
      ); ?>
      <?php if($author): ?>
      <?php echo anchor('admin/messages/edit/'.$message->id.'', 'Edit', 'class="btn btn-primary"'); ?>
      <?php echo anchor('admin/messages/delete/'.$message->id.'', 'Delete', 'class="btn btn-danger"'); ?>
      <?php endif; ?>
      <?php if(!$author): ?>
      <?php echo anchor('admin/messages/approve/'.$message->id.'', 'Approve', 'class="btn btn-success"'); ?>
      <?php endif; ?>
    </td>

The code below is the *approve* METHOD in my CONTROLLER which is supposed to check the **condition** before passing data to the MODEL 


    public function approve($id)
{


$this->db->select('*');
   $this->db->from('approval');
   $this->db->join('messages', 'messages.id = approval.sms_id');
$query = $this->db->get();
$first_approval = $query->row('first_approval');
$second_approval = $query->row('second_approval');
$third_approval = $query->row('third_approval');


if ($first_approval == null) {

$data  = array(
     'first_approval' =>  $this->session->userdata('user_id')
    );

$approval_data  = array(
  'approvals'  => 'one'
  );

  $this->Message_model->some_approve($id, $approval_data);

$this->Message_model->approve($id, $data);

//Activity array
$data  = array(
'resource_id' => '',
'type' => 'message',
'action' => 'approved',
'user_id' => $this->session->userdata('user_id'),
'message' => 'Message was approved'

);
//Insert Activity
$this->Activity_model->add($data);


//isset Message
$this->session->set_flashdata('success', 'Your approval was send');

//Redirect
redirect('admin/messages');


} elseif ($second_approval == null && $this->session->userdata('user_id') != $first_approval) {

$data  = array(
     'second_approval' =>  $this->session->userdata('user_id')
    );

$approval_data  = array(
  'approvals'  => 'two'
  );

  $this->Message_model->some_approve($id, $approval_data);

$this->Message_model->approve($id, $data);

//Activity array
$data  = array(
'resource_id' => '',
'type' => 'message',
'action' => 'approved',
'user_id' => $this->session->userdata('user_id'),
'message' => 'Message was approved'

);
//Insert Activity
$this->Activity_model->add($data);


//isset Message
$this->session->set_flashdata('success', 'Your approval was send');

//Redirect
redirect('admin/messages');


     } elseif ($third_approval == null && $this->session->userdata('user_id') != $second_approval && $this->session->userdata('user_id') != $first_approval) {

$data  = array(
     'third_approval' =>  $this->session->userdata('user_id')
    );
$approval_data  = array(
       'status'  => 'Approved',
'approvals'  => 'three'
      );

$this->Message_model->approve($id, $data);
$this->Message_model->some_approve($id, $approval_data);

//Activity array
$data  = array(
'resource_id' => '',
'type' => 'message',
'action' => 'approved',
'user_id' => $this->session->userdata('user_id'),
'message' => 'Message was approved'

);
//Insert Activity
$this->Activity_model->add($data);


//isset Message
$this->session->set_flashdata('success', 'Your approval was send and the message has passed');

//Redirect
redirect('admin/messages');


      } elseif ($third_approval == $this->session->userdata('user_id') || $this->session->userdata('user_id') == $second_approval || $this->session->userdata('user_id') == $first_approval) {

//isset Message
$this->session->set_flashdata('success', 'You already have send an approval');

//Redirect
redirect('admin/messages');

      } else {

$approval_data  = array(
'status'  => 'Approved',
'approvals'  => 'three'
);

$this->Message_model->some_approve($id, $approval_data);

//isset Message
$this->session->set_flashdata('success', 'Your approval was send and the message has already been send');

//Redirect
redirect('admin/messages');

    }

}

The METHODS below are working 

    public function approve($id, $data) {
    $this->db->where('sms_id', $id);
    $this->db->update('approval',$data);
    }

    public function some_approve($id, $approval_data)
    {
    $this->db->where('id', $id);
    $this->db->update('messages',$approval_data);
    }


The if conditions in my controller and on the buttons are the ones which I need help on because the are not showing any error but they are not working as they should

Moving applications and system folder to Dropbox

$
0
0
New CI user here. I am developing a site using two different machines. I have XAMPP installed and running both at home (Win10) and at work (Mac OS X). I have installed CI on both systems. My goal is to move the system and application folders into Dropbox so that changes I make on one machine are available from the other. I have successfully done this on the PC, but I am having problems configuring the local CI index.php on the Mac.

On the Mac, CI is installed at /Applications/XAMPP/xamppfiles/htdocs/codeigniter. I can access it from http://localhost/codeigniter, and it works fine when I reference the locally installed system and application folders:
PHP Code:
$system_path 'system';
$application_folder 'application'

However, I get an error message telling me to properly configure index.php when I reference the Dropbox-based folders:
PHP Code:
$system_path '//Macintosh HD/Users/lonr8x/Dropbox/ccc/codeigniter/system';
$application_folder '//Macintosh HD/Users/lonr8x/Dropbox/ccc/codeigniter/application'
On the Win10 machine I successfully used relative references (e.g. "../../Users/Dropbox/etc.") These have not worked on the Mac. Since I know CI is able to do this from the Win10 machine, I am sure that the problem is either with my directory referencing or the folder permissions.

I would appreciate any insight.

Community auth for full password protected website

$
0
0
I need some support on this.

I have a full password protected website on several controllers.

All I need is being able to check if there someone is logged in and if yes display the views or login form.


PHP Code:
if(  if$this->require_min_level(0) ) 
{

//my stuff



Is there a possiblity to make the check in the __construct() ?

For now it's working in the same controller (not in the construct but in each function) but if I want to go to another controller after login it give me again the login form like the user is not logged in correctly.
Should I make a  if( $this->require_min_level(0) ) on the main controller and a if( $this->verify_min_level(0) ) in the other controllers ?


I'm lost here.

Thanks again

codeigniter3 file uploading not working

$
0
0
I have facing a problem on codeigniter3 file upload. getting following response 

"is currently unable to handle this request.

HTTP ERROR 500"


Not getting any errors.  but validation working fine.
anybody can  suggest me a solution fr this. Thank you.
following are my code
$this->load->helper('url');

$this->load->library('pagination');

$this->load->model('Video_model');



if($this->input->post('submit')){

$upload_path = './upload/';

           $config['upload_path'] = $upload_path;

           //allowed file types. * means all types

           $config['allowed_types'] = 'wmv|mp4|avi|mov';

           //allowed max file size. 0 means unlimited file size

           $config['max_size'] = '50000';

           //max file name size

           $config['max_filename'] = '255';

           //whether file name should be encrypted or not

           $config['encrypt_name'] = true;

           //store video info once uploaded

           $video_data = array();

           //check for errors

           $is_file_error = FALSE;

           if (!$_FILES) {

               $is_file_error = TRUE;

               $this->handle_error('Select a video file.');

           }



         

if (!$is_file_error) {



               //load the preferences

               $this->load->library('upload', $config);

             

               //check file successfully uploaded. 'video_name' is the name of the input

               if (!$this->upload->do_upload('userfile')) {

                   //if file upload failed then catch the errors

                   $this->handle_error($this->upload->display_errors());

                   $is_file_error = TRUE;

               } else {

                   //store the video file info

                   $video_data = $this->upload->data();

                   

                  

                  $this->save_video($video_data['file_name']);

               }
       }


Document Root

$
0
0
Hi friends,

For testing, I upload CI 4 on my testing server and finding how I can set document root to CI public folder, but I can not find so, I talk to my hosting provider and he said we do not allow to change the document root path (shared hosting).

Any idea how can I  test ci 4 without changing document root ?

How to use case statement instead of if statement in codeigniter

$
0
0
I have a code below which seems not to be working so I would want to try case statement instead
Code:
 <td>
      <?php $is_author = $message->user_id == $this->session->userdata('id'); ?>
      <?php if($is_author): ?>
      <?php echo anchor('admin/messages/edit/'.$message->id.'', 'Edit', 'class="btn btn-primary"'); ?>
      <?php echo anchor('admin/messages/delete/'.$message->id.'', 'Delete', 'class="btn btn-danger"'); ?>
      <?php else: ?>
      <?php echo anchor('admin/messages/approve/'.$message->id.'', 'Approve', 'class="btn btn-success"'); ?>
      <?php endif; ?>
  </td>


I need help to solve the if statement or change it to case statement if it can work pliz.

Session issues

$
0
0
Sessions in a browser get other sessions by another users. For eg:

User A -> Browser Chrome -> IP 192.168.0.105
User B -> Browser Mozilla -> IP 192.168.0.200
...
User H...

If you sign in on User A and reflesh the page, automatically change to User C, or User H. Or any other users.

I'm using: php56, CI 311.

I already tried to save sessions on database and files, without different results.

Thanks.

PS: sorry for my english!

CodeIgniter 3.1.2 released

$
0
0
CodeIgniter 3.1.2 was released today, with some security fixes, bug fixes and enhancements.

Security: Fixed some xss_clean() vulnerabilities in the Security library.

Enhancements: allowing PHP4 style constructors for routes.

Bug fixes: for the Query Builder and Session library.

This is recommended for all users of version 3. Download v3.1.2 now, and we encourage you to read the changelog, and to check the directions for upgrading from a previous version.

standard Form Validation for textareas

$
0
0
Hello, what do you all use for set_rules for a textarea:

I have so far:

PHP Code:
$this->form_validation->set_rules('f_why''Why or why not?', array('trim','max_length[400]', array('customAlpha','customAlpha'))); 


However, I'm thinking this won't work, or I'll have to edit my customAlpha function to get it to work right with carriage returns and such.

Thanks,
Donovan

URI handling

$
0
0
On CI 3.1.0

For my site If I enter http://<domainname>/search/results?type=event, all works fine

However if I enter http://<domainname>/search/results/&type=event  I get this error

Fatal error: Class 'CI_Controller' not found in /var/www/html/system/core/CodeIgniter.php on line 366

Any pointers to troubleshoot appreciated.

Usage of some deprecated methods

$
0
0
Hi,
I am not sure if this is the correct sub-forum. If it is not, please tell me where is the correct place.

I am using PHP 7.0.9 with the latest release of CI (3.1.0)

I added a hook for error handling:
PHP Code:
set_error_handler('exceptions_error_handler'); 

And the first time I run something, it gives me this message:

Quote:{
"status": false
"type": "deprecated"
"data": 
{
"filename": "...\system\core\CodeIgniter.php"
"line": 249
"message": "ini_set(): Use of mbstring.internal_encoding is deprecated"
}
}


Fine, So I added "allowed errors", because I don't wanna ignore all deprecation:
PHP Code:
    $allowed = [
        
"ini_set(): Use of mbstring.internal_encoding is deprecated"    
        
];
    foreach (
$allowed as $a)
        if (
$message == $a)
            return; 

So now it gave me:
Quote:{
"status": false
"type": "deprecated"
"data": 
{
"filename": "...\system\core\CodeIgniter.php"
"line": 266
"message": "ini_set(): Use of iconv.internal_encoding is deprecated"
}
}

So now my allowed methods array looks like this:
PHP Code:
$allowed = [
        
"ini_set(): Use of mbstring.internal_encoding is deprecated",
        
"ini_set(): Use of iconv.internal_encoding is deprecated",
    ]; 

And it works.



These two were deprecated in 5.6.0
Solutions are:
mbstring - http://php.net/manual/en/mbstring.config...l-encoding
iconv - http://php.net/manual/en/iconv.configura...l-encoding

Language subdomain not working on hosting

$
0
0
Hi everyone. I'm using CI 3.1.0 and modify output languages by subdomain. For example:

Quote:localhost:4001 for defaut language

en.localhost:4001 for english output

It woking good on localhost but recently when I upload the project to localhost, the main domain still working but when I enter the subdomain, it show


.jpg   DefaultSite.jpg (Size: 105.19 KB / Downloads: 4)

I have very little knowledge about hosting. So any ideas ?

Need someone for a new project

$
0
0
I am looking for some help, let me know if you are available for freelance work. Please post examples of your recent work.

Multiple admin areas & user identification - best approach?

$
0
0
I am completely new to CodeIgniter, so please bear with me. 

To better understand and learn how CodeIgniter works, I am currently building a sample job board application with a login area using Ion Auth. The idea here is to have a super administrator, who has complete access to edit and manage users, posts, settings etc. and a normal user group, that can post and edit only their own jobs and profile details.

With this in mind, I would like to show different admin-areas with different functions to the different user groups; one for the super-admin and one for the normal users.

My question now is, how to organize these two admin-dashboards.

I currently use a single controller "Dashboard.php" to basically load different menu-views depending on the users status (admin vs non-admin):


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

class 
Dashboard extends MY_Controller
{
 
   function __construct()
 
   {
 
       parent::__construct();

 
       // Load authentication library
 
       $this->load->library('ion_auth');

 
       // Check user status
 
       if (!$this->ion_auth->logged_in())
 
       {
 
           redirect('auth/login');
 
       }
 
   }

 
   public function index()
 
   {
 
       if ($this->ion_auth->is_admin()) {
 
           $this->load->view('common/header');
 
           $this->load->view('dashboard/top_nav_admin');
 
           echo 'This is the administrators page';
 
           $this->load->view('common/footer');
 
       } else {
 
           $this->load->view('common/header');
 
           $this->load->view('dashboard/top_nav_user');
 
           $this->load->view('dashboard/index_view');
 
           $this->load->view('common/footer');
 
       }

 
   }

 

I am not sure if this is a good idea or if it is better to have a unique controller for every user group, also in order to define different methods for each group. I don't want to repeat much code regarding the views in the admin-area (i.e. basically same design but different menus).


Also, another question concerns how to identify a specific user once he or she is logged in to the admin-area in order to only show his posts / user details.

Is there a way to get the user ID and for instance save it in a session or what is the best approach here?

Thanks for your feedback.

Duplicating (with slight modification) a MVC "module"

$
0
0
For the sake of discussion lets define a module as the model view and controller for a certain category of information displayed. 

In my example we have a "Clients" module that I want to replicate into a new module called "Vendors"

This would have all the functions of clients, but read/write from a different database. 

Other than find/replacing all the references to "client/s" to "vendor/s" what would be an easy way to do this?

Can I use the client model AS vendor model? I know I will need a new controller, but mostly the code is going to be the same thing. I don't want to reinvent the wheel. Somebody already wrote a great CRM and I'm just trying to modify it to include a separate area for Vendors. 

I've tried to start rewriting the "module" from scratch but only got to reading/writing to a table and inserting into the database before I realized how much more the original clients "module" does. 

The CRM is Perfex fyi. It's a great bit of software and well worth the money, but just trying to add a couple custom elements to it. 


Any help/advice would be greatly appreciate as I am very new to the MVC/CI way of doing things. 

THANKS!

PHP / jQuery Developer Needed

$
0
0
Hi there,

We are looking for a developer that is well versed in using both PHP (Codeigniter framework specifically) and jQuery javascript libraries. We are anticipating using open sources including Codeigniter, jQuery, Bootstrap and a few other third party libraries.

The project we are building relies on the following quite heavily:

1. Restful Integration - there will be a lot of developing javascript to reach out to third party API's to pull back information as needed.
2. We are looking at integrating something similar to what another Codeigniter project has done at Hoosk (Sir Trevor JS) by developing a simply CMS system into the solution.
3. Experience with Bootstrap preferable, users will be able to apply themes to the solution we are building.

You will be getting fairly specific requirements including wireframes, database diagrams...etc. We're a development shop but with lack of time and some budget to build this out with a contractor.

Geography doesn't matter but you will need to accessible during business hours in the Pacific time zone (Vancouver) for meetings with our Project Manager.

We anticipate a project schedule of 2 to 3 months.

Please shoot me a message with some information on yourself. We have no time frame to kick this off other than if we find the right person we'll get going sooner than later.

Thanks folks!

Rest APIs Issues

$
0
0
Hi To All ,
I am Using Codeignter Restfull APIs .
print_r($s); I am Getting Out Put Of the Array .
But I am send response Like
$this->response($s);
I am Getting Empty Response . How To resolve the Issue ...

Twig template for CI4

Confirmations Email

$
0
0
Hello,

i'm new in Codeigniter. I'm try to make login and registration user with email address. Link activation has been sended to user , and if user want to active their account its always failed to confirm the account. Any help ?

Here is my code.

Model


PHP Code:
class Voter_model extends CI_Model
{
    
        
 
    function __construct()
 
    {
 
         // Call the Model constructor
 
         parent::__construct();
 
    }

 
    //get the username & password from tbl_usrs
 
    function get_user($username$password)
 
    {
 
         $sql "select * from user where username = '" $username "' and password = '" $password "' and status = '1'";
 
         $query $this->db->query($sql);
 
         return $query->num_rows();
 
    }
     
     
     
//insert into user table
 
   function insertUser($data)
 
   {
 
       return $this->db->insert('user'$data);
 
   }
 
   
    
//send verification email to user's email id
 
   function sendEmail($to_email)
 
   {
 
       $from_email '@gmail.com'//change this to yours
 
       $subject 'Aktivasi Akun';
 
       $message 'Dear'$username .'<br /><br />Please click on the below activation link to verify your email address.<br /><br /> 
  '
site_url('voter/voter_register/verify/'.md5($to_email)) . '<br /><br /><br />Thanks<br />Admin, Gus bala';
 
       
        
//configure email settings
 
       $config['protocol'] = 'smtp';
 
       $config['smtp_host'] = 'ssl://smtp.googlemail.com'//smtp host name
 
       $config['smtp_port'] = '465'//smtp port number
 
       $config['smtp_user'] = $from_email;
 
       $config['smtp_pass'] = ''//$from_email password
 
       $config['mailtype'] = 'html';
 
       $config['charset'] = 'iso-8859-1';
 
       $config['wordwrap'] = TRUE;
 
       $config['newline'] = "\r\n"//use double quotes
 
       $this->email->initialize($config);
 
       
        
//send mail
 
       $this->email->from($from_email'Admin Evoting');
 
       $this->email->to($to_email);
 
       $this->email->subject($subject);
 
       $this->email->message($message);
 
       return $this->email->send();
 
   }
 
   
    
//activate user account
 
   function verifyEmailID($key)
 
   {
 
       $data = array('status' => 1);
 
       $this->db->where('md5(email)'$key);
 
       $this->db->update('user'$data);
 
   


and here is my Controller.


PHP Code:
<?php
class Voter_register extends CI_Controller
{
 
   public function __construct()
 
   {
 
       parent::__construct();
 
       $this->load->helper(array('form','url'));
 
       $this->load->library(array('session''form_validation''email'));
 
       $this->load->database();
 
       $this->load->model('Voter_model');
 
   }
 
   
    function index
()
 
   {
 
       $this->register();
 
   }
    
    
    
 
   function register()
 
   {
 
       //set validation rules
 
       
        $this
->form_validation->set_rules('email''Email ID''trim|required|valid_email|is_unique[user.email]');
 
       $this->form_validation->set_rules('password''Password''trim|required|matches[cpassword]');
 
       $this->form_validation->set_rules('cpassword''Confirm Password''trim|required');
 
       
        
//validate form input
 
       if ($this->form_validation->run() == FALSE)
 
       {
 
           // fails
 
           $this->load->view('voter/voter_register');
 
       }
 
       else
        
{
 
           //insert the user registration details into database
 
           $data = array(
 
               'fname' => $this->input->post('fname'),
 
               'lname' => $this->input->post('lname'),
 
               'email' => $this->input->post('email'),
 
               'password' => $this->input->post('password'),
                 
'username' => $this->input->post('username')
 
           );
 
           
            
// insert form data into database
 
           if ($this->Voter_model->insertUser($data))
 
           {
 
               // send email
 
               if ($this->Voter_model->sendEmail($this->input->post('email')))
 
               {
 
                   // successfully sent mail
 
                   $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Registrasi Sukses, silakan cek e-mail Anda untuk melakukan konfirmasi dan aktivasi akun.</div>');
 
                   redirect('admin_voter');
 
               }
 
               else
                
{
 
                   // error
 
                   $this->session->set_flashdata('msg','<div class="alert alert-info text-center">Registrasi Sukses, gagal mengirim e-mail verifikasi.</div>');
 
                   redirect('admin_voter');
 
               }
 
           }
 
           else
            
{
 
               // error
 
               $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
 
               redirect('admin_voter');
 
           }
 
       }
 
   }
 
   
    function verify
($hash)
 
   {
        
$this->load->helper('url');
         
$this->load->model('voter_model');

 
       if ($this->voter_model->verifyEmailID($hash))
 
       {
 
           
            $this
->load->view('voter/voter_aktivasiok');
 
       }
 
       else
        
{
 
          
            $this
->load->view('voter/voter_aktivasifail');
 
       }
 
   }
}
?>

Thanks for any help.

Using preg_replace_callback with a href

$
0
0
In my preg_replace_callback I can allow some elements to be showing in preview using the preg_replace_callback

How ever when the user has typed in a link lets say <a href="http://www.example.com">Example</a>

The preview will only put out <a href="http://www.example.com">Example

Is there any way I can integrate this


PHP Code:
preg_replace("~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~","<a href=\"\\0\">\\0</a>"$string


Into the code below


PHP Code:
public function preview() {
    $data = array('success' => false'question' => '');

    if ($_POST) {

        $string $this->input->post('question');

           $match = array(
            '<' => '<',
            '>' => '>',
        );

        $new_data preg_replace_callback("#</?(pre|code|h1|h2|h3|h4|h5|h6|b|strong|i|u|hr)>|[<>]#", function ($match) {
            return $match[0] == '<' '<' : ($match[0] == '>' '>' $match[0]);
        }, $string);

        $data['question'] = parse_smileys($new_database_url('assets/img/smiley'));
        $data['success'] = true;
    }

    $this->output
           
->set_content_type('application/json')
        ->set_output(json_encode($data));

Viewing all 14075 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>