Email::email_delete_multiple()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
###############################################################################
4
# ASTPP - Open Source VoIP Billing Solution
5
#
6
# Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
7
# Samir Doshi <[email protected]>
8
# ASTPP Version 3.0 and above
9
# License https://www.gnu.org/licenses/agpl-3.0.html
10
#
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU Affero General Public License as
13
# published by the Free Software Foundation, either version 3 of the
14
# License, or (at your option) any later version.
15
# 
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
# GNU Affero General Public License for more details.
20
# 
21
# You should have received a copy of the GNU Affero General Public License
22
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
###############################################################################
24
25
class Email extends MX_Controller {
26
27 View Code Duplication
	function Email() {
28
		parent::__construct();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (__construct() instead of Email()). Are you sure this is correct? If so, you might want to change this to $this->__construct().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
29
30
		$this->load->helper('template_inheritance');
31
32
		$this->load->library('session');
33
		$this->load->library('email_form');
34
		$this->load->library('astpp/form');
35
		$this->load->model('email_model');
36
		$this->load->library('csvreader');
37
	$this->load->library('astpp/email_lib');
38
		if ($this->session->userdata('user_login') == FALSE)
39
			redirect(base_url() . '/astpp/login');
40
	}
41
42
	function email_edit($edit_id = '') {
43
		$data['page_title'] = 'Edit Email List';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
44
		if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) {
45
			$account_data = $this->session->userdata("accountinfo");
46
			$reseller = $account_data['id'];
47
			$where = array('id' => $edit_id, "reseller_id" => $reseller);
48
		} else {
49
			$where = array('id' => $edit_id);
50
		}
51
		$account = $this->db_model->getSelect("*", "mail_details", $where);
52 View Code Duplication
		if ($account->num_rows > 0) {
53
			foreach ($account->result_array() as $key => $value) {
54
				$edit_data = $value;
55
			}
56
			$data['form'] = $this->form->build_form($this->email_form->get_form_fields_email(), $edit_data);
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
57
			$this->load->view('view_email_add_edit', $data);
58
		} else {
59
			redirect(base_url() . 'email/email_history_list/');
60
		}
61
			redirect(base_url() . 'email/email_history_list/');
62
	}
63
64
	function email_resend() {
65
		$add_array = $this->input->post();
66
/**
67
ASTPP  3.0 
68
For Signup Email broadcast link change 
69
**/        
70
	$add_array = $this->db_model->getSelect("*", 'mail_details', array('id' => $add_array['id']));
71
	$add_array = $add_array->result_array();
72
	$add_array = $add_array[0];
73
/************************************************************/
74
75
		$data['page_title'] = 'Resand Email';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
76
			$where = array('id' => $add_array['id']);
77
		$account = $this->db_model->getSelect("*", "mail_details", $where);
78
			foreach ($account->result_array() as $key => $value) {
79
				$edit_data = $value;
80
			}
81
		$add_array=array('accountid'=>$edit_data['accountid'],
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
82
				 'subject'=>$add_array['subject'],
83
				 'body'=>$add_array['body'],
84
				 'from'=>$edit_data['from'],
85
				 'to'=>$edit_data['to'],
86
				 'status'=>$edit_data['status'],
87
				 'template'=>$edit_data['template'],
88
				 'attachment'=>$edit_data['attachment'],
89
			
90
				);
91
				$this->email_re_send($add_array);		
92
        
93
		$this->session->set_flashdata('astpp_errormsg', 'Email resend successfully!');
94
			redirect(base_url() . 'email/email_history_list/');
95
	}
96
	function email_resend_edit($edit_id = '') {
97
	$data['page_title'] = 'Resend Email';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
98
		$where = array('id' => $edit_id);
99
		$account = $this->db_model->getSelect("*", "mail_details", $where);
100
	  if ($account->num_rows > 0) {
101
			foreach ($account->result_array() as $key => $value) {
102
				$edit_data = $value;
103
			}
104
			$data['maildata'] = $edit_data['attachment'];            
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
105
			$data['form'] = $this->form->build_form($this->email_form->get_form_fields_email_edit(), $edit_data);
106
107
			$this->load->view('view_email_add_edit', $data);
108
		} else {
109
			redirect(base_url() . 'email/email_history_list/');
110
		}
111
112
	}
