Passed
Pull Request — v3.0 (#166)
by Samir
12:13
created
web_interface/astpp/application/models/astpp_common.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -22,133 +22,133 @@
 block discarded – undo
22 22
 ###############################################################################
23 23
 
24 24
 class Astpp_common extends CI_Model {
25
-    // ------------------------------------------------------------------------
26
-    /**
27
-     * initialises the class inheriting the methods of the class Model 
28
-     *
29
-     * @return Usermodel
30
-     */
31
-    function Astpp_common() {
32
-        parent::__construct();
33
-    }
34
-    /**
35
-     * -------Here we write code for model astpp_common_model functions list_applyable_charges------
36
-     * Purpose: build array for applyable charge dropdown list.
37
-     * @param 
38
-     * @return return array of applyable chargelist.
39
-     */
40
-    function list_applyable_charges($accountid = '') {
41
-        $accountinfo = $this->session->userdata('accountinfo');
42
-        $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0;
25
+	// ------------------------------------------------------------------------
26
+	/**
27
+	 * initialises the class inheriting the methods of the class Model 
28
+	 *
29
+	 * @return Usermodel
30
+	 */
31
+	function Astpp_common() {
32
+		parent::__construct();
33
+	}
34
+	/**
35
+	 * -------Here we write code for model astpp_common_model functions list_applyable_charges------
36
+	 * Purpose: build array for applyable charge dropdown list.
37
+	 * @param 
38
+	 * @return return array of applyable chargelist.
39
+	 */
40
+	function list_applyable_charges($accountid = '') {
41
+		$accountinfo = $this->session->userdata('accountinfo');
42
+		$reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0;
43 43
 	$q = " SELECT * FROM `charges` where reseller_id =$reseller_id and id NOT IN(select charge_id from charge_to_account where accountid  =$accountid) AND pricelist_id = '0'";
44
-        $item_arr = array();
45
-        $query = $this->db->query($q);
46
-        if ($query->num_rows() > 0) {
47
-            foreach ($query->result_array() as $row) {
48
-                if ($row['charge'] > 0) {
49
-                    $row['charge'] = $this->common_model->calculate_currency($row['charge']);
50
-                }
51
-                $item_arr[$row['id']] = $row['description'].' - '.$row['charge'];
52
-            }
53
-        }
54
-        return $item_arr;
55
-    }
56
-    function quote($inp) {
57
-        return "'".$this->db->escape_str($inp)."'";
58
-    }
44
+		$item_arr = array();
45
+		$query = $this->db->query($q);
46
+		if ($query->num_rows() > 0) {
47
+			foreach ($query->result_array() as $row) {
48
+				if ($row['charge'] > 0) {
49
+					$row['charge'] = $this->common_model->calculate_currency($row['charge']);
50
+				}
51
+				$item_arr[$row['id']] = $row['description'].' - '.$row['charge'];
52
+			}
53
+		}
54
+		return $item_arr;
55
+	}
56
+	function quote($inp) {
57
+		return "'".$this->db->escape_str($inp)."'";
58
+	}
59 59
 
60
-    /**
61
-     * @param string $q
62
-     * @param string $colname
63
-     */
64
-    function db_get_item($q, $colname) {
65
-        $item_arr = array();
66
-        $query = $this->db->query($q);
67
-        if ($query->num_rows() > 0) {
68
-            $row = $query->row_array();
69
-            return $row[$colname];
70
-        }
71
-        return '';
72
-    }
73
-    // Return the balance for a specific ASTPP account.
74
-    function accountbalance($account) {
75
-        $debit = 0;
76
-        $q = "SELECT SUM(debit) as val1 FROM cdrs WHERE accountid=".$this->quote($account)." AND status NOT IN (1, 2)";
77
-        $query = $this->db->query($q);
78
-        if ($query->num_rows() > 0) {
79
-            $row = $query->row_array();
80
-            $debit = $row['val1'];
81
-        }
82
-        $credit = 0;
83
-        $q = "SELECT SUM(credit) as val1  FROM cdrs WHERE accountid= ".$this->quote($account)." AND status NOT IN (1, 2)";
84
-        $query = $this->db->query($q);
85
-        if ($query->num_rows() > 0) {
86
-            $row = $query->row_array();
87
-            $credit = $row['val1'];
88
-        }
89
-        $posted_balance = 0;
90
-        $q = "SELECT * FROM accounts WHERE id = ".$this->quote($account);
91
-        $query = $this->db->query($q);
92
-        if ($query->num_rows() > 0) {
93
-            $row = $query->row_array();
94
-            $posted_balance = $row['balance'];
95
-        }
96
-        $balance = ($debit - $credit + $posted_balance);
97
-        return $balance;
98
-    }
99
-    function accounts_total_balance($reseller) {
100
-        $debit = 0;
101
-        $credit = 0;
102
-        if ($reseller == "") {
103
-            $q = "SELECT SUM(debit) as val1 FROM cdrs WHERE status NOT IN (1, 2)";
104
-            $debit = $this->db_get_item($q, 'val1');
60
+	/**
61
+	 * @param string $q
62
+	 * @param string $colname
63
+	 */
64
+	function db_get_item($q, $colname) {
65
+		$item_arr = array();
66
+		$query = $this->db->query($q);
67
+		if ($query->num_rows() > 0) {
68
+			$row = $query->row_array();
69
+			return $row[$colname];
70
+		}
71
+		return '';
72
+	}
73
+	// Return the balance for a specific ASTPP account.
74
+	function accountbalance($account) {
75
+		$debit = 0;
76
+		$q = "SELECT SUM(debit) as val1 FROM cdrs WHERE accountid=".$this->quote($account)." AND status NOT IN (1, 2)";
77
+		$query = $this->db->query($q);
78
+		if ($query->num_rows() > 0) {
79
+			$row = $query->row_array();
80
+			$debit = $row['val1'];
81
+		}
82
+		$credit = 0;
83
+		$q = "SELECT SUM(credit) as val1  FROM cdrs WHERE accountid= ".$this->quote($account)." AND status NOT IN (1, 2)";
84
+		$query = $this->db->query($q);
85
+		if ($query->num_rows() > 0) {
86
+			$row = $query->row_array();
87
+			$credit = $row['val1'];
88
+		}
89
+		$posted_balance = 0;
90
+		$q = "SELECT * FROM accounts WHERE id = ".$this->quote($account);
91
+		$query = $this->db->query($q);
92
+		if ($query->num_rows() > 0) {
93
+			$row = $query->row_array();
94
+			$posted_balance = $row['balance'];
95
+		}
96
+		$balance = ($debit - $credit + $posted_balance);
97
+		return $balance;
98
+	}
99
+	function accounts_total_balance($reseller) {
100
+		$debit = 0;
101
+		$credit = 0;
102
+		if ($reseller == "") {
103
+			$q = "SELECT SUM(debit) as val1 FROM cdrs WHERE status NOT IN (1, 2)";
104
+			$debit = $this->db_get_item($q, 'val1');
105 105
 
106
-            $q = "SELECT SUM(credit)  as val1 FROM cdrs WHERE status NOT IN (1, 2)";
107
-            $credit = $this->db_get_item($q, 'val1');
106
+			$q = "SELECT SUM(credit)  as val1 FROM cdrs WHERE status NOT IN (1, 2)";
107
+			$credit = $this->db_get_item($q, 'val1');
108 108
 
109
-            $tmp = "SELECT SUM(balance) as val1 FROM accounts WHERE reseller_id = ''";
110
-        } else {
111
-            $tmp = "SELECT SUM(balance) as val1 FROM accounts WHERE reseller_id = ".$this->quote($reseller);
112
-        }
113
-        $posted_balance = $this->db_get_item($tmp, "val1");
109
+			$tmp = "SELECT SUM(balance) as val1 FROM accounts WHERE reseller_id = ''";
110
+		} else {
111
+			$tmp = "SELECT SUM(balance) as val1 FROM accounts WHERE reseller_id = ".$this->quote($reseller);
112
+		}
113
+		$posted_balance = $this->db_get_item($tmp, "val1");
114 114
 
115
-        $balance = ($debit - $credit + $posted_balance);
116
-        return $balance;
117
-    }
118
-    function count_dids($test) {
119
-        $tmp = "SELECT COUNT(*) as val1 FROM dids ".$test;
120
-        return $this->db_get_item($tmp, 'val1');
121
-    }
115
+		$balance = ($debit - $credit + $posted_balance);
116
+		return $balance;
117
+	}
118
+	function count_dids($test) {
119
+		$tmp = "SELECT COUNT(*) as val1 FROM dids ".$test;
120
+		return $this->db_get_item($tmp, 'val1');
121
+	}
122 122
 
123
-    function count_callingcards($where, $field = 'COUNT(*)') {
124
-        $tmp = "SELECT $field as val FROM callingcards ".$where;
125
-        return $this->db_get_item($tmp, 'val');
126
-    }
123
+	function count_callingcards($where, $field = 'COUNT(*)') {
124
+		$tmp = "SELECT $field as val FROM callingcards ".$where;
125
+		return $this->db_get_item($tmp, 'val');
126
+	}
127 127
 
128
-    function count_accounts($test) {
129
-        $tmp = "SELECT COUNT(*) as val1 FROM accounts ".$test;
130
-        return $this->db_get_item($tmp, 'val1');
131
-    }
128
+	function count_accounts($test) {
129
+		$tmp = "SELECT COUNT(*) as val1 FROM accounts ".$test;
130
+		return $this->db_get_item($tmp, 'val1');
131
+	}
132 132
 
133
-    function count_rategroup($test) {
133
+	function count_rategroup($test) {
134 134
 	 $tmp = "SELECT COUNT(*) as val1 FROM pricelists ".$test;
135
-        return $this->db_get_item($tmp, 'val1');
136
-    }
135
+		return $this->db_get_item($tmp, 'val1');
136
+	}
137 137
 
138
-    function count_termination($test = '') {
138
+	function count_termination($test = '') {
139 139
 	 $tmp = "SELECT COUNT(*) as val1 FROM outbound_routes ".$test;
140
-        return $this->db_get_item($tmp, 'val1');
141
-    }
140
+		return $this->db_get_item($tmp, 'val1');
141
+	}
142 142
 
143
-    function count_trunk($test = '') {
143
+	function count_trunk($test = '') {
144 144
 	 $tmp = "SELECT COUNT(*) as val1 FROM trunks ".$test;
145
-        return $this->db_get_item($tmp, 'val1');
146
-    }
145
+		return $this->db_get_item($tmp, 'val1');
146
+	}
147 147
 
148
-    function count_origination($test = '') {
148
+	function count_origination($test = '') {
149 149
 	 $tmp = "SELECT COUNT(*) as val1 FROM routes ".$test;
150
-        return $this->db_get_item($tmp, 'val1');
151
-    }
150
+		return $this->db_get_item($tmp, 'val1');
151
+	}
152 152
 
153 153
 } 
154 154
 ?>
Please login to merge, or discard this patch.
web_interface/astpp/application/models/auth_model.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -23,33 +23,33 @@
 block discarded – undo
23 23
 
24 24
 class Auth_model extends CI_Model {
25 25
 
26
-    function Auth_model() {
27
-        parent::__construct();
28
-    }
29
-    /**
30
-     * -------Here we write code for model auth_model functions verify_login------
31
-     * Purpose: Validate Login Name and Password.
32
-     * @param $username,$password.
33
-     * @return integer login user name and password is valid then return true else return false.
34
-     */
35
-       function verify_login($username, $password) {
36
-        $q = "SELECT COUNT(*) as cnt FROM accounts WHERE (number = '".$this->db->escape_str($username)."'";
26
+	function Auth_model() {
27
+		parent::__construct();
28
+	}
29
+	/**
30
+	 * -------Here we write code for model auth_model functions verify_login------
31
+	 * Purpose: Validate Login Name and Password.
32
+	 * @param $username,$password.
33
+	 * @return integer login user name and password is valid then return true else return false.
34
+	 */
35
+	   function verify_login($username, $password) {
36
+		$q = "SELECT COUNT(*) as cnt FROM accounts WHERE (number = '".$this->db->escape_str($username)."'";
37 37
 	$q .= " OR email = '".$this->db->escape_str($username)."')";
38
-        $q .= " AND password = '".$this->db->escape_str($password)."'";
39
-        $q .= " AND status = 0 AND type IN (1,2,3,4,5,0,-1) AND deleted = 0";
40
-        $query = $this->db->query($q);
41
-        if ($query->num_rows() > 0) {
42
-            $row = $query->row();
43
-            if ($row->cnt > 0) {
44
-                $this->session->set_userdata('user_name', $username);
45
-                return 1;
46
-            } else {
47
-                return 0;
48
-            }
49
-        }
38
+		$q .= " AND password = '".$this->db->escape_str($password)."'";
39
+		$q .= " AND status = 0 AND type IN (1,2,3,4,5,0,-1) AND deleted = 0";
40
+		$query = $this->db->query($q);
41
+		if ($query->num_rows() > 0) {
42
+			$row = $query->row();
43
+			if ($row->cnt > 0) {
44
+				$this->session->set_userdata('user_name', $username);
45
+				return 1;
46
+			} else {
47
+				return 0;
48
+			}
49
+		}
50 50
 
51
-        return 0;
52
-    }
51
+		return 0;
52
+	}
53 53
 }
54 54
 
55 55
 //end class
Please login to merge, or discard this patch.
web_interface/astpp/application/controllers/currencyupdate.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -21,48 +21,48 @@  discard block
 block discarded – undo
21 21
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 22
 ###############################################################################
23 23
 class Currencyupdate extends CI_Controller {
24
-    function __construct()
25
-    {
26
-        parent::__construct();
27
-     //   if(!defined( 'CRON' ) )
28
-       //   exit();
29
-        $this->load->model("db_model");
30
-        $this->load->library("astpp/common");
31
-    }
32
-    function update_currency() {
33
-        $where = array("currency <>"=> Common_model::$global_config['system_config']['base_currency']);
34
-        $query = $this->db_model->getSelect("*", "currency", $where);
24
+	function __construct()
25
+	{
26
+		parent::__construct();
27
+	 //   if(!defined( 'CRON' ) )
28
+	   //   exit();
29
+		$this->load->model("db_model");
30
+		$this->load->library("astpp/common");
31
+	}
32
+	function update_currency() {
33
+		$where = array("currency <>"=> Common_model::$global_config['system_config']['base_currency']);
34
+		$query = $this->db_model->getSelect("*", "currency", $where);
35 35
 
36
-        if ($query->num_rows > 0) {
37
-            $currency_data = $query->result_array();
38
-    		$url = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=";
39
-	    	foreach ($currency_data as $currency_value) {
40
-	    	    $url .= Common_model::$global_config['system_config']['base_currency'].$currency_value['currency'].'=X+';
41
-	    	}
42
-	    	$url .= '&f=l1';
36
+		if ($query->num_rows > 0) {
37
+			$currency_data = $query->result_array();
38
+			$url = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=";
39
+			foreach ($currency_data as $currency_value) {
40
+				$url .= Common_model::$global_config['system_config']['base_currency'].$currency_value['currency'].'=X+';
41
+			}
42
+			$url .= '&f=l1';
43 43
 
44
-	    	$sql = '';
45
-	    	$response = $this->curl_response($url);
46
-	    	$content_data = explode(' ', $response);
44
+			$sql = '';
45
+			$response = $this->curl_response($url);
46
+			$content_data = explode(' ', $response);
47 47
 
48
-	    	foreach ($content_data as $content_data1) {
49
-	    	   $currency_arr = explode("\n", $content_data1);
50
-	    	    foreach ($currency_arr as $final_val)
51
-	    	    {
52
-	    	        $currency_final = array();
53
-	    		    $currency_final = explode(',', $final_val);
54
-	    		    if (isset($currency_final[1]) && $currency_final[1] != "" && $currency_final[0] != '' && $currency_final[1] != 'N/A') {
55
-			      $sql = "UPDATE currency SET currencyRate = ".$currency_final[1]." WHERE currency = '".substr($currency_final[0], 4, 3)."'";
56
-			      $this->db->query($sql);
57
-	    		    }
58
-	    	    }
59
-	    	}
60
-	    	$sql = "UPDATE currency SET currencyRate = '1' WHERE currency = '".Common_model::$global_config['system_config']['base_currency']."'";
61
-                $this->db->query($sql);
62
-      }
63
-	      $this->session->set_flashdata("astpp_errormsg", "Currency exchange rates successfully updated.");
64
-	      redirect(base_url()."/systems/currency_list/");
65
-	      exit;
48
+			foreach ($content_data as $content_data1) {
49
+			   $currency_arr = explode("\n", $content_data1);
50
+				foreach ($currency_arr as $final_val)
51
+				{
52
+					$currency_final = array();
53
+					$currency_final = explode(',', $final_val);
54
+					if (isset($currency_final[1]) && $currency_final[1] != "" && $currency_final[0] != '' && $currency_final[1] != 'N/A') {
55
+				  $sql = "UPDATE currency SET currencyRate = ".$currency_final[1]." WHERE currency = '".substr($currency_final[0], 4, 3)."'";
56
+				  $this->db->query($sql);
57
+					}
58
+				}
59
+			}
60
+			$sql = "UPDATE currency SET currencyRate = '1' WHERE currency = '".Common_model::$global_config['system_config']['base_currency']."'";
61
+				$this->db->query($sql);
62
+	  }
63
+		  $this->session->set_flashdata("astpp_errormsg", "Currency exchange rates successfully updated.");
64
+		  redirect(base_url()."/systems/currency_list/");
65
+		  exit;
66 66
 	}
67 67
 
68 68
 	/**
@@ -70,15 +70,15 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	function curl_response($url)
72 72
 	{
73
-		    $ch = curl_init(); // Initialising cURL
74
-		    curl_setopt($ch, CURLOPT_URL, $url);
75
-		    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
76
-		    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
77
-		    curl_setopt($ch, CURLOPT_ENCODING, "");
78
-		    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
79
-		    $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
80
-		    curl_close($ch); // Closing cURL
81
-		    return $data;
73
+			$ch = curl_init(); // Initialising cURL
74
+			curl_setopt($ch, CURLOPT_URL, $url);
75
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
76
+			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
77
+			curl_setopt($ch, CURLOPT_ENCODING, "");
78
+			curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
79
+			$data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
80
+			curl_close($ch); // Closing cURL
81
+			return $data;
82 82
 	}
83 83
 }
84 84
 ?>
Please login to merge, or discard this patch.
web_interface/astpp/application/controllers/updateBalance.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -24,271 +24,271 @@
 block discarded – undo
24 24
 
25 25
 class UpdateBalance extends MX_Controller {
26 26
 
27
-    public $account_arr = array();
28
-    public $currentdate = '';
27
+	public $account_arr = array();
28
+	public $currentdate = '';
29 29
 
30
-    function __construct() {
31
-        parent::__construct();
32
-        $this->load->model("db_model");
33
-        $this->load->model("common_model");
34
-        $this->load->library("astpp/common");
35
-        $this->currentdate = gmdate('Y-m-d H:i:s');
36
-    }
30
+	function __construct() {
31
+		parent::__construct();
32
+		$this->load->model("db_model");
33
+		$this->load->model("common_model");
34
+		$this->load->library("astpp/common");
35
+		$this->currentdate = gmdate('Y-m-d H:i:s');
36
+	}
37 37
 
38
-    function GetUpdateBalance() {
39
-        $accounts_data = $this->get_table_data("*", "accounts", array("status" => "0", "deleted" => "0"));
40
-        foreach ($accounts_data as $account_val) {
41
-            $this->process_subscriptions($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
42
-            $this->process_DID_charges($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
43
-        }
44
-    }
38
+	function GetUpdateBalance() {
39
+		$accounts_data = $this->get_table_data("*", "accounts", array("status" => "0", "deleted" => "0"));
40
+		foreach ($accounts_data as $account_val) {
41
+			$this->process_subscriptions($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
42
+			$this->process_DID_charges($account_val, gmdate("Y-m-d H:i:s"), gmdate("Y-m-d H:i:s"));
43
+		}
44
+	}
45 45
 
46
-    function process_subscriptions($accountinfo, $startdate, $enddate, $Manualflg = false) {
46
+	function process_subscriptions($accountinfo, $startdate, $enddate, $Manualflg = false) {
47 47
 //        Defined Original Sweep it for calculation start date for first time.
48
-        $accountinfo['original_sweep_id'] = $accountinfo['sweep_id'];
49
-        $invoiceid = 0;
48
+		$accountinfo['original_sweep_id'] = $accountinfo['sweep_id'];
49
+		$invoiceid = 0;
50 50
         
51
-        // Check Charge is applied that is for first time or already calculated before
51
+		// Check Charge is applied that is for first time or already calculated before
52 52
 
53
-        $where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='".gmdate("Y-m-d H:i:s")."')";
54
-        $this->db->where('accountid', $accountinfo['id']);
55
-        $this->db->where($where);
56
-        $this->db->select('*');
57
-        $account_charges = $this->db->get('charge_to_account');
58
-        if ($account_charges->num_rows() > 0) {
59
-            $accountchargs = $account_charges->result_array();
53
+		$where = "(charge_upto ='0000-00-00 00:00:00' OR charge_upto <='".gmdate("Y-m-d H:i:s")."')";
54
+		$this->db->where('accountid', $accountinfo['id']);
55
+		$this->db->where($where);
56
+		$this->db->select('*');
57
+		$account_charges = $this->db->get('charge_to_account');
58
+		if ($account_charges->num_rows() > 0) {
59
+			$accountchargs = $account_charges->result_array();
60 60
 
61
-            foreach ($accountchargs as $accharges) {
62
-                //Get information from database of active charges.
63
-                $charge_data = $this->get_table_data("*", "charges", array("id" => $accharges['charge_id'], "status" => "0"));
64
-                if ($charge_data && ! empty($charge_data)) {
65
-                    $charge_data = $charge_data[0];
66
-                    //Get Start Date of Charge
67
-                    $charge_upto = ($accharges["charge_upto"] != "0000-00-00 00:00:00" && $accharges["charge_upto"] != "") ?
68
-                            date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) : $accharges["assign_date"];
69
-                   if ($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day'] < gmdate("d", strtotime($accharges['assign_date'])))) {
70
-                      $charge_upto = date("Y-m-".$accountinfo['invoice_day']." H:i:s", strtotime($accharges["assign_date"]));
71
-                   }
72
-                    //Overwrite Billing scehdule of customer assign proper charge
73
-                    if ($accountinfo['sweep_id'] != $charge_data['sweep_id']) {
74
-                        $accountinfo['sweep_id'] = $charge_data['sweep_id'];
75
-                    }
76
-                    //IF its already assigned before invoice start date then no need to applied same charge one more time
77
-                    if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
78
-                        $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
79
-                        if ($Manualflg) {
80
-                            $todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
81
-                        } else {
82
-                            $todate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
83
-                        }
84
-                        /*
61
+			foreach ($accountchargs as $accharges) {
62
+				//Get information from database of active charges.
63
+				$charge_data = $this->get_table_data("*", "charges", array("id" => $accharges['charge_id'], "status" => "0"));
64
+				if ($charge_data && ! empty($charge_data)) {
65
+					$charge_data = $charge_data[0];
66
+					//Get Start Date of Charge
67
+					$charge_upto = ($accharges["charge_upto"] != "0000-00-00 00:00:00" && $accharges["charge_upto"] != "") ?
68
+							date("Y-m-d H:i:s", strtotime("+1 Second", strtotime($accharges["charge_upto"]))) : $accharges["assign_date"];
69
+				   if ($accountinfo['original_sweep_id'] == 2 && $charge_data['pro_rate'] == 0 && $charge_data['sweep_id'] == 2 && ($accountinfo['invoice_day'] < gmdate("d", strtotime($accharges['assign_date'])))) {
70
+					  $charge_upto = date("Y-m-".$accountinfo['invoice_day']." H:i:s", strtotime($accharges["assign_date"]));
71
+				   }
72
+					//Overwrite Billing scehdule of customer assign proper charge
73
+					if ($accountinfo['sweep_id'] != $charge_data['sweep_id']) {
74
+						$accountinfo['sweep_id'] = $charge_data['sweep_id'];
75
+					}
76
+					//IF its already assigned before invoice start date then no need to applied same charge one more time
77
+					if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
78
+						$fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
79
+						if ($Manualflg) {
80
+							$todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
81
+						} else {
82
+							$todate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
83
+						}
84
+						/*
85 85
                          * Add assign_date and charge_upto variable for calculation purpose.
86 86
                          */
87
-                        $itemArr = array('description' => $charge_data['description'],
88
-                            'item_id' => $charge_data['id'],
89
-                            "type" => "SUBCHRG",
90
-                            "cycle" => $charge_data["sweep_id"],
91
-                            "assign_date"=>$accharges['assign_date'],
92
-                            "charge_upto"=>$accharges['charge_upto']);
87
+						$itemArr = array('description' => $charge_data['description'],
88
+							'item_id' => $charge_data['id'],
89
+							"type" => "SUBCHRG",
90
+							"cycle" => $charge_data["sweep_id"],
91
+							"assign_date"=>$accharges['assign_date'],
92
+							"charge_upto"=>$accharges['charge_upto']);
93 93
 			//Add a new arguement ($accharges) which have all information of charges.
94
-                        $lastdate = $this->calculate_charges($accountinfo, $itemArr, $charge_data["charge"], $fromdate, $todate, $charge_data["pro_rate"]);
95
-                        if ($lastdate) {
96
-                                               $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"]));
97
-                        }
98
-                    }
99
-                }
100
-            }
101
-        }
102
-    }
94
+						$lastdate = $this->calculate_charges($accountinfo, $itemArr, $charge_data["charge"], $fromdate, $todate, $charge_data["pro_rate"]);
95
+						if ($lastdate) {
96
+											   $this->db->update("charge_to_account", array("charge_upto" => $lastdate), array("charge_id" => $charge_data["id"], "accountid" => $accountinfo["id"]));
97
+						}
98
+					}
99
+				}
100
+			}
101
+		}
102
+	}
103 103
 
104
-    function process_DID_charges($AccountDATA, $startdate, $enddate, $Manualflg = false) {
105
-        $dids_data = $this->get_table_data("*", "dids", array("status" => "0", "accountid " => $AccountDATA["id"]));
106
-        $AccountDATA['original_sweep_id'] = $AccountDATA['sweep_id'];
107
-        $AccountDATA['sweep_id'] = '2';
108
-        if ($dids_data) {
109
-            foreach ($dids_data as $did_value) {
110
-                $charge_upto = ($did_value["charge_upto"] != "0000-00-00 00:00:00" && $did_value["charge_upto"] != "") ? $did_value["charge_upto"] : $did_value["assign_date"];
104
+	function process_DID_charges($AccountDATA, $startdate, $enddate, $Manualflg = false) {
105
+		$dids_data = $this->get_table_data("*", "dids", array("status" => "0", "accountid " => $AccountDATA["id"]));
106
+		$AccountDATA['original_sweep_id'] = $AccountDATA['sweep_id'];
107
+		$AccountDATA['sweep_id'] = '2';
108
+		if ($dids_data) {
109
+			foreach ($dids_data as $did_value) {
110
+				$charge_upto = ($did_value["charge_upto"] != "0000-00-00 00:00:00" && $did_value["charge_upto"] != "") ? $did_value["charge_upto"] : $did_value["assign_date"];
111 111
 
112
-                if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
113
-                    $fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
114
-                    if ($Manualflg) {
115
-                        $todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
116
-                    } else {
117
-                        $todate = gmdate("Y-m-d H:i:s", strtotime($did_value["upto_date"]));
118
-                    }
119
-                    $itemArr = array('description' => $did_value['number'],
120
-                                    'item_id' => $did_value['id'],
121
-                                    "type" => "DIDCHRG",
122
-                                    "cycle" => "2",
123
-                                    "assign_date"=>$did_value['assign_date'],
124
-                                    "charge_upto"=>$did_value['charge_upto']);
125
-                    if ($did_value['parent_id'] > 0) {
126
-                        $parent_id = $did_value['parent_id'];
127
-                        while ($parent_id != 0) {
128
-                            $reseller_dids = $this->get_table_data("*", "reseller_pricing", array("reseller_id" => $parent_id, "note" => $did_value['number']));
129
-                            $reseller_acc_data = $this->get_table_data("*", "accounts", array("id" => $parent_id));
130
-                            $reseller_acc_data = $reseller_acc_data['0'];
131
-                            $reseller_acc_data['sweep_id'] = '2';
132
-                            $reseller_dids = $reseller_dids[0];
133
-                            if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) {
134
-                                //Apply charges to resellers customers.
135
-                                $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
136
-                                if ($lastdate)
137
-                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
138
-                            } else {
139
-                                //Apply charges to Resellers.
140
-                                $lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
141
-                                if ($lastdate)
142
-                                    $this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
143
-                            }
144
-                            $parent_id = $reseller_dids['parent_id'];
145
-                        }
146
-                    }
112
+				if ($charge_upto != "0000-00-00 00:00:00" && $charge_upto != "" && strtotime($charge_upto) < strtotime($enddate)) {
113
+					$fromdate = gmdate("Y-m-d H:i:s", strtotime($charge_upto));
114
+					if ($Manualflg) {
115
+						$todate = gmdate("Y-m-d H:i:s", strtotime($enddate));
116
+					} else {
117
+						$todate = gmdate("Y-m-d H:i:s", strtotime($did_value["upto_date"]));
118
+					}
119
+					$itemArr = array('description' => $did_value['number'],
120
+									'item_id' => $did_value['id'],
121
+									"type" => "DIDCHRG",
122
+									"cycle" => "2",
123
+									"assign_date"=>$did_value['assign_date'],
124
+									"charge_upto"=>$did_value['charge_upto']);
125
+					if ($did_value['parent_id'] > 0) {
126
+						$parent_id = $did_value['parent_id'];
127
+						while ($parent_id != 0) {
128
+							$reseller_dids = $this->get_table_data("*", "reseller_pricing", array("reseller_id" => $parent_id, "note" => $did_value['number']));
129
+							$reseller_acc_data = $this->get_table_data("*", "accounts", array("id" => $parent_id));
130
+							$reseller_acc_data = $reseller_acc_data['0'];
131
+							$reseller_acc_data['sweep_id'] = '2';
132
+							$reseller_dids = $reseller_dids[0];
133
+							if (($parent_id == $reseller_dids['reseller_id'] && $did_value['accountid'] > 0) || $reseller_dids['parent_id'] == 0) {
134
+								//Apply charges to resellers customers.
135
+								$lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
136
+								if ($lastdate)
137
+									$this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
138
+							} else {
139
+								//Apply charges to Resellers.
140
+								$lastdate = $this->calculate_charges($reseller_acc_data, $itemArr, $reseller_dids["monthlycost"], $fromdate, $todate, "1");
141
+								if ($lastdate)
142
+									$this->db->update("reseller_pricing", array("charge_upto" => $lastdate), array("note" => $did_value["number"], "reseller_id" => $reseller_acc_data["id"]));
143
+							}
144
+							$parent_id = $reseller_dids['parent_id'];
145
+						}
146
+					}
147 147
 //   		else{
148
-                    $lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1");
149
-                    if ($lastdate)
150
-                      $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"]));
148
+					$lastdate = $this->calculate_charges($AccountDATA, $itemArr, $did_value["monthlycost"], $fromdate, $todate, "1");
149
+					if ($lastdate)
150
+					  $this->db->update("dids", array("charge_upto" => $lastdate), array("id" => $did_value["id"], "accountid" => $AccountDATA["id"]));
151 151
 //            	}
152
-                }
153
-            }
154
-        }
155
-    }
152
+				}
153
+			}
154
+		}
155
+	}
156 156
 
157
-    /**
158
-     * @param string $fromdate
159
-     * @param string $todate
160
-     */
161
-    function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") {
162
-        $lastdate = false;
163
-        $billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month";
164
-        $last_invoice_date = $this->common->get_invoice_date("invoice_date", $AccountDATA['id'], $AccountDATA['reseller_id']);
165
-      //Below variable gives date based on assign or creation or monthly user billing day
166
-        $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day'] < gmdate("d", strtotime($itemArr['assign_date'])))) ? date("Y-m-".$AccountDATA['invoice_day']." 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation']))));
167
-        $last_invoice_date = ($last_invoice_date <= $fromdate) ? $last_invoice_date : $fromdate;
168
-        $Charges_date_range = array();
169
-        $prorate_array = array();
170
-        $daylen = 60 * 60 * 24;
171
-        /*Get assign day and billing day for postpaid monthly user.
157
+	/**
158
+	 * @param string $fromdate
159
+	 * @param string $todate
160
+	 */
161
+	function calculate_charges($AccountDATA, $itemArr, $charge, $fromdate, $todate, $pro_rate = "1") {
162
+		$lastdate = false;
163
+		$billing_cycle = ($AccountDATA['sweep_id'] == "0") ? "1 day" : "1 month";
164
+		$last_invoice_date = $this->common->get_invoice_date("invoice_date", $AccountDATA['id'], $AccountDATA['reseller_id']);
165
+	  //Below variable gives date based on assign or creation or monthly user billing day
166
+		$last_invoice_date = ($last_invoice_date) ? $last_invoice_date : (($pro_rate == 0 && $AccountDATA['original_sweep_id'] == 2 && ($AccountDATA['invoice_day'] < gmdate("d", strtotime($itemArr['assign_date'])))) ? date("Y-m-".$AccountDATA['invoice_day']." 00:00:00") : (($pro_rate == 1 && $AccountDATA['original_sweep_id'] == 0) ? date("Y-m-d 00:00:00", strtotime($itemArr['assign_date'])) : date("Y-m-d 00:00:00", strtotime($AccountDATA['creation']))));
167
+		$last_invoice_date = ($last_invoice_date <= $fromdate) ? $last_invoice_date : $fromdate;
168
+		$Charges_date_range = array();
169
+		$prorate_array = array();
170
+		$daylen = 60 * 60 * 24;
171
+		/*Get assign day and billing day for postpaid monthly user.
172 172
          */
173
-        $assign_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? gmdate("d", strtotime($itemArr['assign_date'])) : 0;
174
-        $billing_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? $AccountDATA['invoice_day'] : 0;
175
-        //Create an array if charge not applied yet and invoice day is greater than assign_day
176
-        if ($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2) {
173
+		$assign_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? gmdate("d", strtotime($itemArr['assign_date'])) : 0;
174
+		$billing_day = ($AccountDATA['original_sweep_id'] == 2 && $AccountDATA['posttoexternal'] == 1) ? $AccountDATA['invoice_day'] : 0;
175
+		//Create an array if charge not applied yet and invoice day is greater than assign_day
176
+		if ($itemArr['charge_upto'] == "0000-00-00 00:00:00" && ($billing_day > $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2) {
177 177
 	  $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("-1 second", strtotime(date("Y-m-".$AccountDATA['invoice_day']." 00:00:00", strtotime($itemArr["assign_date"])))));
178 178
 	  $prorate_array[] = array("start_date" => date("Y-m-d H:i:s", strtotime($itemArr['assign_date'])), "end_date" => $last_invoice_date);
179 179
 	  
180
-        }
181
-        while (strtotime($last_invoice_date) <= strtotime($todate)) {
182
-            $startdate = $last_invoice_date;
183
-            $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+".$billing_cycle, strtotime($last_invoice_date)));
184
-            $Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($startdate))), "end_date" => $last_invoice_date);
185
-        }
186
-        if ( ! empty($prorate_array)) {
187
-         array_pop($Charges_date_range);
188
-         $Charges_date_range = array_merge($prorate_array, $Charges_date_range);
189
-        }
190
-        if ( ! empty($Charges_date_range)) {
191
-            foreach ($Charges_date_range as $ChargeVal) {
192
-                if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2)) {
193
-                    $ChargeVal['end_date'] = gmdate("Y-m-d 23:59:59", strtotime("-1 Day", strtotime($ChargeVal['end_date'])));
194
-                }
195
-                if ( ! empty($itemArr['charge_upto']) && empty($lastdate)) {
196
-                    $start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2) ? $itemArr['assign_date'] : $ChargeVal['start_date'];
197
-                } else {
198
-                    $start_date = (empty($lastdate)) ? $ChargeVal['start_date'] : gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate)));
199
-                }
180
+		}
181
+		while (strtotime($last_invoice_date) <= strtotime($todate)) {
182
+			$startdate = $last_invoice_date;
183
+			$last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+".$billing_cycle, strtotime($last_invoice_date)));
184
+			$Charges_date_range[] = array("start_date" =>gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($startdate))), "end_date" => $last_invoice_date);
185
+		}
186
+		if ( ! empty($prorate_array)) {
187
+		 array_pop($Charges_date_range);
188
+		 $Charges_date_range = array_merge($prorate_array, $Charges_date_range);
189
+		}
190
+		if ( ! empty($Charges_date_range)) {
191
+			foreach ($Charges_date_range as $ChargeVal) {
192
+				if (($pro_rate == 0 && $itemArr['cycle'] != 2) || (($billing_day <= $assign_day) && $pro_rate == 0 && $itemArr['cycle'] == 2 && $AccountDATA['original_sweep_id'] == 2)) {
193
+					$ChargeVal['end_date'] = gmdate("Y-m-d 23:59:59", strtotime("-1 Day", strtotime($ChargeVal['end_date'])));
194
+				}
195
+				if ( ! empty($itemArr['charge_upto']) && empty($lastdate)) {
196
+					$start_date = ($itemArr['charge_upto'] == '0000-00-00 00:00:00' && $AccountDATA['sweep_id'] == 2) ? $itemArr['assign_date'] : $ChargeVal['start_date'];
197
+				} else {
198
+					$start_date = (empty($lastdate)) ? $ChargeVal['start_date'] : gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate)));
199
+				}
200 200
 
