From 29561fb5916fed48baa64084cbfc86a4b8fbb56c Mon Sep 17 00:00:00 2001
From: Adrien <af@brain-networks.fr>
Date: Mon, 7 Jan 2019 17:36:50 +0100
Subject: [PATCH] Module constructor php 7

---
 modules/Campaigns/Campaigns.php            |  10 +-
 modules/Contacts/Contacts.php              |  10 +-
 modules/CustomView/CustomView.php          |  21 +--
 modules/Documents/Documents.php            |  14 +-
 modules/Emails/Emails.php                  |  15 +-
 modules/Faq/Faq.php                        |  13 +-
 modules/HelpDesk/HelpDesk.php              |  13 +-
 modules/Install/models/ConfigFileUtils.php |  54 +++----
 modules/Invoice/Invoice.php                |  13 +-
 modules/Leads/Leads.php                    |  13 +-
 modules/Potentials/Potentials.php          |  11 +-
 modules/PriceBooks/PriceBooks.php          |  13 +-
 modules/Products/Products.php              |  13 +-
 modules/PurchaseOrder/PurchaseOrder.php    |   9 +-
 modules/Quotes/Quotes.php                  |   9 +-
 modules/Reports/ReportRun.php              |  19 +--
 modules/Reports/Reports.php                | 160 +++++++++++----------
 modules/SalesOrder/SalesOrder.php          |   9 +-
 modules/Users/DefaultDataPopulator.php     |   7 +-
 modules/Users/Users.php                    |  30 ++--
 modules/Vendors/Vendors.php                |  13 +-
 21 files changed, 265 insertions(+), 204 deletions(-)