113
	function email_resend_edit_customer($edit_id = '') {
114
	$data['page_title'] = 'Resent Email';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
115
		$where = array('id' => $edit_id);
116
		$account = $this->db_model->getSelect("*", "mail_details", $where);
117
	  if ($account->num_rows > 0) {
118
			foreach ($account->result_array() as $key => $value) {
119
				$edit_data = $value;
120
			}
121
			$data['maildata'] = $edit_data['attachment'];
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
122
			$data['form'] = $this->form->build_form($this->email_form->get_form_fields_email_view_cus_edit(), $edit_data);
123
124
			$this->load->view('view_email_add_edit', $data);
125
		} else {
126
			redirect(base_url() . 'email/email_history_list/');
127
		}
128
129
	}
130
131
	function email_resend_customer($edit_id = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $edit_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
132
		$add_array = $this->input->post();
133
		$data['page_title'] = 'Resand Email';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
134
			$where = array('id' => $add_array['id']);
135
		$account = $this->db_model->getSelect("*", "mail_details", $where);
136
			foreach ($account->result_array() as $key => $value) {
137
				$edit_data = $value;
138
			}
139
		$add_array=array('accountid'=>$edit_data['accountid'],
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
140
				 'subject'=>$add_array['subject'],
141
				 'body'=>$add_array['body'],
142
				 'from'=>$edit_data['from'],
143
				 'to'=>$edit_data['to'],
144
				 'status'=>$edit_data['status'],
145
				 'template'=>$edit_data['template'],
146
				 'attachment'=>$edit_data['attachment'],
147
				);
148
			$this->email_model->add_email($add_array);
149
			$this->email_lib->send_email('',$add_array,'','',1);
150
151
			$this->load->module('accounts/accounts');
152
		$this->session->set_flashdata('astpp_errormsg', 'Email resend successfully!');
153
			redirect(base_url() . 'accounts/customer_edit/'.$value["accountid"]);
0 ignored issues
show
Bug introduced by
The variable $value seems to be defined by a foreach iteration on line 136. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
154
	}
155 View Code Duplication
	function email_add($type = "") {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
156
157
		$data['username'] = $this->session->userdata('user_name');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
158
		$data['flag'] = 'create';
159
		$data['page_title'] = 'Create Commission Rate';
160
		$data['form'] = $this->form->build_form($this->email_form->get_form_fields_email(), '');
161
162
		$this->load->view('view_email_add_edit', $data);
163
	}
164 View Code Duplication
	function email_save() {
165
		$add_array = $this->input->post();
166
		$data['form'] = $this->form->build_form($this->email_form->get_form_fields_email(), $add_array);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
167
		if ($add_array['id'] != '') {
168
			$data['page_title'] = 'Edit email List';
169
			if ($this->form_validation->run() == FALSE) {
170
				$data['validation_errors'] = validation_errors();
171
				echo $data['validation_errors'];
172
				exit;
173
			} else {
174
				$this->email_model->edit_email($add_array, $add_array['id']);
175
				echo json_encode(array("SUCCESS"=> "Email list updated successfully!"));
176
				exit;
177
			}
178
		} else {
179
			$data['page_title'] = 'Create Email List';
180
			if ($this->form_validation->run() == FALSE) {
181
				$data['validation_errors'] = validation_errors();
182
				echo $data['validation_errors'];
183
				exit;
184
			} else {
185
				$this->email_model->add_email($add_array);
186
				echo json_encode(array("SUCCESS"=> "Email list added successfully!"));
187
				exit;
188
			}
189
		}
190
	}
191
	function email_re_send($edit_data) {
192
	$this->email_lib->send_email('',$edit_data,'',$edit_data['attachment'],1);
193
	$this->session->set_flashdata('astpp_errormsg', 'Email resend successfully!');
194
		redirect(base_url() . '/email/email_history_list/');
195
	}