201
-                $lastdate = date("Y-m-d H:i:s", strtotime($ChargeVal['end_date']));
202
-                $end_date_str_time = strtotime("+1 Seconds", strtotime($lastdate));
203
-                $start_date_str_time = strtotime(gmdate("Y-m-d 00:00:00", strtotime($start_date)));
204
-                $temp_f_date = new DateTime(gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate))));
205
-                $temp_t_date = new DateTime($start_date);
206
-                $diff = $temp_f_date->diff($temp_t_date);
207
-                $month = (($diff->format('%y') * 12) + $diff->format('%m'));
208
-                $temp_charge = $charge;
209
-                if (($month != "1" || $pro_rate == "0") && $itemArr['cycle'] != '0') {
210
-                  //Calculate Number of days in month from start date
211
-                    $total_num_of_day = cal_days_in_month(CAL_GREGORIAN, date('m', $start_date_str_time), date('Y', $start_date_str_time));
212
-                    $days_diff = floor(($end_date_str_time - $start_date_str_time) / $daylen);
213
-                    $chrg_per_day = ($charge / $total_num_of_day);
214
-                    $temp_charge = ($chrg_per_day * $days_diff);
215
-                }
201
+				$lastdate = date("Y-m-d H:i:s", strtotime($ChargeVal['end_date']));
202
+				$end_date_str_time = strtotime("+1 Seconds", strtotime($lastdate));
203
+				$start_date_str_time = strtotime(gmdate("Y-m-d 00:00:00", strtotime($start_date)));
204
+				$temp_f_date = new DateTime(gmdate("Y-m-d H:i:s", strtotime("+1 second", strtotime($lastdate))));
205
+				$temp_t_date = new DateTime($start_date);
206
+				$diff = $temp_f_date->diff($temp_t_date);
207
+				$month = (($diff->format('%y') * 12) + $diff->format('%m'));
208
+				$temp_charge = $charge;
209
+				if (($month != "1" || $pro_rate == "0") && $itemArr['cycle'] != '0') {
210
+				  //Calculate Number of days in month from start date
211
+					$total_num_of_day = cal_days_in_month(CAL_GREGORIAN, date('m', $start_date_str_time), date('Y', $start_date_str_time));
212
+					$days_diff = floor(($end_date_str_time - $start_date_str_time) / $daylen);
213
+					$chrg_per_day = ($charge / $total_num_of_day);
214
+					$temp_charge = ($chrg_per_day * $days_diff);
215
+				}
216 216
                 
217
-                if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date'])) {
218
-                                    $this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate);
219
-                }
220
-                //                echo "<br/> ORG CHARG : " . $charge . " Charges : " . $temp_charge . "<br/>";
221
-            }
222
-        }
223
-        return $lastdate;
224
-    }
217
+				if (strtotime($ChargeVal['start_date']) < strtotime($ChargeVal['end_date'])) {
218
+									$this->Manage_invoice_item($AccountDATA, $itemArr['description'], $itemArr['item_id'], $temp_charge, $itemArr['type'], $start_date, $lastdate, $todate);
219
+				}
220
+				//                echo "<br/> ORG CHARG : " . $charge . " Charges : " . $temp_charge . "<br/>";
221
+			}
222
+		}
223
+		return $lastdate;
224
+	}
225 225
 
226
-    /**
227
-     * @param string $todate
228
-     */
229
-    function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) {
230
-        $invoiceid = 0;
231
-        $Bal = "0.00"; 
232
-        if ($AccountData["posttoexternal"] == 0) {
233
-	    $reseller_id = $AccountData['type'] == 1 ? $AccountData['id'] : 0;
234
-	    $where = "accountid IN ('".$reseller_id."','1')";
235
-	    $this->db->where($where);
236
-	    $this->db->select('*');
237
-	    $this->db->order_by('accountid', 'desc');
238
-	    $this->db->limit(1);
239
-	    $invoiceconf = $this->db->get('invoice_conf');
240
-	    $invoice_conf = (array)$invoiceconf->first_row();
241
-	    $last_invoiceid = $this->common->get_invoice_date('invoiceid', '', $AccountData['reseller_id']);
242
-	    if ($last_invoiceid && $last_invoiceid > 0) {
243
-	    	$last_invoiceid = ($last_invoiceid + 1);
244
-  	    } else {
245
-	    	$last_invoiceid = $invoice_conf['invoice_start_from'];
246
-	    }
247
-	    $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
248
-	    $invoice_prefix = $invoice_conf['invoice_prefix'];
249
-	    $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days"));
226
+	/**
227
+	 * @param string $todate
228
+	 */
229
+	function Manage_invoice_item($AccountData, $description, $item_id, $charge, $type, $fromdate, $todate, $invoicedate) {
230
+		$invoiceid = 0;
231
+		$Bal = "0.00"; 
232
+		if ($AccountData["posttoexternal"] == 0) {
233
+		$reseller_id = $AccountData['type'] == 1 ? $AccountData['id'] : 0;
234
+		$where = "accountid IN ('".$reseller_id."','1')";
235
+		$this->db->where($where);
236
+		$this->db->select('*');
237
+		$this->db->order_by('accountid', 'desc');
238
+		$this->db->limit(1);
239
+		$invoiceconf = $this->db->get('invoice_conf');
240
+		$invoice_conf = (array)$invoiceconf->first_row();
241
+		$last_invoiceid = $this->common->get_invoice_date('invoiceid', '', $AccountData['reseller_id']);
242
+		if ($last_invoiceid && $last_invoiceid > 0) {
243
+			$last_invoiceid = ($last_invoiceid + 1);
244
+  		} else {
245
+			$last_invoiceid = $invoice_conf['invoice_start_from'];
246
+		}
247
+		$last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
248
+		$invoice_prefix = $invoice_conf['invoice_prefix'];
249
+		$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days"));
250 250
 
251
-            $invoiceid = $this->common_model->generate_receipt($AccountData["id"], $charge, $AccountData, $last_invoiceid, $invoice_prefix, $due_date);
252
-            $this->db->set('balance', 'balance-'.$charge, FALSE);
253
-            $this->db->where('id', $AccountData["id"]);
254
-            $this->db->update("accounts");
255
-            $AccountData['balance'] = ($AccountData['balance'] - $charge);
256
-            $Bal = $AccountData['balance'];
257
-        } else {
258
-            $Bal = ($AccountData["credit_limit"] - $AccountData["balance"]);
259
-        }
260
-        if ($Bal <= 0) {
261
-            $this->db->set('status', "1", FALSE);
262
-            $this->db->where('id', $AccountData["id"]);
263
-            $this->db->update("accounts");
264
-        }
265
-        $invoice_item_arr = array("accountid" => $AccountData["id"],
266
-            "reseller_id" => $AccountData["reseller_id"],
267
-            "description" => trim($description."-".$fromdate." to ".$todate),
268
-            "item_id" => $item_id, "debit" => $charge, "invoiceid" => $invoiceid,
269
-            "created_date" => trim($invoicedate),
270
-            "item_type" => $type
271
-        );
272
-        $this->manage_invoice($invoice_item_arr);
273
-    }
251
+			$invoiceid = $this->common_model->generate_receipt($AccountData["id"], $charge, $AccountData, $last_invoiceid, $invoice_prefix, $due_date);
252
+			$this->db->set('balance', 'balance-'.$charge, FALSE);
253
+			$this->db->where('id', $AccountData["id"]);
254
+			$this->db->update("accounts");
255
+			$AccountData['balance'] = ($AccountData['balance'] - $charge);
256
+			$Bal = $AccountData['balance'];
257
+		} else {
258
+			$Bal = ($AccountData["credit_limit"] - $AccountData["balance"]);
259
+		}
260
+		if ($Bal <= 0) {
261
+			$this->db->set('status', "1", FALSE);
262
+			$this->db->where('id', $AccountData["id"]);
263
+			$this->db->update("accounts");
264
+		}
265
+		$invoice_item_arr = array("accountid" => $AccountData["id"],
266
+			"reseller_id" => $AccountData["reseller_id"],
267
+			"description" => trim($description."-".$fromdate." to ".$todate),
268
+			"item_id" => $item_id, "debit" => $charge, "invoiceid" => $invoiceid,
269
+			"created_date" => trim($invoicedate),
270
+			"item_type" => $type
271
+		);
272
+		$this->manage_invoice($invoice_item_arr);
273
+	}
274 274
     
275
-    /**
276
-     * @param string $select
277
-     * @param string $table
278
-     */
279
-    function get_table_data($select, $table, $where) {
280
-        $query = $this->db_model->getSelect($select, $table, $where);
281
-        if ($query->num_rows > 0) {
282
-            $query_result = $query->result_array();
283
-            return $query_result;
284
-        } else {
285
-            return false;
286
-        }
287
-    }
275
+	/**
276
+	 * @param string $select
277
+	 * @param string $table
278
+	 */
279
+	function get_table_data($select, $table, $where) {
280
+		$query = $this->db_model->getSelect($select, $table, $where);
281
+		if ($query->num_rows > 0) {
282
+			$query_result = $query->result_array();
283
+			return $query_result;
284
+		} else {
285
+			return false;
286
+		}
287
+	}
288 288
 
289
-    function Manage_Invoice($invoice_item_arr) {
290
-       $this->db->insert("invoice_details", $invoice_item_arr);
291
-    }
289
+	function Manage_Invoice($invoice_item_arr) {
290
+	   $this->db->insert("invoice_details", $invoice_item_arr);
291
+	}
292 292
 
293 293
 }
294 294
 ?> 
Please login to merge, or discard this patch.
web_interface/astpp/application/controllers/generateInvoice.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -24,264 +24,264 @@
 block discarded – undo
24 24
 
25 25
 class GenerateInvoice extends MX_Controller {
26 26
 
27
-    public static $global_config;
27
+	public static $global_config;
28 28
 
29
-    function __construct() {
30
-        parent::__construct();
31
-        $this->load->model("db_model");
32
-        $this->load->library("astpp/common");
33
-        $this->load->library('html2pdf');
34
-        ini_set("memory_limit", "2048M");
35
-        ini_set("max_execution_time", "259200");
36
-        $this->get_system_config();
37
-    }
29
+	function __construct() {
30
+		parent::__construct();
31
+		$this->load->model("db_model");
32
+		$this->load->library("astpp/common");
33
+		$this->load->library('html2pdf');
34
+		ini_set("memory_limit", "2048M");
35
+		ini_set("max_execution_time", "259200");
36
+		$this->get_system_config();
37
+	}
38 38
 
39
-    function get_system_config() {
40
-        $query = $this->db->get("system");
41
-        $config = array();
42
-        $result = $query->result_array();
43
-        foreach ($result as $row) {
44
-            $config[$row['name']] = $row['value'];
45
-        }
46
-        self::$global_config['system_config'] = $config;
47
-    }
39
+	function get_system_config() {
40
+		$query = $this->db->get("system");
41
+		$config = array();
42
+		$result = $query->result_array();
43
+		foreach ($result as $row) {
44
+			$config[$row['name']] = $row['value'];
45
+		}
46
+		self::$global_config['system_config'] = $config;
47
+	}
48 48
 
49
-    function getInvoiceData() {
50
-        $where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0");
51
-        $query = $this->db_model->getSelect("*", "accounts", $where);
52
-        if ($query->num_rows > 0) {
53
-            $account_data = $query->result_array();
54
-            foreach ($account_data as $data_key => $account_value) {
55
-                $end_date = gmdate("Y-m-d")." 23:59:59";
56
-                $account_value['sweep_id'] = (int)$account_value['sweep_id'];
57
-                switch ($account_value['sweep_id']) {
58
-                    case 0:
59
-                        $start_date = $this->validate_invoice_date($account_value);
60
-                        if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
61
-                            $start_date = gmdate("Y-m-d H:i:s");
62
-                        }
63
-                        $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 days"));
64
-                        $this->Generate_Daily_invoice($account_value, $start_date, $end_date);
65
-                        break;
66
-                    case 2:
67
-                        if (date("d") == $account_value['invoice_day']) {
68
-                            $start_date = $this->validate_invoice_date($account_value);
69
-                            if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
70
-                                $start_date = gmdate("Y-m-d H:i:s");
71
-                            }
72
-                            $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 month"));
73
-                            $this->Generate_Monthly_invoice($account_value, $start_date, $end_date);
74
-                        }
75
-                        break;
76
-                }
77
-            }
78
-            $screen_path = getcwd()."/cron";
79
-            $screen_filename = "Email_Broadcast_".strtotime('now');
80
-            $command = "cd ".$screen_path." && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
81
-            exec($command);
82
-        }
83
-    }
49
+	function getInvoiceData() {
50
+		$where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0");
51
+		$query = $this->db_model->getSelect("*", "accounts", $where);
52
+		if ($query->num_rows > 0) {
53
+			$account_data = $query->result_array();
54
+			foreach ($account_data as $data_key => $account_value) {
55
+				$end_date = gmdate("Y-m-d")." 23:59:59";
56
+				$account_value['sweep_id'] = (int)$account_value['sweep_id'];
57
+				switch ($account_value['sweep_id']) {
58
+					case 0:
59
+						$start_date = $this->validate_invoice_date($account_value);
60
+						if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
61
+							$start_date = gmdate("Y-m-d H:i:s");
62
+						}
63
+						$end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 days"));
64
+						$this->Generate_Daily_invoice($account_value, $start_date, $end_date);
65
+						break;
66
+					case 2:
67
+						if (date("d") == $account_value['invoice_day']) {
68
+							$start_date = $this->validate_invoice_date($account_value);
69
+							if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) {
70
+								$start_date = gmdate("Y-m-d H:i:s");
71
+							}
72
+							$end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 month"));
73
+							$this->Generate_Monthly_invoice($account_value, $start_date, $end_date);
74
+						}
75
+						break;
76
+				}
77
+			}
78
+			$screen_path = getcwd()."/cron";
79
+			$screen_filename = "Email_Broadcast_".strtotime('now');
80
+			$command = "cd ".$screen_path." && /usr/bin/screen -d -m -S  $screen_filename php cron.php BroadcastEmail";
81
+			exec($command);
82
+		}
83
+	}
84 84
 
85
-    function validate_invoice_date($account_value) {
86
-        $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"], $account_value['reseller_id'], "to_date");
87
-        $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation'];
88
-        $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($last_invoice_date)));
89
-        return $last_invoice_date;
90
-    }
85
+	function validate_invoice_date($account_value) {
86
+		$last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"], $account_value['reseller_id'], "to_date");
87
+		$last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation'];
88
+		$last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($last_invoice_date)));
89
+		return $last_invoice_date;
90
+	}
91 91
 
92
-    /**
93
-     * @param string $start_date
94
-     * @param string $end_date
95
-     */
96
-    function Generate_Daily_invoice($account_value, $start_date, $end_date) {
97
-        //  echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date;
92
+	/**
93
+	 * @param string $start_date
94
+	 * @param string $end_date
95
+	 */
96
+	function Generate_Daily_invoice($account_value, $start_date, $end_date) {
97
+		//  echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date;
98 98
 
99
-        require_once('updateBalance.php');
100
-        $updateBalance = new updateBalance();
101
-        $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
102
-        $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE);
103
-        $this->process_invoice($account_value, $start_date, $end_date);
104
-    }
99
+		require_once('updateBalance.php');
100
+		$updateBalance = new updateBalance();
101
+		$updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
102
+		$updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE);
103
+		$this->process_invoice($account_value, $start_date, $end_date);
104
+	}
105 105
 
106
-    /**
107
-     * @param string $start_date
108
-     * @param string $end_date
109
-     */
110
-    function Generate_Monthly_invoice($account_value, $start_date, $end_date) {
111
-        require_once('updateBalance.php');
112
-        $updateBalance = new updateBalance();
113
-        $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
114
-        $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); 
115
-        $this->process_invoice($account_value, $start_date, $end_date);
116
-    }
106
+	/**
107
+	 * @param string $start_date
108
+	 * @param string $end_date
109
+	 */
110
+	function Generate_Monthly_invoice($account_value, $start_date, $end_date) {
111
+		require_once('updateBalance.php');
112
+		$updateBalance = new updateBalance();
113
+		$updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE);
114
+		$updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); 
115
+		$this->process_invoice($account_value, $start_date, $end_date);
116
+	}
117 117
 
118
-    function process_invoice($accountdata, $start_date, $end_date) {
119
-        //Get Invoice configuration using single query instead of multiple queries.
120
-        $invoice_conf = array();
121
-        $reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id'];
122
-        $where = "accountid IN ('".$reseller_id."','1')";
123
-        $this->db->select('*');
124
-        $this->db->where($where);
125
-        $this->db->order_by('accountid', 'desc');
126
-        $this->db->limit(1);
127
-        $invoice_conf = $this->db->get('invoice_conf');
128
-        $invoice_conf = (array)$invoice_conf->first_row();
129
-        /*******************************************************/
130
-        $last_invoice_ID = $this->common->get_invoice_date("invoiceid", "", $accountdata['reseller_id']);
131
-        if ($last_invoice_ID && $last_invoice_ID > 0) {
132
-            $last_invoice_ID = ($last_invoice_ID + 1);
133
-        } else {
134
-            $last_invoice_ID = $invoice_conf['invoice_start_from'];
135
-        }
136
-        $last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT);
137
-        $invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date);
138
-        if ($invoice_sub_total > 0) {
139
-            $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
140
-            $this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date);
141
-            $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
142
-            $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
143
-            $this->download_invoice($invoiceid, $accountdata, $invoice_conf);
144
-        } else {
145
-            $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
146
-            $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
147
-            $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
148
-        }
149
-    }
118
+	function process_invoice($accountdata, $start_date, $end_date) {
119
+		//Get Invoice configuration using single query instead of multiple queries.
120
+		$invoice_conf = array();
121
+		$reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id'];
122
+		$where = "accountid IN ('".$reseller_id."','1')";
123
+		$this->db->select('*');
124
+		$this->db->where($where);
125
+		$this->db->order_by('accountid', 'desc');
126
+		$this->db->limit(1);
127
+		$invoice_conf = $this->db->get('invoice_conf');
128
+		$invoice_conf = (array)$invoice_conf->first_row();
129
+		/*******************************************************/
130
+		$last_invoice_ID = $this->common->get_invoice_date("invoiceid", "", $accountdata['reseller_id']);
131
+		if ($last_invoice_ID && $last_invoice_ID > 0) {
132
+			$last_invoice_ID = ($last_invoice_ID + 1);
133
+		} else {
134
+			$last_invoice_ID = $invoice_conf['invoice_start_from'];
135
+		}
136
+		$last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT);
137
+		$invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date);
138
+		if ($invoice_sub_total > 0) {
139
+			$invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
140
+			$this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date);
141
+			$sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
142
+			$invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
143
+			$this->download_invoice($invoiceid, $accountdata, $invoice_conf);
144
+		} else {
145
+			$invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf);
146
+			$sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date);
147
+			$invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']);
148
+		}
149
+	}
150 150
 
151
-    function count_invoice_data($account, $start_date = "", $end_date = "") {
152
-        $cdr_query = "";
153
-        $inv_data_query = "";
154
-        $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = ".$account['id'];
155
-        $cdr_query .= " AND callstart >='".$start_date."' AND callstart <= '".$end_date."' AND invoiceid=0 group by calltype";
151
+	function count_invoice_data($account, $start_date = "", $end_date = "") {
152
+		$cdr_query = "";
153
+		$inv_data_query = "";
154
+		$cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = ".$account['id'];
155
+		$cdr_query .= " AND callstart >='".$start_date."' AND callstart <= '".$end_date."' AND invoiceid=0 group by calltype";
156 156
 //echo $cdr_query; 
157
-        $cdr_data = $this->db->query($cdr_query);
158
-        if ($cdr_data->num_rows > 0) {
159
-            $cdr_data = $cdr_data->result_array();
160
-            //echo '<pre>'; print_r($cdr_data); exit;
161
-            foreach ($cdr_data as $cdrvalue) {
162
-                $cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']);
163
-                $tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0",
164
-                    "description" => $cdrvalue['calltype']." CALLS for the period (".$start_date." to ".$end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date);
165
-                $this->db->insert("invoice_details", $tempArr);
166
-            }
167
-        }
168
-        $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=".$account['id']." AND created_date >='".$start_date."' AND created_date <= '".$end_date."'  AND invoiceid=0 AND item_type != 'FREECALL'";
157
+		$cdr_data = $this->db->query($cdr_query);
158
+		if ($cdr_data->num_rows > 0) {
159
+			$cdr_data = $cdr_data->result_array();
160
+			//echo '<pre>'; print_r($cdr_data); exit;
161
+			foreach ($cdr_data as $cdrvalue) {
162
+				$cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']);
163
+				$tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0",
164
+					"description" => $cdrvalue['calltype']." CALLS for the period (".$start_date." to ".$end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date);
165
+				$this->db->insert("invoice_details", $tempArr);
166
+			}
167
+		}
168
+		$inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=".$account['id']." AND created_date >='".$start_date."' AND created_date <= '".$end_date."'  AND invoiceid=0 AND item_type != 'FREECALL'";
169 169
 //echo $inv_data_query;         
170
-        $invoice_data = $this->db->query($inv_data_query);
171
-        if ($invoice_data->num_rows > 0) {
172
-            $invoice_data = $invoice_data->result_array();
173
-            foreach ($invoice_data as $data_value) {
174
-                if ($data_value['count'] > 0) {
175
-                    $sub_total = ($data_value['debit'] - $data_value['credit']);
176
-                    $sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']);
177
-                    return $sub_total;
178
-                }
179
-            }
180
-        }
181
-        return "0";
182
-    }
170
+		$invoice_data = $this->db->query($inv_data_query);
171
+		if ($invoice_data->num_rows > 0) {
172
+			$invoice_data = $invoice_data->result_array();
173
+			foreach ($invoice_data as $data_value) {
174
+				if ($data_value['count'] > 0) {
175
+					$sub_total = ($data_value['debit'] - $data_value['credit']);
176
+					$sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']);
177
+					return $sub_total;
178
+				}
179
+			}
180
+		}
181
+		return "0";
182
+	}
183 183
 
184
-    //Change Order of arguements
185
-    function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") {
186
-        $inv_data_query = "update invoice_details SET invoiceid = '".$invoiceid."' where accountid=".$accountid;
187
-        $inv_data_query .= " AND created_date >='".$start_date."' AND created_date <= '".$end_date."'  AND invoiceid=0 AND item_type !='PAYMENT'";
188
-        $this->db->query($inv_data_query);
189
-        return true;
190
-    }
184
+	//Change Order of arguements
185
+	function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") {
186
+		$inv_data_query = "update invoice_details SET invoiceid = '".$invoiceid."' where accountid=".$accountid;
187
+		$inv_data_query .= " AND created_date >='".$start_date."' AND created_date <= '".$end_date."'  AND invoiceid=0 AND item_type !='PAYMENT'";
188
+		$this->db->query($inv_data_query);
189
+		return true;
190
+	}
191 191
 
192
-    /**
193
-     * @param string $last_invoice_ID
194
-     */
195
-    function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) {
196
-        //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days"));
197
-        if ($invoiceconf['interval'] > 0) {
198
-            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days"));
199
-        } else {
200
-            $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +7 days"));
201
-        }
202
-        // echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; 
203
-        $balance = ($account['credit_limit'] - $account['balance']);
204
-        $automatic_flag = self::$global_config['system_config']['automatic_invoice'];
192
+	/**
193
+	 * @param string $last_invoice_ID
194
+	 */
195
+	function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) {
196
+		//$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days"));
197
+		if ($invoiceconf['interval'] > 0) {
198
+			$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days"));
199
+		} else {
200
+			$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +7 days"));
201
+		}
202
+		// echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; 
203
+		$balance = ($account['credit_limit'] - $account['balance']);
204
+		$automatic_flag = self::$global_config['system_config']['automatic_invoice'];
205 205
 	if ($automatic_flag == 1) {
206
-	        $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
207
-            $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance);
206
+			$invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
207
+			$account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance);
208 208
 	} else {
209
-	        $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
210
-            $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1);
209
+			$invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" =>
210
+			$account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1);
211 211
 	}
212
-        // echo "<pre>"; print_r($invoice_data); exit;
213
-        $this->db->insert("invoices", $invoice_data);
214
-        $invoiceid = $this->db->insert_id();
212
+		// echo "<pre>"; print_r($invoice_data); exit;
213
+		$this->db->insert("invoices", $invoice_data);
214
+		$invoiceid = $this->db->insert_id();
215 215
 	if ($automatic_flag == 0) {
216
-            $this->download_invoice($invoiceid, $account, $invoiceconf);
216
+			$this->download_invoice($invoiceid, $account, $invoiceconf);
217
+	}
218
+		return $invoiceid;
217 219
 	}
218
-        return $invoiceid;
219
-    }
220 220
 
221
-    function set_invoice_total($invoiceid, $accountid) {
222
-        $query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL"));
223
-        $query = $query->result_array();
224
-        $sub_total = $query["0"]["total"];
225
-        $updateArr = array("amount" => $sub_total);
226
-        $this->db->where(array("id" => $invoiceid));
227
-        $this->db->update("invoices", $updateArr);
221
+	function set_invoice_total($invoiceid, $accountid) {
222
+		$query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL"));
223
+		$query = $query->result_array();
224
+		$sub_total = $query["0"]["total"];
225
+		$updateArr = array("amount" => $sub_total);
226
+		$this->db->where(array("id" => $invoiceid));
227
+		$this->db->update("invoices", $updateArr);
228 228
 
229
-        $updateArr = array("balance" => "0.00");
230
-        $this->db->where(array("id" => $accountid));
231
-        $this->db->update("accounts", $updateArr);
229
+		$updateArr = array("balance" => "0.00");
230
+		$this->db->where(array("id" => $accountid));
231
+		$this->db->update("accounts", $updateArr);
232 232
 
233
-        return true;
234
-    }
233
+		return true;
234
+	}
235 235
 
236
-    function download_invoice($invoiceid, $accountdata, $invoice_conf) {
237
-        $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid));
238
-        $invoicedata = $invoicedata->result_array();
239
-        $invoicedata = $invoicedata[0];
240
-        $FilePath = FCPATH."invoices/".$accountdata["id"].'/'.$invoicedata['invoice_prefix']."".$invoicedata['invoiceid']."_invoice.pdf";
241
-        $Filenm = $invoicedata['invoice_prefix']."_".$invoicedata['invoiceid']."_invoice.pdf";
242
-        $this->common->get_invoice_template($invoicedata, $accountdata, false);
243
-        if ($invoice_conf['invoice_notification']) {
244
-            $this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata);
245
-        }
246
-    }
236
+	function download_invoice($invoiceid, $accountdata, $invoice_conf) {
237
+		$invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid));
238
+		$invoicedata = $invoicedata->result_array();
239
+		$invoicedata = $invoicedata[0];
240
+		$FilePath = FCPATH."invoices/".$accountdata["id"].'/'.$invoicedata['invoice_prefix']."".$invoicedata['invoiceid']."_invoice.pdf";
241
+		$Filenm = $invoicedata['invoice_prefix']."_".$invoicedata['invoiceid']."_invoice.pdf";
242
+		$this->common->get_invoice_template($invoicedata, $accountdata, false);
243
+		if ($invoice_conf['invoice_notification']) {
244
+			$this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata);
245
+		}
246
+	}
247 247
 
248
-    /**
249
-     * @param string $FilePath
250
-     * @param string $Filenm
251
-     */
252
-    function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) {
253
-        $TemplateData = array();
254
-        $where = array('name' => 'email_new_invoice');
255
-        $EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where);
256
-        foreach ($EmailTemplate->result_array() as $TemplateVal) {
257
-            $TemplateData = $TemplateVal;
258
-            $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['subject']);
259
-            $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['subject']);
260
-            $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['template']);
261
-            $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['template']);
262
-            $TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']);
248
+	/**
249
+	 * @param string $FilePath
250
+	 * @param string $Filenm
251
+	 */
252
+	function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) {
253
+		$TemplateData = array();
254
+		$where = array('name' => 'email_new_invoice');
255
+		$EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where);
256
+		foreach ($EmailTemplate->result_array() as $TemplateVal) {
257
+			$TemplateData = $TemplateVal;
258
+			$TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['subject']);
259
+			$TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['subject']);
260
+			$TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['template']);
261
+			$TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['template']);
262
+			$TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']);
263 263
 
264
-            $TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']);
265
-            $TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']);
266
-            $TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']);
267
-            $TemplateData['template'] = str_replace("#INVOICE_DATE#", $invData['invoice_date'], $TemplateData['template']);
268
-            $TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']);
269
-        }
270
-        $dir_path = getcwd()."/attachments/";
271
-        $path = $dir_path.$Filenm;
272
-        $command = "cp ".$FilePath." ".$path;
273
-        exec($command);
274
-        $email_array = array('accountid' => $AccountData['id'],
275
-            'subject' => $TemplateData['subject'],
276
-            'body' => $TemplateData['template'],
277
-            'from' => $invoice_conf['emailaddress'],
278
-            'to' => $AccountData['email'],
279
-            'status' => "1",
280
-            'attachment' => $Filenm,
281
-            'template' => '');
282
-        //echo "<pre>"; print_r($TemplateData); exit;
283
-        $this->db->insert("mail_details", $email_array);
284
-    }
264
+			$TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']);
265
+			$TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']);
266
+			$TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']);
267
+			$TemplateData['template'] = str_replace("#INVOICE_DATE#", $invData['invoice_date'], $TemplateData['template']);
268
+			$TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']);
269
+		}
270
+		$dir_path = getcwd()."/attachments/";
271
+		$path = $dir_path.$Filenm;
272
+		$command = "cp ".$FilePath." ".$path;
273
+		exec($command);
274
+		$email_array = array('accountid' => $AccountData['id'],
275
+			'subject' => $TemplateData['subject'],
276
+			'body' => $TemplateData['template'],
277
+			'from' => $invoice_conf['emailaddress'],
278
+			'to' => $AccountData['email'],
279
+			'status' => "1",
280
+			'attachment' => $Filenm,
281
+			'template' => '');
282
+		//echo "<pre>"; print_r($TemplateData); exit;
283
+		$this->db->insert("mail_details", $email_array);
284
+	}
285 285
 
286 286
 }
287 287
 
Please login to merge, or discard this patch.
web_interface/astpp/application/libraries/astpp/common.php 1 patch
Indentation   +1327 added lines, -1327 removed lines patch added patch discarded remove patch
@@ -23,466 +23,466 @@  discard block
 block discarded – undo
23 23
 ###############################################################################
24 24
 
25 25
 if ( ! defined('BASEPATH'))
26
-    exit('No direct script access allowed');
26
+	exit('No direct script access allowed');
27 27
 
28 28
 /**
29 29
  * Dynamically build forms for display
30 30
  */