diff --git a/modules/Campaigns/Campaigns.php b/modules/Campaigns/Campaigns.php
index cc99d855f..206e4b8b5 100644
--- a/modules/Campaigns/Campaigns.php
+++ b/modules/Campaigns/Campaigns.php
@@ -68,12 +68,14 @@ class Campaigns extends CRMEntity {
 
 	// For Alphabetical search
 	var $def_basicsearch_col = 'campaignname';
-
+        function __construct() {
+            $this->log =LoggerManager::getLogger('campaign');
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Campaigns');
+        }   
 	function Campaigns()
 	{
-		$this->log =LoggerManager::getLogger('campaign');
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Campaigns');
+            self::__construct();	
 	}
 
 	/** Function to handle module specific operations when saving a entity
diff --git a/modules/Contacts/Contacts.php b/modules/Contacts/Contacts.php
index 2e33d8b7a..e87bee5bc 100644
--- a/modules/Contacts/Contacts.php
+++ b/modules/Contacts/Contacts.php
@@ -144,11 +144,13 @@ class Contacts extends CRMEntity {
 		'Emails' => array('table_name' => 'vtiger_seactivityrel', 'table_index' => 'crmid', 'rel_index' => 'activityid'),
         'Vendors' => array('table_name' => 'vtiger_vendorcontactrel', 'table_index' => 'vendorid', 'rel_index' => 'contactid'),
 	);
-
+        function __construct() {
+            $this->log = LoggerManager::getLogger('contact');
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Contacts');
+        }       
 	function Contacts() {
-		$this->log = LoggerManager::getLogger('contact');
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Contacts');
+            self::__construct();
 	}
 
 	// Mike Crowe Mod --------------------------------------------------------Default ordering for us
diff --git a/modules/CustomView/CustomView.php b/modules/CustomView/CustomView.php
index db8bf8c97..af3ea9c50 100644
--- a/modules/CustomView/CustomView.php
+++ b/modules/CustomView/CustomView.php
@@ -52,16 +52,19 @@ class CustomView extends CRMEntity {
 	 * @param $module -- The module Name:: Type String(optional)
 	 * @returns  nothing
 	 */
+        function __construct($module = "") {
+            global $current_user;
+            $this->customviewmodule = $module;
+            $this->escapemodule[] = $module . "_";
+            $this->escapemodule[] = "_";
+            $this->smownerid = $current_user->id;
+            $this->moduleMetaInfo = array();
+            if ($module != "" && $module != 'Calendar') {
+                    $this->meta = $this->getMeta($module, $current_user);
+            }
+        }   
 	function CustomView($module = "") {
-		global $current_user, $adb;
-		$this->customviewmodule = $module;
-		$this->escapemodule[] = $module . "_";
-		$this->escapemodule[] = "_";
-		$this->smownerid = $current_user->id;
-		$this->moduleMetaInfo = array();
-		if ($module != "" && $module != 'Calendar') {
-			$this->meta = $this->getMeta($module, $current_user);
-		}
+            self::__construct($module);
 	}
 
 	/**
diff --git a/modules/Documents/Documents.php b/modules/Documents/Documents.php
index 1a615f67e..e740b3876 100644
--- a/modules/Documents/Documents.php
+++ b/modules/Documents/Documents.php
@@ -70,12 +70,16 @@ class Documents extends CRMEntity {
 	//Added these variables which are used as default order by and sortorder in ListView
 	var $default_order_by = 'title';
 	var $default_sort_order = 'ASC';
+        
+        function __construct() {
+            $this->log = LoggerManager::getLogger('notes');
+            $this->log->debug("Entering Documents() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Documents');
+            $this->log->debug("Exiting Documents method ...");
+        }   
 	function Documents() {
-		$this->log = LoggerManager::getLogger('notes');
-		$this->log->debug("Entering Documents() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Documents');
-		$this->log->debug("Exiting Documents method ...");
+            self::__construct();
 	}
 
 	function save_module($module)
diff --git a/modules/Emails/Emails.php b/modules/Emails/Emails.php
index f3dac4473..bcb39fcc5 100644
--- a/modules/Emails/Emails.php
+++ b/modules/Emails/Emails.php
@@ -67,13 +67,16 @@ class Emails extends CRMEntity {
 
 	/** This function will set the columnfields for Email module
 	 */
+        function __construct() {
+            $this->log = LoggerManager::getLogger('email');
+            $this->log->debug("Entering Emails() method ...");
+            $this->log = LoggerManager::getLogger('email');
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Emails');
+            $this->log->debug("Exiting Email method ...");
+        }   
 	function Emails() {
-		$this->log = LoggerManager::getLogger('email');
-		$this->log->debug("Entering Emails() method ...");
-		$this->log = LoggerManager::getLogger('email');
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Emails');
-		$this->log->debug("Exiting Email method ...");
+            self::__construct();
 	}
 
 	function save_module($module) {
diff --git a/modules/Faq/Faq.php b/modules/Faq/Faq.php
index 992fd0a75..3cbd5f538 100755
--- a/modules/Faq/Faq.php
+++ b/modules/Faq/Faq.php
@@ -79,12 +79,15 @@ class Faq extends CRMEntity {
 
 	/**	Constructor which will set the column_fields in this object
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('faq');
+            $this->log->debug("Entering Faq() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Faq');
+            $this->log->debug("Exiting Faq method ...");
+        }   
 	function Faq() {
-		$this->log =LoggerManager::getLogger('faq');
-		$this->log->debug("Entering Faq() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Faq');
-		$this->log->debug("Exiting Faq method ...");
+            self::__construct();
 	}
 
 	function save_module($module)
diff --git a/modules/HelpDesk/HelpDesk.php b/modules/HelpDesk/HelpDesk.php
index 9bd40d4b2..b173438a3 100644
--- a/modules/HelpDesk/HelpDesk.php
+++ b/modules/HelpDesk/HelpDesk.php
@@ -100,13 +100,16 @@ class HelpDesk extends CRMEntity {
 
 	/**	Constructor which will set the column_fields in this object
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('helpdesk');
+            $this->log->debug("Entering HelpDesk() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('HelpDesk');
+            $this->log->debug("Exiting HelpDesk method ...");
+        }   
 	function HelpDesk()
 	{
-		$this->log =LoggerManager::getLogger('helpdesk');
-		$this->log->debug("Entering HelpDesk() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('HelpDesk');
-		$this->log->debug("Exiting HelpDesk method ...");
+            self::__construct();
 	}
 
 
diff --git a/modules/Install/models/ConfigFileUtils.php b/modules/Install/models/ConfigFileUtils.php
index b5b89fc41..b7d202970 100644
--- a/modules/Install/models/ConfigFileUtils.php
+++ b/modules/Install/models/ConfigFileUtils.php
@@ -24,32 +24,36 @@ class Install_ConfigFileUtils_Model {
 	private $currencyName;
 	private $adminEmail;
 
+        function __construct($configFileParameters) {
+            if (isset($configFileParameters['root_directory'])){
+                $this->rootDirectory = $configFileParameters['root_directory'];
+            }
+
+        if (isset($configFileParameters['db_hostname'])) {
+                    if(strpos($configFileParameters['db_hostname'], ":")) {
+                            list($this->dbHostname,$this->dbPort) = explode(":",$configFileParameters['db_hostname']);
+                    } else {
+                            $this->dbHostname = $configFileParameters['db_hostname'];
+                    }
+            }
+
+            if (isset($configFileParameters['db_username'])) $this->dbUsername = $configFileParameters['db_username'];
+            if (isset($configFileParameters['db_password'])) $this->dbPassword = $configFileParameters['db_password'];
+            if (isset($configFileParameters['db_name'])) $this->dbName = $configFileParameters['db_name'];
+            if (isset($configFileParameters['db_type'])) $this->dbType = $configFileParameters['db_type'];
+            if (isset($configFileParameters['site_URL'])) $this->siteUrl = $configFileParameters['site_URL'];
+            if (isset($configFileParameters['admin_email'])) $this->adminEmail = $configFileParameters['admin_email'];
+            if (isset($configFileParameters['currency_name'])) $this->currencyName = $configFileParameters['currency_name'];
+            if (isset($configFileParameters['vt_charset'])) $this->vtCharset = $configFileParameters['vt_charset'];
+            if (isset($configFileParameters['default_language'])) $this->vtDefaultLanguage = $configFileParameters['default_language'];
+
+            // update default port
+            if ($this->dbPort == '') $this->dbPort = self::getDbDefaultPort($this->dbType);
+
+            $this->cacheDir = 'cache/';
+        }   
 	function Install_ConfigFileUtils_Model($configFileParameters) {
-		if (isset($configFileParameters['root_directory']))
-			$this->rootDirectory = $configFileParameters['root_directory'];
-
-		if (isset($configFileParameters['db_hostname'])) {
-			if(strpos($configFileParameters['db_hostname'], ":")) {
-				list($this->dbHostname,$this->dbPort) = explode(":",$configFileParameters['db_hostname']);
-			} else {
-				$this->dbHostname = $configFileParameters['db_hostname'];
-			}
-		}
-
-		if (isset($configFileParameters['db_username'])) $this->dbUsername = $configFileParameters['db_username'];
-		if (isset($configFileParameters['db_password'])) $this->dbPassword = $configFileParameters['db_password'];
-		if (isset($configFileParameters['db_name'])) $this->dbName = $configFileParameters['db_name'];
-		if (isset($configFileParameters['db_type'])) $this->dbType = $configFileParameters['db_type'];
-		if (isset($configFileParameters['site_URL'])) $this->siteUrl = $configFileParameters['site_URL'];
-		if (isset($configFileParameters['admin_email'])) $this->adminEmail = $configFileParameters['admin_email'];
-		if (isset($configFileParameters['currency_name'])) $this->currencyName = $configFileParameters['currency_name'];
-		if (isset($configFileParameters['vt_charset'])) $this->vtCharset = $configFileParameters['vt_charset'];
-		if (isset($configFileParameters['default_language'])) $this->vtDefaultLanguage = $configFileParameters['default_language'];
-
-		// update default port
-		if ($this->dbPort == '') $this->dbPort = self::getDbDefaultPort($this->dbType);
-
-		$this->cacheDir = 'cache/';
+            self::__construct($configFileParameters);
 	}
 
 	static function getDbDefaultPort($dbType) {
diff --git a/modules/Invoice/Invoice.php b/modules/Invoice/Invoice.php
index 01b57227b..46f8f255f 100755
--- a/modules/Invoice/Invoice.php
+++ b/modules/Invoice/Invoice.php
@@ -104,12 +104,15 @@ class Invoice extends CRMEntity {
 
 	/**	Constructor which will set the column_fields in this object
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('Invoice');
+            $this->log->debug("Entering Invoice() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Invoice');
+            $this->log->debug("Exiting Invoice method ...");
+        }   
 	function Invoice() {
-		$this->log =LoggerManager::getLogger('Invoice');
-		$this->log->debug("Entering Invoice() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Invoice');
-		$this->log->debug("Exiting Invoice method ...");
+            self::__construct();
 	}
 
 
diff --git a/modules/Leads/Leads.php b/modules/Leads/Leads.php
index bd7bb6ae6..25f47856a 100755
--- a/modules/Leads/Leads.php
+++ b/modules/Leads/Leads.php
@@ -85,12 +85,15 @@ class Leads extends CRMEntity {
 	var $LBL_LEAD_MAPPING = 'LBL_LEAD_MAPPING';
 	//var $groupTable = Array('vtiger_leadgrouprelation','leadid');
 
+        function __construct() {
+            $this->log = LoggerManager::getLogger('lead');
+            $this->log->debug("Entering Leads() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Leads');
+            $this->log->debug("Exiting Lead method ...");
+        }   
 	function Leads()	{
-		$this->log = LoggerManager::getLogger('lead');
-		$this->log->debug("Entering Leads() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Leads');
-		$this->log->debug("Exiting Lead method ...");
+            self::__construct();
 	}
 
 	/** Function to handle module specific operations when saving a entity
diff --git a/modules/Potentials/Potentials.php b/modules/Potentials/Potentials.php
index b58308fa0..96e1f9a9c 100644
--- a/modules/Potentials/Potentials.php
+++ b/modules/Potentials/Potentials.php
@@ -92,10 +92,13 @@ class Potentials extends CRMEntity {
 
 	var $LBL_POTENTIAL_MAPPING = 'LBL_OPPORTUNITY_MAPPING';
 	//var $groupTable = Array('vtiger_potentialgrouprelation','potentialid');
-	function Potentials() {
-		$this->log = LoggerManager::getLogger('potential');
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Potentials');
+	function __construct() {
+            $this->log = LoggerManager::getLogger('potential');
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Potentials');
+        }   
+        function Potentials() {
+            self::__construct();
 	}
 
 	function save_module($module)
diff --git a/modules/PriceBooks/PriceBooks.php b/modules/PriceBooks/PriceBooks.php
index 725c35611..44efad2d6 100755
--- a/modules/PriceBooks/PriceBooks.php
+++ b/modules/PriceBooks/PriceBooks.php
@@ -54,12 +54,15 @@ class PriceBooks extends CRMEntity {
 
 	/**	Constructor which will set the column_fields in this object
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('pricebook');
+            $this->log->debug("Entering PriceBooks() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('PriceBooks');
+            $this->log->debug("Exiting PriceBook method ...");
+        }
 	function PriceBooks() {
-		$this->log =LoggerManager::getLogger('pricebook');
-		$this->log->debug("Entering PriceBooks() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('PriceBooks');
-		$this->log->debug("Exiting PriceBook method ...");
+            self::__construct();
 	}
 
 	function save_module($module)
diff --git a/modules/Products/Products.php b/modules/Products/Products.php
index 3d2449677..4ea28bde2 100755
--- a/modules/Products/Products.php
+++ b/modules/Products/Products.php
@@ -73,12 +73,15 @@ class Products extends CRMEntity {
 
 	/**	Constructor which will set the column_fields in this object
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('product');
+            $this->log->debug("Entering Products() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Products');
+            $this->log->debug("Exiting Product method ...");
+        }
 	function Products() {
-		$this->log =LoggerManager::getLogger('product');
-		$this->log->debug("Entering Products() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Products');
-		$this->log->debug("Exiting Product method ...");
+            self::__construct();	
 	}
 
 	function save_module($module)
diff --git a/modules/PurchaseOrder/PurchaseOrder.php b/modules/PurchaseOrder/PurchaseOrder.php
index 81c15375a..452e3510f 100644
--- a/modules/PurchaseOrder/PurchaseOrder.php
+++ b/modules/PurchaseOrder/PurchaseOrder.php
@@ -97,10 +97,13 @@ class PurchaseOrder extends CRMEntity {
 	 *  This function creates an instance of LoggerManager class using getLogger method
 	 *  creates an instance for PearDatabase class and get values for column_fields array of Order class.
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('PurchaseOrder');
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('PurchaseOrder');
+        }
 	function PurchaseOrder() {
-		$this->log =LoggerManager::getLogger('PurchaseOrder');
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('PurchaseOrder');
+            self::__construct();
 	}
 
 	function save_module($module)
diff --git a/modules/Quotes/Quotes.php b/modules/Quotes/Quotes.php
index 4df4199d4..19089618a 100755
--- a/modules/Quotes/Quotes.php
+++ b/modules/Quotes/Quotes.php
@@ -104,10 +104,13 @@ class Quotes extends CRMEntity {
 
 	/**	Constructor which will set the column_fields in this object
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('quote');
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Quotes');
+        }
 	function Quotes() {
-		$this->log =LoggerManager::getLogger('quote');
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Quotes');
+            self::__construct();
 	}
 
 	function save_module()
diff --git a/modules/Reports/ReportRun.php b/modules/Reports/ReportRun.php
index 617ec6ba5..1d6525bd8 100644
--- a/modules/Reports/ReportRun.php
+++ b/modules/Reports/ReportRun.php
@@ -325,15 +325,18 @@ class ReportRun extends CRMEntity {
 	 *  To ensure single-instance is present for $reportid
 	 *  as we optimize using ReportRunPlanner and setup temporary tables.
 	 */
+        function __construct($reportid) {
+            $oReport = new Reports($reportid);
+            $this->reportid = $reportid;
+            $this->primarymodule = $oReport->primodule;
+            $this->secondarymodule = $oReport->secmodule;
+            $this->reporttype = $oReport->reporttype;
+            $this->reportname = $oReport->reportname;
+            $this->queryPlanner = new ReportRunQueryPlanner();
+            $this->queryPlanner->reportRun = $this;
+        }
 	function ReportRun($reportid) {
-		$oReport = new Reports($reportid);
-		$this->reportid = $reportid;
-		$this->primarymodule = $oReport->primodule;
-		$this->secondarymodule = $oReport->secmodule;
-		$this->reporttype = $oReport->reporttype;
-		$this->reportname = $oReport->reportname;
-		$this->queryPlanner = new ReportRunQueryPlanner();
-		$this->queryPlanner->reportRun = $this;
+            self::__construct($reportid);
 	}
 
 	public static function getInstance($reportid) {
diff --git a/modules/Reports/Reports.php b/modules/Reports/Reports.php
index 65efa848d..44ceb2a5f 100644
--- a/modules/Reports/Reports.php
+++ b/modules/Reports/Reports.php
@@ -110,87 +110,89 @@ class Reports extends CRMEntity{
 	 *  This function accepts the vtiger_reportid as argument
 	 *  It sets primodule,secmodule,reporttype,reportname,reportdescription,folderid for the given vtiger_reportid
 	 */
-
+        function __construct($reportid="") {
+            global $adb,$current_user,$theme,$mod_strings;
+            $this->initListOfModules();
+            if($reportid != "")
+            {
+                // Lookup information in cache first
+                $cachedInfo = VTCacheUtils::lookupReport_Info($current_user->id, $reportid);
+                $subordinate_users = VTCacheUtils::lookupReport_SubordinateUsers($reportid);
+
+                $reportModel = Reports_Record_Model::getCleanInstance($reportid);
+                $sharingType = $reportModel->get('sharingtype');
+
+                if($cachedInfo === false) {
+                        $ssql = "select vtiger_reportmodules.*,vtiger_report.* from vtiger_report inner join vtiger_reportmodules on vtiger_report.reportid = vtiger_reportmodules.reportmodulesid";
+                        $ssql .= " where vtiger_report.reportid = ?";
+                        $params = array($reportid);
+
+                        require_once('include/utils/GetUserGroups.php');
+                        require('user_privileges/user_privileges_'.$current_user->id.'.php');
+                        $userGroups = new GetUserGroups();
+                        $userGroups->getAllUserGroups($current_user->id);
+                        $user_groups = $userGroups->user_groups;
+                        if(!empty($user_groups) && $sharingType == 'Private'){
+                                $user_group_query = " (shareid IN (".generateQuestionMarks($user_groups).") AND setype='groups') OR";
+                                array_push($params, $user_groups);
+                        }
+
+                        $non_admin_query = " vtiger_report.reportid IN (SELECT reportid from vtiger_reportsharing WHERE $user_group_query (shareid=? AND setype='users'))";
+                        if($sharingType == 'Private'){
+                                $ssql .= " and (( (".$non_admin_query.") or vtiger_report.sharingtype='Public' or vtiger_report.owner = ? or vtiger_report.owner in(select vtiger_user2role.userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'))";
+                                array_push($params, $current_user->id);
+                                array_push($params, $current_user->id);
+                        }
+
+                        $query = $adb->pquery("select userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'",array());
+                        $subordinate_users = Array();
+                        for($i=0;$i<$adb->num_rows($query);$i++){
+                                $subordinate_users[] = $adb->query_result($query,$i,'userid');
+                        }
+
+                        // Update subordinate user information for re-use
+                        VTCacheUtils::updateReport_SubordinateUsers($reportid, $subordinate_users);
+
+                        //Report sharing for vtiger7
+                        $queryObj = new stdClass();
+                        $queryObj->query = $ssql;
+                        $queryObj->queryParams = $params;
+                        $queryObj = self::getReportSharingQuery($queryObj, $sharingType);
+
+                        $result = $adb->pquery($queryObj->query, $queryObj->queryParams);
+                        if($result && $adb->num_rows($result)) {
+                                $reportmodulesrow = $adb->fetch_array($result);
+
+                                // Update information in cache now
+                                VTCacheUtils::updateReport_Info(
+                                        $current_user->id, $reportid, $reportmodulesrow["primarymodule"],
+                                        $reportmodulesrow["secondarymodules"], $reportmodulesrow["reporttype"],
+                                        $reportmodulesrow["reportname"], $reportmodulesrow["description"],
+                                        $reportmodulesrow["folderid"], $reportmodulesrow["owner"]
+                                );
+                        }
+
+                        // Re-look at cache to maintain code-consistency below
+                        $cachedInfo = VTCacheUtils::lookupReport_Info($current_user->id, $reportid);
+                }
+
+                if($cachedInfo) {
+                        $this->primodule = $cachedInfo["primarymodule"];
+                        $this->secmodule = $cachedInfo["secondarymodules"];
+                        $this->reporttype = $cachedInfo["reporttype"];
+                        $this->reportname = decode_html($cachedInfo["reportname"]);
+                        $this->reportdescription = decode_html($cachedInfo["description"]);
+                        $this->folderid = $cachedInfo["folderid"];
+                        if($is_admin==true || in_array($cachedInfo["owner"],$subordinate_users) || $cachedInfo["owner"]==$current_user->id)
+                                $this->is_editable = 'true';
+                        else
+                                $this->is_editable = 'false';
+                } 
+            }
+        }
 	function Reports($reportid="")
 	{
-		global $adb,$current_user,$theme,$mod_strings;
-		$this->initListOfModules();
-		if($reportid != "")
-		{
-			// Lookup information in cache first
-			$cachedInfo = VTCacheUtils::lookupReport_Info($current_user->id, $reportid);
-			$subordinate_users = VTCacheUtils::lookupReport_SubordinateUsers($reportid);
-			
-			$reportModel = Reports_Record_Model::getCleanInstance($reportid);
-			$sharingType = $reportModel->get('sharingtype');
-			
-			if($cachedInfo === false) {
-				$ssql = "select vtiger_reportmodules.*,vtiger_report.* from vtiger_report inner join vtiger_reportmodules on vtiger_report.reportid = vtiger_reportmodules.reportmodulesid";
-				$ssql .= " where vtiger_report.reportid = ?";
-				$params = array($reportid);
-
-				require_once('include/utils/GetUserGroups.php');
-				require('user_privileges/user_privileges_'.$current_user->id.'.php');
-				$userGroups = new GetUserGroups();
-				$userGroups->getAllUserGroups($current_user->id);
-				$user_groups = $userGroups->user_groups;
-				if(!empty($user_groups) && $sharingType == 'Private'){
-					$user_group_query = " (shareid IN (".generateQuestionMarks($user_groups).") AND setype='groups') OR";
-					array_push($params, $user_groups);
-				}
-
-				$non_admin_query = " vtiger_report.reportid IN (SELECT reportid from vtiger_reportsharing WHERE $user_group_query (shareid=? AND setype='users'))";
-				if($sharingType == 'Private'){
-					$ssql .= " and (( (".$non_admin_query.") or vtiger_report.sharingtype='Public' or vtiger_report.owner = ? or vtiger_report.owner in(select vtiger_user2role.userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'))";
-					array_push($params, $current_user->id);
-					array_push($params, $current_user->id);
-				}
-
-				$query = $adb->pquery("select userid from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like '".$current_user_parent_role_seq."::%'",array());
-				$subordinate_users = Array();
-				for($i=0;$i<$adb->num_rows($query);$i++){
-					$subordinate_users[] = $adb->query_result($query,$i,'userid');
-				}
-
-				// Update subordinate user information for re-use
-				VTCacheUtils::updateReport_SubordinateUsers($reportid, $subordinate_users);
-				
-				//Report sharing for vtiger7
-				$queryObj = new stdClass();
-				$queryObj->query = $ssql;
-				$queryObj->queryParams = $params;
-				$queryObj = self::getReportSharingQuery($queryObj, $sharingType);
-				
-				$result = $adb->pquery($queryObj->query, $queryObj->queryParams);
-				if($result && $adb->num_rows($result)) {
-					$reportmodulesrow = $adb->fetch_array($result);
-
-					// Update information in cache now
-					VTCacheUtils::updateReport_Info(
-						$current_user->id, $reportid, $reportmodulesrow["primarymodule"],
-						$reportmodulesrow["secondarymodules"], $reportmodulesrow["reporttype"],
-						$reportmodulesrow["reportname"], $reportmodulesrow["description"],
-						$reportmodulesrow["folderid"], $reportmodulesrow["owner"]
-					);
-				}
-
-				// Re-look at cache to maintain code-consistency below
-				$cachedInfo = VTCacheUtils::lookupReport_Info($current_user->id, $reportid);
-			}
-
-			if($cachedInfo) {
-				$this->primodule = $cachedInfo["primarymodule"];
-				$this->secmodule = $cachedInfo["secondarymodules"];
-				$this->reporttype = $cachedInfo["reporttype"];
-				$this->reportname = decode_html($cachedInfo["reportname"]);
-				$this->reportdescription = decode_html($cachedInfo["description"]);
-				$this->folderid = $cachedInfo["folderid"];
-				if($is_admin==true || in_array($cachedInfo["owner"],$subordinate_users) || $cachedInfo["owner"]==$current_user->id)
-					$this->is_editable = 'true';
-				else
-					$this->is_editable = 'false';
-			} 
-			}
+            self::__construct($reportid);
 	}
 
 	// Update the module list for listing columns for report creation.
diff --git a/modules/SalesOrder/SalesOrder.php b/modules/SalesOrder/SalesOrder.php
index 3e4b3e8ba..4e20c2ac8 100644
--- a/modules/SalesOrder/SalesOrder.php
+++ b/modules/SalesOrder/SalesOrder.php
@@ -106,10 +106,13 @@ class SalesOrder extends CRMEntity {
 	 *  This function creates an instance of LoggerManager class using getLogger method
 	 *  creates an instance for PearDatabase class and get values for column_fields array of SalesOrder class.
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('SalesOrder');
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('SalesOrder');
+        }
 	function SalesOrder() {
-		$this->log =LoggerManager::getLogger('SalesOrder');
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('SalesOrder');
+            self::__construct();
 	}
 
 	function save_module($module)
diff --git a/modules/Users/DefaultDataPopulator.php b/modules/Users/DefaultDataPopulator.php
index 3743a4311..ca62ac692 100644
--- a/modules/Users/DefaultDataPopulator.php
+++ b/modules/Users/DefaultDataPopulator.php
@@ -17,9 +17,12 @@ require_once('include/utils/utils.php');
  */
 class DefaultDataPopulator extends CRMEntity {
 
+        function __construct() {
+            $this->log = LoggerManager::getLogger('DefaultDataPopulator');
+            $this->db = PearDatabase::getInstance();
+        }
 	function DefaultDataPopulator() {
-		$this->log = LoggerManager::getLogger('DefaultDataPopulator');
-		$this->db = PearDatabase::getInstance();
+            self::__construct();
 	}
 
 	var $new_schema = true;
diff --git a/modules/Users/Users.php b/modules/Users/Users.php
index cf70a282d..75eccabd6 100755
--- a/modules/Users/Users.php
+++ b/modules/Users/Users.php
@@ -132,21 +132,23 @@ class Users extends CRMEntity {
 	 instantiates the Logger class and PearDatabase Class
 	 *
 	 */
-
+        function __construct() {
+            $this->log = LoggerManager::getLogger('user');
+            $this->log->debug("Entering Users() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->DEFAULT_PASSWORD_CRYPT_TYPE = (version_compare(PHP_VERSION, '5.3.0') >= 0)? 'PHP5.3MD5': 'MD5';
+            if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
+                    $this->DEFAULT_PASSWORD_CRYPT_TYPE = 'PHASH';
+            }
+            $this->column_fields = getColumnFields('Users');
+            $this->column_fields['currency_name'] = '';
+            $this->column_fields['currency_code'] = '';
+            $this->column_fields['currency_symbol'] = '';
+            $this->column_fields['conv_rate'] = '';
+            $this->log->debug("Exiting Users() method ...");
+        }
 	function Users() {
-		$this->log = LoggerManager::getLogger('user');
-		$this->log->debug("Entering Users() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->DEFAULT_PASSWORD_CRYPT_TYPE = (version_compare(PHP_VERSION, '5.3.0') >= 0)? 'PHP5.3MD5': 'MD5';
-		if (version_compare(PHP_VERSION, '5.5.0') >= 0) {
-			$this->DEFAULT_PASSWORD_CRYPT_TYPE = 'PHASH';
-		}
-		$this->column_fields = getColumnFields('Users');
-		$this->column_fields['currency_name'] = '';
-		$this->column_fields['currency_code'] = '';
-		$this->column_fields['currency_symbol'] = '';
-		$this->column_fields['conv_rate'] = '';
-		$this->log->debug("Exiting Users() method ...");
+            self::__construct();
 	}
 
 	/**
diff --git a/modules/Vendors/Vendors.php b/modules/Vendors/Vendors.php
index d76741a1f..e9cd0c16b 100755
--- a/modules/Vendors/Vendors.php
+++ b/modules/Vendors/Vendors.php
@@ -64,12 +64,15 @@ class Vendors extends CRMEntity {
 
 	/**	Constructor which will set the column_fields in this object
 	 */
+        function __construct() {
+            $this->log =LoggerManager::getLogger('vendor');
+            $this->log->debug("Entering Vendors() method ...");
+            $this->db = PearDatabase::getInstance();
+            $this->column_fields = getColumnFields('Vendors');
+            $this->log->debug("Exiting Vendor method ...");
+        }
 	function Vendors() {
-		$this->log =LoggerManager::getLogger('vendor');
-		$this->log->debug("Entering Vendors() method ...");
-		$this->db = PearDatabase::getInstance();
-		$this->column_fields = getColumnFields('Vendors');
-		$this->log->debug("Exiting Vendor method ...");
+            self::__construct();
 	}
 
 	function save_module($module)
-- 
GitLab