196
	function email_view($edit_id = '') {
197
	$data['page_title'] = 'View Email';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
198
		$where = array('id' => $edit_id);
199
		$account = $this->db_model->getSelect("*", "mail_details", $where);
200
	  if ($account->num_rows > 0) {
201
			foreach ($account->result_array() as $key => $value) {
202
				$edit_data = $value;
203
			}  
204
			if($edit_data['status'] == 1){
205
				$edit_data['status']='Not Sent';
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
206
			} else{
207
				$edit_data['status']='Sent';
208
			}
209
			$data['form'] = $this->form->build_form($this->email_form->get_form_fields_email_view(), $edit_data);
210
211
			$this->load->view('view_email_add_edit', $data);
212
		} else {
213
			redirect(base_url() . 'email/email_history_list/');
214
		}
215
	}
216
	function email_view_customer($edit_id = '') {
217
	$data['page_title'] = 'View Email';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
218
		$where = array('id' => $edit_id);
219
		$account = $this->db_model->getSelect("*", "mail_details", $where);
220 View Code Duplication
	  if ($account->num_rows > 0) {
221
			foreach ($account->result_array() as $key => $value) {
222
				$edit_data = $value;
223
			}
224
			$data['form'] = $this->form->build_form($this->email_form->get_form_fields_email_view_cus(), $edit_data);
0 ignored issues
show
Bug introduced by
The variable $edit_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
225
			$this->load->view('view_email_add_edit', $data);
226
		} else {
227
			redirect(base_url() . 'email/email_history_list/'.$edit_id);
228
		}
229
	}
230
	function email_delete($id) {
231
		$this->email_model->remove_email($id);
232
		$this->session->set_flashdata('astpp_notification', 'Email removed successfully!');
233
		redirect(base_url() . '/email/email_history_list/');
234
	}
235
	function email_delete_customer($accounttype,$accountid,$id) {
236
		$this->email_model->remove_email($id);
237
		$where = array('id' => $id);
238
		$account = $this->db_model->getSelect("*", "mail_details", $where);
239
	foreach ($account->result_array() as $key => $value) {
240
		$edit_data = $value;
241
	}
242
		$url ="accounts/".$accounttype."_emailhistory/$accountid/";
243
		$this->session->set_flashdata('astpp_notification', 'Email removed successfully!');
244
	$this->load->module('accounts/accounts');
245
		redirect(base_url() . $url);
246
	}
247
	function email_mass() {
248
		$account_data = $this->session->userdata("accountinfo");
249
		if ($account_data['type'] == '1' || $account_data['type']== 0 || $account_data['type']==3)
250
			redirect(base_url() . '/astpp/dashboard/');
251
	$data['username'] = $this->session->userdata('user_name');	
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
252
		$data['page_title'] = 'Email Mass';
253
		$data['form'] = $this->form->build_form($this->email_form->build_list_for_email_client_area(), '');
254
	$this->load->view('view_email_client_area',$data); 
255
	}
256
 /*Mass Email*/
257 View Code Duplication
   function attachment_icons($select = "", $table = "", $attachement="") {
0 ignored issues
show
Unused Code introduced by
The parameter $select is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
258
	if($attachement!="")
259
	{
260
		$array=explode(",", $attachement);
261
		$str='';
262
		foreach($array as $key =>$val){
263
			$link = base_url() . "email/email_history_list_attachment/".$val;
264
			$str.="<a href='".$link."' title='".$val."' class='btn btn-royelblue btn-sm'><i class='fa fa-paperclip fa-fw'></i></a>&nbsp;&nbsp;";
265
		}
266
		return $str;
267
	} else{
268
		return "";
269
	}
270
	}
271
	function email_client_get()