31 31
 class common {
32 32
 
33
-    protected $CI; // codeigniter
33
+	protected $CI; // codeigniter
34 34
 
35
-    function __construct($library_name = '') {
35
+	function __construct($library_name = '') {
36 36
 
37
-        $this->CI = & get_instance();
38
-        $this->CI->load->library("timezone");
39
-        $this->CI->load->model('db_model');
40
-        $this->CI->load->library('email');
41
-        $this->CI->load->library('session');
42
-    }
37
+		$this->CI = & get_instance();
38
+		$this->CI->load->library("timezone");
39
+		$this->CI->load->model('db_model');
40
+		$this->CI->load->library('email');
41
+		$this->CI->load->library('session');
42
+	}
43 43
 
44 44
 // __construct
45
-    /**
46
-     * adds raw html to the field array
47
-     */
48
-    function generate_password() {
49
-        $pass = substr(md5(rand(0, 1000000000)), 0, common_model::$global_config['system_config']['pinlength']);
50
-        return $pass;
51
-    }
52
-
53
-    function find_uniq_rendno($size = '', $field = '', $tablename = '') {
54
-
55
-        if ($tablename != '') {
56
-            $accounttype_array = array();
57
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
58
-            $where = array($field => $uname);
59
-            $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
60
-            $acc_result = $acc_result->result();
61
-            while ($acc_result[0]->count != 0) {
62
-                $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
63
-                $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
64
-            }
65
-        } else {
66
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
67
-        }
68
-        return $uname;
69
-    }
70
-
71
-    function find_uniq_rendno_customer($size = '', $field = '', $tablename = '') {
72
-        if ($tablename != '') {
73
-            $accounttype_array = array();
74
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
75
-            $where = array($field => $uname);
76
-            $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
77
-            $acc_result = $acc_result->result();
78
-            while ($acc_result[0]->count != 0) {
79
-                $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
80
-                $acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
81
-            }
82
-        } else {
83
-            $uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
84
-        }
85
-        $start_prifix_value = common_model::$global_config['system_config']['startingdigit'];
86
-        if ($tablename == 'accounts' && $start_prifix_value != 0) {
87
-            $length = strlen($start_prifix_value);
88
-            $uname = substr($uname, $length);
89
-            $uname = $start_prifix_value.$uname;
90
-        }
91
-        return $uname;
92
-    }
93
-
94
-    /**
95
-     * @param string $length
96
-     */
97
-    function random_string($length) {
98
-        $chars = "1234567890"; //length:36
99
-        $final_rand = '';
100
-        for ($i = 0; $i < $length; $i++) {
101
-            $final_rand .= $chars[rand(0, strlen($chars) - 1)];
102
-        }
103
-        return $final_rand;
104
-    }
105
-
106
-    function find_uniq_rendno_accno($length = '', $field = '', $tablename = '', $default, $creation_count) {
107
-        $number = array();
108
-        $j = 0;
109
-
110
-        $total_count = pow(10, $length);
111
-        for ($i = 1; $i <= $total_count; $i++) {
112
-
113
-            $flag = false;
114
-            $uname = $this->random_string($length);
115
-            $uname = strtolower($uname);
116
-            if (isset($default))
117
-                $uname = $default.$uname;
118
-            if ( ! in_array($uname, $number)) {
119
-                $where = array($field => $uname);
120
-                $acc_result = $this->CI->db_model->getSelect('Count(id) as count', $tablename, $where);
121
-                $acc_result = $acc_result->result_array();
122
-                if ($acc_result[0]['count'] == 0 && ! in_array($uname, $number)) {
123
-                    $number[] = $uname;
124
-                    $j++;
125
-                }
126
-                if ($j == $creation_count) {
127
-                    break;
128
-                }
129
-            } else {
130
-                $total_count++;
131
-            }
132
-        }
133
-        return $number;
134
-    }
135
-
136
-    /**
137
-     * @param string $select
138
-     * @param string $table
139
-     */
140
-    function get_field_count($select, $table, $where) {
45
+	/**
46
+	 * adds raw html to the field array
47
+	 */
48
+	function generate_password() {
49
+		$pass = substr(md5(rand(0, 1000000000)), 0, common_model::$global_config['system_config']['pinlength']);
50
+		return $pass;
51
+	}
52
+
53
+	function find_uniq_rendno($size = '', $field = '', $tablename = '') {
54
+
55
+		if ($tablename != '') {
56
+			$accounttype_array = array();
57
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
58
+			$where = array($field => $uname);
59
+			$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
60
+			$acc_result = $acc_result->result();
61
+			while ($acc_result[0]->count != 0) {
62
+				$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
63
+				$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
64
+			}
65
+		} else {
66
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
67
+		}
68
+		return $uname;
69
+	}
70
+
71
+	function find_uniq_rendno_customer($size = '', $field = '', $tablename = '') {
72
+		if ($tablename != '') {
73
+			$accounttype_array = array();
74
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
75
+			$where = array($field => $uname);
76
+			$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
77
+			$acc_result = $acc_result->result();
78
+			while ($acc_result[0]->count != 0) {
79
+				$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
80
+				$acc_result = $this->CI->db_model->getSelect('Count(*) as count', $tablename, $where);
81
+			}
82
+		} else {
83
+			$uname = rand(pow(10, $size - 1), pow(10, $size) - 1);
84
+		}
85
+		$start_prifix_value = common_model::$global_config['system_config']['startingdigit'];
86
+		if ($tablename == 'accounts' && $start_prifix_value != 0) {
87
+			$length = strlen($start_prifix_value);
88
+			$uname = substr($uname, $length);
89
+			$uname = $start_prifix_value.$uname;
90
+		}
91
+		return $uname;
92
+	}
93
+
94
+	/**
95
+	 * @param string $length
96
+	 */
97
+	function random_string($length) {
98
+		$chars = "1234567890"; //length:36
99
+		$final_rand = '';
100
+		for ($i = 0; $i < $length; $i++) {
101
+			$final_rand .= $chars[rand(0, strlen($chars) - 1)];
102
+		}
103
+		return $final_rand;
104
+	}
105
+
106
+	function find_uniq_rendno_accno($length = '', $field = '', $tablename = '', $default, $creation_count) {
107
+		$number = array();
108
+		$j = 0;
109
+
110
+		$total_count = pow(10, $length);
111
+		for ($i = 1; $i <= $total_count; $i++) {
112
+
113
+			$flag = false;
114
+			$uname = $this->random_string($length);
115
+			$uname = strtolower($uname);
116
+			if (isset($default))
117
+				$uname = $default.$uname;
118
+			if ( ! in_array($uname, $number)) {
119
+				$where = array($field => $uname);
120
+				$acc_result = $this->CI->db_model->getSelect('Count(id) as count', $tablename, $where);
121
+				$acc_result = $acc_result->result_array();
122
+				if ($acc_result[0]['count'] == 0 && ! in_array($uname, $number)) {
123
+					$number[] = $uname;
124
+					$j++;
125
+				}
126
+				if ($j == $creation_count) {
127
+					break;
128
+				}
129
+			} else {
130
+				$total_count++;
131
+			}
132
+		}
133
+		return $number;
134
+	}
135
+
136
+	/**
137
+	 * @param string $select
138
+	 * @param string $table
139
+	 */
140
+	function get_field_count($select, $table, $where) {
141 141
 //        echo $select."=====".$table."===".$where;
142
-        if (is_array($where)) {
143
-            $where = $where;
144
-        } else {
145
-            $where = array($select => $where);
146
-        }
147
-        $field_name = $this->CI->db_model->countQuery($select, $table, $where);
148
-        if (isset($field_name) && ! empty($field_name)) {
149
-            return $field_name;
150
-        } else {
151
-            return "0";
152
-        }
153
-    }
154
-
155
-    /**
156
-     * @param string $select
157
-     * @param string $table
158
-     */
159
-    function get_field_name($select, $table, $where) {
160
-        if (is_array($where)) {
161
-            $where = $where;
162
-        } else {
163
-            $where = array("id" => $where);
164
-        }
165
-        $field_name = $this->CI->db_model->getSelect($select, $table, $where);
166
-        $field_name = $field_name->result();
167
-        if (isset($field_name) && ! empty($field_name)) {
168
-            return $field_name[0]->$select;
169
-        } else {
170
-            return "";
171
-        }
172
-    }
173
-
174
-    /**
175
-     * @param string $select
176
-     * @param string $table
177
-     */
178
-    function get_field_name_coma_new($select, $table, $where) {
179
-        $value = '';
180
-        if (is_array($where)) {
181
-            $where = $where;
182
-        } else {
183
-            $where = explode(',', $where);
184
-        }
185
-        $select1 = explode(',', $select);
186
-        for ($i = 0; $i < count($where); $i++) {
187
-            $where_in = array("id" => $where[$i]);
188
-
189
-            $field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
190
-            $field_name = $field_name->result();
191
-            if (isset($field_name) && ! empty($field_name)) {
192
-                foreach ($select1 as $sel) {
193
-                    if ($sel == 'number') {
194
-                        $value .= "(".$field_name[0]->$sel.")";
195
-                    } else {
196
-                        $value .= $field_name[0]->$sel." ";
197
-                    }
198
-                }
199
-            } else {
200
-                $value = "";
201
-            }
202
-        }
203
-        return rtrim($value, ',');
204
-    }
205
-
206
-    function check_did_avl($select, $table, $where) {
207
-        $accountinfo = $this->CI->session->userdata('accountinfo');
208
-        $flag_status = "";
209
-        $where = array("number" => $where);
210
-        $field_name = $this->CI->db_model->getSelect("id,accountid,parent_id", 'dids', $where);
211
-        $field_name = $field_name->result();
212
-        if (isset($field_name) && ! empty($field_name)) {
213
-            if (isset($field_name[0]) && $accountinfo['type'] != 1) {
214
-                if ($field_name[0]->accountid != 0 && $field_name[0]->parent_id == 0) {
215
-                    $flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
216
-                } else if ($field_name[0]->parent_id != 0) {
217
-                    $flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
218
-                } else {
219
-                    $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
220
-                }
221
-            } else {
222
-                $reseller_id = $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
223
-                $where = array("note" => $field_name[0]->number, 'parent_id' => $reseller_id);
224
-                $field_name_re = $this->CI->db_model->getSelect("reseller_id", 'reseller_pricing', $where);
225
-                $field_name_re = $field_name_re->result();
226
-
227
-                if (isset($field_name_re) && ! empty($field_name_re)) {
228
-                    $flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
229
-                } else {
230
-                    $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
231
-                }
232
-            }
233
-        } else {
234
-            $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
235
-        }
236
-        return $flag_status;
237
-    }
238
-    function check_did_avl_export($number) {
239
-      $this->CI->db->where('number', $number);
240
-      $this->CI->db->select('id,accountid,parent_id');
241
-      $status = null;
242
-      $did_info = (array)$this->CI->db->get('dids')->first_row();
243
-      $accountinfo = $this->CI->session->userdata('accountinfo');
244
-      if ($did_info['accountid'] == 0 && $did_info['parent_id'] == 0) {
142
+		if (is_array($where)) {
143
+			$where = $where;
144
+		} else {
145
+			$where = array($select => $where);
146
+		}
147
+		$field_name = $this->CI->db_model->countQuery($select, $table, $where);
148
+		if (isset($field_name) && ! empty($field_name)) {
149
+			return $field_name;
150
+		} else {
151
+			return "0";
152
+		}
153
+	}
154
+
155
+	/**
156
+	 * @param string $select
157
+	 * @param string $table
158
+	 */
159
+	function get_field_name($select, $table, $where) {
160
+		if (is_array($where)) {
161
+			$where = $where;
162
+		} else {
163
+			$where = array("id" => $where);
164
+		}
165
+		$field_name = $this->CI->db_model->getSelect($select, $table, $where);
166
+		$field_name = $field_name->result();
167
+		if (isset($field_name) && ! empty($field_name)) {
168
+			return $field_name[0]->$select;
169
+		} else {
170
+			return "";
171
+		}
172
+	}
173
+
174
+	/**
175
+	 * @param string $select
176
+	 * @param string $table
177
+	 */
178
+	function get_field_name_coma_new($select, $table, $where) {
179
+		$value = '';
180
+		if (is_array($where)) {
181
+			$where = $where;
182
+		} else {
183
+			$where = explode(',', $where);
184
+		}
185
+		$select1 = explode(',', $select);
186
+		for ($i = 0; $i < count($where); $i++) {
187
+			$where_in = array("id" => $where[$i]);
188
+
189
+			$field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
190
+			$field_name = $field_name->result();
191
+			if (isset($field_name) && ! empty($field_name)) {
192
+				foreach ($select1 as $sel) {
193
+					if ($sel == 'number') {
194
+						$value .= "(".$field_name[0]->$sel.")";
195
+					} else {
196
+						$value .= $field_name[0]->$sel." ";
197
+					}
198
+				}
199
+			} else {
200
+				$value = "";
201
+			}
202
+		}
203
+		return rtrim($value, ',');
204
+	}
205
+
206
+	function check_did_avl($select, $table, $where) {
207
+		$accountinfo = $this->CI->session->userdata('accountinfo');
208
+		$flag_status = "";
209
+		$where = array("number" => $where);
210
+		$field_name = $this->CI->db_model->getSelect("id,accountid,parent_id", 'dids', $where);
211
+		$field_name = $field_name->result();
212
+		if (isset($field_name) && ! empty($field_name)) {
213
+			if (isset($field_name[0]) && $accountinfo['type'] != 1) {
214
+				if ($field_name[0]->accountid != 0 && $field_name[0]->parent_id == 0) {
215
+					$flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
216
+				} else if ($field_name[0]->parent_id != 0) {
217
+					$flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
218
+				} else {
219
+					$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
220
+				}
221
+			} else {
222
+				$reseller_id = $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
223
+				$where = array("note" => $field_name[0]->number, 'parent_id' => $reseller_id);
224
+				$field_name_re = $this->CI->db_model->getSelect("reseller_id", 'reseller_pricing', $where);
225
+				$field_name_re = $field_name_re->result();
226
+
227
+				if (isset($field_name_re) && ! empty($field_name_re)) {
228
+					$flag_status = "<a href='../did_list_release/".$field_name[0]->id."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
229
+				} else {
230
+					$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
231
+				}
232
+			}
233
+		} else {
234
+			$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
235
+		}
236
+		return $flag_status;
237
+	}
238
+	function check_did_avl_export($number) {
239
+	  $this->CI->db->where('number', $number);
240
+	  $this->CI->db->select('id,accountid,parent_id');
241
+	  $status = null;
242
+	  $did_info = (array)$this->CI->db->get('dids')->first_row();
243
+	  $accountinfo = $this->CI->session->userdata('accountinfo');
244
+	  if ($did_info['accountid'] == 0 && $did_info['parent_id'] == 0) {
245 245
 	$status = 'Not in use';
246
-      }
247
-      elseif ($accountinfo['type'] != 1) {
246
+	  }
247
+	  elseif ($accountinfo['type'] != 1) {
248 248
 	if ($did_info['accountid'] == 0 && $did_info['parent_id'] > 0) {
249 249
 	  $status = 'Purchase by Reseller';
250 250
 	}
251 251
 	if ($did_info['accountid'] > 0 && $did_info['parent_id'] == 0) {
252 252
 	  $status = 'Purchase by Customer';
253 253
 	}
254
-      } else {
255
-       $where_arr = array('note'=>$did_info['number'], "parent_id"=>$accountinfo['id']);
256
-       $this->db->where($where);
257
-       $this->CI->db->select('reseller_id,parent_id');
258
-       $reseller_pricing = (array)$this->db->get('reseller_pricing')->first_row();
259
-       if ($reseller_pricing['reseller_id'] == 0 && $did_info['accountid'] == 0 && $did_info['parent_id'] == $accountinfo['id']) {
260
-        $status = 'Not in use';
261
-       }
262
-       if ($reseller_pricing['reseller_id'] == 0 && $did_info['accountid'] == 0) {
263
-       $status = 'Not in use';
264
-       }
265
-      }
266
-      return $status;
254
+	  } else {
255
+	   $where_arr = array('note'=>$did_info['number'], "parent_id"=>$accountinfo['id']);
256
+	   $this->db->where($where);
257
+	   $this->CI->db->select('reseller_id,parent_id');
258
+	   $reseller_pricing = (array)$this->db->get('reseller_pricing')->first_row();
259
+	   if ($reseller_pricing['reseller_id'] == 0 && $did_info['accountid'] == 0 && $did_info['parent_id'] == $accountinfo['id']) {
260
+		$status = 'Not in use';
261
+	   }
262
+	   if ($reseller_pricing['reseller_id'] == 0 && $did_info['accountid'] == 0) {
263
+	   $status = 'Not in use';
264
+	   }
265
+	  }
266
+	  return $status;
267 267
       
268
-    }
269
-    function check_did_avl_reseller($select, $table, $where) {
270
-        $accountinfo = $this->CI->session->userdata('accountinfo');
271
-        $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
272
-        $this->CI->db->where('number', $where);
273
-        $this->CI->db->select('id,accountid,parent_id,number');
274
-        $did_info = (array)$this->CI->db->get('dids')->first_row();
275
-        if ($did_info['accountid'] > 0 && $did_info['parent_id'] == $accountinfo['id']) {
276
-	    $flag_status = "<a href='../did_list_release/".$did_info['id']."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
277
-	}
278
-        else if ($accountinfo['type'] != 1 && $did_info['parent_id'] != $accountinfo['id']) {
279
-	    $flag_status = "<a href='../did_list_release/".$did_info['id']."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
280
-        } else {
281
-	    $reseller_id = $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
282
-	    $where = array("note" => $did_info['number'], 'parent_id'=>$reseller_id);
283
-            $this->CI->db->where($where);
284
-	    $this->CI->db->select('reseller_id,id');
285
-	    $reseller_pricing_info = (array)$this->CI->db->get('reseller_pricing')->first_row();
286
-	    if (isset($reseller_pricing_info) && ! empty($reseller_pricing_info)) {
268
+	}
269
+	function check_did_avl_reseller($select, $table, $where) {
270
+		$accountinfo = $this->CI->session->userdata('accountinfo');
271
+		$flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
272
+		$this->CI->db->where('number', $where);
273
+		$this->CI->db->select('id,accountid,parent_id,number');
274
+		$did_info = (array)$this->CI->db->get('dids')->first_row();
275
+		if ($did_info['accountid'] > 0 && $did_info['parent_id'] == $accountinfo['id']) {
276
+		$flag_status = "<a href='../did_list_release/".$did_info['id']."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(C)<span></a>";
277
+	}
278
+		else if ($accountinfo['type'] != 1 && $did_info['parent_id'] != $accountinfo['id']) {
279
+		$flag_status = "<a href='../did_list_release/".$did_info['id']."' title='Release' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
280
+		} else {
281
+		$reseller_id = $accountinfo['type'] != 1 ? 0 : $accountinfo['id'];
282
+		$where = array("note" => $did_info['number'], 'parent_id'=>$reseller_id);
283
+			$this->CI->db->where($where);
284
+		$this->CI->db->select('reseller_id,id');
285
+		$reseller_pricing_info = (array)$this->CI->db->get('reseller_pricing')->first_row();
286
+		if (isset($reseller_pricing_info) && ! empty($reseller_pricing_info)) {
287 287
 		  $flag_status = "<a href='../did/did_reseller_edit/delete/".$reseller_pricing_info['id']."' title='Reliase' onClick='return get_reliase_msg();'><span class=' label label-sm label-inverse_blue arrowed_blue-in' title='release'>Release(R)</span></a>";
288
-	    } else {
289
-	      $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
290
-	    }
291
-        }
292
-        return $flag_status;
293
-    }
288
+		} else {
289
+		  $flag_status = "<span class=' label label-sm label-inverse arrowed-in' title='Not in use'>Not in use</span>";
290
+		}
291
+		}
292
+		return $flag_status;
293
+	}
294 294
 
295 295
 //    get data for Comma seprated
296
-    function get_field_name_coma($select, $table, $where) {
297
-        $value = '';
298
-        if (is_array($where)) {
299
-            $where = $where;
300
-        } else {
301
-            $where = explode(',', $where);
302
-        }
303
-        for ($i = 0; $i < count($where); $i++) {
304
-            $where_in = array("id" => $where[$i]);
305
-
306
-            $field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
307
-            $field_name = $field_name->result();
308
-            if (isset($field_name) && ! empty($field_name)) {
309
-                $value .= $field_name[0]->$select.",";
310
-            } else {
311
-                $value = "";
312
-            }
313
-        }
314
-        return rtrim($value, ',');
315
-    }
316
-
317
-    function set_invoice_option($select = "", $table = "", $call_type = "", $edit_value = '') {
318
-
319
-        $invoice_date = false;
320
-        $uri_segment = $this->CI->uri->segments;
321
-        if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
322
-            $field_name = $this->CI->db_model->getSelect("sweep_id,invoice_day", "accounts", array("id" => $uri_segment[3]));
323
-            $field_name = $field_name->result_array();
324
-            $select = $field_name[0]["sweep_id"];
325
-            $invoice_date = $field_name[0]["invoice_day"];
326
-        } else {
327
-            $invoice_date = $edit_value;
328
-        }
329
-        if ($select == "" || $select == "0") {
330
-            $daily_arr = array("0" => "0");
331
-            return $daily_arr;
332
-        }
333
-        if ($select == 1) {
334
-            $week_arr = array("1" => "Monday", "2" => "Tuesday", "3" => "Wednesday", "4" => "Thursday", "5" => "Friday",
335
-                "6" => "Saturday", "7" => "Sunday");
336
-            $rawDate = date("Y-m-d");
337
-            $day = date('N', strtotime($rawDate));
338
-            if (isset($uri_segment[3])) {
339
-                return $week_arr;
340
-            } else {
341
-                $week_drp = form_dropdown(array("name" => 'invoice_day', 'style'=>"width: 100% !important;", "class" => "invoice_day"), $week_arr, $day);
342
-                return $week_drp;
343
-            }
344
-        }
345
-        if ($select != 0 && $select != 1) {
346
-            for ($i = 1; $i < 29; $i++) {
347
-                $mon_arr[$i] = $i;
348
-            }
349
-            if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
350
-                return $mon_arr;
351
-            } else {
352
-                $day = $invoice_date > 0 ? $invoice_date : date('d');
353
-                $month_drp = form_dropdown(array("name" => 'invoice_day', "class" => "width_dropdown invoice_day"), $mon_arr, $day);
354
-                return $month_drp;
355
-            }
356
-        }
357
-    }
358
-
359
-    function set_status($status = '') {
360
-        $status_array = array('0' => 'Active', '1' => 'Inactive',);
361
-        return $status_array;
362
-    }
363
-
364
-    function set_routetype($status = '') {
365
-        $status_array = array('0' => 'LCR', '1' => 'COST',);
366
-        return $status_array;
367
-    }
368
-
369
-    function set_prorate($status = '') {
370
-        $status_array = array('0' => 'Yes', '1' => 'No',);
371
-        return $status_array;
372
-    }
373
-    /*
296
+	function get_field_name_coma($select, $table, $where) {
297
+		$value = '';
298
+		if (is_array($where)) {
299
+			$where = $where;
300
+		} else {
301
+			$where = explode(',', $where);
302
+		}
303
+		for ($i = 0; $i < count($where); $i++) {
304
+			$where_in = array("id" => $where[$i]);
305
+
306
+			$field_name = $this->CI->db_model->getSelect($select, $table, $where_in);
307
+			$field_name = $field_name->result();
308
+			if (isset($field_name) && ! empty($field_name)) {
309
+				$value .= $field_name[0]->$select.",";
310
+			} else {
311
+				$value = "";
312
+			}
313
+		}
314
+		return rtrim($value, ',');
315
+	}
316
+
317
+	function set_invoice_option($select = "", $table = "", $call_type = "", $edit_value = '') {
318
+
319
+		$invoice_date = false;
320
+		$uri_segment = $this->CI->uri->segments;
321
+		if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
322
+			$field_name = $this->CI->db_model->getSelect("sweep_id,invoice_day", "accounts", array("id" => $uri_segment[3]));
323
+			$field_name = $field_name->result_array();
324
+			$select = $field_name[0]["sweep_id"];
325
+			$invoice_date = $field_name[0]["invoice_day"];
326
+		} else {
327
+			$invoice_date = $edit_value;
328
+		}
329
+		if ($select == "" || $select == "0") {
330
+			$daily_arr = array("0" => "0");
331
+			return $daily_arr;
332
+		}
333
+		if ($select == 1) {
334
+			$week_arr = array("1" => "Monday", "2" => "Tuesday", "3" => "Wednesday", "4" => "Thursday", "5" => "Friday",
335
+				"6" => "Saturday", "7" => "Sunday");
336
+			$rawDate = date("Y-m-d");
337
+			$day = date('N', strtotime($rawDate));
338
+			if (isset($uri_segment[3])) {
339
+				return $week_arr;
340
+			} else {
341
+				$week_drp = form_dropdown(array("name" => 'invoice_day', 'style'=>"width: 100% !important;", "class" => "invoice_day"), $week_arr, $day);
342
+				return $week_drp;
343
+			}
344
+		}
345
+		if ($select != 0 && $select != 1) {
346
+			for ($i = 1; $i < 29; $i++) {
347
+				$mon_arr[$i] = $i;
348
+			}
349
+			if (isset($uri_segment[3]) && $uri_segment[3] > 0 && empty($edit_value)) {
350
+				return $mon_arr;
351
+			} else {
352
+				$day = $invoice_date > 0 ? $invoice_date : date('d');
353
+				$month_drp = form_dropdown(array("name" => 'invoice_day', "class" => "width_dropdown invoice_day"), $mon_arr, $day);
354
+				return $month_drp;
355
+			}
356
+		}
357
+	}
358
+
359
+	function set_status($status = '') {
360
+		$status_array = array('0' => 'Active', '1' => 'Inactive',);
361
+		return $status_array;
362
+	}
363
+
364
+	function set_routetype($status = '') {
365
+		$status_array = array('0' => 'LCR', '1' => 'COST',);
366
+		return $status_array;
367
+	}
368
+
369
+	function set_prorate($status = '') {
370
+		$status_array = array('0' => 'Yes', '1' => 'No',);
371
+		return $status_array;
372
+	}
373
+	/*
374 374
       Add For Package Inbound or Outbound or both?
375 375
     */
376
-    function set_package_type($applicable_for = "") {
377
-        $package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
378
-        return $package_applicable;
379
-    }
380
-
381
-    function get_package_type($status = '', $table = "", $applicable_for) {
382
-        $package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
383
-        return $package_applicable[$applicable_for];
384
-    }
385
-    /******************************************** */
386
-    function set_allow($status = '') {
387
-        $status_array = array('1' => 'Yes', '0' => 'No');
388
-        return $status_array;
389
-    }
390
-    function set_allow_invoice($status = '') {
391
-        $status_array = array('1' => 'Yes', '0' => 'No');
392
-        return $status_array;
393
-    }
394
-    function set_pin_allow($status = '') {
395
-        $status_array = array('0' => 'Disable', '1' => 'Enable');
396
-        return $status_array;
397
-    }
398
-    function set_pin_allow_customer($status = '') {
399
-        $status_array = array('0' => 'No', '1' => 'Yes');
400
-        return $status_array;
401
-    }
402
-    function get_allow($select = "", $table = "", $status) {
403
-        return ($status == 1) ? "Yes" : "No";
404
-    }
405
-
406
-    function set_call_type($call_type = "") {
407
-        $call_type_array = array("-1" => "--Select--", '1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other',);
408
-        return $call_type_array;
409
-    }
410
-    function set_call_type_search() {
376
+	function set_package_type($applicable_for = "") {
377
+		$package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
378
+		return $package_applicable;
379
+	}
380
+
381
+	function get_package_type($status = '', $table = "", $applicable_for) {
382
+		$package_applicable = array('0' => 'Outbound', '1' => 'Inbound', '2' => 'Both');
383
+		return $package_applicable[$applicable_for];
384
+	}
385
+	/******************************************** */
386
+	function set_allow($status = '') {
387
+		$status_array = array('1' => 'Yes', '0' => 'No');
388
+		return $status_array;
389
+	}
390
+	function set_allow_invoice($status = '') {
391
+		$status_array = array('1' => 'Yes', '0' => 'No');
392
+		return $status_array;
393
+	}
394
+	function set_pin_allow($status = '') {
395
+		$status_array = array('0' => 'Disable', '1' => 'Enable');
396
+		return $status_array;
397
+	}
398
+	function set_pin_allow_customer($status = '') {
399
+		$status_array = array('0' => 'No', '1' => 'Yes');
400
+		return $status_array;
401
+	}
402
+	function get_allow($select = "", $table = "", $status) {
403
+		return ($status == 1) ? "Yes" : "No";
404
+	}
405
+
406
+	function set_call_type($call_type = "") {
407
+		$call_type_array = array("-1" => "--Select--", '1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other',);
408
+		return $call_type_array;
409
+	}
410
+	function set_call_type_search() {
411 411
 	$call_type_array = array("" => "--Select--", '1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other',);
412
-        return $call_type_array;
413
-    }
414
-    function get_call_type($select = "", $table = "", $call_type) {
415
-        $call_type_array = array('1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other', '-1'=>"");
416
-        return $call_type_array[$call_type];
417
-    }
418
-
419
-    function get_custom_call_type($call_type) {
420
-        $call_type_array = array('DID-Local' => '1', "SIP-DID"=>"3", 'PSTN' => '0', 'Other' => '2', ""=>"-1");
421
-        return $call_type_array[$call_type];
422
-    }
423
-
424
-    function set_sip_config_option($option = "") {
425
-        $config_option = array("true" => "True", "false" => "False");
426
-        return $config_option;
427
-    }
428
-
429
-    function get_entity_type($select = "", $table = "", $entity_type) {
430
-        $entity_array = array('-1' => "Administrator", '0' => 'Customer', '1' => 'Reseller', '2' => 'Admin', '3' => "Provider", "4" => "Subadmin", "5" => "Callshop");
431
-        return($entity_array[$entity_type]);
432
-    }
433
-
434
-    function set_entity_type_customer($entity_type = "") {
435
-        $entity_array = array('' => "--Select--", '0' => 'Customer', '3' => "Provider");
436
-        return $entity_array;
437
-    }
438
-
439
-    function set_entity_type_admin($entity_type = "") {
440
-        $entity_array = array('' => "--Select--", '2' => 'Admin', "4" => "Sub Admin");
441
-        return $entity_array;
442
-    }
412
+		return $call_type_array;
413
+	}
414
+	function get_call_type($select = "", $table = "", $call_type) {
415
+		$call_type_array = array('1' => 'DID-Local', "3"=>"SIP-DID", '0' => 'PSTN', '2' => 'Other', '-1'=>"");
416
+		return $call_type_array[$call_type];
417
+	}
418
+
419
+	function get_custom_call_type($call_type) {
420
+		$call_type_array = array('DID-Local' => '1', "SIP-DID"=>"3", 'PSTN' => '0', 'Other' => '2', ""=>"-1");
421
+		return $call_type_array[$call_type];
422
+	}
423
+
424
+	function set_sip_config_option($option = "") {
425
+		$config_option = array("true" => "True", "false" => "False");
426
+		return $config_option;
427
+	}
428
+
429
+	function get_entity_type($select = "", $table = "", $entity_type) {
430
+		$entity_array = array('-1' => "Administrator", '0' => 'Customer', '1' => 'Reseller', '2' => 'Admin', '3' => "Provider", "4" => "Subadmin", "5" => "Callshop");
431
+		return($entity_array[$entity_type]);
432
+	}
433
+
434
+	function set_entity_type_customer($entity_type = "") {
435
+		$entity_array = array('' => "--Select--", '0' => 'Customer', '3' => "Provider");
436
+		return $entity_array;
437
+	}
438
+
439
+	function set_entity_type_admin($entity_type = "") {
440
+		$entity_array = array('' => "--Select--", '2' => 'Admin', "4" => "Sub Admin");
441
+		return $entity_array;
442
+	}
443 443
 
444 444
 	function set_entity_type_email_mass($entity_type = "") {
445
-        $entity_array = array('' => "--Select--", '0' => 'Customer', '1'=>'Reseller', '3' => "Provider");
446
-        return $entity_array;
447
-    }
448
-
449
-    function set_sip_config_options($option = "") {
450
-        $config_option = array("false" => "False", "true" => "True");
451
-        return $config_option;
452
-    }
453
-
454
-    function set_sip_config_default($option = "") {
455
-        $config_option = array("" => "--SELECT--", "false" => "False", "true" => "True");
456
-        return $config_option;
457
-    }
458
-
459
-    function set_sip_bind_params($option = "") {
460
-        $config_option = array("" => "--SELECT--", "udp" => "UDP", "tcp" => "TCP");
461
-        return $config_option;
462
-    }
463
-
464
-    function set_sip_vad_option() {
465
-        $config_option = array("in" => "In", "out" => "Out", "both" => "Both");
466
-        return $config_option;
467
-    }
468
-
469
-    function set_sip_drp_option($option = "") {
470
-        $status_array = array('no' => 'No', 'yes' => 'Yes');
471
-        return $status_array;
472
-    }
473
-
474
-    function set_status_callingcard($status = '') {
475
-        $status_array = array('1' => 'Active', '0' => 'Inactive', '2' => 'Deleted');
476
-        return $status_array;
477
-    }
445
+		$entity_array = array('' => "--Select--", '0' => 'Customer', '1'=>'Reseller', '3' => "Provider");
446
+		return $entity_array;
447
+	}
448
+
449
+	function set_sip_config_options($option = "") {
450
+		$config_option = array("false" => "False", "true" => "True");
451
+		return $config_option;
452
+	}
453
+
454
+	function set_sip_config_default($option = "") {
455
+		$config_option = array("" => "--SELECT--", "false" => "False", "true" => "True");
456
+		return $config_option;
457
+	}
458
+
459
+	function set_sip_bind_params($option = "") {
460
+		$config_option = array("" => "--SELECT--", "udp" => "UDP", "tcp" => "TCP");
461
+		return $config_option;
462
+	}
463
+
464
+	function set_sip_vad_option() {
465
+		$config_option = array("in" => "In", "out" => "Out", "both" => "Both");
466
+		return $config_option;
467
+	}
468
+
469
+	function set_sip_drp_option($option = "") {
470
+		$status_array = array('no' => 'No', 'yes' => 'Yes');
471
+		return $status_array;
472
+	}
473
+
474
+	function set_status_callingcard($status = '') {
475
+		$status_array = array('1' => 'Active', '0' => 'Inactive', '2' => 'Deleted');
476
+		return $status_array;
477
+	}
478 478
    /*
479 479
    show status on all grid
480 480
    */
481 481
    function get_status($select = "", $table = "", $status) {
482
-       if ($select != 'export') {
483
-        $status_tab = $this->encode($table);
484
-        $status['table'] = "'".$status_tab."'";
485
-        if ($status['status'] == 0) {
482
+	   if ($select != 'export') {
483
+		$status_tab = $this->encode($table);
484
+		$status['table'] = "'".$status_tab."'";
485
+		if ($status['status'] == 0) {
486 486
 	$status_array = '<div style="width: 100%; text-align: -moz-center; padding: 0;"><input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id=switch'.$status['id'].' value='.$status['status'].' onclick="javascript:processForm('.$status['id'].','.$status['table'].')" checked>
487 487
 	<label class="onoffswitch-label" for=switch'.$status["id"].'>
488 488
      	<span class="onoffswitch-inner"></span>
@@ -497,249 +497,249 @@  discard block
 block discarded – undo
497 497
 		return ($status == 0) ? "Active" : "Inactive";
498 498
 	}
499 499
 	return $status_array;
500
-    }
500
+	}
501 501
    
502
-    function get_routetype($select = "", $table = "", $status) {
503
-        return ($status == 0) ? "LCR" : "COST";
504
-    }
502
+	function get_routetype($select = "", $table = "", $status) {
503
+		return ($status == 0) ? "LCR" : "COST";
504
+	}
505 505
    
506 506
    function get_prorate($select = "", $table = "", $status) {
507
-        return ($status == 0) ? "Yes" : "No";
508
-    }
507
+		return ($status == 0) ? "Yes" : "No";
508
+	}
509 509
     
510
-    function get_import_status($status) {
511
-     return strtolower(trim($status)) == 'active' ? 0 : 1;
510
+	function get_import_status($status) {
511
+	 return strtolower(trim($status)) == 'active' ? 0 : 1;
512 512
      
513
-    }
514
-    function get_did_status($select, $table, $status) {
513
+	}
514
+	function get_did_status($select, $table, $status) {
515 515
     
516
-      return ($status['status'] == 0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
517
-    }
516
+	  return ($status['status'] == 0) ? "<span class='label label-sm label-inverse arrowed-in' title='release'>Active<span>" : "<span class='label label-sm' title='release'>Inactive<span>";
517
+	}
518 518
    
519 519
 
520
-    /**
521
-     * @param string $select
522
-     */
523
-    function get_invoice_date($select, $accountid = 0, $reseller_id, $order_by = 'id') {
524
-        $where = array("reseller_id" => $reseller_id);
525
-        if ($accountid > 0) {
526
-            $where['accountid'] = $accountid;
527
-        }
528
-        $invoice_res = $this->CI->db_model->select($select, "invoices", $where, $order_by, "DESC", "1", "0");
529
-        if ($invoice_res->num_rows > 0) {
530
-            $invoice_info = (array)$invoice_res->first_row();
531
-            return $invoice_info[$select];
532
-        }
533
-        return false;
534
-    }
535
-
536
-    function convert_to_date($select = '', $table = '', $from_date) {
537
-
538
-        $from_date = date('Y-m-d', strtotime($from_date));
539
-        return $from_date;
540
-    }
541
-
542
-
543
-    function get_account_balance($select = "", $table = "", $amount) {
544
-        $this->CI->load->model('common_model');
545
-        if ($amount == 0) {
546
-            return $amount;
547
-        } else {
548
-            $balance = $this->CI->common_model->add_calculate_currency(($amount), "", '', true, true);
549
-
550
-            return $balance;
551
-        }
552
-    }
553
-
554
-    function convert_to_currency($select = "", $table = "", $amount) {
555
-        $this->CI->load->model('common_model');
556
-        return $this->CI->common_model->calculate_currency($amount, '', '', true, false);
557
-    }
558
-    function account_number_icon($select = "", $table = "", $number) {
559
-    $return_value = '';
560
-    $where = array('number'=>$number);
561
-    $account_res = (array)$this->CI->db->get_where("accounts", $where)->first_row();
562
-    if ($account_res['type'] == 0) {
563
-    $return_value = '<div class="flx_font flx_magenta" title="Customer">C</div>'." <span title='Edit'>".$account_res['number']." </span>";    
564
-    }
565
-    if ($account_res['type'] == 3) {
566
-    $return_value = '<div class="flx_font flx_blue" title="Provider">P</div>'." <span title='Edit'>".$account_res['number']." </span>";
567
-    }
568
-    if ($account_res['type'] == -1 || $account_res['type'] == 2) {
569
-      $return_value = '<div class="flx_font flx_pink" title="Admin">A</div>'." <span title='Edit'>".$account_res['number']." </span>";
570
-    }
571
-    if ($account_res['type'] == 4) {
572
-      $return_value = '<div class="flx_font flx_purple" title="Subadmin">S</div>'." <span title='Edit'>".$account_res['number']." </span>";
573
-    }
574
-    return $return_value;
575
-    }
576
-    function convert_to_currency_account($select = "", $table = "", $amount) {
577
-        $this->CI->load->model('common_model');
578
-        return $this->CI->common_model->calculate_currency_customer($amount);
579
-    }
580
-
581
-    function get_paid_status($select = "", $table = "", $status) {
582
-        return ($status == 1) ? "Paid" : "Unpaid";
583
-    }
584
-
585
-    function set_account_type($status = '') {
586
-        $status_array = array('0' => 'Prepaid', '1' => 'Postpaid');
587
-        return $status_array;
588
-    }
589
-
590
-    function set_account_type_search($status = '') {
591
-        $status_array = array('' => "--Select--", '0' => 'Prepaid', '1' => 'Postpaid');
592
-        return $status_array;
593
-    }
594
-
595
-    function get_account_type($select = "", $table = "", $PTE) {
596
-        return ($PTE == 1) ? "Postpaid" : "Prepaid";
597
-    }
598
-
599
-    /******
520
+	/**
521
+	 * @param string $select
522
+	 */
523
+	function get_invoice_date($select, $accountid = 0, $reseller_id, $order_by = 'id') {
524
+		$where = array("reseller_id" => $reseller_id);
525
+		if ($accountid > 0) {
526
+			$where['accountid'] = $accountid;
527
+		}
528
+		$invoice_res = $this->CI->db_model->select($select, "invoices", $where, $order_by, "DESC", "1", "0");
529
+		if ($invoice_res->num_rows > 0) {
530
+			$invoice_info = (array)$invoice_res->first_row();
531
+			return $invoice_info[$select];
532
+		}
533
+		return false;
534
+	}
535
+
536
+	function convert_to_date($select = '', $table = '', $from_date) {
537
+
538
+		$from_date = date('Y-m-d', strtotime($from_date));
539
+		return $from_date;
540
+	}
541
+
542
+
543
+	function get_account_balance($select = "", $table = "", $amount) {
544
+		$this->CI->load->model('common_model');
545
+		if ($amount == 0) {
546
+			return $amount;
547
+		} else {
548
+			$balance = $this->CI->common_model->add_calculate_currency(($amount), "", '', true, true);
549
+
550
+			return $balance;
551
+		}
552
+	}
553
+
554
+	function convert_to_currency($select = "", $table = "", $amount) {
555
+		$this->CI->load->model('common_model');
556
+		return $this->CI->common_model->calculate_currency($amount, '', '', true, false);
557
+	}
558
+	function account_number_icon($select = "", $table = "", $number) {
559
+	$return_value = '';
560
+	$where = array('number'=>$number);
561
+	$account_res = (array)$this->CI->db->get_where("accounts", $where)->first_row();
562
+	if ($account_res['type'] == 0) {
563
+	$return_value = '<div class="flx_font flx_magenta" title="Customer">C</div>'." <span title='Edit'>".$account_res['number']." </span>";    
564
+	}
565
+	if ($account_res['type'] == 3) {
566
+	$return_value = '<div class="flx_font flx_blue" title="Provider">P</div>'." <span title='Edit'>".$account_res['number']." </span>";
567
+	}
568
+	if ($account_res['type'] == -1 || $account_res['type'] == 2) {
569
+	  $return_value = '<div class="flx_font flx_pink" title="Admin">A</div>'." <span title='Edit'>".$account_res['number']." </span>";
570
+	}
571
+	if ($account_res['type'] == 4) {
572
+	  $return_value = '<div class="flx_font flx_purple" title="Subadmin">S</div>'." <span title='Edit'>".$account_res['number']." </span>";
573
+	}
574
+	return $return_value;
575
+	}
576
+	function convert_to_currency_account($select = "", $table = "", $amount) {
577
+		$this->CI->load->model('common_model');
578
+		return $this->CI->common_model->calculate_currency_customer($amount);
579
+	}
580
+
581
+	function get_paid_status($select = "", $table = "", $status) {
582
+		return ($status == 1) ? "Paid" : "Unpaid";
583
+	}
584
+
585
+	function set_account_type($status = '') {
586
+		$status_array = array('0' => 'Prepaid', '1' => 'Postpaid');
587
+		return $status_array;
588
+	}
589
+
590
+	function set_account_type_search($status = '') {
591
+		$status_array = array('' => "--Select--", '0' => 'Prepaid', '1' => 'Postpaid');
592
+		return $status_array;
593
+	}
594
+
595
+	function get_account_type($select = "", $table = "", $PTE) {
596
+		return ($PTE == 1) ? "Postpaid" : "Prepaid";
597
+	}
598
+
599
+	/******
600 600
       Payment to refill
601 601
     ******/
602 602
 
603
-    function get_refill_by($select = "", $table = "", $type) {
604
-        if ($type == '-1') {
605
-            $type = "Admin";
606
-        } else {
607
-            $type = $this->get_field_name("number", "accounts", array("id" => $type));
608
-        }
609
-        return $type;
610
-    }
611
-
612
-    /******************* */
613
-
614
-    function get_payment_by($select = "", $table = "", $type) {
615
-        if ($type == '-1') {
616
-            $type = "Admin";
617
-        } else {
618
-            $type = $this->get_field_name("number", "accounts", array("id" => $type));
619
-        }
620
-        return $type;
621
-    }
622
-
623
-    function set_payment_type($payment_type = '') {
624
-        /*
603
+	function get_refill_by($select = "", $table = "", $type) {
604
+		if ($type == '-1') {
605
+			$type = "Admin";
606
+		} else {
607
+			$type = $this->get_field_name("number", "accounts", array("id" => $type));
608
+		}
609
+		return $type;
610
+	}
611
+
612
+	/******************* */
613
+
614
+	function get_payment_by($select = "", $table = "", $type) {
615
+		if ($type == '-1') {
616
+			$type = "Admin";
617
+		} else {
618
+			$type = $this->get_field_name("number", "accounts", array("id" => $type));
619
+		}
620
+		return $type;
621
+	}
622
+
623
+	function set_payment_type($payment_type = '') {
624
+		/*
625 625
          * Recharge to Refill
626 626
          */
627
-        $status_array = array('0' => 'Refill', '1' => 'Postcharge',);
628
-        return $status_array;
629
-    }
630
-
631
-    function search_int_type($status = '') {
632
-        $status_array = array('1' => 'Is Equal To', '2' => 'Is Not Equal To', '3' => 'Greater Than', '4' => 'Less Than', '5' => 'Greater Or Equal Than', '6' => 'Less Or Equal Than');
633
-        return $status_array;
634
-    }
635
-
636
-    function update_int_type($status = '') {
637
-        $status_array = array('1' => 'Preserve', '2' => 'Set To', '3' => 'Increase By', '4' => 'Decrease By');
638
-        return $status_array;
639
-    }
640
-
641
-    function update_drp_type($status = '') {
642
-        $status_array = array('1' => 'Preserve', '2' => 'Set To');
643
-        return $status_array;
644
-    }
645
-
646
-    function search_string_type($status = '') {
647
-        $status_array = array('5'=>"Begins With", '1' => 'Contains', '2' => 'Doesnt Contain', '3' => 'Is Equal To', '4' => 'Is Not Equal To', "6"=>"Ends With");
648
-        return $status_array;
649
-    }
650
-
651
-    function set_protocal($protpcal = '') {
652
-        $status_array = array('SIP' => 'SIP', 'IAX2' => 'IAX2', 'Zap' => 'Zap', 'Local' => 'Local', 'OH323' => 'OH323', 'OOH323C' => 'OOH323C');
653
-        return $status_array;
654
-    }
655
-
656
-    /*
627
+		$status_array = array('0' => 'Refill', '1' => 'Postcharge',);
628
+		return $status_array;
629
+	}
630
+
631
+	function search_int_type($status = '') {
632
+		$status_array = array('1' => 'Is Equal To', '2' => 'Is Not Equal To', '3' => 'Greater Than', '4' => 'Less Than', '5' => 'Greater Or Equal Than', '6' => 'Less Or Equal Than');
633
+		return $status_array;
634
+	}
635
+
636
+	function update_int_type($status = '') {
637
+		$status_array = array('1' => 'Preserve', '2' => 'Set To', '3' => 'Increase By', '4' => 'Decrease By');
638
+		return $status_array;
639
+	}
640
+
641
+	function update_drp_type($status = '') {
642
+		$status_array = array('1' => 'Preserve', '2' => 'Set To');
643
+		return $status_array;
644
+	}
645
+
646
+	function search_string_type($status = '') {
647
+		$status_array = array('5'=>"Begins With", '1' => 'Contains', '2' => 'Doesnt Contain', '3' => 'Is Equal To', '4' => 'Is Not Equal To', "6"=>"Ends With");
648
+		return $status_array;
649
+	}
650
+
651
+	function set_protocal($protpcal = '') {
652
+		$status_array = array('SIP' => 'SIP', 'IAX2' => 'IAX2', 'Zap' => 'Zap', 'Local' => 'Local', 'OH323' => 'OH323', 'OOH323C' => 'OOH323C');
653
+		return $status_array;
654
+	}
655
+
656
+	/*
657 657
      *
658 658
      * Purpose : Add Profit Margin report
659 659
      * Version 2.1
660 660
      */
661 661
 
662
-    function set_notify_by($status = '') {
663
-        $status_array = array('' => 'Select Notify By', '0' => 'CSV', '1' => 'Email');
664
-        return $status_array;
665
-    }
662
+	function set_notify_by($status = '') {
663
+		$status_array = array('' => 'Select Notify By', '0' => 'CSV', '1' => 'Email');
664
+		return $status_array;
665
+	}
666 666
 
667
-    function convert_to_percentage($select = "", $table = "", $amount) {
668
-        return round($amount, 2)." %";
669
-    }
667
+	function convert_to_percentage($select = "", $table = "", $amount) {
668
+		return round($amount, 2)." %";
669
+	}
670 670
 
671
-    function convert_to_minutes($select = "", $table = "", $amount) {
672
-        return str_replace('.', ':', round($amount / 60, 2));
673
-    }
671
+	function convert_to_minutes($select = "", $table = "", $amount) {
672
+		return str_replace('.', ':', round($amount / 60, 2));
673
+	}
674 674
 
675
-    function set_filter_type_search($status = '') {
676
-        $status_array = array('pricelist_id' => 'Rate Group', 'accountid' => 'Customer', 'reseller_id' => 'Reseller');
677
-        return $status_array;
678
-    }
675
+	function set_filter_type_search($status = '') {
676
+		$status_array = array('pricelist_id' => 'Rate Group', 'accountid' => 'Customer', 'reseller_id' => 'Reseller');
677
+		return $status_array;
678
+	}
679 679
     
680
-    	function set_routetype_status($select = '') {
681
-        $status_array = array("" => "--Select--",
682
-            "0" => "LCR",
683
-            "1" => "COST"
684
-        );
685
-        return $status_array;
680
+		function set_routetype_status($select = '') {
681
+		$status_array = array("" => "--Select--",
682
+			"0" => "LCR",
683
+			"1" => "COST"
684
+		);
685
+		return $status_array;
686 686
 }
687 687
 	
688 688
 
689
-    //attachment download in email module...
690
-    function attachment_icons($select = "", $table = "", $attachement = "") {
691
-        if ($attachement != "") {
692
-            $array = explode(",", $attachement);
693
-            $str = '';	
694
-            foreach ($array as $key => $val) {
695
-                $link = base_url()."email/email_history_list_attachment/".$val;
696
-                $str .= "<a href='".$link."' title='".$val."' class='btn btn-royelblue btn-sm'><i class='fa fa-paperclip fa-fw'></i></a>&nbsp;&nbsp;";
697
-            }
698
-            return $str;
699
-        } else {
700
-            return "";
701
-        }
702
-    }
703
-
704
-    /*     * ************************************************************* */
705
-
706
-    function set_despostion($dis = '') {
707
-        $status_array = array("" => "--Select Disposition--",
708
-            "UNSPECIFIED" => "UNSPECIFIED",
709
-            "UNALLOCATED_NUMBER" => "UNALLOCATED_NUMBER",
710
-            "NO_ROUTE_DESTINATION" => "NO_ROUTE_DESTINATION",
711
-            "CHANNEL_UNACCEPTABLE" => "CHANNEL_UNACCEPTABLE",
712
-            "NORMAL_CLEARING" => "NORMAL_CLEARING",
713
-            "SUCCESS" => "SUCCESS",
714
-            "USER_BUSY" => "USER_BUSY",
715
-            "NO_USER_RESPONSE" => "NO_USER_RESPONSE",
716
-            "NO_ANSWER" => "NO_ANSWER",
717
-            "CALL_REJECTED" => "CALL_REJECTED",
718
-            "NUMBER_CHANGED" => "NUMBER_CHANGED",
719
-            "DESTINATION_OUT_OF_ORDER" => "DESTINATION_OUT_OF_ORDER",
720
-            "INVALID_NUMBER_FORMAT" => "INVALID_NUMBER_FORMAT",
721
-            "FACILITY_REJECTED" => "FACILITY_REJECTED",
722
-            "NORMAL_UNSPECIFIED" => "NORMAL_UNSPECIFIED",
723
-            "NORMAL_CIRCUIT_CONGESTION" => "NORMAL_CIRCUIT_CONGESTION",
724
-            "NETWORK_OUT_OF_ORDER" => "NETWORK_OUT_OF_ORDER",
725
-            "NORMAL_TEMPORARY_FAILURE" => "NORMAL_TEMPORARY_FAILURE",
726
-            "SWITCH_CONGESTION" => "SWITCH_CONGESTION",
727
-            "FACILITY_NOT_SUBSCRIBED" => "FACILITY_NOT_SUBSCRIBED",
728
-            "OUTGOING_CALL_BARRED" => "OUTGOING_CALL_BARRED",
729
-            "BEARERCAPABILITY_NOTAUTH" => "BEARERCAPABILITY_NOTAUTH",
730
-            "BEARERCAPABILITY_NOTAVAIL" => "BEARERCAPABILITY_NOTAVAIL",
731
-            "SERVICE_UNAVAILABLE" => "SERVICE_UNAVAILABLE",
732
-            "BEARERCAPABILITY_NOTIMPL" => "BEARERCAPABILITY_NOTIMPL",
733
-            "CHAN_NOT_IMPLEMENTED" => "CHAN_NOT_IMPLEMENTED",
734
-            "FACILITY_NOT_IMPLEMENTED" => "FACILITY_NOT_IMPLEMENTED",
735
-            "SERVICE_NOT_IMPLEMENTED" => "SERVICE_NOT_IMPLEMENTED",
736
-            "INCOMPATIBLE_DESTINATION" => "INCOMPATIBLE_DESTINATION",
737
-            "RECOVERY_ON_TIMER_EXPIRE" => "RECOVERY_ON_TIMER_EXPIRE",
738
-            "ORIGINATOR_CANCEL" => "ORIGINATOR_CANCEL",
739
-            "ALLOTTED_TIMEOUT" => "ALLOTTED_TIMEOUT",
740
-            "MEDIA_TIMEOUT" => "MEDIA_TIMEOUT",
741
-            "PROGRESS_TIMEOUT" => "PROGRESS_TIMEOUT",
742
-            "AUTHENTICATION_FAIL" => "AUTHENTICATION_FAIL",
689
+	//attachment download in email module...
690
+	function attachment_icons($select = "", $table = "", $attachement = "") {
691
+		if ($attachement != "") {
692
+			$array = explode(",", $attachement);
693
+			$str = '';	
694
+			foreach ($array as $key => $val) {
695
+				$link = base_url()."email/email_history_list_attachment/".$val;
696
+				$str .= "<a href='".$link."' title='".$val."' class='btn btn-royelblue btn-sm'><i class='fa fa-paperclip fa-fw'></i></a>&nbsp;&nbsp;";
697
+			}
698
+			return $str;
699
+		} else {
700
+			return "";
701
+		}
702
+	}
703
+
704
+	/*     * ************************************************************* */
705
+
706
+	function set_despostion($dis = '') {
707
+		$status_array = array("" => "--Select Disposition--",
708
+			"UNSPECIFIED" => "UNSPECIFIED",
709
+			"UNALLOCATED_NUMBER" => "UNALLOCATED_NUMBER",
710
+			"NO_ROUTE_DESTINATION" => "NO_ROUTE_DESTINATION",
711
+			"CHANNEL_UNACCEPTABLE" => "CHANNEL_UNACCEPTABLE",
712
+			"NORMAL_CLEARING" => "NORMAL_CLEARING",
713
+			"SUCCESS" => "SUCCESS",
714
+			"USER_BUSY" => "USER_BUSY",
715
+			"NO_USER_RESPONSE" => "NO_USER_RESPONSE",
716
+			"NO_ANSWER" => "NO_ANSWER",
717
+			"CALL_REJECTED" => "CALL_REJECTED",
718
+			"NUMBER_CHANGED" => "NUMBER_CHANGED",
719
+			"DESTINATION_OUT_OF_ORDER" => "DESTINATION_OUT_OF_ORDER",
720
+			"INVALID_NUMBER_FORMAT" => "INVALID_NUMBER_FORMAT",
721
+			"FACILITY_REJECTED" => "FACILITY_REJECTED",
722
+			"NORMAL_UNSPECIFIED" => "NORMAL_UNSPECIFIED",
723
+			"NORMAL_CIRCUIT_CONGESTION" => "NORMAL_CIRCUIT_CONGESTION",
724
+			"NETWORK_OUT_OF_ORDER" => "NETWORK_OUT_OF_ORDER",
725
+			"NORMAL_TEMPORARY_FAILURE" => "NORMAL_TEMPORARY_FAILURE",
726
+			"SWITCH_CONGESTION" => "SWITCH_CONGESTION",
727
+			"FACILITY_NOT_SUBSCRIBED" => "FACILITY_NOT_SUBSCRIBED",
728
+			"OUTGOING_CALL_BARRED" => "OUTGOING_CALL_BARRED",
729
+			"BEARERCAPABILITY_NOTAUTH" => "BEARERCAPABILITY_NOTAUTH",
730
+			"BEARERCAPABILITY_NOTAVAIL" => "BEARERCAPABILITY_NOTAVAIL",
731
+			"SERVICE_UNAVAILABLE" => "SERVICE_UNAVAILABLE",
732
+			"BEARERCAPABILITY_NOTIMPL" => "BEARERCAPABILITY_NOTIMPL",
733
+			"CHAN_NOT_IMPLEMENTED" => "CHAN_NOT_IMPLEMENTED",
734
+			"FACILITY_NOT_IMPLEMENTED" => "FACILITY_NOT_IMPLEMENTED",
735
+			"SERVICE_NOT_IMPLEMENTED" => "SERVICE_NOT_IMPLEMENTED",
736
+			"INCOMPATIBLE_DESTINATION" => "INCOMPATIBLE_DESTINATION",
737
+			"RECOVERY_ON_TIMER_EXPIRE" => "RECOVERY_ON_TIMER_EXPIRE",
738
+			"ORIGINATOR_CANCEL" => "ORIGINATOR_CANCEL",
739
+			"ALLOTTED_TIMEOUT" => "ALLOTTED_TIMEOUT",
740
+			"MEDIA_TIMEOUT" => "MEDIA_TIMEOUT",
741
+			"PROGRESS_TIMEOUT" => "PROGRESS_TIMEOUT",
742
+			"AUTHENTICATION_FAIL" => "AUTHENTICATION_FAIL",
743 743
 			"ACCOUNT_INACTIVE_DELETED" => "ACCOUNT_INACTIVE_DELETED",
744 744
 			"ACCOUNT_EXPIRE" => "ACCOUNT_EXPIRE",
745 745
 			"NO_SUFFICIENT_FUND" => "NO_SUFFICIENT_FUND",
@@ -1154,780 +1154,780 @@  discard block
 block discarded – undo
1154 1154
 				} else{
1155 1155
 					$accountinfo['did_maxchannels'] = "Unlimited";
1156 1156
 				}
1157
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1158
-                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'] , $message);
1159
-                $message = str_replace('#COUNTRYNAME#',$accountinfo['did_country_id'], $message);
1160
-                $message = str_replace('#SETUPFEE#',$accountinfo['did_setup'], $message);
1161
-                $message = str_replace('#MONTHLYFEE#',$accountinfo['did_monthlycost'], $message);
1162
-                $message = str_replace('#MAXCHANNEL#',$accountinfo['did_maxchannels'], $message);
1163
-                $message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1157
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1158
+				$message = str_replace('#DIDNUMBER#', $accountinfo['did_number'] , $message);
1159
+				$message = str_replace('#COUNTRYNAME#',$accountinfo['did_country_id'], $message);
1160
+				$message = str_replace('#SETUPFEE#',$accountinfo['did_setup'], $message);
1161
+				$message = str_replace('#MONTHLYFEE#',$accountinfo['did_monthlycost'], $message);
1162
+				$message = str_replace('#MAXCHANNEL#',$accountinfo['did_maxchannels'], $message);
1163
+				$message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1164 1164
 				$subject = $query[0]->subject;
1165 1165
 				$subject = str_replace("#NUMBER#", $accountinfo['number'], $subject);
1166 1166
 				$subject = str_replace("#DIDNUMBER#", $accountinfo['did_number'], $subject);
1167
-                break;
1168
-            case 'email_remove_did';
1169
-                $message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1170
-                $message = str_replace('#DIDNUMBER#', $accountinfo['did_number'],$message);
1171
-                $message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1167
+				break;
1168
+			case 'email_remove_did';
1169
+				$message = str_replace('#NAME#', $accountinfo['first_name'] . " " . $accountinfo['last_name'], $message);
1170
+				$message = str_replace('#DIDNUMBER#', $accountinfo['did_number'],$message);
1171
+				$message = str_replace('#NUMBER#', $accountinfo['number'], $message);	
1172 1172
 				$subject = $query[0]->subject;
1173 1173
 				$subject = str_replace("#NUMBER#", $accountinfo['number'], $subject);
1174 1174
 				$subject = str_replace("#DIDNUMBER#", $accountinfo['did_number'], $subject);
1175
-                break;
1176
-        }
1175
+				break;
1176
+		}
1177 1177
         
1178
-        if ($subject == "") {
1178
+		if ($subject == "") {
1179 1179
 			$subject = $query[0]->subject;
1180 1180
 			$subject = str_replace("#NAME#", $accountinfo['first_name']." ".$accountinfo['last_name'], $subject);
1181 1181
 			$subject = str_replace("#COMPANY_NAME#", $company_name, $subject);	
1182 1182
 		}
1183
-        $account_id = (isset($accountinfo['last_id']) && $accountinfo['last_id'] != "") ? $accountinfo['last_id'] : $accountinfo['id'];
1184
-        $reseller_id = $accountinfo['reseller_id'];
1185
-        if ($reseller_id != "0") {
1186
-            $reseller_result = $this->CI->db_model->getSelect("email", "accounts", array("id" => $reseller_id));
1187
-            $reseller_info = (array)$reseller_result->first_row();
1188
-            $settings_reply_email = $reseller_info['email'];
1189
-        }
1190
-        $this->emailFunction($settings_reply_email, $useremail, $subject, $message, $company_name, $attachment, $account_id, $reseller_id);
1183
+		$account_id = (isset($accountinfo['last_id']) && $accountinfo['last_id'] != "") ? $accountinfo['last_id'] : $accountinfo['id'];
1184
+		$reseller_id = $accountinfo['reseller_id'];
1185
+		if ($reseller_id != "0") {
1186
+			$reseller_result = $this->CI->db_model->getSelect("email", "accounts", array("id" => $reseller_id));
1187
+			$reseller_info = (array)$reseller_result->first_row();
1188
+			$settings_reply_email = $reseller_info['email'];
1189
+		}
1190
+		$this->emailFunction($settings_reply_email, $useremail, $subject, $message, $company_name, $attachment, $account_id, $reseller_id);
1191 1191
 
1192
-    }
1192
+	}
1193 1193
 
1194
-    /**
1195
-     * @param string $message
1196
-     */
1197
-    function emailFunction($from, $to, $subject, $message, $company_name = "", $attachment = "", $account_id, $reseller_id) {
1198
-        $send_mail_details = array('from' => $from,
1199
-            'to' => $to,
1200
-            'subject' => $subject,
1201
-            'body' => $message,
1202
-            'accountid' => $account_id,
1203
-            'status' => '1',
1204
-            'attachment' => $attachment,
1205
-            'reseller_id' => $reseller_id,
1206
-        );
1194
+	/**
1195
+	 * @param string $message
1196
+	 */
1197
+	function emailFunction($from, $to, $subject, $message, $company_name = "", $attachment = "", $account_id, $reseller_id) {
1198
+		$send_mail_details = array('from' => $from,
1199
+			'to' => $to,
1200
+			'subject' => $subject,
1201
+			'body' => $message,
1202
+			'accountid' => $account_id,
1203
+			'status' => '1',
1204
+			'attachment' => $attachment,
1205
+			'reseller_id' => $reseller_id,
1206
+		);
1207 1207
                 
1208
-        $this->CI->db->insert('mail_details', $send_mail_details);
1209
-        return $this->CI->db->insert_id();
1210
-    }
1208
+		$this->CI->db->insert('mail_details', $send_mail_details);
1209
+		return $this->CI->db->insert_id();
1210
+	}
1211 1211
 
1212
-    /*
1212
+	/*
1213 1213
       convert GMT id 0000 condition
1214 1214
      */
1215 1215
 
1216
-    function convert_GMT_to($select = "", $table = "", $date) {
1217
-        if ($date == '0000-00-00 00:00:00') {
1218
-            return $date;
1219
-        } else {
1220
-            return $this->CI->timezone->display_GMT($date);
1221
-        }
1222
-    }
1223
-
1224
-    function convert_GMT($date) {
1225
-        return $this->CI->timezone->convert_to_GMT($select = "", $table = "", $date);
1226
-    }
1227
-
1228
-    function convert_to_ucfirst($select = "", $table = "", $str_value) {
1229
-        return ucfirst($str_value);
1230
-    }
1231
-
1232
-    function set_charge_type($status = '') {
1233
-        $status_array = array('1' => 'Accounts', '2' => 'Rate Group');
1234
-        return $status_array;
1235
-    }
1236
-
1237
-    function build_concat_string($select, $table, $id_where = '') {
1238
-        $select_params = explode(',', $select);
1239
-        $where = array("1");
1240
-        if ($id_where != '') {
1241
-            $where = array("id" => $id_where);
1242
-        }
1243
-        $select_params = explode(',', $select);
1244
-        if (isset($select_params[3])) {
1245
-            $cnt_str = " $select_params[0],' ',$select_params[1],' ','(',$select_params[2],')' ";
1246
-        } else {
1247
-            $cnt_str = " $select_params[0],' (',$select_params[1],')' ";
1248
-        }
1249
-        $select = "concat($cnt_str) as $select_params[0] ";
1250
-        $drp_array = $this->CI->db_model->getSelect($select, $table, $where);
1251
-        $drp_array = $drp_array->result();
1252
-        if (isset($drp_array[0])) {
1253
-                    return $drp_array[0]->$select_params[0];
1254
-        }
1255
-    }
1256
-
1257
-    /* 
1216
+	function convert_GMT_to($select = "", $table = "", $date) {
1217
+		if ($date == '0000-00-00 00:00:00') {
1218
+			return $date;
1219
+		} else {
1220
+			return $this->CI->timezone->display_GMT($date);
1221
+		}
1222
+	}
1223
+
1224
+	function convert_GMT($date) {
1225
+		return $this->CI->timezone->convert_to_GMT($select = "", $table = "", $date);
1226
+	}
1227
+
1228
+	function convert_to_ucfirst($select = "", $table = "", $str_value) {
1229
+		return ucfirst($str_value);
1230
+	}
1231
+
1232
+	function set_charge_type($status = '') {
1233
+		$status_array = array('1' => 'Accounts', '2' => 'Rate Group');
1234
+		return $status_array;
1235
+	}
1236
+
1237
+	function build_concat_string($select, $table, $id_where = '') {
1238
+		$select_params = explode(',', $select);
1239
+		$where = array("1");
1240
+		if ($id_where != '') {
1241
+			$where = array("id" => $id_where);
1242
+		}
1243
+		$select_params = explode(',', $select);
1244
+		if (isset($select_params[3])) {
1245
+			$cnt_str = " $select_params[0],' ',$select_params[1],' ','(',$select_params[2],')' ";
1246
+		} else {
1247
+			$cnt_str = " $select_params[0],' (',$select_params[1],')' ";
1248
+		}
1249
+		$select = "concat($cnt_str) as $select_params[0] ";
1250
+		$drp_array = $this->CI->db_model->getSelect($select, $table, $where);
1251
+		$drp_array = $drp_array->result();
1252
+		if (isset($drp_array[0])) {
1253
+					return $drp_array[0]->$select_params[0];
1254
+		}
1255
+	}
1256
+
1257
+	/* 
1258 1258
      * Change invoice_total to invoice details 
1259 1259
      */
1260 1260
 
1261
-    function get_invoice_total($select = '', $table = '', $id) {
1262
-        $where_arr = array('invoiceid' => $id, 'item_type <>' => "FREE");
1263
-        $this->CI->db->where($where_arr);
1264
-        $this->CI->db->select('*');
1265
-        $result = $this->CI->db->get('invoice_details');
1266
-        if ($result->num_rows() > 0) {
1267
-            $result = $result->result_array();
1268
-	    if ($select == 'debit') {
1261
+	function get_invoice_total($select = '', $table = '', $id) {
1262
+		$where_arr = array('invoiceid' => $id, 'item_type <>' => "FREE");
1263
+		$this->CI->db->where($where_arr);
1264
+		$this->CI->db->select('*');
1265
+		$result = $this->CI->db->get('invoice_details');
1266
+		if ($result->num_rows() > 0) {
1267
+			$result = $result->result_array();
1268
+		if ($select == 'debit') {
1269 1269
 		if ($result[0]['item_type'] == 'POSTCHARG') {
1270
-	            return $this->convert_to_currency('', '', $result[0]['debit']);
1270
+				return $this->convert_to_currency('', '', $result[0]['debit']);
1271 1271
 		} else {
1272
-	            return $this->convert_to_currency('', '', $result[0]['credit']);
1272
+				return $this->convert_to_currency('', '', $result[0]['credit']);
1273 1273
 		}
1274
-	    } else {
1274
+		} else {
1275 1275
 		   return $result[0][$select];
1276
-	    }
1277
-        } else {
1278
-            return null;
1279
-        }
1280
-    }
1281
-
1282
-    function get_array($select, $table_name, $where = false) {
1283
-        $new_array = array();
1284
-        $select_params = array();
1285
-        $select_params = explode(",", $select);
1286
-        if (isset($select_params[3])) {
1287
-            $cnt_str = " $select_params[1],'(',$select_params[2],' ',$select_params[3],')' ";
1288
-            $select = "concat($cnt_str) as $select_params[3] ";
1289
-            $field_name = $select_params[3];
1290
-        } elseif (isset($select_params[2])) {
1291
-            $cnt_str = " $select_params[1],' ','(',$select_params[2],')' ";
1292
-            $select = "concat($cnt_str) as $select_params[2] ";
1293
-            $field_name = $select_params[2];
1294
-        } else {
1295
-            $select = $select_params[1];
1296
-            $field_name = $select_params[1];
1297
-        }
1298
-        if ($where) {
1299
-            $this->CI->db->where($where);
1300
-        }
1301
-        $this->CI->db->select("$select_params[0],$select", false);
1302
-        $result = $this->CI->db->get($table_name);
1303
-        foreach ($result->result_array() as $key => $value) {
1304
-            $new_array[$value[$select_params[0]]] = $value[$field_name];
1305
-        }
1306
-        ksort($new_array);
1307
-        return $new_array;
1308
-    }
1309
-
1310
-    function get_timezone_offset() {
1311
-        $gmtoffset = 0;
1312
-        $accountinfo = $this->CI->session->userdata('accountinfo');
1313
-        $account_result = $this->CI->db->get_where('accounts', array('id' => $accountinfo['id']));
1314
-        $account_result = $account_result->result_array();
1315
-        $accountinfo = $account_result[0];
1316
-        $timezone_id_arr = array($accountinfo['timezone_id']);
1317
-        $this->CI->db->where_in('id', $timezone_id_arr);
1318
-        $this->CI->db->select('gmtoffset');
1319
-        $this->CI->db->from('timezone');
1320
-        $timezone_result = $this->CI->db->get();
1321
-        if ($timezone_result->num_rows() > 0) {
1322
-
1323
-            $timezone_result = $timezone_result->result_array();
1324
-            foreach ($timezone_result as $data) {
1325
-                $gmtoffset += $data['gmtoffset'];
1326
-            }
1327
-        }
1276
+		}
1277
+		} else {
1278
+			return null;
1279
+		}
1280
+	}
1281
+
1282
+	function get_array($select, $table_name, $where = false) {
1283
+		$new_array = array();
1284
+		$select_params = array();
1285
+		$select_params = explode(",", $select);
1286
+		if (isset($select_params[3])) {
1287
+			$cnt_str = " $select_params[1],'(',$select_params[2],' ',$select_params[3],')' ";
1288
+			$select = "concat($cnt_str) as $select_params[3] ";
1289
+			$field_name = $select_params[3];
1290
+		} elseif (isset($select_params[2])) {
1291
+			$cnt_str = " $select_params[1],' ','(',$select_params[2],')' ";
1292
+			$select = "concat($cnt_str) as $select_params[2] ";
1293
+			$field_name = $select_params[2];
1294
+		} else {
1295
+			$select = $select_params[1];
1296
+			$field_name = $select_params[1];
1297
+		}
1298
+		if ($where) {
1299
+			$this->CI->db->where($where);
1300
+		}
1301
+		$this->CI->db->select("$select_params[0],$select", false);
1302
+		$result = $this->CI->db->get($table_name);
1303
+		foreach ($result->result_array() as $key => $value) {
1304
+			$new_array[$value[$select_params[0]]] = $value[$field_name];
1305
+		}
1306
+		ksort($new_array);
1307
+		return $new_array;
1308
+	}
1309
+
1310
+	function get_timezone_offset() {
1311
+		$gmtoffset = 0;
1312
+		$accountinfo = $this->CI->session->userdata('accountinfo');
1313
+		$account_result = $this->CI->db->get_where('accounts', array('id' => $accountinfo['id']));
1314
+		$account_result = $account_result->result_array();
1315
+		$accountinfo = $account_result[0];
1316
+		$timezone_id_arr = array($accountinfo['timezone_id']);
1317
+		$this->CI->db->where_in('id', $timezone_id_arr);
1318
+		$this->CI->db->select('gmtoffset');
1319
+		$this->CI->db->from('timezone');
1320
+		$timezone_result = $this->CI->db->get();
1321
+		if ($timezone_result->num_rows() > 0) {
1322
+
1323
+			$timezone_result = $timezone_result->result_array();
1324
+			foreach ($timezone_result as $data) {
1325
+				$gmtoffset += $data['gmtoffset'];
1326
+			}
1327
+		}
1328 1328
 // 	  echo $gmtoffset;exit;
1329
-        return $gmtoffset;
1330
-    }
1331
-    /** Version 2.1
1332
-     * Purpose : Set default data for new created profile
1333
-     * */
1334
-    function sip_profile_date() {
1335
-        $defualt_profile_data = '{"rtp_ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"false","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"default","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false"}';
1336
-        return $defualt_profile_data;
1337
-    }
1329
+		return $gmtoffset;
1330
+	}
1331
+	/** Version 2.1
1332
+	 * Purpose : Set default data for new created profile
1333
+	 * */
1334
+	function sip_profile_date() {
1335
+		$defualt_profile_data = '{"rtp_ip":"$${local_ip_v4}","dialplan":"XML","user-agent-string":"ASTPP","debug":"0","sip-trace":"no","tls":"false","inbound-reg-force-matching-username":"true","disable-transcoding":"true","all-reg-options-ping":"false","unregister-on-options-fail":"true","log-auth-failures":"true","status":"0","inbound-bypass-media":"false","inbound-proxy-media":"false","disable-transfer":"true","enable-100rel":"false","rtp-timeout-sec":"60","dtmf-duration":"2000","manual-redirect":"false","aggressive-nat-detection":"false","enable-timer":"false","minimum-session-expires":"120","session-timeout-pt":"1800","auth-calls":"true","apply-inbound-acl":"default","inbound-codec-prefs":"PCMU,PCMA,G729","outbound-codec-prefs":"PCMU,PCMA,G729","inbound-late-negotiation":"false"}';
1336
+		return $defualt_profile_data;
1337
+	}
1338 1338
 
1339
-    /* ===================================================================== */
1340
-    /*
1339
+	/* ===================================================================== */
1340
+	/*
1341 1341
      * Purpose : Add following for mass mail and mail history
1342 1342
      * Version 2.1
1343 1343
      */
1344 1344
 
1345
-    function set_search_temp($select = '') {
1346
-        $status_array = array("0" => "--Select--",
1347
-            "1" => "Voip account refilled",
1348
-            "3" => "Email add user",
1349
-            "4" => "Add sip device",
1350
-            "8" => "Email add did",
1351
-            "9" => "Email remove did",
1352
-            "10" => "Email new invoice",
1353
-            "11" => "Email low balance",
1354
-            "12" => "Email signup confirmation",
1355
-            "13" => "Password successfully changed",
1356
-            "14" => "Reset your password",
1357
-            "15" => "Email add subscription",
1358
-            "16" => "Email remove subscription",
1359
-            "17" => "Email add package",
1360
-            "18" => "Email remove package",
1361
-            "19" => "Voip child accont refilled",
1362
-        );
1363
-        return $status_array;
1364
-    }
1365
-
1366
-    /*     ***
1345
+	function set_search_temp($select = '') {
1346
+		$status_array = array("0" => "--Select--",
1347
+			"1" => "Voip account refilled",
1348
+			"3" => "Email add user",
1349
+			"4" => "Add sip device",
1350
+			"8" => "Email add did",
1351
+			"9" => "Email remove did",
1352
+			"10" => "Email new invoice",
1353
+			"11" => "Email low balance",
1354
+			"12" => "Email signup confirmation",
1355
+			"13" => "Password successfully changed",
1356
+			"14" => "Reset your password",
1357
+			"15" => "Email add subscription",
1358
+			"16" => "Email remove subscription",
1359
+			"17" => "Email add package",
1360
+			"18" => "Email remove package",
1361
+			"19" => "Voip child accont refilled",
1362
+		);
1363
+		return $status_array;
1364
+	}
1365
+
1366
+	/*     ***
1367 1367
       Refill coupon dropdown
1368 1368
      * ** */
1369 1369
 
1370
-    function set_refill_coupon_status($select = '', $table = '', $status = '') {
1371
-        $refill_coupon_array = array("" => "--Select--", '2' => 'Yes', '0' => 'No');
1372
-        return $refill_coupon_array;
1373
-    }
1370
+	function set_refill_coupon_status($select = '', $table = '', $status = '') {
1371
+		$refill_coupon_array = array("" => "--Select--", '2' => 'Yes', '0' => 'No');
1372
+		return $refill_coupon_array;
1373
+	}
1374 1374
 
1375
-    function get_refill_coupon_status($select = '', $table = '', $status) {
1376
-        $refill_coupon_array = array('0' => 'Inactive', '1' => 'Active', '2' => 'Inuse', "3" => "Expired");
1377
-        return $refill_coupon_array[$status];
1378
-    }
1375
+	function get_refill_coupon_status($select = '', $table = '', $status) {
1376
+		$refill_coupon_array = array('0' => 'Inactive', '1' => 'Active', '2' => 'Inuse', "3" => "Expired");
1377
+		return $refill_coupon_array[$status];
1378
+	}
1379 1379
 
1380
-    function firstused_check($select = '', $table = '', $status) {
1380
+	function firstused_check($select = '', $table = '', $status) {
1381 1381
 
1382
-        if ($status == '0000-00-00 00:00:00') {
1383
-            return '-';
1384
-        }
1385
-        return $status;
1386
-    }
1382
+		if ($status == '0000-00-00 00:00:00') {
1383
+			return '-';
1384
+		}
1385
+		return $status;
1386
+	}
1387 1387
 
1388
-    function get_refill_coupon_used($select = '', $table = '', $status) {
1389
-        return $status['status'] == 2 ? '<img src= "'.base_url().'assets/images/true.png" style="height:20px;width:20px;" title="Yes">' : '<img src= "'.base_url().'/assets/images/false.png" style="height:20px;width:20px;" title="No">';
1390
-    }
1388
+	function get_refill_coupon_used($select = '', $table = '', $status) {
1389
+		return $status['status'] == 2 ? '<img src= "'.base_url().'assets/images/true.png" style="height:20px;width:20px;" title="Yes">' : '<img src= "'.base_url().'/assets/images/false.png" style="height:20px;width:20px;" title="No">';
1390
+	}
1391 1391
 
1392
-    /*     * *******
1392
+	/*     * *******
1393 1393
       Password encode decode
1394 1394
      * ******* */
1395 1395
 
1396
-    /**
1397
-     * @param string $string
1398
-     */
1399
-    function encode_params($string) {
1400
-        $data = base64_encode($string);
1401
-        $data = str_replace(array('+', '/', '='), array('-', '$', ''), $data);
1402
-        return $data;
1403
-    }
1404
-
1405
-    /**
1406
-     * @param string $value
1407
-     */
1408
-    function encode($value) {
1409
-        $text = $value;
1410
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1411
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1412
-        $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $text, MCRYPT_MODE_ECB, $iv);
1413
-        return trim($this->encode_params($crypttext));
1414
-    }
1415
-
1416
-    function decode_params($string) {
1417
-        $data = str_replace(array('-', '$'), array('+', '/'), $string);
1418
-        $mod4 = strlen($data) % 4;
1419
-        if ($mod4) {
1420
-            $data .= substr('====', $mod4);
1421
-        }
1422
-        return base64_decode($data);
1423
-    }
1424
-
1425
-    function decode($value) {
1426
-        $crypttext = $this->decode_params($value);
1427
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1428
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1429
-        $decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $crypttext, MCRYPT_MODE_ECB, $iv);
1430
-        return trim($decrypttext);
1431
-    }
1432
-
1433
-    /******
1396
+	/**
1397
+	 * @param string $string
1398
+	 */
1399
+	function encode_params($string) {
1400
+		$data = base64_encode($string);
1401
+		$data = str_replace(array('+', '/', '='), array('-', '$', ''), $data);
1402
+		return $data;
1403
+	}
1404
+
1405
+	/**
1406
+	 * @param string $value
1407
+	 */
1408
+	function encode($value) {
1409
+		$text = $value;
1410
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1411
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1412
+		$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $text, MCRYPT_MODE_ECB, $iv);
1413
+		return trim($this->encode_params($crypttext));
1414
+	}
1415
+
1416
+	function decode_params($string) {
1417
+		$data = str_replace(array('-', '$'), array('+', '/'), $string);
1418
+		$mod4 = strlen($data) % 4;
1419
+		if ($mod4) {
1420
+			$data .= substr('====', $mod4);
1421
+		}
1422
+		return base64_decode($data);
1423
+	}
1424
+
1425
+	function decode($value) {
1426
+		$crypttext = $this->decode_params($value);
1427
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
1428
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
1429
+		$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->CI->config->item('private_key'), $crypttext, MCRYPT_MODE_ECB, $iv);
1430
+		return trim($decrypttext);
1431
+	}
1432
+
1433
+	/******
1434 1434
       Recording enable/disable dropdown
1435 1435
      * ** */
1436 1436
 
1437
-    function set_recording($status = '') {
1438
-        $status_array = array('0' => 'On', '1' => 'Off',);
1439
-        return $status_array;
1440
-    }
1437
+	function set_recording($status = '') {
1438
+		$status_array = array('0' => 'On', '1' => 'Off',);
1439
+		return $status_array;
1440
+	}
1441 1441
 
1442
-    /*     * ************************** */
1442
+	/*     * ************************** */
1443 1443
 
1444
-    function email_status($select = "", $table = "", $status) {
1445
-        $status = ($status['status'] == 0) ? "Sent" : "Not Sent";
1444
+	function email_status($select = "", $table = "", $status) {
1445
+		$status = ($status['status'] == 0) ? "Sent" : "Not Sent";
1446 1446
 	return $status;    
1447
-    }
1447
+	}
1448 1448
 
1449
-    function email_search_status($select = '') {
1450
-        $status_array = array("" => "--Select--",
1451
-            "0" => "Sent",
1452
-            "1" => "Not Sent"
1453
-        );
1454
-        return $status_array;
1455
-    }
1449
+	function email_search_status($select = '') {
1450
+		$status_array = array("" => "--Select--",
1451
+			"0" => "Sent",
1452
+			"1" => "Not Sent"
1453
+		);
1454
+		return $status_array;
1455
+	}
1456 1456
 
1457
-    /* ===================================================================== */
1457
+	/* ===================================================================== */
1458 1458
 
1459 1459
 
1460
-    /*
1460
+	/*
1461 1461
      * Purpose : Add following for setting page
1462 1462
      * Version 2.1
1463 1463
      */
1464 1464
 
1465
-    function paypal_status($status = '') {
1466
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1467
-        return $status_array;
1468
-    }
1469
-    function playback_audio_notification($status = '') {
1470
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1471
-        return $status_array;
1472
-    }
1473
-    function custom_status($status) {
1465
+	function paypal_status($status = '') {
1466
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1467
+		return $status_array;
1468
+	}
1469
+	function playback_audio_notification($status = '') {
1470
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1471
+		return $status_array;
1472
+	}
1473
+	function custom_status($status) {
1474 1474
 		$status_array = array('0' => 'Yes', '1' => 'No');
1475
-        return $status_array;
1476
-    }
1475
+		return $status_array;
1476
+	}
1477 1477
     