272
	  {
273
		   $files=$_FILES;
274
		   $add_array = $this->input->post();
275
		   $add_array['page_title'] = 'Compose email';
276
		   $nooffile= $files['file']['name'];
277
		   $count=count($nooffile);
278
		   $add_array['attachment']='';
279
		   $add_array['file']='';
280
		   for($i=0;$i<$count;$i++){
281
			   $tmp_name[]= $files['file']['tmp_name'][$i];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tmp_name was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tmp_name = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
282
			   if($files['file']['error'][$i]==0){
283
				   $cur_name = $files['file']['name'][$i];
284
				   $parts = explode(".", $cur_name);
285
				   $add_array['attachment'].=date('ymdhis').$i.'.'.$parts[1].',';
286
				   $add_array['file'].=date('ymdhis').$i.'.'.$parts[1].',';
287
			 		   $uploadedFile1 = $files['file']['tmp_name'][$i];
288
				   $user_name='inextrix';
289
				   $actual_file_name=date('ymdhis').$i.'.'.$parts[1];
290
				   $dir_path=  getcwd()."/attachments/";
291
				   $path =$dir_path.$actual_file_name;
292
				   if (move_uploaded_file($uploadedFile1,$path)) {
293
				   $this->session->set_flashdata('astpp_errormsg', 'files added successfully!');
294
				   }
295
				   else{
296
					$this->session->set_flashdata('astpp_errormsg', 'Please try again   !');
297
				   }
298
			   }
299
		   }
300
		   $add_array['attachment']=trim($add_array['attachment'],',');
301
		   $add_array['file']=trim($add_array['file'],',');
302
			   $add_array['email']= explode(",",$add_array['to']);   
303
			   $this->email_model->multipal_email($add_array);
304
			   $screen_path = getcwd()."/cron";
305
			   $screen_filename = "Email_Broadcast_".strtotime('now');
306
			   $command = "cd ".$screen_path." && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
307
			   exec($command);
308
			   $this->session->set_flashdata('astpp_errormsg', 'Email broad cast successfully!');
309
			   redirect(base_url() . 'email/email_history_list/');
310
			   exit; 
311
		}
312
    
313
	   function email_client_area() {
314
		$add_array = $this->input->post();
315
		if($add_array['temp'] == ''){
316
	 	$subject = '';
317
		$body ='';	
318
			 }
319
		else{
320
				$where = array('id' => $add_array['temp']);
321
		$account = $this->db_model->getSelect("subject,template", "default_templates", $where);
322
		$account_data =$account->result_array();
323
				$subject = isset($account_data[0]['subject'])?$account_data[0]['subject']:'';
324
		$body = isset($account_data[0]['template'])?$account_data[0]['template']:'';	
325
	
326
            
327
		}
328
	   	$count_all = $this->email_model->get_email_client_data($add_array);
329
	$email_arr = array();
330
	$id_arr = array();
331
	foreach($count_all as $key=>$value){
332
		$value = $value;
0 ignored issues
show
Bug introduced by
Why assign $value to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
333
		if($value['email']!=''){
334
		$email_arr[$value['email']]= $value['email'];
335
		$id_arr[]= $value['id'];}
336
	} 
337
	if (empty($email_arr))
338
	{
339
			$this->session->set_flashdata('astpp_notification', 'No record found! ');
340
			redirect(base_url() . 'email/email_mass/');
341
	}
342
	$to_email = $email_arr;
343
	
344
	$to_id = $id_arr;
345
	$to_send_mail = implode(",",$to_email);
346
	if($to_send_mail != ''){
347
		$add_arr['email']= $email_arr;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$add_arr was never initialized. Although not strictly required by PHP, it is generally a good practice to add $add_arr = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
348
	}
349
	$data['username'] = $this->session->userdata('user_name');	
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
350
	$data['page_title'] = 'Compose Email';
351
	$send_id = $this->db_model->getSelect("emailaddress", "invoice_conf", array());
352
	$send_id =$send_id->result_array();
353
	$send_id =$send_id[0]['emailaddress'];
354
	$add_arr['template'] = $body;
0 ignored issues
show
Bug introduced by
The variable $add_arr does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
355
	$add_arr['subject'] = $subject;
356
		$add_arr['accountid'] = $id_arr;
357
	$add_arr['from'] = $send_id;
358
	$add_arr['temp'] = $add_array['temp'];
359
	$add_arr['to']=$to_send_mail;
360
	$add_arr['temp']=$add_array['temp'];
361
		$this->load->view('view_email_brod', $add_arr);
362
	}
363
364
/********************************************************/
365
	function email_history_list_customer() {
366
	$add_array = $this->input->post();
367
			$where = array('id' => $add_array['id']);
368
		$account = $this->db_model->getSelect("*", "mail_details", $where);
369
			foreach ($account->result_array() as $key => $value) {
370
				$edit_data = $value;
371
			}
372
		$this->load->module('accounts/accounts');
373
			redirect(base_url() . 'accounts/customer_edit/'.$value['accountid']);
0 ignored issues
show
Bug introduced by
The variable $value seems to be defined by a foreach iteration on line 369. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
374
	}