1478
-    function custom_status_active($status) {
1479
-      $status_array = array('0' => 'Active', '1' => 'InActive');
1480
-      return $status_array;
1481
-    }
1482
-    function custom_status_true($status) {
1483
-      $status_array = array('0' => 'TRUE', '1' => 'FALSE');
1484
-      return $status_array;
1485
-    }
1486
-    function custom_status_voicemail($status) {
1487
-      $status_array = array('true' => 'True', 'false' => 'False');
1488
-      return $status_array;
1489
-    }
1490
-
1491
-    /******
1478
+	function custom_status_active($status) {
1479
+	  $status_array = array('0' => 'Active', '1' => 'InActive');
1480
+	  return $status_array;
1481
+	}
1482
+	function custom_status_true($status) {
1483
+	  $status_array = array('0' => 'TRUE', '1' => 'FALSE');
1484
+	  return $status_array;
1485
+	}
1486
+	function custom_status_voicemail($status) {
1487
+	  $status_array = array('true' => 'True', 'false' => 'False');
1488
+	  return $status_array;
1489
+	}
1490
+
1491
+	/******
1492 1492
       For enable Signup module
1493 1493
      * */
1494
-    function create_sipdevice($status = '') {
1495
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1496
-        return $status_array;
1497
-    }
1494
+	function create_sipdevice($status = '') {
1495
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1496
+		return $status_array;
1497
+	}
1498 1498
 
1499
-    function enable_signup($status = '') {
1500
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1501
-        return $status_array;
1502
-    }
1499
+	function enable_signup($status = '') {
1500
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1501
+		return $status_array;
1502
+	}
1503 1503
 
1504 1504
 	function balance_announce($status = '') {
1505
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1506
-        return $status_array;
1507
-    }
1505
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1506
+		return $status_array;
1507
+	}
1508 1508
 	function minutes_announce($status = '') {
1509
-        $status_array = array('0' => 'Enable', '1' => 'Disable');
1510
-        return $status_array;
1511
-    }
1509
+		$status_array = array('0' => 'Enable', '1' => 'Disable');
1510
+		return $status_array;
1511
+	}
1512 1512
 	
1513
-    function enable_disable_option() {
1514
-        $option_array = array('0' => 'Enable', '1' => 'Disable');
1515
-        return $option_array;
1516
-    }
1517
-
1518
-    function paypal_mode($status = '') {
1519
-        $status_array = array('0' => 'Live', '1' => 'Sandbox',);
1520
-        return $status_array;
1521
-    }
1522
-
1523
-    function paypal_fee($status = '') {
1524
-        $status_array = array('0' => 'Paid By Admin', '1' => 'Paid By Customer',);
1525
-        return $status_array;
1526
-    }
1527
-
1528
-    function email() {
1529
-        $status_array = array('1' => 'Enable', '0' => 'Disable',);
1530
-        return $status_array;
1531
-    }
1532
-
1533
-    function smtp() {
1534
-        return $this->set_allow();
1535
-    }
1536
-
1537
-    function debug() {
1538
-        $status_array = array('1' => 'Enable', '0' => 'Disable',);
1539
-        return $status_array;
1540
-    }
1541
-    function default_signup_rategroup() {
1542
-        $this->CI->db->select("id,name");
1543
-        $this->CI->db->where("status", 0);
1544
-        $this->CI->db->where("reseller_id", 0);
1545
-        $pricelist_result = $this->CI->db->get("pricelists")->result_array();
1546
-        $pricelist_arr = array();
1547
-        foreach ($pricelist_result as $result) {
1548
-            $pricelist_arr[$result['id']] = $result['name'];
1549
-        }
1550
-        return $pricelist_arr;
1513
+	function enable_disable_option() {
1514
+		$option_array = array('0' => 'Enable', '1' => 'Disable');
1515
+		return $option_array;
1516
+	}
1517
+
1518
+	function paypal_mode($status = '') {
1519
+		$status_array = array('0' => 'Live', '1' => 'Sandbox',);
1520
+		return $status_array;
1521
+	}
1522
+
1523
+	function paypal_fee($status = '') {
1524
+		$status_array = array('0' => 'Paid By Admin', '1' => 'Paid By Customer',);
1525
+		return $status_array;
1526
+	}
1527
+
1528
+	function email() {
1529
+		$status_array = array('1' => 'Enable', '0' => 'Disable',);
1530
+		return $status_array;
1531
+	}
1532
+
1533
+	function smtp() {
1534
+		return $this->set_allow();
1535
+	}
1536
+
1537
+	function debug() {
1538
+		$status_array = array('1' => 'Enable', '0' => 'Disable',);
1539
+		return $status_array;
1540
+	}
1541
+	function default_signup_rategroup() {
1542
+		$this->CI->db->select("id,name");
1543
+		$this->CI->db->where("status", 0);
1544
+		$this->CI->db->where("reseller_id", 0);
1545
+		$pricelist_result = $this->CI->db->get("pricelists")->result_array();
1546
+		$pricelist_arr = array();
1547
+		foreach ($pricelist_result as $result) {
1548
+			$pricelist_arr[$result['id']] = $result['name'];
1549
+		}
1550
+		return $pricelist_arr;
1551 1551
         
1552
-    }
1553
-    /******
1552
+	}
1553
+	/******
1554 1554
       Enable Fax feature
1555 1555
      * */
1556
-    function outbound_fax() {
1557
-        $status_array = array('0' => 'Enable', '1' => 'Disable',);
1558
-        return $status_array;
1559
-    }
1560
-
1561
-    function inbound_fax() {
1562
-        $status_array = array('0' => 'Enable', '1' => 'Disable',);
1563
-        return $status_array;
1564
-    }
1565
-
1566
-
1567
-    function opensips() {
1568
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1569
-        return $status_array;
1570
-    }
1571
-
1572
-    function cc_ani_auth() {
1573
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1574
-        return $status_array;
1575
-    }
1576
-
1577
-    function calling_cards_balance_announce() {
1578
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1579
-        return $status_array;
1580
-    }
1581
-
1582
-    function calling_cards_timelimit_announce() {
1583
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1584
-        return $status_array;
1585
-    }
1586
-
1587
-    function calling_cards_rate_announce() {
1588
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1589
-        return $status_array;
1590
-    }
1591
-
1592
-    function startingdigit() {
1593
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1594
-        return $status_array;
1595
-    }
1596
-
1597
-    function SMPT() {
1598
-        $status_array = array('1' => 'Enable', '0' => 'Disable');
1599
-        return $status_array;
1600
-    }
1601
-
1602
-    function country() {
1603
-        return $this->CI->common_model->get_country_list();
1604
-    }
1605
-
1606
-    function default_timezone() {
1607
-        return $this->CI->db_model->build_dropdown('id,gmtzone', 'timezone');
1608
-    }
1609
-
1610
-    function timezone() {
1611
-        return $this->CI->db_model->build_dropdown('gmttime,gmttime', 'timezone');
1612
-    }
1613
-
1614
-    function base_currency() {
1615
-        return $this->CI->db_model->build_dropdown('currency,currencyname', 'currency');
1616
-    }
1617
-
1618
-    /******	
1556
+	function outbound_fax() {
1557
+		$status_array = array('0' => 'Enable', '1' => 'Disable',);
1558
+		return $status_array;
1559
+	}
1560
+
1561
+	function inbound_fax() {
1562
+		$status_array = array('0' => 'Enable', '1' => 'Disable',);
1563
+		return $status_array;
1564
+	}
1565
+
1566
+
1567
+	function opensips() {
1568
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1569
+		return $status_array;
1570
+	}
1571
+
1572
+	function cc_ani_auth() {
1573
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1574
+		return $status_array;
1575
+	}
1576
+
1577
+	function calling_cards_balance_announce() {
1578
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1579
+		return $status_array;
1580
+	}
1581
+
1582
+	function calling_cards_timelimit_announce() {
1583
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1584
+		return $status_array;
1585
+	}
1586
+
1587
+	function calling_cards_rate_announce() {
1588
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1589
+		return $status_array;
1590
+	}
1591
+
1592
+	function startingdigit() {
1593
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1594
+		return $status_array;
1595
+	}
1596
+
1597
+	function SMPT() {
1598
+		$status_array = array('1' => 'Enable', '0' => 'Disable');
1599
+		return $status_array;
1600
+	}
1601
+
1602
+	function country() {
1603
+		return $this->CI->common_model->get_country_list();
1604
+	}
1605
+
1606
+	function default_timezone() {
1607
+		return $this->CI->db_model->build_dropdown('id,gmtzone', 'timezone');
1608
+	}
1609
+
1610
+	function timezone() {
1611
+		return $this->CI->db_model->build_dropdown('gmttime,gmttime', 'timezone');
1612
+	}
1613
+
1614
+	function base_currency() {
1615
+		return $this->CI->db_model->build_dropdown('currency,currencyname', 'currency');
1616
+	}
1617
+
1618
+	/******	
1619 1619
       Calculate Currency manually.
1620 1620
      */
1621 1621
 
1622
-    function calculate_currency_manually($currency_info, $amount, $show_currency_flag = true, $number_format = true) {
1623
-        $decimal_points = $currency_info['decimalpoints'];
1624
-        $system_currency_rate = $currency_info['base_currency']['currencyrate'];
1625
-        $user_currency_rate = $currency_info['user_currency']['currencyrate'];
1626
-        $calculated_amount = (float)(($amount * $currency_info['user_currency']['currencyrate']) / $currency_info['base_currency']['currencyrate']); 
1627
-        if ($number_format) {
1628
-         $calculated_amount = number_format($calculated_amount, $currency_info['decimalpoints']);
1629
-        }
1630
-        if ($show_currency_flag) {
1631
-          return $calculated_amount." ".$currency_info['user_currency']['currency'];
1632
-        } else {
1633
-          return $calculated_amount;
1634
-        }
1635
-    }
1636
-
1637
-    /*
1622
+	function calculate_currency_manually($currency_info, $amount, $show_currency_flag = true, $number_format = true) {
1623
+		$decimal_points = $currency_info['decimalpoints'];
1624
+		$system_currency_rate = $currency_info['base_currency']['currencyrate'];
1625
+		$user_currency_rate = $currency_info['user_currency']['currencyrate'];
1626
+		$calculated_amount = (float)(($amount * $currency_info['user_currency']['currencyrate']) / $currency_info['base_currency']['currencyrate']); 
1627
+		if ($number_format) {
1628
+		 $calculated_amount = number_format($calculated_amount, $currency_info['decimalpoints']);
1629
+		}
1630
+		if ($show_currency_flag) {
1631
+		  return $calculated_amount." ".$currency_info['user_currency']['currency'];
1632
+		} else {
1633
+		  return $calculated_amount;
1634
+		}
1635
+	}
1636
+
1637
+	/*
1638 1638
       Using By Summary Report search
1639 1639
      */
1640 1640
 
1641
-    function search_report_in($select = '') {
1642
-        $status_array = array("minutes" => "Minutes", "seconds" => "Seconds");
1643
-        return $status_array;
1644
-    }
1645
-
1646
-    function set_summarycustomer_groupby($status = '') {
1647
-        $status_array = array('' => "--Select--", 'accountid' => 'Account', 'pattern' => 'Code', 'package_id'=>"Package");
1648
-        return $status_array;
1649
-    }
1650
-
1651
-    function set_summaryprovider_groupby($status = '') {
1652
-        $status_array = array('' => "--Select--", 'provider_id' => 'Account', 'trunk_id' => "Trunks", 'pattern' => 'Code');
1653
-        return $status_array;
1654
-    }
1655
-
1656
-    function get_currency_info() {
1657
-        //System Currency info 
1658
-        $base_currency = Common_model::$global_config['system_config']['base_currency'];
1659
-        //Get Account Information from session to get currency_id
1660
-        $accountinfo = $this->CI->session->userdata('accountinfo');
1661
-        //Get User Currency id 
1662
-        $user_currency_id = $accountinfo['currency_id'] > 0 ? $accountinfo['currency_id'] : $base_currency;
1663
-        $where = "currency = '".$base_currency."' OR id= ".$user_currency_id;
1664
-        $this->CI->db->where($where);
1665
-        $this->CI->db->select('*');
1666
-        $currency_result = $this->CI->db->get('currency');
1667
-
1668
-        if ($currency_result->num_rows() == 2) {
1669
-            $currency_result = $currency_result->result_array();
1670
-            foreach ($currency_result as $key => $records) {
1671
-                //User Currency is currency details of logged in user.
1672
-                if ($records['id'] == $user_currency_id) {
1673
-                    $currency_info['user_currency'] = $records;
1674
-                }
1675
-                //System Currency is currency details of system.
1676
-                if ($records['currency'] == Common_model::$global_config['system_config']['base_currency']) {
1677
-                    $currency_info['base_currency'] = $records;
1678
-                }
1679
-            }
1680
-        } else if ($currency_result->num_rows() == 1) {
1681
-            $currency_info['user_currency'] = $currency_info['base_currency'] = (array)$currency_result->first_row();
1682
-        }
1683
-        //Get Decimal points as per defined from system.
1684
-        $currency_info['decimalpoints'] = Common_model::$global_config['system_config']['decimalpoints'];
1685
-        return $currency_info;
1686
-    }
1687
-
1688
-    function convert_to_show_in($search_name = "", $table = "", $second) {
1689
-        $search_arr = $this->CI->session->userdata($search_name);
1690
-        $show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1691
-        return ($show_seconds === 'minutes') ? ($second > 0) ?
1692
-                        sprintf('%02d', $second / 60).":".sprintf('%02d', ($second % 60)) : "00:00" : sprintf('%02d', $second);
1693
-    }
1694
-
1695
-    function array_column($input, $columnKey, $indexKey = null) {
1696
-        $array = array();
1697
-        foreach ($input as $value) {
1698
-            if ( ! isset($value[$columnKey])) {
1699
-                trigger_error("Key \"$columnKey\" does not exist in array");
1700
-                return false;
1701
-            }
1702
-
1703
-            if (is_null($indexKey)) {
1704
-                $array[] = $value[$columnKey];
1705
-            } else {
1706
-                if ( ! isset($value[$indexKey])) {
1707
-                    trigger_error("Key \"$indexKey\" does not exist in array");
1708
-                    return false;
1709
-                }
1710
-                if ( ! is_scalar($value[$indexKey])) {
1711
-                    trigger_error("Key \"$indexKey\" does not contain scalar value");
1712
-                    return false;
1713
-                }
1714
-                $array[$value[$indexKey]] = $value[$columnKey];
1715
-            }
1716
-        }
1717
-
1718
-        return $array;
1719
-    }
1720
-
1721
-    function group_by_time() {
1722
-        $status_array = array('' => "--Select--", 'HOUR' => 'Hour', 'DAY' => "Day", 'MONTH' => 'Month', "YEAR" => "Year");
1723
-        return $status_array;
1724
-    }
1725
-
1726
-    function currency_decimal($amount) {
1641
+	function search_report_in($select = '') {
1642
+		$status_array = array("minutes" => "Minutes", "seconds" => "Seconds");
1643
+		return $status_array;
1644
+	}
1645
+
1646
+	function set_summarycustomer_groupby($status = '') {
1647
+		$status_array = array('' => "--Select--", 'accountid' => 'Account', 'pattern' => 'Code', 'package_id'=>"Package");
1648
+		return $status_array;
1649
+	}
1650
+
1651
+	function set_summaryprovider_groupby($status = '') {
1652
+		$status_array = array('' => "--Select--", 'provider_id' => 'Account', 'trunk_id' => "Trunks", 'pattern' => 'Code');
1653
+		return $status_array;
1654
+	}
1655
+
1656
+	function get_currency_info() {
1657
+		//System Currency info 
1658
+		$base_currency = Common_model::$global_config['system_config']['base_currency'];
1659
+		//Get Account Information from session to get currency_id
1660
+		$accountinfo = $this->CI->session->userdata('accountinfo');
1661
+		//Get User Currency id 
1662
+		$user_currency_id = $accountinfo['currency_id'] > 0 ? $accountinfo['currency_id'] : $base_currency;
1663
+		$where = "currency = '".$base_currency."' OR id= ".$user_currency_id;
1664
+		$this->CI->db->where($where);
1665
+		$this->CI->db->select('*');
1666
+		$currency_result = $this->CI->db->get('currency');
1667
+
1668
+		if ($currency_result->num_rows() == 2) {
1669
+			$currency_result = $currency_result->result_array();
1670
+			foreach ($currency_result as $key => $records) {
1671
+				//User Currency is currency details of logged in user.
1672
+				if ($records['id'] == $user_currency_id) {
1673
+					$currency_info['user_currency'] = $records;
1674
+				}
1675
+				//System Currency is currency details of system.
1676
+				if ($records['currency'] == Common_model::$global_config['system_config']['base_currency']) {
1677
+					$currency_info['base_currency'] = $records;
1678
+				}
1679
+			}
1680
+		} else if ($currency_result->num_rows() == 1) {
1681
+			$currency_info['user_currency'] = $currency_info['base_currency'] = (array)$currency_result->first_row();
1682
+		}
1683
+		//Get Decimal points as per defined from system.
1684
+		$currency_info['decimalpoints'] = Common_model::$global_config['system_config']['decimalpoints'];
1685
+		return $currency_info;
1686
+	}
1687
+
1688
+	function convert_to_show_in($search_name = "", $table = "", $second) {
1689
+		$search_arr = $this->CI->session->userdata($search_name);
1690
+		$show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1691
+		return ($show_seconds === 'minutes') ? ($second > 0) ?
1692
+						sprintf('%02d', $second / 60).":".sprintf('%02d', ($second % 60)) : "00:00" : sprintf('%02d', $second);
1693
+	}
1694
+
1695
+	function array_column($input, $columnKey, $indexKey = null) {
1696
+		$array = array();
1697
+		foreach ($input as $value) {
1698
+			if ( ! isset($value[$columnKey])) {
1699
+				trigger_error("Key \"$columnKey\" does not exist in array");
1700
+				return false;
1701
+			}
1702
+
1703
+			if (is_null($indexKey)) {
1704
+				$array[] = $value[$columnKey];
1705
+			} else {
1706
+				if ( ! isset($value[$indexKey])) {
1707
+					trigger_error("Key \"$indexKey\" does not exist in array");
1708
+					return false;
1709
+				}
1710
+				if ( ! is_scalar($value[$indexKey])) {
1711
+					trigger_error("Key \"$indexKey\" does not contain scalar value");
1712
+					return false;
1713
+				}
1714
+				$array[$value[$indexKey]] = $value[$columnKey];
1715
+			}
1716
+		}
1717
+
1718
+		return $array;
1719
+	}
1720
+
1721
+	function group_by_time() {
1722
+		$status_array = array('' => "--Select--", 'HOUR' => 'Hour', 'DAY' => "Day", 'MONTH' => 'Month', "YEAR" => "Year");
1723
+		return $status_array;
1724
+	}
1725
+
1726
+	function currency_decimal($amount) {
1727 1727
 		$amount = str_replace(',', '', $amount);
1728
-        $decimal_amount = Common_model::$global_config['system_config']['decimalpoints'];
1729
-        $number_convert = number_format((float)$amount, $decimal_amount, '.', '');
1730
-        return $number_convert;
1731
-    }
1732
-
1733
-    function add_invoice_details($account_arr, $charge_type, $amount, $description) {
1734
-        $accountinfo = $this->CI->session->userdata('accountinfo');
1735
-        $reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0;
1736
-        $where = "accountid IN ('".$reseller_id."','1')";
1737
-        $this->CI->db->where($where);
1738
-        $this->CI->db->select('*');
1739
-        $this->CI->db->order_by('accountid', 'desc');
1740
-        $this->CI->db->limit(1);
1741
-        $invoiceconf = $this->CI->db->get('invoice_conf');
1742
-        $invoice_conf = (array)$invoiceconf->first_row();
1743
-        $last_invoiceid = $this->get_invoice_date('invoiceid', '', $account_arr['reseller_id']);
1744
-        if ($last_invoiceid && $last_invoiceid > 0) {
1745
-            $last_invoiceid = ($last_invoiceid + 1);
1746
-        } else {
1747
-            $last_invoiceid = $invoice_conf['invoice_start_from'];
1748
-        }
1749
-        $last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
1750
-        $invoice_prefix = $invoice_conf['invoice_prefix'];
1751
-        $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days"));
1752
-        $invoiceid = $account_arr['posttoexternal'] == 0 ? $this->CI->common_model->generate_receipt($account_arr['id'], $amount, $account_arr, $last_invoiceid, $invoice_prefix, $due_date) : 0;
1728
+		$decimal_amount = Common_model::$global_config['system_config']['decimalpoints'];
1729
+		$number_convert = number_format((float)$amount, $decimal_amount, '.', '');
1730
+		return $number_convert;
1731
+	}
1732
+
1733
+	function add_invoice_details($account_arr, $charge_type, $amount, $description) {
1734
+		$accountinfo = $this->CI->session->userdata('accountinfo');
1735
+		$reseller_id = $accountinfo['type'] == 1 ? $accountinfo['id'] : 0;
1736
+		$where = "accountid IN ('".$reseller_id."','1')";
1737
+		$this->CI->db->where($where);
1738
+		$this->CI->db->select('*');
1739
+		$this->CI->db->order_by('accountid', 'desc');
1740
+		$this->CI->db->limit(1);
1741
+		$invoiceconf = $this->CI->db->get('invoice_conf');
1742
+		$invoice_conf = (array)$invoiceconf->first_row();
1743
+		$last_invoiceid = $this->get_invoice_date('invoiceid', '', $account_arr['reseller_id']);
1744
+		if ($last_invoiceid && $last_invoiceid > 0) {
1745
+			$last_invoiceid = ($last_invoiceid + 1);
1746
+		} else {
1747
+			$last_invoiceid = $invoice_conf['invoice_start_from'];
1748
+		}
1749
+		$last_invoiceid = str_pad($last_invoiceid, (strlen($last_invoiceid) + 4), '0', STR_PAD_LEFT);
1750
+		$invoice_prefix = $invoice_conf['invoice_prefix'];
1751
+		$due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoice_conf['interval']." days"));
1752
+		$invoiceid = $account_arr['posttoexternal'] == 0 ? $this->CI->common_model->generate_receipt($account_arr['id'], $amount, $account_arr, $last_invoiceid, $invoice_prefix, $due_date) : 0;
1753 1753
         
1754
-        $insert_arr = array("accountid" => $account_arr['id'],
1755
-            "description" => $description,
1756
-            "debit" => $amount,
1757
-            "credit" => '0',
1758
-            "created_date" => gmdate("Y-m-d H:i:s"),
1759
-            "invoiceid" => $invoiceid,
1760
-            "reseller_id" => $account_arr['reseller_id'],
1761
-            "item_type" => $charge_type,
1762
-            "item_id" => '0',
1763
-        );
1764
-        $this->CI->db->insert("invoice_details", $insert_arr);
1765
-        return true;
1766
-    }
1767
-    /* ASTPP  3.0  Remove all information related to going to delete customer.
1754
+		$insert_arr = array("accountid" => $account_arr['id'],
1755
+			"description" => $description,
1756
+			"debit" => $amount,
1757
+			"credit" => '0',
1758
+			"created_date" => gmdate("Y-m-d H:i:s"),
1759
+			"invoiceid" => $invoiceid,
1760
+			"reseller_id" => $account_arr['reseller_id'],
1761
+			"item_type" => $charge_type,
1762
+			"item_id" => '0',
1763
+		);
1764
+		$this->CI->db->insert("invoice_details", $insert_arr);
1765
+		return true;
1766
+	}
1767
+	/* ASTPP  3.0  Remove all information related to going to delete customer.
1768 1768
      */
1769
-    function customer_delete_dependencies($id){
1770
-          $this->delete_data('ani_map',array('accountid'=>$id));
1771
-          $this->delete_data('block_patterns',array('accountid'=>$id));
1772
-          $this->delete_data('charge_to_account',array('accountid'=>$id));
1773
-          $this->delete_data('counters',array('accountid'=>$id));
1774
-          $this->delete_data('ip_map',array('accountid'=>$id));
1775
-          $this->delete_data('sip_devices',array('accountid'=>$id));
1776
-          $this->delete_data('speed_dial',array('accountid'=>$id));
1777
-          $this->delete_data('taxes_to_accounts',array('accountid'=>$id));
1778
-          $this->delete_data('mail_details',array('accountid'=>$id));
1779
-          $this->update_data('dids',array("accountid"=>$id),array('accountid'=>0));
1780
-          $this->update_data("accounts",array("id"=>$id),array("deleted"=>1));
1781
-    }
1782
-    /*
1769
+	function customer_delete_dependencies($id){
1770
+		  $this->delete_data('ani_map',array('accountid'=>$id));
1771
+		  $this->delete_data('block_patterns',array('accountid'=>$id));
1772
+		  $this->delete_data('charge_to_account',array('accountid'=>$id));
1773
+		  $this->delete_data('counters',array('accountid'=>$id));
1774
+		  $this->delete_data('ip_map',array('accountid'=>$id));
1775
+		  $this->delete_data('sip_devices',array('accountid'=>$id));
1776
+		  $this->delete_data('speed_dial',array('accountid'=>$id));
1777
+		  $this->delete_data('taxes_to_accounts',array('accountid'=>$id));
1778
+		  $this->delete_data('mail_details',array('accountid'=>$id));
1779
+		  $this->update_data('dids',array("accountid"=>$id),array('accountid'=>0));
1780
+		  $this->update_data("accounts",array("id"=>$id),array("deleted"=>1));
1781
+	}
1782
+	/*
1783 1783
      *  ASTPP  3.0 
1784 1784
      *  Remove all information related to going to delete reseller.
1785 1785
      */
1786
-    function reseller_delete_dependencies($id){
1787
-        $accountinfo=$this->CI->session->userdata('accountinfo');
1788
-        $child_arr=$this->select_data("accounts",array("reseller_id"=>$id,"type"=>0),'id,reseller_id');
1789
-        if($child_arr){
1790
-            foreach($child_arr as $value){
1791
-                $this->customer_delete_dependencies($value['id']);
1792
-            }
1793
-        }
1794
-        $package_arr=$this->select_data("packages",array("reseller_id"=>$id),'id');
1795
-        if($package_arr){
1796
-            foreach($package_arr as $value){
1797
-                $this->delete_data('package_patterns',array("id"=>$value['id']));
1798
-            }
1799
-        }
1800
-        $acc_arr=$this->select_data('accounts',array("id"=>$id),'id,reseller_id');
1801
-        $parent_id=0;
1802
-        if($acc_arr){
1803
-            $parent_id=$acc_arr[0]['reseller_id'];
1804
-        }
1805
-        $pricelist_arr=$this->select_data('pricelists',array('reseller_id'=>$id),'id');
1806
-        if($pricelist_arr){
1807
-             foreach($pricelist_arr as $value){
1808
-                $this->delete_data("routing",array("pricelist_id"=>$value['id']));
1809
-                $this->delete_data("routes",array("pricelist_id"=>$value['id']));
1810
-                $this->update_data('pricelists',array('id'=>$value['id']),array('status'=>2));         
1811
-             }
1812
-        }
1813
-        $charge_arr=$this->select_data('charges',array('reseller_id'=>$id),'id');
1814
-        if($charge_arr){
1815
-             foreach($charge_arr as $value){
1816
-                $this->delete_data("charge_to_account",array("charge_id"=>$value['id']));
1817
-             }
1818
-        }
1819
-        $this->delete_data('charges',array('reseller_id'=>$id));
1820
-        $this->update_data('dids',array('parent_id'=>$id),array("parent_id"=>$parent_id));
1821
-        $this->delete_data('reseller_pricing',array("reseller_id"=>$id));
1822
-        $this->delete_data('refill_coupon',array("reseller_id"=>$id));
1823
-        $this->delete_data('mail_details',array('accountid'=>$id));
1824
-        $taxes_arr=$this->select_data('taxes',array("reseller_id"=>$id),'id');
1825
-        if($taxes_arr){
1826
-             foreach($taxes_arr as $value){
1827
-                $this->delete_data("taxes_to_accounts",array("taxes_id"=>$value['id']));
1828
-             }
1829
-        }
1830
-        $this->delete_data('taxes',array("reseller_id"=>$id));
1831
-        $this->delete_data('default_templates',array("reseller_id"=>$id));
1832
-        $package_arr=$this->select_data('packages',array('reseller_id'=>$id),'id');
1833
-        if($package_arr){
1834
-            $this->delete_data("counters",array("package_id"=>$value['id']));
1835
-            $this->delete_data("package_patterns",array("package_id"=>$value['id']));
1836
-        }
1837
-        $this->delete_data('invoice_conf',array('accountid'=>$id));
1838
-        $this->delete_data('packages',array("reseller_id"=>$id));
1839
-        $this->update_data('accounts',array("id"=>$id),array("deleted"=>1));
1840
-    }
1841
-    function subreseller_list($parent_id = '') {
1842
-        $customer_id = $parent_id;
1843
-        $this->reseller_delete_dependencies($parent_id);
1844
-        $query = 'select id,type from accounts where reseller_id = ' . $parent_id .' AND deleted =0';
1845
-        $result = $this->CI->db->query($query);
1846
-        if ($result->num_rows() > 0) {
1847
-            $result = $result->result_array();
1848
-            foreach ($result as $data) {
1849
-	      if($data['type']==1){
1786
+	function reseller_delete_dependencies($id){
1787
+		$accountinfo=$this->CI->session->userdata('accountinfo');
1788
+		$child_arr=$this->select_data("accounts",array("reseller_id"=>$id,"type"=>0),'id,reseller_id');
1789
+		if($child_arr){
1790
+			foreach($child_arr as $value){
1791
+				$this->customer_delete_dependencies($value['id']);
1792
+			}
1793
+		}
1794
+		$package_arr=$this->select_data("packages",array("reseller_id"=>$id),'id');
1795
+		if($package_arr){
1796
+			foreach($package_arr as $value){
1797
+				$this->delete_data('package_patterns',array("id"=>$value['id']));
1798
+			}
1799
+		}
1800
+		$acc_arr=$this->select_data('accounts',array("id"=>$id),'id,reseller_id');
1801
+		$parent_id=0;
1802
+		if($acc_arr){
1803
+			$parent_id=$acc_arr[0]['reseller_id'];
1804
+		}
1805
+		$pricelist_arr=$this->select_data('pricelists',array('reseller_id'=>$id),'id');
1806
+		if($pricelist_arr){
1807
+			 foreach($pricelist_arr as $value){
1808
+				$this->delete_data("routing",array("pricelist_id"=>$value['id']));
1809
+				$this->delete_data("routes",array("pricelist_id"=>$value['id']));
1810
+				$this->update_data('pricelists',array('id'=>$value['id']),array('status'=>2));         
1811
+			 }
1812
+		}
1813
+		$charge_arr=$this->select_data('charges',array('reseller_id'=>$id),'id');
1814
+		if($charge_arr){
1815
+			 foreach($charge_arr as $value){
1816
+				$this->delete_data("charge_to_account",array("charge_id"=>$value['id']));
1817
+			 }
1818
+		}
1819
+		$this->delete_data('charges',array('reseller_id'=>$id));
1820
+		$this->update_data('dids',array('parent_id'=>$id),array("parent_id"=>$parent_id));
1821
+		$this->delete_data('reseller_pricing',array("reseller_id"=>$id));
1822
+		$this->delete_data('refill_coupon',array("reseller_id"=>$id));
1823
+		$this->delete_data('mail_details',array('accountid'=>$id));
1824
+		$taxes_arr=$this->select_data('taxes',array("reseller_id"=>$id),'id');
1825
+		if($taxes_arr){
1826
+			 foreach($taxes_arr as $value){
1827
+				$this->delete_data("taxes_to_accounts",array("taxes_id"=>$value['id']));
1828
+			 }
1829
+		}
1830
+		$this->delete_data('taxes',array("reseller_id"=>$id));
1831
+		$this->delete_data('default_templates',array("reseller_id"=>$id));
1832
+		$package_arr=$this->select_data('packages',array('reseller_id'=>$id),'id');
1833
+		if($package_arr){
1834
+			$this->delete_data("counters",array("package_id"=>$value['id']));
1835
+			$this->delete_data("package_patterns",array("package_id"=>$value['id']));
1836
+		}
1837
+		$this->delete_data('invoice_conf',array('accountid'=>$id));
1838
+		$this->delete_data('packages',array("reseller_id"=>$id));
1839
+		$this->update_data('accounts',array("id"=>$id),array("deleted"=>1));
1840
+	}
1841
+	function subreseller_list($parent_id = '') {
1842
+		$customer_id = $parent_id;
1843
+		$this->reseller_delete_dependencies($parent_id);
1844
+		$query = 'select id,type from accounts where reseller_id = ' . $parent_id .' AND deleted =0';
1845
+		$result = $this->CI->db->query($query);
1846
+		if ($result->num_rows() > 0) {
1847
+			$result = $result->result_array();
1848
+			foreach ($result as $data) {
1849
+		  if($data['type']==1){
1850 1850
 		  $this->reseller_delete_dependencies($data['id']);
1851 1851
 		  $this->subreseller_list($data['id']);
1852
-	      } else{
1852
+		  } else{
1853 1853
 		  $this->customer_delete_dependencies($data['id']);
1854
-	      }
1855
-            }
1856
-        }
1857
-    }
1854
+		  }
1855
+			}
1856
+		}
1857
+	}
1858 1858
     
1859
-    /**
1860
-     * @param string $table_name
1861
-     */
1862
-    function delete_data($table_name,$where_arr){
1863
-        $this->CI->db->where($where_arr);
1864
-        $this->CI->db->delete($table_name);
1865
-    }
1859
+	/**
1860
+	 * @param string $table_name
1861
+	 */
1862
+	function delete_data($table_name,$where_arr){
1863
+		$this->CI->db->where($where_arr);
1864
+		$this->CI->db->delete($table_name);
1865
+	}
1866 1866
 
1867
-    /**
1868
-     * @param string $table_name
1869
-     */
1870
-    function update_data($table_name,$where_arr,$update_arr){
1871
-        $this->CI->db->where($where_arr);
1872
-        $this->CI->db->update($table_name,$update_arr);
1873
-    }
1874
-
1875
-    /**
1876
-     * @param string $table_name
1877
-     * @param string $select
1878
-     */
1879
-    function select_data($table_name,$where_arr,$select){
1880
-        $this->CI->db->where($where_arr);
1881
-        $this->CI->db->select($select);
1882
-        $result=$this->CI->db->get($table_name);
1883
-        if($result->num_rows() > 0){
1884
-            return $result->result_array();
1885
-        } else{
1886
-            return false;
1887
-        }
1888
-    }
1867
+	/**
1868
+	 * @param string $table_name
1869
+	 */
1870
+	function update_data($table_name,$where_arr,$update_arr){
1871
+		$this->CI->db->where($where_arr);
1872
+		$this->CI->db->update($table_name,$update_arr);
1873
+	}
1874
+
1875
+	/**
1876
+	 * @param string $table_name
1877
+	 * @param string $select
1878
+	 */
1879
+	function select_data($table_name,$where_arr,$select){
1880
+		$this->CI->db->where($where_arr);
1881
+		$this->CI->db->select($select);
1882
+		$result=$this->CI->db->get($table_name);
1883
+		if($result->num_rows() > 0){
1884
+			return $result->result_array();
1885
+		} else{
1886
+			return false;
1887
+		}
1888
+	}
1889 1889
     
1890
-    function set_call_waiting($status = '') {
1890
+	function set_call_waiting($status = '') {
1891 1891
 		$status_array = array('0' => 'Enable', '1' => 'Disable');
1892 1892
 		return $status_array;
1893 1893
 	} 
1894
-    function get_call_waiting($select = "", $table = "", $status) {
1895
-        return ($status == 0) ? "Enable" : "Disable";
1894
+	function get_call_waiting($select = "", $table = "", $status) {
1895
+		return ($status == 0) ? "Enable" : "Disable";
1896 1896
 	}
1897 1897
   function set_invoice_details($select= ''){
1898
-        $status_array = array("invoice_select" => "--Select--",
1899
-            "invoice_inactive" => "Deleted Invoices",
1900
-            "invoice_active" => "All Invoices",
1901
-        );
1902
-        return $status_array;
1898
+		$status_array = array("invoice_select" => "--Select--",
1899
+			"invoice_inactive" => "Deleted Invoices",
1900
+			"invoice_active" => "All Invoices",
1901
+		);
1902
+		return $status_array;
1903 1903
 }
1904 1904
 function get_invoice_template($invoicedata,$accountdata,$flag){
1905
-      $login_info = $this->CI->session->userdata('accountinfo');
1906
-
1907
-      $invoice_config = $this->CI->db_model->getSelect("*", "invoice_conf", array('accountid'=>$login_info['id']));
1908
-      $invoice_config= $invoice_config->result_array();
1909
-      $invoice_config_res= $invoice_config[0];
1910
-
1911
-      $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $accountdata["currency_id"]);
1912
-      $accountdata["country"] = $this->get_field_name('country', 'countrycode', $accountdata["country_id"]);
1913
-      $data["to_currency"] = Common_model::$global_config['system_config']['base_currency'];
1914
-      if($login_info['type'] == -1){
1915
-          $currency = $data["to_currency"];
1916
-      } elseif($login_info['type'] == 1){
1905
+	  $login_info = $this->CI->session->userdata('accountinfo');
1906
+
1907
+	  $invoice_config = $this->CI->db_model->getSelect("*", "invoice_conf", array('accountid'=>$login_info['id']));
1908
+	  $invoice_config= $invoice_config->result_array();
1909
+	  $invoice_config_res= $invoice_config[0];
1910
+
1911
+	  $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $accountdata["currency_id"]);
1912
+	  $accountdata["country"] = $this->get_field_name('country', 'countrycode', $accountdata["country_id"]);
1913
+	  $data["to_currency"] = Common_model::$global_config['system_config']['base_currency'];
1914
+	  if($login_info['type'] == -1){
1915
+		  $currency = $data["to_currency"];
1916
+	  } elseif($login_info['type'] == 1){
1917 1917
 	  $accountdata["currency_id"] = $this->get_field_name('currency', 'currency', $login_info["currency_id"]);
1918
-          $currency = $accountdata["currency_id"];
1919
-      } else{
1920
-          $currency = $accountdata["currency_id"];
1921
-      }
1922
-      $decimal_amount=Common_model::$global_config['system_config']['decimalpoints'];
1923
-      ob_start();
1924
-      $this->CI->load->library('/html2pdf/html2pdf');
1925
-      $this->CI->html2pdf = new HTML2PDF('P','A4','en');
1926
-      $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
1927
-      $template_config=$this->CI->config->item('invoice_template');
1928
-      include($template_config.'invoice_template.php');
1929
-      $content = ob_get_clean();
1930
-      ob_clean();
1918
+		  $currency = $accountdata["currency_id"];
1919
+	  } else{
1920
+		  $currency = $accountdata["currency_id"];
1921
+	  }
1922
+	  $decimal_amount=Common_model::$global_config['system_config']['decimalpoints'];
1923
+	  ob_start();
1924
+	  $this->CI->load->library('/html2pdf/html2pdf');
1925
+	  $this->CI->html2pdf = new HTML2PDF('P','A4','en');
1926
+	  $this->CI->html2pdf->pdf->SetDisplayMode('fullpage');
1927
+	  $template_config=$this->CI->config->item('invoice_template');
1928
+	  include($template_config.'invoice_template.php');
1929
+	  $content = ob_get_clean();
1930
+	  ob_clean();
1931 1931
 
1932 1932
 	$ACCOUNTADD = '';
1933 1933
 	$ACCOUNTADD_CUSTOMER ='';
Please login to merge, or discard this patch.
web_interface/astpp/application/libraries/astpp/email_lib.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -88,29 +88,29 @@  discard block
 block discarded – undo
88 88
 		unset($query[0]['number']);
89 89
 		return $query[0];
90 90
 	}
91
-        return false;
92
-    }
91
+		return false;
92
+	}
93 93
 
94
-    /**
95
-     * @param string $detail_type
96
-     */
97
-    function get_info($id,$detail_type)
98
-    {
94
+	/**
95
+	 * @param string $detail_type
96
+	 */
97
+	function get_info($id,$detail_type)
98
+	{
99 99
 	$where = array('id' => $id);
100
-        $query = $this->CI->db_model->getSelect("*", $detail_type, $where);
101
-        $query = $query->result_array();
100
+		$query = $this->CI->db_model->getSelect("*", $detail_type, $where);
101
+		$query = $query->result_array();
102 102
 	if(isset($query[0]['accountid'])){
103 103
 		$query=$this->get_account_info($query [0]['accountid']);
104 104
 		return $query[0];
105 105
 	}
106 106
 	return false;
107
-    }
107
+	}
108 108
 
109
-    function get_admin_details()
110
-    {
109
+	function get_admin_details()
110
+	{
111 111
 	$where = array();
112
-        $query = $this->CI->db_model->getSelect("*", "invoice_conf", $where);
113
-        $query = $query->result();
112
+		$query = $this->CI->db_model->getSelect("*", "invoice_conf", $where);
113
+		$query = $query->result();
114 114
 	if(isset($query[0]->emailaddress) && $query[0]->emailaddress!=''){
115 115
 		$this->company_website=$query[0]->website;
116 116
 		$this->from=$query[0]->emailaddress;
@@ -165,33 +165,33 @@  discard block
 block discarded – undo
165 165
 		$this->subject = str_replace("#COMPANY_NAME#", $this->company_name, $this->subject);
166 166
 		switch ($template_type) {
167 167
 		  case 'email_add_user':
168
-		        $this->message = str_replace('#NUMBER#', $templateinfo['username'], $this->message);
169
-		        break;
168
+				$this->message = str_replace('#NUMBER#', $templateinfo['username'], $this->message);
169
+				break;
170 170
 		  case 'email_calling_card':
171
-		        $this->message = str_replace('#CARDNUMBER#', $templateinfo['cardnumber'], $this->message);
172
-		        break;
171
+				$this->message = str_replace('#CARDNUMBER#', $templateinfo['cardnumber'], $this->message);
172
+				break;
173 173
 		  case 'email_new_invoice';
174
-		        $this->message = str_replace('#AMOUNT#', $templateinfo['amount'], $this->message);
175
-		        $this->message = str_replace('#INVOICE_NUMBER#', $templateinfo['id'], $this->message);
176
-		        $this->subject = str_replace("#INVOICE_NUMBER#", $templateinfo['id'], $this->subject);
174
+				$this->message = str_replace('#AMOUNT#', $templateinfo['amount'], $this->message);
175
+				$this->message = str_replace('#INVOICE_NUMBER#', $templateinfo['id'], $this->message);
176
+				$this->subject = str_replace("#INVOICE_NUMBER#", $templateinfo['id'], $this->subject);
177 177
 			break;	
178 178
 		  case 'email_add_did';
179
-		        $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
180
-		        $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
179
+				$this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
180
+				$this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
181 181
 			break;	
182 182
 		  case 'email_remove_did';
183
-		        $this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
184
-		        $this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
183
+				$this->message = str_replace('#NUNBER#', $templateinfo['number'], $this->message);
184
+				$this->subject = str_replace("#NUNBER#", $templateinfo['number'], $this->subject);
185 185
 			break;	
186 186
 		}
187 187
 	}
188
-    }
188
+	}
189 189
 