375
	function email_history_list() {
376
	$data['logintype']=$this->session->userdata('logintype');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
377
		$data['username'] = $this->session->userdata('user_name');
378
		$data['search_flag'] = true;
379
		$this->session->set_userdata('advance_search', 0);
380
	$data['page_title'] = 'Email History List';
381
	$data['grid_fields'] = $this->email_form->build_list_for_email();
382
	$data["grid_buttons"] = $this->email_form->build_grid_buttons_email();
383
		$data['form_search'] = $this->form->build_serach_form($this->email_form->get_email_history_search_form());
384
	$this->load->view('view_email_list', $data);
385
	}
386 View Code Duplication
	function email_history_list_json() {
387
	$data['logintype']=$this->session->userdata('logintype');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
388
		$json_data = array();
389
		$count_all = $this->email_model->get_email_list(false);
390
		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
391
		$json_data = $paging_data["json_paging"];
392
		$query = $this->email_model->get_email_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
393
	$grid_fields = json_decode($this->email_form->build_list_for_email());
394
		$json_data['rows'] = $this->form->build_grid($query, $grid_fields);
395
		echo json_encode($json_data);
396
	}
397
398 View Code Duplication
	function customer_mail_record($accountid,$accounttype){
399
		$json_data = array();
400
		$count_all = $this->email_model->customer_get_email_list(false,$accountid,"","");
401
		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
402
		$json_data = $paging_data["json_paging"];
403
		$query = $this->email_model->customer_get_email_list(true,$accountid,$paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
404
	$grid_fields = json_decode($this->email_form->build_list_for_email_customer($accountid,$accounttype));
405
		$json_data['rows'] = $this->form->build_grid($query, $grid_fields);
406
		echo json_encode($json_data);
407
	}    
408
	function email_delete_multiple() {
409
		$ids = $this->input->post("selected_ids", true);
410
		$where = "id IN ($ids)";
411
		$this->db->where($where);
412
		echo $this->db->delete("email");
413
	}
414
415
	function email_send_multipal(){
416
	$add_array = $this->input->post();
417
	if($add_array['email'] == '' || $add_array['subject'] == '' || $add_array['template'] == ''){
418
		$this->session->set_flashdata('astpp_notification', 'Email address not found!');
419
			redirect(base_url() . '/email/email_client_area/');
420
	}
421
		$this->email_model->multipal_email($add_array);
422
	$screen_path = "/var/www/html/ITPLATP/cron";
423
	$screen_filename = "Email_Broadcast_".strtotime('now');
424
	$command = "cd ".$screen_path." && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
425
		exec($command);
426
	$this->session->set_flashdata('astpp_errormsg', 'Email broad cast successfully!');
427
		redirect(base_url() . 'email/email_history_list/');
428
429
	}
430 View Code Duplication
	function email_history_list_search() {
431
		$ajax_search = $this->input->post('ajax_search', 0);
432
433
		if ($this->input->post('advance_search', TRUE) == 1) {
434
			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
435
			$action = $this->input->post();
436
			unset($action['action']);
437
			unset($action['advance_search']);
438
			$this->session->set_userdata('email_search_list', $action);
439
		}
440
		if (@$ajax_search != 1) {
441
			redirect(base_url() . 'email/email_history_list/');
442
		}
443
	}
444
445
	function email_history_list_clearsearchfilter() {
446
		$this->session->set_userdata('advance_search', 0);
447
		$this->session->set_userdata('email_search', "");
448
	}
449
	/*
450
	* Purpose : Add following code for download attached file
451
	* Version 2.1
452
    */
453
	function email_history_list_attachment($file_name) {
454
	if(file_exists(getcwd().'/attachments/'.$file_name)){
455
		header('Content-Type: application/octet-stream');
456
		header('Content-Disposition: attachment; filename='.$file_name);
457
		ob_clean();
458
		flush();
459
		readfile(getcwd().'/attachments/'.$file_name);
460
	}
461
	}
462
463
}
464
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
465
 
466