190
-    /**
191
-     * @param string $attachment
192
-     */
193
-    function mail_history($attachment)
194
-    {
190
+	/**
191
+	 * @param string $attachment
192
+	 */
193
+	function mail_history($attachment)
194
+	{
195 195
 		$send_mail_details = array('from'=>$this->from,
196 196
 			   'to'=>$this->to,
197 197
 			   'subject'=>$this->subject,
Please login to merge, or discard this patch.
astpp/application/libraries/html2pdf/_tcpdf_5.0.002/qrcode.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -264,12 +264,12 @@
 block discarded – undo
264 264
 
265 265
 	// for compaibility with PHP4
266 266
 	if (!function_exists('str_split')) {
267
-    	/**
268
-    	 * Convert a string to an array (needed for PHP4 compatibility)
269
-    	 * @param string $string The input string.
270
-    	 * @param int $split_length Maximum length of the chunk.
271
-    	 * @return  string[] the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
272
-    	 */
267
+		/**
268
+		 * Convert a string to an array (needed for PHP4 compatibility)
269
+		 * @param string $string The input string.
270
+		 * @param int $split_length Maximum length of the chunk.
271
+		 * @return  string[] the optional split_length  parameter is specified, the returned array will be broken down into chunks with each being split_length  in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
272
+		 */
273 273
 		function str_split($string, $split_length=1) {
274 274
 			if ((strlen($string) > $split_length) OR (!$split_length)) {
275 275
 				do {
Please login to merge, or discard this patch.
web_interface/astpp/application/libraries/html2pdf/_class/myPdf.class.php 1 patch
Indentation   +1423 added lines, -1423 removed lines patch added patch discarded remove patch
@@ -14,1427 +14,1427 @@
 block discarded – undo
14 14
 
15 15
 class HTML2PDF_myPdf extends TCPDF
16 16
 {
17
-    protected $_footerParam = array();
18
-    protected $_transf      = array();
19
-    protected $_myLastPageGroup = null;
20
-    protected $_myLastPageGroupNb = 0;
21
-
22
-    // used to make a radius with bezier : (4/3 * (sqrt(2) - 1))
23
-    const MY_ARC = 0.5522847498;
24
-
25
-    // nb of segment to build a arc with bezier curv
26
-    const ARC_NB_SEGMENT = 8;
27
-
28
-    /**
29
-     * class constructor
30
-     *
31
-     * @param string  $orientation page orientation, same as TCPDF
32
-     * @param string  $unit        User measure unit, same as TCPDF
33
-     * @param mixed   $format      The format used for pages, same as TCPDF
34
-     * @param boolean $unicode     TRUE means that the input text is unicode (default = true)
35
-     * @param String  $encoding    charset encoding; default is UTF-8
36
-     * @param boolean $diskcache   if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
37
-     * @access public
38
-     */
39
-    public function __construct(
40
-        $orientation = 'P',
41
-        $unit = 'mm',
42
-        $format = 'A4',
43
-        $unicode = true,
44
-        $encoding = 'UTF-8',
45
-        $diskcache = false)
46
-    {
47
-        // call the parent constructor
48
-        parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache);
49
-
50
-        // init the specific parameters used by HTML2PDF
51
-        $this->SetCreator(PDF_CREATOR);
52
-        $this->SetAutoPageBreak(false, 0);
53
-        $this->linestyleCap = '2 J';
54
-        $this->setPrintHeader(false);
55
-        $this->jpeg_quality = 90;
56
-
57
-        // prepare the automatic footer
58
-        $this->SetMyFooter();
59
-
60
-        $this->cMargin = 0;
61
-    }
62
-
63
-    /**
64
-     * Set the parameters for the automatic footer
65
-     *
66
-     * @param boolean $page display the page number
67
-     * @param boolean $date display the date
68
-     * @param boolean $hour display the hour
69
-     * @param boolean $form display a warning abour forms
70
-     * @access public
71
-     */
72
-    public function SetMyFooter($page = false, $date = false, $hour = false, $form = false)
73
-    {
74
-        $page    = ($page ? true : false);
75
-        $date    = ($date ? true : false);
76
-        $hour    = ($hour ? true : false);
77
-        $form    = ($form ? true : false);
78
-
79
-        $this->_footerParam = array('page' => $page, 'date' => $date, 'hour' => $hour, 'form' => $form);
80
-    }
81
-
82
-    /**
83
-     * This function is call automatically by TCPDF at the end of a page
84
-     * It takes no parameters
85
-     *
86
-     * @access public
87
-     */
88
-    public function Footer()
89
-    {
90
-        // prepare the text from the tranlated text
91
-        $txt = '';
92
-        if ($this->_footerParam['form']) {
93
-            $txt = (HTML2PDF_locale::get('pdf05'));
94
-        }
95
-        if ($this->_footerParam['date'] && $this->_footerParam['hour']) {
96
-            $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf03'));
97
-        }
98
-        if ($this->_footerParam['date'] && ! $this->_footerParam['hour']) {
99
-            $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf01'));
100
-        }
101
-        if ( ! $this->_footerParam['date'] && $this->_footerParam['hour']) {
102
-            $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf02'));
103
-        }
104
-        if ($this->_footerParam['page']) {
105
-            $txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf04'));
106
-        }
107
-
108
-        if (strlen($txt) > 0) {
109
-            // replace some values
110
-            $toReplace = array(
111
-                '[[date_d]]'  => date('d'),
112
-                '[[date_m]]'  => date('m'),
113
-                '[[date_y]]'  => date('Y'),
114
-                '[[date_h]]'  => date('H'),
115
-                '[[date_i]]'  => date('i'),
116
-                '[[date_s]]'  => date('s'),
117
-                '[[page_cu]]' => $this->getMyNumPage(),
118
-                '[[page_nb]]' => $this->getMyAliasNbPages(),
119
-            );
120
-            $txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt);
121
-
122
-            // draw the footer
123
-            parent::SetY(-11);
124
-            $this->SetFont('helvetica', 'I', 8);
125
-            $this->Cell(0, 10, $txt, 0, 0, 'R');
126
-        }
127
-    }
128
-
129
-     /**
130
-     * after cloning a object, we does not want to clone all the front informations
131
-     * because it take a lot a time and a lot of memory => we use reference
132
-     *
133
-     * @param &HTML2PDF_myPdf object
134
-     * @param HTML2PDF_myPdf $pdf
135
-     * @access public
136
-     */
137
-    public function cloneFontFrom(&$pdf)
138
-    {
139
-        $this->fonts            = &$pdf->getFonts();
140
-        $this->FontFiles        = &$pdf->getFontFiles();
141
-        $this->diffs            = &$pdf->getDiffs();
142
-        $this->fontlist         = &$pdf->getFontList();
143
-        $this->numfonts         = &$pdf->getNumFonts();
144
-        $this->fontkeys         = &$pdf->getFontKeys();
145
-        $this->font_obj_ids     = &$pdf->getFontObjIds();
146
-        $this->annotation_fonts = &$pdf->getAnnotFonts();
147
-    }
148
-
149
-    /**
150
-     * multiple public accessor for some private attributs
151
-     * used only by cloneFontFrom
152
-     *
153
-     * @return &array
154
-     * @access public
155
-     */
156
-    public function &getFonts()
157
-    {
158
-        return $this->fonts;
159
-    }
160
-    public function &getFontFiles()
161
-    {
162
-        return $this->FontFiles;
163
-    }
164
-    public function &getDiffs()
165
-    {
166
-        return $this->diffs;
167
-    }
168
-    public function &getFontList()
169
-    {
170
-        return $this->fontlist;
171
-    }
172
-    public function &getNumFonts()
173
-    {
174
-        return $this->numfonts;
175
-    }
176
-    public function &getFontKeys()
177
-    {
178
-        return $this->fontkeys;
179
-    }
180
-    public function &getFontObjIds()
181
-    {
182
-        return $this->font_obj_ids;
183
-    }
184
-    public function &getAnnotFonts()
185
-    {
186
-        return $this->annotation_fonts;
187
-    }
188
-
189
-    /**
190
-     * Verify that a Font is already loaded
191
-     *
192
-     * @param string Font Key
193
-     * @return boolean
194
-     * @access public
195
-     */
196
-    public function isLoadedFont($fontKey)
197
-    {
198
-        if (isset($this->fonts[$fontKey])) {
199
-            return true;
200
-        }
201
-
202
-        if (isset($this->CoreFonts[$fontKey])) {
203
-            return true;
204
-        }
205
-
206
-        return false;
207
-    }
208
-
209
-    /**
210
-     * Get the Word Spacing
211
-     *
212
-     * @access public
213
-     * @return float word spacing
214
-     */
215
-    public function getWordSpacing()
216
-    {
217
-        return $this->ws;
218
-    }
219
-
220
-    /**
221
-     * set the Word Spacing
222
-     *
223
-     * @param float word spacing
224
-     * @access public
225
-     */
226
-    public function setWordSpacing($ws = 0.)
227
-    {
228
-        $this->ws = $ws;
229
-        $this->_out(sprintf('%.3F Tw', $ws * $this->k));
230
-    }
231
-
232
-    /**
233
-     * start to use a rectangular Cliping Path with radius corners
234
-     *
235
-     * @param float $x (top left corner)
236
-     * @param float $y (top left corner)
237
-     * @param float $w (x+w  = botom rigth corner)
238
-     * @param float $h (y+h = botom rigth corner)
239
-     * @param array $cornerTL radius of the Top Left corner
240
-     * @param array $cornerTR radius of the Top Right corner
241
-     * @param array $cornerBL radius of the Bottom Left corner
242
-     * @param array $cornerBR radius of the Bottom Right corner
243
-     * @access public
244
-     */
245
-    public function clippingPathStart(
246
-        $x = null,
247
-        $y = null,
248
-        $w = null,
249
-        $h = null,
250
-        $cornerTL = null,
251
-        $cornerTR = null,
252
-        $cornerBL = null,
253
-        $cornerBR = null)
254
-    {
255
-        // init the path
256
-        $path = '';
257
-
258
-        // if we have the position and the size of the rectangle, we can proceed
259
-        if ($x !== null && $y !== null && $w !== null && $h !== null) {
260
-            // the positions of the rectangle's corners
261
-            $x1 = $x * $this->k;
262
-            $y1 = ($this->h - $y) * $this->k;
263
-
264
-            $x2 = ($x + $w) * $this->k;
265
-            $y2 = ($this->h - $y) * $this->k;
266
-
267
-            $x3 = ($x + $w) * $this->k;
268
-            $y3 = ($this->h - $y - $h) * $this->k;
269
-
270
-            $x4 = $x * $this->k;
271
-            $y4 = ($this->h - $y - $h) * $this->k;
272
-
273
-            // if we have at least one radius corner, then we proceed to a specific path, else it is just a rectangle
274
-            if ($cornerTL || $cornerTR || $cornerBL || $cornerBR) {
275
-                // prepare the radius values
276
-                if ($cornerTL) {
277
-                    $cornerTL[0] = $cornerTL[0] * $this->k;
278
-                    $cornerTL[1] = -$cornerTL[1] * $this->k;
279
-                }
280
-                if ($cornerTR) {
281
-                    $cornerTR[0] = $cornerTR[0] * $this->k;
282
-                    $cornerTR[1] = -$cornerTR[1] * $this->k;
283
-                }
284
-                if ($cornerBL) {
285
-                    $cornerBL[0] = $cornerBL[0] * $this->k;
286
-                    $cornerBL[1] = -$cornerBL[1] * $this->k;
287
-                }
288
-                if ($cornerBR) {
289
-                    $cornerBR[0] = $cornerBR[0] * $this->k;
290
-                    $cornerBR[1] = -$cornerBR[1] * $this->k;
291
-                }
292
-
293
-                // if TL radius then specific start else (X1,Y1)
294
-                if ($cornerTL) {
295
-                    $path .= sprintf('%.2F %.2F m ', $x1 + $cornerTL[0], $y1);
296
-                } else {
297
-                    $path .= sprintf('%.2F %.2F m ', $x1, $y1);
298
-                }
299
-
300
-                // if TR radius then line + arc, else line to (X2,Y2)
301
-                if ($cornerTR) {
302
-                    $xt1 = ($x2 - $cornerTR[0]) + $cornerTR[0] * self::MY_ARC;
303
-                    $yt1 = ($y2 + $cornerTR[1]) - $cornerTR[1];
304
-                    $xt2 = ($x2 - $cornerTR[0]) + $cornerTR[0];
305
-                    $yt2 = ($y2 + $cornerTR[1]) - $cornerTR[1] * self::MY_ARC;
306
-
307
-                    $path .= sprintf('%.2F %.2F l ', $x2 - $cornerTR[0], $y2);
308
-                    $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x2, $y2 + $cornerTR[1]);
309
-                } else {
310
-                    $path .= sprintf('%.2F %.2F l ', $x2, $y2);
311
-                }
312
-
313
-                // if BR radius then line + arc, else line to (X3, Y3)
314
-                if ($cornerBR) {
315
-                    $xt1 = ($x3 - $cornerBR[0]) + $cornerBR[0];
316
-                    $yt1 = ($y3 - $cornerBR[1]) + $cornerBR[1] * self::MY_ARC;
317
-                    $xt2 = ($x3 - $cornerBR[0]) + $cornerBR[0] * self::MY_ARC;
318
-                    $yt2 = ($y3 - $cornerBR[1]) + $cornerBR[1];
319
-
320
-                    $path .= sprintf('%.2F %.2F l ', $x3, $y3 - $cornerBR[1]);
321
-                    $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x3 - $cornerBR[0], $y3);
322
-                } else {
323
-                    $path .= sprintf('%.2F %.2F l ', $x3, $y3);
324
-                }
325
-
326
-                // if BL radius then line + arc, else line to (X4, Y4)
327
-                if ($cornerBL) {
328
-                    $xt1 = ($x4 + $cornerBL[0]) - $cornerBL[0] * self::MY_ARC;
329
-                    $yt1 = ($y4 - $cornerBL[1]) + $cornerBL[1];
330
-                    $xt2 = ($x4 + $cornerBL[0]) - $cornerBL[0];
331
-                    $yt2 = ($y4 - $cornerBL[1]) + $cornerBL[1] * self::MY_ARC;
332
-
333
-                    $path .= sprintf('%.2F %.2F l ', $x4 + $cornerBL[0], $y4);
334
-                    $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x4, $y4 - $cornerBL[1]);
335
-                } else {
336
-                    $path .= sprintf('%.2F %.2F l ', $x4, $y4);
337
-                }
338
-
339
-                // if RL radius then line + arc
340
-                if ($cornerTL) {
341
-                    $xt1 = ($x1 + $cornerTL[0]) - $cornerTL[0];
342
-                    $yt1 = ($y1 + $cornerTL[1]) - $cornerTL[1] * self::MY_ARC;
343
-                    $xt2 = ($x1 + $cornerTL[0]) - $cornerTL[0] * self::MY_ARC;
344
-                    $yt2 = ($y1 + $cornerTL[1]) - $cornerTL[1];
345
-
346
-                    $path .= sprintf('%.2F %.2F l ', $x1, $y1 + $cornerTL[1]);
347
-                    $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x1 + $cornerTL[0], $y1);
348
-                }
349
-            } else {
350
-                $path .= sprintf('%.2F %.2F m ', $x1, $y1);
351
-                $path .= sprintf('%.2F %.2F l ', $x2, $y2);
352
-                $path .= sprintf('%.2F %.2F l ', $x3, $y3);
353
-                $path .= sprintf('%.2F %.2F l ', $x4, $y4);
354
-            }
355
-
356
-            // close the path
357
-            $path .= ' h W n';
358
-        }
359
-
360
-        // using the path as a clipping path
361
-        $this->_out('q '.$path.' ');
362
-    }
363
-
364
-    /**
365
-     * stop to use the Cliping Path
366
-     *
367
-     * @access public
368
-     */
369
-    public function clippingPathStop()
370
-    {
371
-        $this->_out(' Q');
372
-    }
373
-
374
-    /**
375
-     * draw a filled corner of a border with a external and a internal radius
376
-     *         /--------+ ext2
377
-     *        /         |
378
-     *       /  /-------+ int2
379
-     *      /  /
380
-     *      | /
381
-     *      | |
382
-     *      | |
383
-     * ext1 +-+ int1        + cen
384
-     *
385
-     * @param float $ext1X
386
-     * @param float $ext1Y
387
-     * @param float $ext2X
388
-     * @param float $ext2Y
389
-     * @param float $int1X
390
-     * @param float $int1Y
391
-     * @param float $int2X
392
-     * @param float $int2Y
393
-     * @param float $cenX
394
-     * @param float $cenY
395
-     * @access public
396
-     */
397
-    public function drawCurve($ext1X, $ext1Y, $ext2X, $ext2Y, $int1X, $int1Y, $int2X, $int2Y, $cenX, $cenY)
398
-    {
399
-        // prepare the coordinates
400
-        $ext1X = $ext1X * $this->k;
401
-        $ext2X = $ext2X * $this->k;
402
-        $int1X = $int1X * $this->k;
403
-        $int2X = $int2X * $this->k;
404
-        $cenX  = $cenX * $this->k;
405
-
406
-        $ext1Y = ($this->h - $ext1Y) * $this->k;
407
-        $ext2Y = ($this->h - $ext2Y) * $this->k;
408
-        $int1Y = ($this->h - $int1Y) * $this->k;
409
-        $int2Y = ($this->h - $int2Y) * $this->k;
410
-        $cenY  = ($this->h - $cenY) * $this->k;
411
-
412
-        // init the curve
413
-        $path = '';
414
-
415
-        if ($ext1X - $cenX != 0) {
416
-            $xt1 = $cenX + ($ext1X - $cenX);
417
-            $yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC;
418
-            $xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC;
419
-            $yt2 = $cenY + ($ext2Y - $cenY);
420
-        } else {
421
-            $xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC;
422
-            $yt1 = $cenY + ($ext1Y - $cenY);
423
-            $xt2 = $cenX + ($ext2X - $cenX);
424
-            $yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC;
425
-        }
426
-        $path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
427
-        $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
428
-
429
-        if ($int1X - $cenX != 0) {
430
-            $xt1 = $cenX + ($int1X - $cenX) * self::MY_ARC;
431
-            $yt1 = $cenY + ($int2Y - $cenY);
432
-            $xt2 = $cenX + ($int1X - $cenX);
433
-            $yt2 = $cenY + ($int2Y - $cenY) * self::MY_ARC;
434
-        } else {
435
-            $xt1 = $cenX + ($int2X - $cenX);
436
-            $yt1 = $cenY + ($int1Y - $cenY) * self::MY_ARC;
437
-            $xt2 = $cenX + ($int2X - $cenX) * self::MY_ARC;
438
-            $yt2 = $cenY + ($int1Y - $cenY);
439
-        }
440
-        $path .= sprintf('%.2F %.2F l ', $int2X, $int2Y);
441
-        $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $int1X, $int1Y);
442
-
443
-        // draw the curve
444
-        $this->_out($path.'f');
445
-    }
446
-
447
-    /**
448
-     * draw a filled corner of a border with only a external radius
449
-     *         /--+ ext2
450
-     *        /   |
451
-     *       /    |
452
-     *      /     |
453
-     *      |     |
454
-     *      |     |
455
-     *      |     |
456
-     * ext1 +-----+ int      + cen
457
-     *
458
-     * @param float $ext1X
459
-     * @param float $ext1Y
460
-     * @param float $ext2X
461
-     * @param float $ext2Y
462
-     * @param float $intX
463
-     * @param float $intY
464
-     * @param float $cenX
465
-     * @param float $cenY
466
-     * @access public
467
-     */
468
-    public function drawCorner($ext1X, $ext1Y, $ext2X, $ext2Y, $intX, $intY, $cenX, $cenY)
469
-    {
470
-        // prepare the coordinates
471
-        $ext1X = $ext1X * $this->k;
472
-        $ext2X = $ext2X * $this->k;
473
-        $intX  = $intX * $this->k;
474
-        $cenX  = $cenX * $this->k;
475
-
476
-        $ext1Y = ($this->h - $ext1Y) * $this->k;
477
-        $ext2Y = ($this->h - $ext2Y) * $this->k;
478
-        $intY  = ($this->h - $intY) * $this->k;
479
-        $cenY  = ($this->h - $cenY) * $this->k;
480
-
481
-        // init the curve
482
-        $path = '';
483
-
484
-        if ($ext1X - $cenX != 0) {
485
-            $xt1 = $cenX + ($ext1X - $cenX);
486
-            $yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC;
487
-            $xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC;
488
-            $yt2 = $cenY + ($ext2Y - $cenY);
489
-        } else {
490
-            $xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC;
491
-            $yt1 = $cenY + ($ext1Y - $cenY);
492
-            $xt2 = $cenX + ($ext2X - $cenX);
493
-            $yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC;
494
-        }
495
-        $path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
496
-        $path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
497
-        $path .= sprintf('%.2F %.2F l ', $intX, $intY);
498
-        $path .= sprintf('%.2F %.2F l ', $ext1X, $ext1Y);
499
-
500
-        // draw the curve
501
-        $this->_out($path.'f');
502
-    }
503
-
504
-    /**
505
-     * Start a transformation
506
-     *
507
-     * @access public
508
-     */
509
-    public function startTransform()
510
-    {
511
-        $this->_out('q');
512
-    }
513
-
514
-    /**
515
-     * Stop a transformation
516
-     *
517
-     * @access public
518
-     */
519
-    public function stopTransform()
520
-    {
521
-        $this->_out('Q');
522
-    }
523
-
524
-    /**
525
-     * add a Translate transformation
526
-     *
527
-     * @access public
528
-     */
529
-    public function setTranslate($xT, $yT)
530
-    {
531
-        // Matrix for Translate
532
-        $tm[0] = 1;
533
-        $tm[1] = 0;
534
-        $tm[2] = 0;
535
-        $tm[3] = 1;
536
-        $tm[4] = $xT * $this->k;
537
-        $tm[5] = -$yT * $this->k;
538
-
539
-        // apply the Transform Matric
540
-        $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
541
-    }
542
-
543
-    /**
544
-     * add a Rotate transformation
545
-     *
546
-     * @param float $angle
547
-     * @access public
548
-     */
549
-    public function setRotation($angle, $xC = null, $yC = null)
550
-    {
551
-        // if no center, rotate around the current posiition
552
-        if ($xC === null) $xC = $this->x;
553
-        if ($yC === null) $yC = $this->y;
554
-
555
-        // prepare the coordinate
556
-        $yC = ($this->h - $yC) * $this->k;
557
-        $xC *= $this->k;
558
-
559
-        // Matrix for Rotate
560
-        $tm[0] = cos(deg2rad($angle));
561
-        $tm[1] = sin(deg2rad($angle));
562
-        $tm[2] = -$tm[1];
563
-        $tm[3] = $tm[0];
564
-        $tm[4] = $xC + $tm[1] * $yC - $tm[0] * $xC;
565
-        $tm[5] = $yC - $tm[0] * $yC - $tm[1] * $xC;
566
-
567
-        // apply the Transform Matric
568
-        $this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
569
-    }
570
-
571
-    /**
572
-     * we redifine the original SetX method, because we don't want the automatic treatment.
573
-     * It is HTML2PDF that make the treatment
574
-     *
575
-     * @param float   $x
576
-     * @param boolean $rtloff NOT USED
577
-     * @access public
578
-     */
579
-    public function SetX($x, $rtloff = false)
580
-    {
581
-        $this->x = $x;
582
-    }
583
-
584
-    /**
585
-     * we redifine the original SetY method, because we don't want the automatic treatment.
586
-     * It is HTML2PDF that make the treatment
587
-     *
588
-     * @param float   $y
589
-     * @param boolean $resetx Reset the X position
590
-     * @param boolean $rtloff NOT USED
591
-     * @access public
592
-     */
593
-    public function SetY($y, $resetx = true, $rtloff = false)
594
-    {
595
-        if ($resetx)
596
-            $this->x = $this->lMargin;
597
-
598
-        $this->y = $y;
599
-    }
600
-
601
-    /**
602
-     * we redifine the original SetXY method, because we don't want the automatic treatment.
603
-     * It is HTML2PDF that make the treatment
604
-     *
605
-     * @param integer $x
606
-     * @param integer $y
607
-     * @param boolean $rtloff NOT USED
608
-     * @access public
609
-     */
610
-    public function SetXY($x, $y, $rtloff = false)
611
-    {
612
-        $this->x = $x;
613
-        $this->y = $y;
614
-    }
615
-
616
-    /**
617
-     * multiple public accessor because HTML2PDF need to use TCPDF without being a extend of it
618
-     *
619
-     * @param  mixed
620
-     * @return mixed
621
-     * @access public
622
-     */
623
-    public function getK()
624
-    {
625
-        return $this->k;
626
-    }
627
-
628
-    /**
629
-     * @return double
630
-     */
631
-    public function getW()
632
-    {
633
-        return $this->w;
634
-    }
635
-
636
-    /**
637
-     * @return double
638
-     */
639
-    public function getH()
640
-    {
641
-        return $this->h;
642
-    }
643
-    public function getlMargin()
644
-    {
645
-        return $this->lMargin;
646
-    }
647
-
648
-    /**
649
-     * @return double
650
-     */
651
-    public function getrMargin()
652
-    {
653
-        return $this->rMargin;
654
-    }
655
-
656
-    /**
657
-     * @return double
658
-     */
659
-    public function gettMargin()
660
-    {
661
-        return $this->tMargin;
662
-    }
663
-    public function getbMargin()
664
-    {
665
-        return $this->bMargin;
666
-    }
667
-    public function setbMargin($v)
668
-    {
669
-        $this->bMargin = $v;
670
-    }
671
-
672
-    /**
673
-     * SVG - Convert a SVG Style in PDF Style
674
-     *
675
-     * @param  array  $styles SVG Style
676
-     * @return string PDF style
677
-     * @access public
678
-     */
679
-    public function svgSetStyle($styles)
680
-    {
681
-        // init the PDF style
682
-        $style = '';
683
-
684
-        // Style : fill
685
-        if ($styles['fill']) {
686
-            $this->setFillColorArray($styles['fill']);
687
-            $style .= 'F';
688
-        }
689
-
690
-        // Style : stroke
691
-        if ($styles['stroke'] && $styles['stroke-width']) {
692
-            $this->SetDrawColorArray($styles['stroke']);
693
-            $this->SetLineWidth($styles['stroke-width']);
694
-            $style .= 'D';
695
-        }
696
-
697
-        // Style : opacity
698
-        if ($styles['fill-opacity']) {
699
-            $this->SetAlpha($styles['fill-opacity']);
700
-        }
701
-
702
-        return $style;
703
-    }
704
-
705
-    /**
706
-     * SVG - make a Rectangle
707
-     *
708
-     * @param float $x
709
-     * @param float $y
710
-     * @param float $w
711
-     * @param float $h
712
-     * @param string $style PDF Style
713
-     * @access public
714
-     */
715
-    public function svgRect($x, $y, $w, $h, $style)
716
-    {
717
-        // prepare the 4 corners
718
-        $x1 = $x;
719
-        $x2 = $x + $w;
720
-        $x3 = $x + $w;
721
-        $x4 = $x;
722
-
723
-        $y1 = $y;
724
-        $y2 = $y;
725
-        $y3 = $y + $h;
726
-        $y4 = $y + $h;
727
-
728
-        // get the Closing operator from the PDF Style
729
-        if ($style == 'F') $op = 'f';
730
-        elseif ($style == 'FD' || $style == 'DF') $op = 'B';
731
-        else $op = 'S';
732
-
733
-        // drawing
734
-        $this->_Point($x1, $y1, true);
735
-        $this->_Line($x2, $y2, true);
736
-        $this->_Line($x3, $y3, true);
737
-        $this->_Line($x4, $y4, true);
738
-        $this->_Line($x1, $y1, true);
739
-        $this->_out($op);
740
-    }
741
-
742
-    /**
743
-     * SVG - make a Line
744
-     *
745
-     * @param float $x1
746
-     * @param float $y1
747
-     * @param float $x2
748
-     * @param float $y2
749
-     * @access public
750
-     */
751
-    public function svgLine($x1, $y1, $x2, $y2)
752
-    {
753
-        // get the Closing operator
754
-        $op = 'S';
755
-
756
-        // drawing
757
-        $this->_Point($x1, $y1, true);
758
-        $this->_Line($x2, $y2, true);
759
-        $this->_out($op);
760
-    }
761
-
762
-    /**
763
-     * SVG - make a Ellipse
764
-     *
765
-     * @param float  $x0 x Center
766
-     * @param float  $y0 y Center
767
-     * @param float  $rx x radius
768
-     * @param float  $ry y radius
769
-     * @param string $style PDF Style
770
-     * @access public
771
-     */
772
-    public function svgEllipse($x0, $y0, $rx, $ry, $style)
773
-    {
774
-        // get the Closing operator from the PDF Style
775
-        if ($style == 'F') $op = 'f';
776
-        elseif ($style == 'FD' || $style == 'DF') $op = 'B';
777
-        else $op = 'S';
778
-
779
-        // drawing
780
-        $this->_Arc($x0, $y0, $rx, $ry, 0, 2 * M_PI, true, true, true);
781
-        $this->_out($op);
782
-    }
783
-
784
-    /**
785
-     * SVG - make a Advanced Polygone
786
-     *
787
-     * @param array  $actions list of actions
788
-     * @param string $style PDF Style
789
-     * @access public
790
-     */
791
-    public function svgPolygone($actions, $style)
792
-    {
793
-        // get the Closing operator from the PDF Style
794
-        if ($style == 'F') $op = 'f';
795
-        elseif ($style == 'FD' || $style == 'DF') $op = 'B';
796
-        else $op = 'S';
797
-
798
-        // To save the First action and the last point
799
-        $first = array('', 0, 0);
800
-        $last = array(0, 0, 0, 0);
801
-
802
-        foreach ($actions as $action) {
803
-            switch ($action[0])
804
-            {
805
-                // Start the Path
806
-                case 'M':
807
-                case 'm':
808
-                    $first = $action;
809
-                    $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
810
-                    $this->_Point($x, $y, true);
811
-                    break;
812
-
813
-                // Close the Path
814
-                case 'Z':
815
-                case 'z':
816
-                    $x = $first[1]; $y = $first[2]; $xc = $x; $yc = $y;
817
-                    $this->_Line($x, $y, true);
818
-                    break;
819
-
820
-                // Make a Line (new point)
821
-                case 'L':
822
-                    $x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
823
-                    $this->_Line($x, $y, true);
824
-                    break;
825
-
826
-                // Make a Line (vector from last point)
827
-                case 'l':
828
-                    $x = $last[0] + $action[1]; $y = $last[1] + $action[2]; $xc = $x; $yc = $y;
829
-                    $this->_Line($x, $y, true);
830
-                    break;
831
-
832
-                // Make a Horizontal Line (new point)
833
-                case 'H':
834
-                    $x = $action[1]; $y = $last[1]; $xc = $x; $yc = $y;
835
-                    $this->_Line($x, $y, true);
836
-                    break;
837
-
838
-                // Make a Horisontal Line (vector from last point)
839
-                case 'h':
840
-                    $x = $last[0] + $action[1]; $y = $last[1]; $xc = $x; $yc = $y;
841
-                    $this->_Line($x, $y, true);
842
-                    break;
843
-
844
-                // Make a Vertical Line (new point)
845
-                case 'V':
846
-                    $x = $last[0]; $y = $action[1]; $xc = $x; $yc = $y;
847
-                    $this->_Line($x, $y, true);
848
-                    break;
849
-
850
-                // Make a Vertical Line (vector from last point)
851
-                case 'v':
852
-                    $x = $last[0]; $y = $last[1] + $action[1]; $xc = $x; $yc = $y;
853
-                    $this->_Line($x, $y, true);
854
-                    break;
855
-
856
-                // Make a Arc (new point)
857
-                case 'A':
858
-                    $rx = $action[1]; // rx
859
-                    $ry = $action[2]; // ry
860
-                    $a = $action[3]; // deviation angle of the axis X
861
-                    $l = $action[4]; // large-arc-flag
862
-                    $s = $action[5]; // sweep-flag
863
-                    $x1 = $last[0]; // begin x
864
-                    $y1 = $last[1]; // begin y
865
-                    $x2 = $action[6]; // final x
866
-                    $y2 = $action[7]; // final y
867
-
868
-                    $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
869
-                    $x = $x2; $y = $y2; $xc = $x; $yc = $y;
870
-                    break;
871
-
872
-                // Make a Arc (vector from last point)
873
-                case 'a':
874
-                    $rx = $action[1]; // rx
875
-                    $ry = $action[2]; // ry
876
-                    $a = $action[3]; // deviation angle of the axis X
877
-                    $l = $action[4]; // large-arc-flag
878
-                    $s = $action[5]; // sweep-flag
879
-                    $x1 = $last[0]; // begin x
880
-                    $y1 = $last[1]; // begin y
881
-                    $x2 = $last[0] + $action[6]; // final x
882
-                    $y2 = $last[1] + $action[7]; // final y
883
-
884
-                    $this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
885
-                    $x = $x2; $y = $y2; $xc = $x; $yc = $y;
886
-                    break;
887
-
888
-                // Make a Bezier Curve (new point)
889
-                case 'C':
890
-                    $x1 = $action[1];
891
-                    $y1 = $action[2];
892
-                    $x2 = $action[3];
893
-                    $y2 = $action[4];
894
-                    $xf = $action[5];
895
-                    $yf = $action[6];
896
-                    $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
897
-                    $x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
898
-                    break;
899
-
900
-                // Make a Bezier Curve (vector from last point)
901
-                case 'c':
902
-                    $x1 = $last[0] + $action[1];
903
-                    $y1 = $last[1] + $action[2];
904
-                    $x2 = $last[0] + $action[3];
905
-                    $y2 = $last[1] + $action[4];
906
-                    $xf = $last[0] + $action[5];
907
-                    $yf = $last[1] + $action[6];
908
-                    $this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
909
-                    $x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
910
-                    break;
911
-
912
-                // Unknown Path
913
-                default:
914
-                    throw new HTML2PDF_exception(0, 'SVG Path Error : ['.$action[0].'] unkown');
915
-            }
916
-
917
-            // save the last point
918
-            $last = array($x, $y, $xc, $yc);
919
-        }
920
-
921
-        // finish the path
922
-        $this->_out($op);
923
-    }
924
-
925
-    /**
926
-     * SVG - go to a point
927
-     *
928
-     * @param float   $x
929
-     * @param float   $y
930
-     * @param boolean $trans apply transformation
931
-     * @access protected
932
-     */
933
-    protected function _Point($x, $y, $trans = false)
934
-    {
935
-        if ($trans) {
936
-        	$this->ptTransform($x, $y);
937
-        }
938
-
939
-        $this->_out(sprintf('%.2F %.2F m', $x, $y));
940
-    }
941
-
942
-    /**
943
-     * SVG - make a line from the last point to (x,y)
944
-     *
945
-     * @param float   $x
946
-     * @param float   $y
947
-     * @param boolean $trans apply transformation
948
-     * @access protected
949
-     */
950
-    protected function _Line($x, $y, $trans = false)
951
-    {
952
-        if ($trans) {
953
-        	$this->ptTransform($x, $y);
954
-        }
955
-
956
-        $this->_out(sprintf('%.2F %.2F l', $x, $y));
957
-    }
958
-
959
-    /**
960
-     * SVG - make a bezier curve from the last point to (xf,yf), with the 2 direction points (x1,y1) and (x2,y2)
961
-     *
962
-     * @param float $x1
963
-     * @param float $y1
964
-     * @param float $x2
965
-     * @param float $y2
966
-     * @param float $xf
967
-     * @param float $yf
968
-     * @param boolean $trans apply transformation
969
-     * @access protected
970
-     */
971
-    protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false)
972
-    {
973
-        if ($trans) {
974
-            $this->ptTransform($x1, $y1);
975
-            $this->ptTransform($x2, $y2);
976
-            $this->ptTransform($xf, $yf);
977
-        }
978
-        $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1, $y1, $x2, $y2, $xf, $yf));
979
-    }
980
-
981
-    /**
982
-     * SVG - make a arc with Center, Radius, from angleBegin to angleEnd
983
-     *
984
-     * @param float $xc
985
-     * @param float $yc
986
-     * @param float $rx
987
-     * @param float $ry
988
-     * @param float $angleBegin in radians
989
-     * @param float $angleEnd in radians
990
-     * @param boolean $direction
991
-     * @param boolean $drawFirst, true => add the first point
992
-     * @param boolean $trans apply transformation
993
-     * @access protected
994
-     */
995
-    protected function _Arc(
996
-        $xc,
997
-        $yc,
998
-        $rx,
999
-        $ry,
1000
-        $angleBegin,
1001
-        $angleEnd,
1002
-        $direction = true,
1003
-        $drawFirst = true,
1004
-        $trans = false)
1005
-    {
1006
-        // if we want the no trigo direction : add 2PI to the begin angle, to invert the direction
1007
-        if ( ! $direction) $angleBegin += M_PI * 2.;
1008
-
1009
-        // cut in segment to convert in berize curv
1010
-        $dt = ($angleEnd - $angleBegin) / self::ARC_NB_SEGMENT;
1011
-        $dtm = $dt / 3;
1012
-
1013
-        // center of the arc
1014
-        $x0 = $xc; $y0 = $yc;
1015
-
1016
-        // calculing the first point
1017
-        $t1 = $angleBegin;
1018
-        $a0 = $x0 + ($rx * cos($t1));
1019
-        $b0 = $y0 + ($ry * sin($t1));
1020
-        $c0 = -$rx * sin($t1);
1021
-        $d0 = $ry * cos($t1);
1022
-
1023
-        // if drawFirst => draw the first point
1024
-        if ($drawFirst) {
1025
-        	$this->_Point($a0, $b0, $trans);
1026
-        }
1027
-
1028
-        // foreach segment
1029
-        for ($i = 1; $i <= self::ARC_NB_SEGMENT; $i++) {
1030
-            // calculing the next point
1031
-            $t1 = ($i * $dt) + $angleBegin;
1032
-            $a1 = $x0 + ($rx * cos($t1));
1033
-            $b1 = $y0 + ($ry * sin($t1));
1034
-            $c1 = -$rx * sin($t1);
1035
-            $d1 = $ry * cos($t1);
1036
-
1037
-            // make the bezier curv
1038
-            $this->_Curve(
1039
-                $a0 + ($c0 * $dtm), $b0 + ($d0 * $dtm),
1040
-                $a1 - ($c1 * $dtm), $b1 - ($d1 * $dtm),
1041
-                $a1, $b1,
1042
-                $trans
1043
-            );
1044
-
1045
-            // save the point
1046
-            $a0 = $a1;
1047
-            $b0 = $b1;
1048
-            $c0 = $c1;
1049
-            $d0 = $d1;
1050
-        }
1051
-    }
1052
-
1053
-    /**
1054
-     * SVG - make a arc from Pt1 to Pt2, with Radius
1055
-     *
1056
-     * @param float $x1
1057
-     * @param float $y1
1058
-     * @param float $x2
1059
-     * @param float $y2
1060
-     * @param float $rx
1061
-     * @param float $ry
1062
-     * @param float $angle deviation angle of the axis X
1063
-     * @param integer $l large-arc-flag
1064
-     * @param integer $s sweep-flag
1065
-     * @param boolean $trans apply transformation
1066
-     * @access protected
1067
-     */
1068
-    protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle = 0., $l = 0, $s = 0, $trans = false)
1069
-    {
1070
-        // array to stock the parameters
1071
-        $v = array();
1072
-
1073
-        // the original values
1074
-        $v['x1'] = $x1;
1075
-        $v['y1'] = $y1;
1076
-        $v['x2'] = $x2;
1077
-        $v['y2'] = $y2;
1078
-        $v['rx'] = $rx;
1079
-        $v['ry'] = $ry;
1080
-
1081
-        // rotate with the deviation angle of the axis X
1082
-        $v['xr1'] = $v['x1'] * cos($angle) - $v['y1'] * sin($angle);
1083
-        $v['yr1'] = $v['x1'] * sin($angle) + $v['y1'] * cos($angle);
1084
-        $v['xr2'] = $v['x2'] * cos($angle) - $v['y2'] * sin($angle);
1085
-        $v['yr2'] = $v['x2'] * sin($angle) + $v['y2'] * cos($angle);
1086
-
1087
-        // the normalized vector
1088
-        $v['Xr1'] = $v['xr1'] / $v['rx'];
1089
-        $v['Yr1'] = $v['yr1'] / $v['ry'];
1090
-        $v['Xr2'] = $v['xr2'] / $v['rx'];
1091
-        $v['Yr2'] = $v['yr2'] / $v['ry'];
1092
-        $v['dXr'] = $v['Xr2'] - $v['Xr1'];
1093
-        $v['dYr'] = $v['Yr2'] - $v['Yr1'];
1094
-        $v['D'] = $v['dXr'] * $v['dXr'] + $v['dYr'] * $v['dYr'];
1095
-
1096
-        // if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line
1097
-        if ($v['D'] == 0 || $v['D'] > 4) {
1098
-            $this->_Line($x2, $y2, $trans);
1099
-            return false;
1100
-        }
1101
-
1102
-        // convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd
1103
-        $v['s1'] = array();
1104
-        $v['s1']['t'] = sqrt((4. - $v['D']) / $v['D']);
1105
-        $v['s1']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s1']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.;
1106
-        $v['s1']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s1']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.;
1107
-        $v['s1']['xr'] = $v['s1']['Xr'] * $v['rx'];
1108
-        $v['s1']['yr'] = $v['s1']['Yr'] * $v['ry'];
1109
-        $v['s1']['x'] = $v['s1']['xr'] * cos($angle) + $v['s1']['yr'] * sin($angle);
1110
-        $v['s1']['y'] = -$v['s1']['xr'] * sin($angle) + $v['s1']['yr'] * cos($angle);
1111
-        $v['s1']['a1'] = atan2($v['y1'] - $v['s1']['y'], $v['x1'] - $v['s1']['x']);
1112
-        $v['s1']['a2'] = atan2($v['y2'] - $v['s1']['y'], $v['x2'] - $v['s1']['x']);
1113
-        if ($v['s1']['a1'] > $v['s1']['a2']) $v['s1']['a1'] -= 2 * M_PI;
1114
-
1115
-        $v['s2'] = array();
1116
-        $v['s2']['t'] = -$v['s1']['t'];
1117
-        $v['s2']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s2']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.;
1118
-        $v['s2']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s2']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.;
1119
-        $v['s2']['xr'] = $v['s2']['Xr'] * $v['rx'];
1120
-        $v['s2']['yr'] = $v['s2']['Yr'] * $v['ry'];
1121
-        $v['s2']['x'] = $v['s2']['xr'] * cos($angle) + $v['s2']['yr'] * sin($angle);
1122
-        $v['s2']['y'] = -$v['s2']['xr'] * sin($angle) + $v['s2']['yr'] * cos($angle);
1123
-        $v['s2']['a1'] = atan2($v['y1'] - $v['s2']['y'], $v['x1'] - $v['s2']['x']);
1124
-        $v['s2']['a2'] = atan2($v['y2'] - $v['s2']['y'], $v['x2'] - $v['s2']['x']);
1125
-        if ($v['s2']['a1'] > $v['s2']['a2']) $v['s2']['a1'] -= 2 * M_PI;
1126
-
1127
-        if ( ! $l) {
1128
-            if ($s) {
1129
-                $xc = $v['s2']['x'];
1130
-                $yc = $v['s2']['y'];
1131
-                $a1 = $v['s2']['a1'];
1132
-                $a2 = $v['s2']['a2'];
1133
-                $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
1134
-            } else {
1135
-                $xc = $v['s1']['x'];
1136
-                $yc = $v['s1']['y'];
1137
-                $a1 = $v['s1']['a1'];
1138
-                $a2 = $v['s1']['a2'];
1139
-                $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
1140
-            }
1141
-        } else {
1142
-            if ($s) {
1143
-                $xc = $v['s1']['x'];
1144
-                $yc = $v['s1']['y'];
1145
-                $a1 = $v['s1']['a1'];
1146
-                $a2 = $v['s1']['a2'];
1147
-                $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
1148
-            } else {
1149
-                $xc = $v['s2']['x'];
1150
-                $yc = $v['s2']['y'];
1151
-                $a1 = $v['s2']['a1'];
1152
-                $a2 = $v['s2']['a2'];
1153
-                $this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
1154
-            }
1155
-        }
1156
-    }
1157
-
1158
-    /**
1159
-     * SVG - transform the point (reference)
1160
-     *
1161
-     * @param float &$x
1162
-     * @param float &$y
1163
-     * @param boolean $trans true => convert into PDF unit
1164
-     * @param double $x
1165
-     * @param double $y
1166
-     * @return boolean
1167
-     * @access public
1168
-     */
1169
-    public function ptTransform(&$x, &$y, $trans = true)
1170
-    {
1171
-        // load the last Transfomation Matrix
1172
-        $nb = count($this->_transf);
1173
-        if ($nb)    $m = $this->_transf[$nb - 1];
1174
-        else        $m = array(1, 0, 0, 1, 0, 0);
1175
-
1176
-        // apply the Transformation Matrix
1177
-        list($x, $y) = array(($x * $m[0] + $y * $m[2] + $m[4]), ($x * $m[1] + $y * $m[3] + $m[5]));
1178
-
1179
-        // if true => convert into PDF unit
1180
-        if ($trans) {
1181
-            $x = $x * $this->k;
1182
-            $y = ($this->h - $y) * $this->k;
1183
-        }
1184
-
1185
-        return true;
1186
-    }
1187
-
1188
-    /**
1189
-     * SVG - add a transformation Matric
1190
-     *
1191
-     * @param array $n matrix
1192
-     * @access public
1193
-     */
1194
-    public function doTransform($n = null)
1195
-    {
1196
-        // get the last Transformation Matrix
1197
-        $nb = count($this->_transf);
1198
-        if ($nb)    $m = $this->_transf[$nb - 1];
1199
-        else        $m = array(1, 0, 0, 1, 0, 0);
1200
-
1201
-        // if no transform, get the Identity Matrix
1202
-        if ( ! $n) $n = array(1, 0, 0, 1, 0, 0);
1203
-
1204
-        // create the new Transformation Matrix
1205
-        $this->_transf[] = array(
1206
-            $m[0] * $n[0] + $m[2] * $n[1],
1207
-            $m[1] * $n[0] + $m[3] * $n[1],
1208
-            $m[0] * $n[2] + $m[2] * $n[3],
1209
-            $m[1] * $n[2] + $m[3] * $n[3],
1210
-            $m[0] * $n[4] + $m[2] * $n[5] + $m[4],
1211
-            $m[1] * $n[4] + $m[3] * $n[5] + $m[5]
1212
-        );
1213
-    }
1214
-
1215
-    /**
1216
-     * SVG - remove a transformation Matric
1217
-     *
1218
-     * @access public
1219
-     */
1220
-    public function undoTransform()
1221
-    {
1222
-        array_pop($this->_transf);
1223
-    }
1224
-
1225
-    /**
1226
-     * Convert a HTML2PDF barcode in a TCPDF barcode
1227
-     *
1228
-     * @param string $code code to print
1229
-     * @param string $type type of barcode (see tcpdf/barcodes.php for supported formats)
1230
-     * @param int $x x position in user units
1231
-     * @param int $y y position in user units
1232
-     * @param int $w width in user units
1233
-     * @param int $h height in user units
1234
-     * @param int $labelFontsize of the Test Label. If false : no Label
1235
-     * @param array $color color of the foreground
1236
-     * @access public
1237
-     */
1238
-    public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color)
1239
-    {
1240
-        // the style of the barcode
1241
-        $style = array(
1242
-            'position' => 'S',
1243
-            'text' => ($labelFontsize ? true : false),
1244
-            'fgcolor' => $color,
1245
-            'bgcolor' => false,
1246
-        );
1247
-
1248
-        // build the barcode
1249
-        $this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
1250
-
1251
-        // it Label => add the FontSize to the height
1252
-        if ($labelFontsize) $h += ($labelFontsize);
1253
-
1254
-        // return the size of the barcode
1255
-        return array($w, $h);
1256
-    }
1257
-
1258
-    /**
1259
-     * create a automatic Index on a page
1260
-     *
1261
-     * @param html2pdf $obj           parent object
1262
-     * @param string   $titre         Title of the Index Page
1263
-     * @param integer  $sizeTitle     Font size for hthe Title
1264
-     * @param integer  $sizeBookmark  Font size for the bookmarks
1265
-     * @param boolean  $bookmarkTitle Bookmark the Title
1266
-     * @param boolean  $displayPage   Display the page number for each bookmark
1267
-     * @param integer  $page draw the automatic Index on a specific Page. if null => add a page at the end
1268
-     * @param string   $fontName      FontName to use
1269
-     * @access public
1270
-     */
1271
-    public function createIndex(
1272
-        &$obj,
1273
-        $titre = 'Index',
1274
-        $sizeTitle = 20,
1275
-        $sizeBookmark = 15,
1276
-        $bookmarkTitle = true,
1277
-        $displayPage = true,
1278
-        $page = null,
1279
-        $fontName = 'helvetica')
1280
-    {
1281
-        // bookmark the Title if wanted
1282
-        if ($bookmarkTitle) {
1283
-        	$this->Bookmark($titre, 0, -1);
1284
-        }
1285
-
1286
-        // display the Title with the good Font size
1287
-        $this->SetFont($fontName, '', $sizeTitle);
1288
-        $this->Cell(0, 5, $titre, 0, 1, 'C');
1289
-
1290
-        // set the good Font size for the bookmarks
1291
-        $this->SetFont($fontName, '', $sizeBookmark);
1292
-        $this->Ln(10);
1293
-
1294
-        // get the number of bookmarks
1295
-        $size = sizeof($this->outlines);
1296
-
1297
-        // get the size of the "P. xx" cell
1298
-        $pageCellSize = $this->GetStringWidth('p. '.$this->outlines[$size - 1]['p']) + 2;
1299
-
1300
-        // Foreach bookmark
1301
-        for ($i = 0; $i < $size; $i++) {
1302
-            // if we need a new page => add a new page
1303
-            if ($this->getY() + $this->FontSize >= ($this->h - $this->bMargin)) {
1304
-                $obj->_INDEX_NewPage($page);
1305
-                $this->SetFont($fontName, '', $sizeBookmark);
1306
-            }
1307
-
1308
-            // Offset of the current level
1309
-            $level = $this->outlines[$i]['l'];
1310
-            if ($level > 0) $this->Cell($level * 8);
1311
-
1312
-            // Caption (cut to fit on the width page)
1313
-            $str = $this->outlines[$i]['t'];
1314
-            $strsize = $this->GetStringWidth($str);
1315
-            $availableSize = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - 4;
1316
-            while ($strsize >= $availableSize) {
1317
-                $str = substr($str, 0, -1);
1318
-                $strsize = $this->GetStringWidth($str);
1319
-            }
1320
-
1321
-            // if we want to display the page nmber
1322
-            if ($displayPage) {
1323
-                // display the Bookmark Caption
1324
-                $this->Cell($strsize + 2, $this->FontSize + 2, $str);
1325
-
1326
-                //Filling dots
1327
-                $w = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - ($strsize + 2);
1328
-                $nb = $w / $this->GetStringWidth('.');
1329
-                $dots = str_repeat('.', $nb);
1330
-                $this->Cell($w, $this->FontSize + 2, $dots, 0, 0, 'R');
1331
-
1332
-                //Page number
1333
-                $this->Cell($pageCellSize, $this->FontSize + 2, 'p. '.$this->outlines[$i]['p'], 0, 1, 'R');
1334
-            } else {
1335
-                // display the Bookmark Caption
1336
-                $this->Cell($strsize + 2, $this->FontSize + 2, $str, 0, 1);
1337
-            }
1338
-        }
1339
-    }
1340
-
1341
-    /**
1342
-     * Returns the string alias used for the total number of pages.
1343
-     *
1344
-     * @access public
1345
-     * @return string;
1346
-     * @see TCPDF::getAliasNbPages(), TCPDF::getPageGroupAlias()
1347
-     */
1348
-    public function getMyAliasNbPages()
1349
-    {
1350
-        if ($this->_myLastPageGroupNb == 0) {
1351
-            return $this->getAliasNbPages();
1352
-        } else {
1353
-            $old = $this->currpagegroup;
1354
-            $this->currpagegroup = '{nb'.$this->_myLastPageGroupNb.'}';
1355
-            $new = $this->getPageGroupAlias();
1356
-            $this->currpagegroup = $old;
1357
-
1358
-            return $new;
1359
-        }
1360
-    }
1361
-
1362
-    /**
1363
-     * Returns the current page number.
1364
-     *
1365
-     * @access public
1366
-     * @param  integer $page
1367
-     * @return integer;
1368
-     */
1369
-    public function getMyNumPage($page = null)
1370
-    {
1371
-        if ($page === null) {
1372
-            $page = $this->page;
1373
-        }
1374
-
1375
-        if ($this->_myLastPageGroupNb == 0) {
1376
-            return $page;
1377
-        } else {
1378
-            return $page - $this->_myLastPageGroup;
1379
-        }
1380
-    }
1381
-
1382
-    /**
1383
-     * Start a new group of pages
1384
-     *
1385
-     * @access public
1386
-     * @return integer;
1387
-     * @see tcpdf::startPageGroup
1388
-     */
1389
-    public function myStartPageGroup()
1390
-    {
1391
-        $this->_myLastPageGroup = $this->page - 1;
1392
-        $this->_myLastPageGroupNb++;
1393
-    }
1394
-
1395
-    /**
1396
-     * get $_myLastPageGroup;
1397
-     *
1398
-     * @access public
1399
-     * @return integer $_myLastPageGroup;
1400
-     */
1401
-    public function getMyLastPageGroup()
1402
-    {
1403
-        return $this->_myLastPageGroup;
1404
-    }
1405
-
1406
-    /**
1407
-     * set $_myLastPageGroup;
1408
-     *
1409
-     * @access public
1410
-     * @param integer $myLastPageGroup;
1411
-     * @param integer $myLastPageGroup
1412
-     */
1413
-    public function setMyLastPageGroup($myLastPageGroup)
1414
-    {
1415
-        $this->_myLastPageGroup = $myLastPageGroup;
1416
-    }
1417
-
1418
-    /**
1419
-     * get $_myLastPageGroupNb;
1420
-     *
1421
-     * @access public
1422
-     * @return integer $_myLastPageGroupNb;
1423
-     */
1424
-    public function getMyLastPageGroupNb()
1425
-    {
1426
-        return $this->_myLastPageGroupNb;
1427
-    }
1428
-
1429
-    /**
1430
-     * set $_myLastPageGroupNb;
1431
-     *
1432
-     * @access public
1433
-     * @param integer $myLastPageGroupNb;
1434
-     * @param integer $myLastPageGroupNb
1435
-     */
1436
-    public function setMyLastPageGroupNb($myLastPageGroupNb)
1437
-    {
1438
-        $this->_myLastPageGroupNb = $myLastPageGroupNb;
1439
-    }
17
+	protected $_footerParam = array();
18
+	protected $_transf      = array();
19
+	protected $_myLastPageGroup = null;
20
+	protected $_myLastPageGroupNb = 0;
21
+
22
+	// used to make a radius with bezier : (4/3 * (sqrt(2) - 1))
23
+	const MY_ARC = 0.5522847498;
24
+
25
+	// nb of segment to build a arc with bezier curv
26
+	const ARC_NB_SEGMENT = 8;
27
+
28
+	/**
29
+	 * class constructor
30
+	 *
31
+	 * @param string  $orientation page orientation, same as TCPDF
32
+	 * @param string  $unit        User measure unit, same as TCPDF
33
+	 * @param mixed   $format      The format used for pages, same as TCPDF
34
+	 * @param boolean $unicode     TRUE means that the input text is unicode (default = true)
35
+	 * @param String  $encoding    charset encoding; default is UTF-8
36
+	 * @param boolean $diskcache   if TRUE reduce the RAM memory usage by caching temporary data on filesystem (slower).
37
+	 * @access public
38
+	 */
39
+	public function __construct(
40
+		$orientation = 'P',
41
+		$unit = 'mm',
42
+		$format = 'A4',
43
+		$unicode = true,
44
+		$encoding = 'UTF-8',
45
+		$diskcache = false)
46
+	{
47
+		// call the parent constructor
48
+		parent::__construct($orientation, $unit, $format, $unicode, $encoding, $diskcache);
49
+
50
+		// init the specific parameters used by HTML2PDF
51
+		$this->SetCreator(PDF_CREATOR);
52
+		$this->SetAutoPageBreak(false, 0);
53
+		$this->linestyleCap = '2 J';
54
+		$this->setPrintHeader(false);
55
+		$this->jpeg_quality = 90;
56
+
57
+		// prepare the automatic footer
58
+		$this->SetMyFooter();
59
+
60
+		$this->cMargin = 0;
61
+	}
62
+
63
+	/**
64
+	 * Set the parameters for the automatic footer
65
+	 *
66
+	 * @param boolean $page display the page number
67
+	 * @param boolean $date display the date
68
+	 * @param boolean $hour display the hour
69
+	 * @param boolean $form display a warning abour forms
70
+	 * @access public
71
+	 */
72
+	public function SetMyFooter($page = false, $date = false, $hour = false, $form = false)
73
+	{
74
+		$page    = ($page ? true : false);
75
+		$date    = ($date ? true : false);
76
+		$hour    = ($hour ? true : false);
77
+		$form    = ($form ? true : false);
78
+
79
+		$this->_footerParam = array('page' => $page, 'date' => $date, 'hour' => $hour, 'form' => $form);
80
+	}
81
+
82
+	/**
83
+	 * This function is call automatically by TCPDF at the end of a page
84
+	 * It takes no parameters
85
+	 *
86
+	 * @access public
87
+	 */
88
+	public function Footer()
89
+	{
90
+		// prepare the text from the tranlated text
91
+		$txt = '';
92
+		if ($this->_footerParam['form']) {
93
+			$txt = (HTML2PDF_locale::get('pdf05'));
94
+		}
95
+		if ($this->_footerParam['date'] && $this->_footerParam['hour']) {
96
+			$txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf03'));
97
+		}
98
+		if ($this->_footerParam['date'] && ! $this->_footerParam['hour']) {
99
+			$txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf01'));
100
+		}
101
+		if ( ! $this->_footerParam['date'] && $this->_footerParam['hour']) {
102
+			$txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf02'));
103
+		}
104
+		if ($this->_footerParam['page']) {
105
+			$txt .= ($txt ? ' - ' : '').(HTML2PDF_locale::get('pdf04'));
106
+		}
107
+
108
+		if (strlen($txt) > 0) {
109
+			// replace some values
110
+			$toReplace = array(
111
+				'[[date_d]]'  => date('d'),
112
+				'[[date_m]]'  => date('m'),
113
+				'[[date_y]]'  => date('Y'),
114
+				'[[date_h]]'  => date('H'),
115
+				'[[date_i]]'  => date('i'),
116
+				'[[date_s]]'  => date('s'),
117
+				'[[page_cu]]' => $this->getMyNumPage(),
118
+				'[[page_nb]]' => $this->getMyAliasNbPages(),
119
+			);
120
+			$txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt);
121
+
122
+			// draw the footer
123
+			parent::SetY(-11);
124
+			$this->SetFont('helvetica', 'I', 8);
125
+			$this->Cell(0, 10, $txt, 0, 0, 'R');
126
+		}
127
+	}
128
+
129
+	 /**
130
+	  * after cloning a object, we does not want to clone all the front informations
131
+	  * because it take a lot a time and a lot of memory => we use reference
132
+	  *
133
+	  * @param &HTML2PDF_myPdf object
134
+	  * @param HTML2PDF_myPdf $pdf
135
+	  * @access public
136
+	  */
137
+	public function cloneFontFrom(&$pdf)
138
+	{
139
+		$this->fonts            = &$pdf->getFonts();
140
+		$this->FontFiles        = &$pdf->getFontFiles();
141
+		$this->diffs            = &$pdf->getDiffs();
142
+		$this->fontlist         = &$pdf->getFontList();
143
+		$this->numfonts         = &$pdf->getNumFonts();
144
+		$this->fontkeys         = &$pdf->getFontKeys();
145
+		$this->font_obj_ids     = &$pdf->getFontObjIds();
146
+		$this->annotation_fonts = &$pdf->getAnnotFonts();
147
+	}
148
+
149
+	/**
150
+	 * multiple public accessor for some private attributs
151
+	 * used only by cloneFontFrom
152
+	 *
153
+	 * @return &array
154
+	 * @access public
155
+	 */
156
+	public function &getFonts()
157
+	{
158
+		return $this->fonts;
159
+	}
160
+	public function &getFontFiles()
161
+	{
162
+		return $this->FontFiles;
163
+	}
164
+	public function &getDiffs()
165
+	{
166
+		return $this->diffs;
167
+	}
168
+	public function &getFontList()
169
+	{
170
+		return $this->fontlist;
171
+	}
172
+	public function &getNumFonts()
173
+	{
174
+		return $this->numfonts;
175
+	}
176
+	public function &getFontKeys()
177
+	{
178
+		return $this->fontkeys;
179
+	}
180
+	public function &getFontObjIds()
181
+	{
182
+		return $this->font_obj_ids;
183
+	}
184
+	public function &getAnnotFonts()
185
+	{
186
+		return $this->annotation_fonts;
187
+	}
188
+
189
+	/**
190
+	 * Verify that a Font is already loaded
191
+	 *
192
+	 * @param string Font Key
193
+	 * @return boolean
194
+	 * @access public
195
+	 */
196
+	public function isLoadedFont($fontKey)
197
+	{
198
+		if (isset($this->fonts[$fontKey])) {
199
+			return true;
200
+		}
201
+
202
+		if (isset($this->CoreFonts[$fontKey])) {
203
+			return true;
204
+		}
205
+
206
+		return false;
207
+	}
208
+
209
+	/**
210
+	 * Get the Word Spacing
211
+	 *
212
+	 * @access public
213
+	 * @return float word spacing
214
+	 */
215
+	public function getWordSpacing()
216
+	{
217
+		return $this->ws;
218
+	}
219
+
220
+	/**
221
+	 * set the Word Spacing
222
+	 *
223
+	 * @param float word spacing
224
+	 * @access public
225
+	 */
226
+	public function setWordSpacing($ws = 0.)
227
+	{
228
+		$this->ws = $ws;
229
+		$this->_out(sprintf('%.3F Tw', $ws * $this->k));
230
+	}
231
+
232
+	/**
233
+	 * start to use a rectangular Cliping Path with radius corners
234
+	 *
235
+	 * @param float $x (top left corner)
236
+	 * @param float $y (top left corner)
237
+	 * @param float $w (x+w  = botom rigth corner)
238
+	 * @param float $h (y+h = botom rigth corner)
239
+	 * @param array $cornerTL radius of the Top Left corner
240
+	 * @param array $cornerTR radius of the Top Right corner
241
+	 * @param array $cornerBL radius of the Bottom Left corner
242
+	 * @param array $cornerBR radius of the Bottom Right corner
243
+	 * @access public
244
+	 */
245
+	public function clippingPathStart(
246
+		$x = null,
247
+		$y = null,
248
+		$w = null,
249
+		$h = null,
250
+		$cornerTL = null,
251
+		$cornerTR = null,
252
+		$cornerBL = null,
253
+		$cornerBR = null)
254
+	{
255
+		// init the path
256
+		$path = '';
257
+
258
+		// if we have the position and the size of the rectangle, we can proceed
259
+		if ($x !== null && $y !== null && $w !== null && $h !== null) {
260
+			// the positions of the rectangle's corners
261
+			$x1 = $x * $this->k;
262
+			$y1 = ($this->h - $y) * $this->k;
263
+
264
+			$x2 = ($x + $w) * $this->k;
265
+			$y2 = ($this->h - $y) * $this->k;
266
+
267
+			$x3 = ($x + $w) * $this->k;
268
+			$y3 = ($this->h - $y - $h) * $this->k;
269
+
270
+			$x4 = $x * $this->k;
271
+			$y4 = ($this->h - $y - $h) * $this->k;
272
+
273
+			// if we have at least one radius corner, then we proceed to a specific path, else it is just a rectangle
274
+			if ($cornerTL || $cornerTR || $cornerBL || $cornerBR) {
275
+				// prepare the radius values
276
+				if ($cornerTL) {
277
+					$cornerTL[0] = $cornerTL[0] * $this->k;
278
+					$cornerTL[1] = -$cornerTL[1] * $this->k;
279
+				}
280
+				if ($cornerTR) {
281
+					$cornerTR[0] = $cornerTR[0] * $this->k;
282
+					$cornerTR[1] = -$cornerTR[1] * $this->k;
283
+				}
284
+				if ($cornerBL) {
285
+					$cornerBL[0] = $cornerBL[0] * $this->k;
286
+					$cornerBL[1] = -$cornerBL[1] * $this->k;
287
+				}
288
+				if ($cornerBR) {
289
+					$cornerBR[0] = $cornerBR[0] * $this->k;
290
+					$cornerBR[1] = -$cornerBR[1] * $this->k;
291
+				}
292
+
293
+				// if TL radius then specific start else (X1,Y1)
294
+				if ($cornerTL) {
295
+					$path .= sprintf('%.2F %.2F m ', $x1 + $cornerTL[0], $y1);
296
+				} else {
297
+					$path .= sprintf('%.2F %.2F m ', $x1, $y1);
298
+				}
299
+
300
+				// if TR radius then line + arc, else line to (X2,Y2)
301
+				if ($cornerTR) {
302
+					$xt1 = ($x2 - $cornerTR[0]) + $cornerTR[0] * self::MY_ARC;
303
+					$yt1 = ($y2 + $cornerTR[1]) - $cornerTR[1];
304
+					$xt2 = ($x2 - $cornerTR[0]) + $cornerTR[0];
305
+					$yt2 = ($y2 + $cornerTR[1]) - $cornerTR[1] * self::MY_ARC;
306
+
307
+					$path .= sprintf('%.2F %.2F l ', $x2 - $cornerTR[0], $y2);
308
+					$path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x2, $y2 + $cornerTR[1]);
309
+				} else {
310
+					$path .= sprintf('%.2F %.2F l ', $x2, $y2);
311
+				}
312
+
313
+				// if BR radius then line + arc, else line to (X3, Y3)
314
+				if ($cornerBR) {
315
+					$xt1 = ($x3 - $cornerBR[0]) + $cornerBR[0];
316
+					$yt1 = ($y3 - $cornerBR[1]) + $cornerBR[1] * self::MY_ARC;
317
+					$xt2 = ($x3 - $cornerBR[0]) + $cornerBR[0] * self::MY_ARC;
318
+					$yt2 = ($y3 - $cornerBR[1]) + $cornerBR[1];
319
+
320
+					$path .= sprintf('%.2F %.2F l ', $x3, $y3 - $cornerBR[1]);
321
+					$path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x3 - $cornerBR[0], $y3);
322
+				} else {
323
+					$path .= sprintf('%.2F %.2F l ', $x3, $y3);
324
+				}
325
+
326
+				// if BL radius then line + arc, else line to (X4, Y4)
327
+				if ($cornerBL) {
328
+					$xt1 = ($x4 + $cornerBL[0]) - $cornerBL[0] * self::MY_ARC;
329
+					$yt1 = ($y4 - $cornerBL[1]) + $cornerBL[1];
330
+					$xt2 = ($x4 + $cornerBL[0]) - $cornerBL[0];
331
+					$yt2 = ($y4 - $cornerBL[1]) + $cornerBL[1] * self::MY_ARC;
332
+
333
+					$path .= sprintf('%.2F %.2F l ', $x4 + $cornerBL[0], $y4);
334
+					$path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x4, $y4 - $cornerBL[1]);
335
+				} else {
336
+					$path .= sprintf('%.2F %.2F l ', $x4, $y4);
337
+				}
338
+
339
+				// if RL radius then line + arc
340
+				if ($cornerTL) {
341
+					$xt1 = ($x1 + $cornerTL[0]) - $cornerTL[0];
342
+					$yt1 = ($y1 + $cornerTL[1]) - $cornerTL[1] * self::MY_ARC;
343
+					$xt2 = ($x1 + $cornerTL[0]) - $cornerTL[0] * self::MY_ARC;
344
+					$yt2 = ($y1 + $cornerTL[1]) - $cornerTL[1];
345
+
346
+					$path .= sprintf('%.2F %.2F l ', $x1, $y1 + $cornerTL[1]);
347
+					$path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $x1 + $cornerTL[0], $y1);
348
+				}
349
+			} else {
350
+				$path .= sprintf('%.2F %.2F m ', $x1, $y1);
351
+				$path .= sprintf('%.2F %.2F l ', $x2, $y2);
352
+				$path .= sprintf('%.2F %.2F l ', $x3, $y3);
353
+				$path .= sprintf('%.2F %.2F l ', $x4, $y4);
354
+			}
355
+
356
+			// close the path
357
+			$path .= ' h W n';
358
+		}
359
+
360
+		// using the path as a clipping path
361
+		$this->_out('q '.$path.' ');
362
+	}
363
+
364
+	/**
365
+	 * stop to use the Cliping Path
366
+	 *
367
+	 * @access public
368
+	 */
369
+	public function clippingPathStop()
370
+	{
371
+		$this->_out(' Q');
372
+	}
373
+
374
+	/**
375
+	 * draw a filled corner of a border with a external and a internal radius
376
+	 *         /--------+ ext2
377
+	 *        /         |
378
+	 *       /  /-------+ int2
379
+	 *      /  /
380
+	 *      | /
381
+	 *      | |
382
+	 *      | |
383
+	 * ext1 +-+ int1        + cen
384
+	 *
385
+	 * @param float $ext1X
386
+	 * @param float $ext1Y
387
+	 * @param float $ext2X
388
+	 * @param float $ext2Y
389
+	 * @param float $int1X
390
+	 * @param float $int1Y
391
+	 * @param float $int2X
392
+	 * @param float $int2Y
393
+	 * @param float $cenX
394
+	 * @param float $cenY
395
+	 * @access public
396
+	 */
397
+	public function drawCurve($ext1X, $ext1Y, $ext2X, $ext2Y, $int1X, $int1Y, $int2X, $int2Y, $cenX, $cenY)
398
+	{
399
+		// prepare the coordinates
400
+		$ext1X = $ext1X * $this->k;
401
+		$ext2X = $ext2X * $this->k;
402
+		$int1X = $int1X * $this->k;
403
+		$int2X = $int2X * $this->k;
404
+		$cenX  = $cenX * $this->k;
405
+
406
+		$ext1Y = ($this->h - $ext1Y) * $this->k;
407
+		$ext2Y = ($this->h - $ext2Y) * $this->k;
408
+		$int1Y = ($this->h - $int1Y) * $this->k;
409
+		$int2Y = ($this->h - $int2Y) * $this->k;
410
+		$cenY  = ($this->h - $cenY) * $this->k;
411
+
412
+		// init the curve
413
+		$path = '';
414
+
415
+		if ($ext1X - $cenX != 0) {
416
+			$xt1 = $cenX + ($ext1X - $cenX);
417
+			$yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC;
418
+			$xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC;
419
+			$yt2 = $cenY + ($ext2Y - $cenY);
420
+		} else {
421
+			$xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC;
422
+			$yt1 = $cenY + ($ext1Y - $cenY);
423
+			$xt2 = $cenX + ($ext2X - $cenX);
424
+			$yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC;
425
+		}
426
+		$path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
427
+		$path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
428
+
429
+		if ($int1X - $cenX != 0) {
430
+			$xt1 = $cenX + ($int1X - $cenX) * self::MY_ARC;
431
+			$yt1 = $cenY + ($int2Y - $cenY);
432
+			$xt2 = $cenX + ($int1X - $cenX);
433
+			$yt2 = $cenY + ($int2Y - $cenY) * self::MY_ARC;
434
+		} else {
435
+			$xt1 = $cenX + ($int2X - $cenX);
436
+			$yt1 = $cenY + ($int1Y - $cenY) * self::MY_ARC;
437
+			$xt2 = $cenX + ($int2X - $cenX) * self::MY_ARC;
438
+			$yt2 = $cenY + ($int1Y - $cenY);
439
+		}
440
+		$path .= sprintf('%.2F %.2F l ', $int2X, $int2Y);
441
+		$path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $int1X, $int1Y);
442
+
443
+		// draw the curve
444
+		$this->_out($path.'f');
445
+	}
446
+
447
+	/**
448
+	 * draw a filled corner of a border with only a external radius
449
+	 *         /--+ ext2
450
+	 *        /   |
451
+	 *       /    |
452
+	 *      /     |
453
+	 *      |     |
454
+	 *      |     |
455
+	 *      |     |
456
+	 * ext1 +-----+ int      + cen
457
+	 *
458
+	 * @param float $ext1X
459
+	 * @param float $ext1Y
460
+	 * @param float $ext2X
461
+	 * @param float $ext2Y
462
+	 * @param float $intX
463
+	 * @param float $intY
464
+	 * @param float $cenX
465
+	 * @param float $cenY
466
+	 * @access public
467
+	 */
468
+	public function drawCorner($ext1X, $ext1Y, $ext2X, $ext2Y, $intX, $intY, $cenX, $cenY)
469
+	{
470
+		// prepare the coordinates
471
+		$ext1X = $ext1X * $this->k;
472
+		$ext2X = $ext2X * $this->k;
473
+		$intX  = $intX * $this->k;
474
+		$cenX  = $cenX * $this->k;
475
+
476
+		$ext1Y = ($this->h - $ext1Y) * $this->k;
477
+		$ext2Y = ($this->h - $ext2Y) * $this->k;
478
+		$intY  = ($this->h - $intY) * $this->k;
479
+		$cenY  = ($this->h - $cenY) * $this->k;
480
+
481
+		// init the curve
482
+		$path = '';
483
+
484
+		if ($ext1X - $cenX != 0) {
485
+			$xt1 = $cenX + ($ext1X - $cenX);
486
+			$yt1 = $cenY + ($ext2Y - $cenY) * self::MY_ARC;
487
+			$xt2 = $cenX + ($ext1X - $cenX) * self::MY_ARC;
488
+			$yt2 = $cenY + ($ext2Y - $cenY);
489
+		} else {
490
+			$xt1 = $cenX + ($ext2X - $cenX) * self::MY_ARC;
491
+			$yt1 = $cenY + ($ext1Y - $cenY);
492
+			$xt2 = $cenX + ($ext2X - $cenX);
493
+			$yt2 = $cenY + ($ext1Y - $cenY) * self::MY_ARC;
494
+		}
495
+		$path .= sprintf('%.2F %.2F m ', $ext1X, $ext1Y);
496
+		$path .= sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $xt1, $yt1, $xt2, $yt2, $ext2X, $ext2Y);
497
+		$path .= sprintf('%.2F %.2F l ', $intX, $intY);
498
+		$path .= sprintf('%.2F %.2F l ', $ext1X, $ext1Y);
499
+
500
+		// draw the curve
501
+		$this->_out($path.'f');
502
+	}
503
+
504
+	/**
505
+	 * Start a transformation
506
+	 *
507
+	 * @access public
508
+	 */
509
+	public function startTransform()
510
+	{
511
+		$this->_out('q');
512
+	}
513
+
514
+	/**
515
+	 * Stop a transformation
516
+	 *
517
+	 * @access public
518
+	 */
519
+	public function stopTransform()
520
+	{
521
+		$this->_out('Q');
522
+	}
523
+
524
+	/**
525
+	 * add a Translate transformation
526
+	 *
527
+	 * @access public
528
+	 */
529
+	public function setTranslate($xT, $yT)
530
+	{
531
+		// Matrix for Translate
532
+		$tm[0] = 1;
533
+		$tm[1] = 0;
534
+		$tm[2] = 0;
535
+		$tm[3] = 1;
536
+		$tm[4] = $xT * $this->k;
537
+		$tm[5] = -$yT * $this->k;
538
+
539
+		// apply the Transform Matric
540
+		$this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
541
+	}
542
+
543
+	/**
544
+	 * add a Rotate transformation
545
+	 *
546
+	 * @param float $angle
547
+	 * @access public
548
+	 */
549
+	public function setRotation($angle, $xC = null, $yC = null)
550
+	{
551
+		// if no center, rotate around the current posiition
552
+		if ($xC === null) $xC = $this->x;
553
+		if ($yC === null) $yC = $this->y;
554
+
555
+		// prepare the coordinate
556
+		$yC = ($this->h - $yC) * $this->k;
557
+		$xC *= $this->k;
558
+
559
+		// Matrix for Rotate
560
+		$tm[0] = cos(deg2rad($angle));
561
+		$tm[1] = sin(deg2rad($angle));
562
+		$tm[2] = -$tm[1];
563
+		$tm[3] = $tm[0];
564
+		$tm[4] = $xC + $tm[1] * $yC - $tm[0] * $xC;
565
+		$tm[5] = $yC - $tm[0] * $yC - $tm[1] * $xC;
566
+
567
+		// apply the Transform Matric
568
+		$this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
569
+	}
570
+
571
+	/**
572
+	 * we redifine the original SetX method, because we don't want the automatic treatment.
573
+	 * It is HTML2PDF that make the treatment
574
+	 *
575
+	 * @param float   $x
576
+	 * @param boolean $rtloff NOT USED
577
+	 * @access public
578
+	 */
579
+	public function SetX($x, $rtloff = false)
580
+	{
581
+		$this->x = $x;
582
+	}
583
+
584
+	/**
585
+	 * we redifine the original SetY method, because we don't want the automatic treatment.
586
+	 * It is HTML2PDF that make the treatment
587
+	 *
588
+	 * @param float   $y
589
+	 * @param boolean $resetx Reset the X position
590
+	 * @param boolean $rtloff NOT USED
591
+	 * @access public
592
+	 */
593
+	public function SetY($y, $resetx = true, $rtloff = false)
594
+	{
595
+		if ($resetx)
596
+			$this->x = $this->lMargin;
597
+
598
+		$this->y = $y;
599
+	}
600
+
601
+	/**
602
+	 * we redifine the original SetXY method, because we don't want the automatic treatment.
603
+	 * It is HTML2PDF that make the treatment
604
+	 *
605
+	 * @param integer $x
606
+	 * @param integer $y
607
+	 * @param boolean $rtloff NOT USED
608
+	 * @access public
609
+	 */
610
+	public function SetXY($x, $y, $rtloff = false)
611
+	{
612
+		$this->x = $x;
613
+		$this->y = $y;
614
+	}
615
+
616
+	/**
617
+	 * multiple public accessor because HTML2PDF need to use TCPDF without being a extend of it
618
+	 *
619
+	 * @param  mixed
620
+	 * @return mixed
621
+	 * @access public
622
+	 */
623
+	public function getK()
624
+	{
625
+		return $this->k;
626
+	}
627
+
628
+	/**
629
+	 * @return double
630
+	 */
631
+	public function getW()
632
+	{
633
+		return $this->w;
634
+	}
635
+
636
+	/**
637
+	 * @return double
638
+	 */
639
+	public function getH()
640
+	{
641
+		return $this->h;
642
+	}
643
+	public function getlMargin()
644
+	{
645
+		return $this->lMargin;
646
+	}
647
+
648
+	/**
649
+	 * @return double
650
+	 */
651
+	public function getrMargin()
652
+	{
653
+		return $this->rMargin;
654
+	}
655
+
656
+	/**
657
+	 * @return double
658
+	 */
659
+	public function gettMargin()
660
+	{
661
+		return $this->tMargin;
662
+	}
663
+	public function getbMargin()
664
+	{
665
+		return $this->bMargin;
666
+	}
667
+	public function setbMargin($v)
668
+	{
669
+		$this->bMargin = $v;
670
+	}
671
+
672
+	/**
673
+	 * SVG - Convert a SVG Style in PDF Style
674
+	 *
675
+	 * @param  array  $styles SVG Style
676
+	 * @return string PDF style
677
+	 * @access public
678
+	 */
679
+	public function svgSetStyle($styles)
680
+	{
681
+		// init the PDF style
682
+		$style = '';
683
+
684
+		// Style : fill
685
+		if ($styles['fill']) {
686
+			$this->setFillColorArray($styles['fill']);
687
+			$style .= 'F';
688
+		}
689
+
690
+		// Style : stroke
691
+		if ($styles['stroke'] && $styles['stroke-width']) {
692
+			$this->SetDrawColorArray($styles['stroke']);
693
+			$this->SetLineWidth($styles['stroke-width']);
694
+			$style .= 'D';
695
+		}
696
+
697
+		// Style : opacity
698
+		if ($styles['fill-opacity']) {
699
+			$this->SetAlpha($styles['fill-opacity']);
700
+		}
701
+
702
+		return $style;
703
+	}
704
+
705
+	/**
706
+	 * SVG - make a Rectangle
707
+	 *
708
+	 * @param float $x
709
+	 * @param float $y
710
+	 * @param float $w
711
+	 * @param float $h
712
+	 * @param string $style PDF Style
713
+	 * @access public
714
+	 */
715
+	public function svgRect($x, $y, $w, $h, $style)
716
+	{
717
+		// prepare the 4 corners
718
+		$x1 = $x;
719
+		$x2 = $x + $w;
720
+		$x3 = $x + $w;
721
+		$x4 = $x;
722
+
723
+		$y1 = $y;
724
+		$y2 = $y;
725
+		$y3 = $y + $h;
726
+		$y4 = $y + $h;
727
+
728
+		// get the Closing operator from the PDF Style
729
+		if ($style == 'F') $op = 'f';
730
+		elseif ($style == 'FD' || $style == 'DF') $op = 'B';
731
+		else $op = 'S';
732
+
733
+		// drawing
734
+		$this->_Point($x1, $y1, true);
735
+		$this->_Line($x2, $y2, true);
736
+		$this->_Line($x3, $y3, true);
737
+		$this->_Line($x4, $y4, true);
738
+		$this->_Line($x1, $y1, true);
739
+		$this->_out($op);
740
+	}
741
+
742
+	/**
743
+	 * SVG - make a Line
744
+	 *
745
+	 * @param float $x1
746
+	 * @param float $y1
747
+	 * @param float $x2
748
+	 * @param float $y2
749
+	 * @access public
750
+	 */
751
+	public function svgLine($x1, $y1, $x2, $y2)
752
+	{
753
+		// get the Closing operator
754
+		$op = 'S';
755
+
756
+		// drawing
757
+		$this->_Point($x1, $y1, true);
758
+		$this->_Line($x2, $y2, true);
759
+		$this->_out($op);
760
+	}
761
+
762
+	/**
763
+	 * SVG - make a Ellipse
764
+	 *
765
+	 * @param float  $x0 x Center
766
+	 * @param float  $y0 y Center
767
+	 * @param float  $rx x radius
768
+	 * @param float  $ry y radius
769
+	 * @param string $style PDF Style
770
+	 * @access public
771
+	 */
772
+	public function svgEllipse($x0, $y0, $rx, $ry, $style)
773
+	{
774
+		// get the Closing operator from the PDF Style
775
+		if ($style == 'F') $op = 'f';
776
+		elseif ($style == 'FD' || $style == 'DF') $op = 'B';
777
+		else $op = 'S';
778
+
779
+		// drawing
780
+		$this->_Arc($x0, $y0, $rx, $ry, 0, 2 * M_PI, true, true, true);
781
+		$this->_out($op);
782
+	}
783
+
784
+	/**
785
+	 * SVG - make a Advanced Polygone
786
+	 *
787
+	 * @param array  $actions list of actions
788
+	 * @param string $style PDF Style
789
+	 * @access public
790
+	 */
791
+	public function svgPolygone($actions, $style)
792
+	{
793
+		// get the Closing operator from the PDF Style
794
+		if ($style == 'F') $op = 'f';
795
+		elseif ($style == 'FD' || $style == 'DF') $op = 'B';
796
+		else $op = 'S';
797
+
798
+		// To save the First action and the last point
799
+		$first = array('', 0, 0);
800
+		$last = array(0, 0, 0, 0);
801
+
802
+		foreach ($actions as $action) {
803
+			switch ($action[0])
804
+			{
805
+				// Start the Path
806
+				case 'M':
807
+				case 'm':
808
+					$first = $action;
809
+					$x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
810
+					$this->_Point($x, $y, true);
811
+					break;
812
+
813
+				// Close the Path
814
+				case 'Z':
815
+				case 'z':
816
+					$x = $first[1]; $y = $first[2]; $xc = $x; $yc = $y;
817
+					$this->_Line($x, $y, true);
818
+					break;
819
+
820
+				// Make a Line (new point)
821
+				case 'L':
822
+					$x = $action[1]; $y = $action[2]; $xc = $x; $yc = $y;
823
+					$this->_Line($x, $y, true);
824
+					break;
825
+
826
+				// Make a Line (vector from last point)
827
+				case 'l':
828
+					$x = $last[0] + $action[1]; $y = $last[1] + $action[2]; $xc = $x; $yc = $y;
829
+					$this->_Line($x, $y, true);
830
+					break;
831
+
832
+				// Make a Horizontal Line (new point)
833
+				case 'H':
834
+					$x = $action[1]; $y = $last[1]; $xc = $x; $yc = $y;
835
+					$this->_Line($x, $y, true);
836
+					break;
837
+
838
+				// Make a Horisontal Line (vector from last point)
839
+				case 'h':
840
+					$x = $last[0] + $action[1]; $y = $last[1]; $xc = $x; $yc = $y;
841
+					$this->_Line($x, $y, true);
842
+					break;
843
+
844
+				// Make a Vertical Line (new point)
845
+				case 'V':
846
+					$x = $last[0]; $y = $action[1]; $xc = $x; $yc = $y;
847
+					$this->_Line($x, $y, true);
848
+					break;
849
+
850
+				// Make a Vertical Line (vector from last point)
851
+				case 'v':
852
+					$x = $last[0]; $y = $last[1] + $action[1]; $xc = $x; $yc = $y;
853
+					$this->_Line($x, $y, true);
854
+					break;
855
+
856
+				// Make a Arc (new point)
857
+				case 'A':
858
+					$rx = $action[1]; // rx
859
+					$ry = $action[2]; // ry
860
+					$a = $action[3]; // deviation angle of the axis X
861
+					$l = $action[4]; // large-arc-flag
862
+					$s = $action[5]; // sweep-flag
863
+					$x1 = $last[0]; // begin x
864
+					$y1 = $last[1]; // begin y
865
+					$x2 = $action[6]; // final x
866
+					$y2 = $action[7]; // final y
867
+
868
+					$this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
869
+					$x = $x2; $y = $y2; $xc = $x; $yc = $y;
870
+					break;
871
+
872
+				// Make a Arc (vector from last point)
873
+				case 'a':
874
+					$rx = $action[1]; // rx
875
+					$ry = $action[2]; // ry
876
+					$a = $action[3]; // deviation angle of the axis X
877
+					$l = $action[4]; // large-arc-flag
878
+					$s = $action[5]; // sweep-flag
879
+					$x1 = $last[0]; // begin x
880
+					$y1 = $last[1]; // begin y
881
+					$x2 = $last[0] + $action[6]; // final x
882
+					$y2 = $last[1] + $action[7]; // final y
883
+
884
+					$this->_Arc2($x1, $y1, $x2, $y2, $rx, $ry, $a, $l, $s, true);
885
+					$x = $x2; $y = $y2; $xc = $x; $yc = $y;
886
+					break;
887
+
888
+				// Make a Bezier Curve (new point)
889
+				case 'C':
890
+					$x1 = $action[1];
891
+					$y1 = $action[2];
892
+					$x2 = $action[3];
893
+					$y2 = $action[4];
894
+					$xf = $action[5];
895
+					$yf = $action[6];
896
+					$this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
897
+					$x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
898
+					break;
899
+
900
+				// Make a Bezier Curve (vector from last point)
901
+				case 'c':
902
+					$x1 = $last[0] + $action[1];
903
+					$y1 = $last[1] + $action[2];
904
+					$x2 = $last[0] + $action[3];
905
+					$y2 = $last[1] + $action[4];
906
+					$xf = $last[0] + $action[5];
907
+					$yf = $last[1] + $action[6];
908
+					$this->_Curve($x1, $y1, $x2, $y2, $xf, $yf, true);
909
+					$x = $xf; $y = $yf; $xc = $x2; $yc = $y2;
910
+					break;
911
+
912
+				// Unknown Path
913
+				default:
914
+					throw new HTML2PDF_exception(0, 'SVG Path Error : ['.$action[0].'] unkown');
915
+			}
916
+
917
+			// save the last point
918
+			$last = array($x, $y, $xc, $yc);
919
+		}
920
+
921
+		// finish the path
922
+		$this->_out($op);
923
+	}
924
+
925
+	/**
926
+	 * SVG - go to a point
927
+	 *
928
+	 * @param float   $x
929
+	 * @param float   $y
930
+	 * @param boolean $trans apply transformation
931
+	 * @access protected
932
+	 */
933
+	protected function _Point($x, $y, $trans = false)
934
+	{
935
+		if ($trans) {
936
+			$this->ptTransform($x, $y);
937
+		}
938
+
939
+		$this->_out(sprintf('%.2F %.2F m', $x, $y));
940
+	}
941
+
942
+	/**
943
+	 * SVG - make a line from the last point to (x,y)
944
+	 *
945
+	 * @param float   $x
946
+	 * @param float   $y
947
+	 * @param boolean $trans apply transformation
948
+	 * @access protected
949
+	 */
950
+	protected function _Line($x, $y, $trans = false)
951
+	{
952
+		if ($trans) {
953
+			$this->ptTransform($x, $y);
954
+		}
955
+
956
+		$this->_out(sprintf('%.2F %.2F l', $x, $y));
957
+	}
958
+
959
+	/**
960
+	 * SVG - make a bezier curve from the last point to (xf,yf), with the 2 direction points (x1,y1) and (x2,y2)
961
+	 *
962
+	 * @param float $x1
963
+	 * @param float $y1
964
+	 * @param float $x2
965
+	 * @param float $y2
966
+	 * @param float $xf
967
+	 * @param float $yf
968
+	 * @param boolean $trans apply transformation
969
+	 * @access protected
970
+	 */
971
+	protected function _Curve($x1, $y1, $x2, $y2, $xf, $yf, $trans = false)
972
+	{
973
+		if ($trans) {
974
+			$this->ptTransform($x1, $y1);
975
+			$this->ptTransform($x2, $y2);
976
+			$this->ptTransform($xf, $yf);
977
+		}
978
+		$this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c', $x1, $y1, $x2, $y2, $xf, $yf));
979
+	}
980
+
981
+	/**
982
+	 * SVG - make a arc with Center, Radius, from angleBegin to angleEnd
983
+	 *
984
+	 * @param float $xc
985
+	 * @param float $yc
986
+	 * @param float $rx
987
+	 * @param float $ry
988
+	 * @param float $angleBegin in radians
989
+	 * @param float $angleEnd in radians
990
+	 * @param boolean $direction
991
+	 * @param boolean $drawFirst, true => add the first point
992
+	 * @param boolean $trans apply transformation
993
+	 * @access protected
994
+	 */
995
+	protected function _Arc(
996
+		$xc,
997
+		$yc,
998
+		$rx,
999
+		$ry,
1000
+		$angleBegin,
1001
+		$angleEnd,
1002
+		$direction = true,
1003
+		$drawFirst = true,
1004
+		$trans = false)
1005
+	{
1006
+		// if we want the no trigo direction : add 2PI to the begin angle, to invert the direction
1007
+		if ( ! $direction) $angleBegin += M_PI * 2.;
1008
+
1009
+		// cut in segment to convert in berize curv
1010
+		$dt = ($angleEnd - $angleBegin) / self::ARC_NB_SEGMENT;
1011
+		$dtm = $dt / 3;
1012
+
1013
+		// center of the arc
1014
+		$x0 = $xc; $y0 = $yc;
1015
+
1016
+		// calculing the first point
1017
+		$t1 = $angleBegin;
1018
+		$a0 = $x0 + ($rx * cos($t1));
1019
+		$b0 = $y0 + ($ry * sin($t1));
1020
+		$c0 = -$rx * sin($t1);
1021
+		$d0 = $ry * cos($t1);
1022
+
1023
+		// if drawFirst => draw the first point
1024
+		if ($drawFirst) {
1025
+			$this->_Point($a0, $b0, $trans);
1026
+		}
1027
+
1028
+		// foreach segment
1029
+		for ($i = 1; $i <= self::ARC_NB_SEGMENT; $i++) {
1030
+			// calculing the next point
1031
+			$t1 = ($i * $dt) + $angleBegin;
1032
+			$a1 = $x0 + ($rx * cos($t1));
1033
+			$b1 = $y0 + ($ry * sin($t1));
1034
+			$c1 = -$rx * sin($t1);
1035
+			$d1 = $ry * cos($t1);
1036
+
1037
+			// make the bezier curv
1038
+			$this->_Curve(
1039
+				$a0 + ($c0 * $dtm), $b0 + ($d0 * $dtm),
1040
+				$a1 - ($c1 * $dtm), $b1 - ($d1 * $dtm),
1041
+				$a1, $b1,
1042
+				$trans
1043
+			);
1044
+
1045
+			// save the point
1046
+			$a0 = $a1;
1047
+			$b0 = $b1;
1048
+			$c0 = $c1;
1049
+			$d0 = $d1;
1050
+		}
1051
+	}
1052
+
1053
+	/**
1054
+	 * SVG - make a arc from Pt1 to Pt2, with Radius
1055
+	 *
1056
+	 * @param float $x1
1057
+	 * @param float $y1
1058
+	 * @param float $x2
1059
+	 * @param float $y2
1060
+	 * @param float $rx
1061
+	 * @param float $ry
1062
+	 * @param float $angle deviation angle of the axis X
1063
+	 * @param integer $l large-arc-flag
1064
+	 * @param integer $s sweep-flag
1065
+	 * @param boolean $trans apply transformation
1066
+	 * @access protected
1067
+	 */
1068
+	protected function _Arc2($x1, $y1, $x2, $y2, $rx, $ry, $angle = 0., $l = 0, $s = 0, $trans = false)
1069
+	{
1070
+		// array to stock the parameters
1071
+		$v = array();
1072
+
1073
+		// the original values
1074
+		$v['x1'] = $x1;
1075
+		$v['y1'] = $y1;
1076
+		$v['x2'] = $x2;
1077
+		$v['y2'] = $y2;
1078
+		$v['rx'] = $rx;
1079
+		$v['ry'] = $ry;
1080
+
1081
+		// rotate with the deviation angle of the axis X
1082
+		$v['xr1'] = $v['x1'] * cos($angle) - $v['y1'] * sin($angle);
1083
+		$v['yr1'] = $v['x1'] * sin($angle) + $v['y1'] * cos($angle);
1084
+		$v['xr2'] = $v['x2'] * cos($angle) - $v['y2'] * sin($angle);
1085
+		$v['yr2'] = $v['x2'] * sin($angle) + $v['y2'] * cos($angle);
1086
+
1087
+		// the normalized vector
1088
+		$v['Xr1'] = $v['xr1'] / $v['rx'];
1089
+		$v['Yr1'] = $v['yr1'] / $v['ry'];
1090
+		$v['Xr2'] = $v['xr2'] / $v['rx'];
1091
+		$v['Yr2'] = $v['yr2'] / $v['ry'];
1092
+		$v['dXr'] = $v['Xr2'] - $v['Xr1'];
1093
+		$v['dYr'] = $v['Yr2'] - $v['Yr1'];
1094
+		$v['D'] = $v['dXr'] * $v['dXr'] + $v['dYr'] * $v['dYr'];
1095
+
1096
+		// if |vector| is Null, or if |vector| > 2 : impossible to make a arc => Line
1097
+		if ($v['D'] == 0 || $v['D'] > 4) {
1098
+			$this->_Line($x2, $y2, $trans);
1099
+			return false;
1100
+		}
1101
+
1102
+		// convert paramters for make a arc with Center, Radius, from angleBegin to angleEnd
1103
+		$v['s1'] = array();
1104
+		$v['s1']['t'] = sqrt((4. - $v['D']) / $v['D']);
1105
+		$v['s1']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s1']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.;
1106
+		$v['s1']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s1']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.;
1107
+		$v['s1']['xr'] = $v['s1']['Xr'] * $v['rx'];
1108
+		$v['s1']['yr'] = $v['s1']['Yr'] * $v['ry'];
1109
+		$v['s1']['x'] = $v['s1']['xr'] * cos($angle) + $v['s1']['yr'] * sin($angle);
1110
+		$v['s1']['y'] = -$v['s1']['xr'] * sin($angle) + $v['s1']['yr'] * cos($angle);
1111
+		$v['s1']['a1'] = atan2($v['y1'] - $v['s1']['y'], $v['x1'] - $v['s1']['x']);
1112
+		$v['s1']['a2'] = atan2($v['y2'] - $v['s1']['y'], $v['x2'] - $v['s1']['x']);
1113
+		if ($v['s1']['a1'] > $v['s1']['a2']) $v['s1']['a1'] -= 2 * M_PI;
1114
+
1115
+		$v['s2'] = array();
1116
+		$v['s2']['t'] = -$v['s1']['t'];
1117
+		$v['s2']['Xr'] = ($v['Xr1'] + $v['Xr2']) / 2. + $v['s2']['t'] * ($v['Yr2'] - $v['Yr1']) / 2.;
1118
+		$v['s2']['Yr'] = ($v['Yr1'] + $v['Yr2']) / 2. + $v['s2']['t'] * ($v['Xr1'] - $v['Xr2']) / 2.;
1119
+		$v['s2']['xr'] = $v['s2']['Xr'] * $v['rx'];
1120
+		$v['s2']['yr'] = $v['s2']['Yr'] * $v['ry'];
1121
+		$v['s2']['x'] = $v['s2']['xr'] * cos($angle) + $v['s2']['yr'] * sin($angle);
1122
+		$v['s2']['y'] = -$v['s2']['xr'] * sin($angle) + $v['s2']['yr'] * cos($angle);
1123
+		$v['s2']['a1'] = atan2($v['y1'] - $v['s2']['y'], $v['x1'] - $v['s2']['x']);
1124
+		$v['s2']['a2'] = atan2($v['y2'] - $v['s2']['y'], $v['x2'] - $v['s2']['x']);
1125
+		if ($v['s2']['a1'] > $v['s2']['a2']) $v['s2']['a1'] -= 2 * M_PI;
1126
+
1127
+		if ( ! $l) {
1128
+			if ($s) {
1129
+				$xc = $v['s2']['x'];
1130
+				$yc = $v['s2']['y'];
1131
+				$a1 = $v['s2']['a1'];
1132
+				$a2 = $v['s2']['a2'];
1133
+				$this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
1134
+			} else {
1135
+				$xc = $v['s1']['x'];
1136
+				$yc = $v['s1']['y'];
1137
+				$a1 = $v['s1']['a1'];
1138
+				$a2 = $v['s1']['a2'];
1139
+				$this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
1140
+			}
1141
+		} else {
1142
+			if ($s) {
1143
+				$xc = $v['s1']['x'];
1144
+				$yc = $v['s1']['y'];
1145
+				$a1 = $v['s1']['a1'];
1146
+				$a2 = $v['s1']['a2'];
1147
+				$this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, true, false, $trans);
1148
+			} else {
1149
+				$xc = $v['s2']['x'];
1150
+				$yc = $v['s2']['y'];
1151
+				$a1 = $v['s2']['a1'];
1152
+				$a2 = $v['s2']['a2'];
1153
+				$this->_Arc($xc, $yc, $rx, $ry, $a1, $a2, false, false, $trans);
1154
+			}
1155
+		}
1156
+	}
1157
+
1158
+	/**
1159
+	 * SVG - transform the point (reference)
1160
+	 *
1161
+	 * @param float &$x
1162
+	 * @param float &$y
1163
+	 * @param boolean $trans true => convert into PDF unit
1164
+	 * @param double $x
1165
+	 * @param double $y
1166
+	 * @return boolean
1167
+	 * @access public
1168
+	 */
1169
+	public function ptTransform(&$x, &$y, $trans = true)
1170
+	{
1171
+		// load the last Transfomation Matrix
1172
+		$nb = count($this->_transf);
1173
+		if ($nb)    $m = $this->_transf[$nb - 1];
1174
+		else        $m = array(1, 0, 0, 1, 0, 0);
1175
+
1176
+		// apply the Transformation Matrix
1177
+		list($x, $y) = array(($x * $m[0] + $y * $m[2] + $m[4]), ($x * $m[1] + $y * $m[3] + $m[5]));
1178
+
1179
+		// if true => convert into PDF unit
1180
+		if ($trans) {
1181
+			$x = $x * $this->k;
1182
+			$y = ($this->h - $y) * $this->k;
1183
+		}
1184
+
1185
+		return true;
1186
+	}
1187
+
1188
+	/**
1189
+	 * SVG - add a transformation Matric
1190
+	 *
1191
+	 * @param array $n matrix
1192
+	 * @access public
1193
+	 */
1194
+	public function doTransform($n = null)
1195
+	{
1196
+		// get the last Transformation Matrix
1197
+		$nb = count($this->_transf);
1198
+		if ($nb)    $m = $this->_transf[$nb - 1];
1199
+		else        $m = array(1, 0, 0, 1, 0, 0);
1200
+
1201
+		// if no transform, get the Identity Matrix
1202
+		if ( ! $n) $n = array(1, 0, 0, 1, 0, 0);
1203
+
1204
+		// create the new Transformation Matrix
1205
+		$this->_transf[] = array(
1206
+			$m[0] * $n[0] + $m[2] * $n[1],
1207
+			$m[1] * $n[0] + $m[3] * $n[1],
1208
+			$m[0] * $n[2] + $m[2] * $n[3],
1209
+			$m[1] * $n[2] + $m[3] * $n[3],
1210
+			$m[0] * $n[4] + $m[2] * $n[5] + $m[4],
1211
+			$m[1] * $n[4] + $m[3] * $n[5] + $m[5]
1212
+		);
1213
+	}
1214
+
1215
+	/**
1216
+	 * SVG - remove a transformation Matric
1217
+	 *
1218
+	 * @access public
1219
+	 */
1220
+	public function undoTransform()
1221
+	{
1222
+		array_pop($this->_transf);
1223
+	}
1224
+
1225
+	/**
1226
+	 * Convert a HTML2PDF barcode in a TCPDF barcode
1227
+	 *
1228
+	 * @param string $code code to print
1229
+	 * @param string $type type of barcode (see tcpdf/barcodes.php for supported formats)
1230
+	 * @param int $x x position in user units
1231
+	 * @param int $y y position in user units
1232
+	 * @param int $w width in user units
1233
+	 * @param int $h height in user units
1234
+	 * @param int $labelFontsize of the Test Label. If false : no Label
1235
+	 * @param array $color color of the foreground
1236
+	 * @access public
1237
+	 */
1238
+	public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color)
1239
+	{
1240
+		// the style of the barcode
1241
+		$style = array(
1242
+			'position' => 'S',
1243
+			'text' => ($labelFontsize ? true : false),
1244
+			'fgcolor' => $color,
1245
+			'bgcolor' => false,
1246
+		);
1247
+
1248
+		// build the barcode
1249
+		$this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
1250
+
1251
+		// it Label => add the FontSize to the height
1252
+		if ($labelFontsize) $h += ($labelFontsize);
1253
+
1254
+		// return the size of the barcode
1255
+		return array($w, $h);
1256
+	}
1257
+
1258
+	/**
1259
+	 * create a automatic Index on a page
1260
+	 *
1261
+	 * @param html2pdf $obj           parent object
1262
+	 * @param string   $titre         Title of the Index Page
1263
+	 * @param integer  $sizeTitle     Font size for hthe Title
1264
+	 * @param integer  $sizeBookmark  Font size for the bookmarks
1265
+	 * @param boolean  $bookmarkTitle Bookmark the Title
1266
+	 * @param boolean  $displayPage   Display the page number for each bookmark
1267
+	 * @param integer  $page draw the automatic Index on a specific Page. if null => add a page at the end
1268
+	 * @param string   $fontName      FontName to use
1269
+	 * @access public
1270
+	 */
1271
+	public function createIndex(
1272
+		&$obj,
1273
+		$titre = 'Index',
1274
+		$sizeTitle = 20,
1275
+		$sizeBookmark = 15,
1276
+		$bookmarkTitle = true,
1277
+		$displayPage = true,
1278
+		$page = null,
1279
+		$fontName = 'helvetica')
1280
+	{
1281
+		// bookmark the Title if wanted
1282
+		if ($bookmarkTitle) {
1283
+			$this->Bookmark($titre, 0, -1);
1284
+		}
1285
+
1286
+		// display the Title with the good Font size
1287
+		$this->SetFont($fontName, '', $sizeTitle);
1288
+		$this->Cell(0, 5, $titre, 0, 1, 'C');
1289
+
1290
+		// set the good Font size for the bookmarks
1291
+		$this->SetFont($fontName, '', $sizeBookmark);
1292
+		$this->Ln(10);
1293
+
1294
+		// get the number of bookmarks
1295
+		$size = sizeof($this->outlines);
1296
+
1297
+		// get the size of the "P. xx" cell
1298
+		$pageCellSize = $this->GetStringWidth('p. '.$this->outlines[$size - 1]['p']) + 2;
1299
+
1300
+		// Foreach bookmark
1301
+		for ($i = 0; $i < $size; $i++) {
1302
+			// if we need a new page => add a new page
1303
+			if ($this->getY() + $this->FontSize >= ($this->h - $this->bMargin)) {
1304
+				$obj->_INDEX_NewPage($page);
1305
+				$this->SetFont($fontName, '', $sizeBookmark);
1306
+			}
1307
+
1308
+			// Offset of the current level
1309
+			$level = $this->outlines[$i]['l'];
1310
+			if ($level > 0) $this->Cell($level * 8);
1311
+
1312
+			// Caption (cut to fit on the width page)
1313
+			$str = $this->outlines[$i]['t'];
1314
+			$strsize = $this->GetStringWidth($str);
1315
+			$availableSize = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - 4;
1316
+			while ($strsize >= $availableSize) {
1317
+				$str = substr($str, 0, -1);
1318
+				$strsize = $this->GetStringWidth($str);
1319
+			}
1320
+
1321
+			// if we want to display the page nmber
1322
+			if ($displayPage) {
1323
+				// display the Bookmark Caption
1324
+				$this->Cell($strsize + 2, $this->FontSize + 2, $str);
1325
+
1326
+				//Filling dots
1327
+				$w = $this->w - $this->lMargin - $this->rMargin - $pageCellSize - ($level * 8) - ($strsize + 2);
1328
+				$nb = $w / $this->GetStringWidth('.');
1329
+				$dots = str_repeat('.', $nb);
1330
+				$this->Cell($w, $this->FontSize + 2, $dots, 0, 0, 'R');
1331
+
1332
+				//Page number
1333
+				$this->Cell($pageCellSize, $this->FontSize + 2, 'p. '.$this->outlines[$i]['p'], 0, 1, 'R');
1334
+			} else {
1335
+				// display the Bookmark Caption
1336
+				$this->Cell($strsize + 2, $this->FontSize + 2, $str, 0, 1);
1337
+			}
1338
+		}
1339
+	}
1340
+
1341
+	/**
1342
+	 * Returns the string alias used for the total number of pages.
1343
+	 *
1344
+	 * @access public
1345
+	 * @return string;
1346
+	 * @see TCPDF::getAliasNbPages(), TCPDF::getPageGroupAlias()
1347
+	 */
1348
+	public function getMyAliasNbPages()
1349
+	{
1350
+		if ($this->_myLastPageGroupNb == 0) {
1351
+			return $this->getAliasNbPages();
1352
+		} else {
1353
+			$old = $this->currpagegroup;
1354
+			$this->currpagegroup = '{nb'.$this->_myLastPageGroupNb.'}';
1355
+			$new = $this->getPageGroupAlias();
1356
+			$this->currpagegroup = $old;
1357
+
1358
+			return $new;
1359
+		}
1360
+	}
1361
+
1362
+	/**
1363
+	 * Returns the current page number.
1364
+	 *
1365
+	 * @access public
1366
+	 * @param  integer $page
1367
+	 * @return integer;
1368
+	 */
1369
+	public function getMyNumPage($page = null)
1370
+	{
1371
+		if ($page === null) {
1372
+			$page = $this->page;
1373
+		}
1374
+
1375
+		if ($this->_myLastPageGroupNb == 0) {
1376
+			return $page;
1377
+		} else {
1378
+			return $page - $this->_myLastPageGroup;
1379
+		}
1380
+	}
1381
+
1382
+	/**
1383
+	 * Start a new group of pages
1384
+	 *
1385
+	 * @access public
1386
+	 * @return integer;
1387
+	 * @see tcpdf::startPageGroup
1388
+	 */
1389
+	public function myStartPageGroup()
1390
+	{
1391
+		$this->_myLastPageGroup = $this->page - 1;
1392
+		$this->_myLastPageGroupNb++;
1393
+	}
1394
+
1395
+	/**
1396
+	 * get $_myLastPageGroup;
1397
+	 *
1398
+	 * @access public
1399
+	 * @return integer $_myLastPageGroup;
1400
+	 */
1401
+	public function getMyLastPageGroup()
1402
+	{
1403
+		return $this->_myLastPageGroup;
1404
+	}
1405
+
1406
+	/**
1407
+	 * set $_myLastPageGroup;
1408
+	 *
1409
+	 * @access public
1410
+	 * @param integer $myLastPageGroup;
1411
+	 * @param integer $myLastPageGroup
1412
+	 */
1413
+	public function setMyLastPageGroup($myLastPageGroup)
1414
+	{
1415
+		$this->_myLastPageGroup = $myLastPageGroup;
1416
+	}
1417
+
1418
+	/**
1419
+	 * get $_myLastPageGroupNb;
1420
+	 *
1421
+	 * @access public
1422
+	 * @return integer $_myLastPageGroupNb;
1423
+	 */
1424
+	public function getMyLastPageGroupNb()
1425
+	{
1426
+		return $this->_myLastPageGroupNb;
1427
+	}
1428
+
1429
+	/**
1430
+	 * set $_myLastPageGroupNb;
1431
+	 *
1432
+	 * @access public
1433
+	 * @param integer $myLastPageGroupNb;
1434
+	 * @param integer $myLastPageGroupNb
1435
+	 */
1436
+	public function setMyLastPageGroupNb($myLastPageGroupNb)
1437
+	{
1438
+		$this->_myLastPageGroupNb = $myLastPageGroupNb;
1439
+	}
1440 1440
 }
Please login to merge, or discard this patch.