305 lines
13 KiB
PHP
305 lines
13 KiB
PHP
<?php
|
|
|
|
/*+***********************************************************************************
|
|
|
|
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
|
|
|
* ("License"); You may not use this file except in compliance with the License
|
|
|
|
* The Original Code is: vtiger CRM Open Source
|
|
|
|
* The Initial Developer of the Original Code is vtiger.
|
|
|
|
* Portions created by vtiger are Copyright (C) vtiger.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*************************************************************************************/
|
|
|
|
|
|
|
|
require_once 'SUtiles.php';
|
|
|
|
|
|
|
|
class Accounts_ListView_Model extends Vtiger_ListView_Model {
|
|
|
|
|
|
|
|
protected $isVMPharma = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to get the list of Mass actions for the module
|
|
|
|
* @param <Array> $linkParams
|
|
|
|
* @return <Array> - Associative array of Link type to List of Vtiger_Link_Model instances for Mass Actions
|
|
|
|
*/
|
|
|
|
public function getListViewMassActions($linkParams) {
|
|
|
|
$massActionLinks = parent::getListViewMassActions($linkParams);
|
|
|
|
|
|
|
|
$currentUserModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
|
|
|
|
$emailModuleModel = Vtiger_Module_Model::getInstance('Emails');
|
|
|
|
|
|
|
|
if($currentUserModel->hasModulePermission($emailModuleModel->getId())) {
|
|
|
|
$massActionLink = array(
|
|
|
|
'linktype' => 'LISTVIEWMASSACTION',
|
|
|
|
'linklabel' => 'LBL_SEND_EMAIL',
|
|
|
|
'linkurl' => 'javascript:Vtiger_List_Js.triggerSendEmail("index.php?module='.$this->getModule()->getName().'&view=MassActionAjax&mode=showComposeEmailForm&step=step1","Emails");',
|
|
|
|
'linkicon' => ''
|
|
|
|
);
|
|
|
|
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
$SMSNotifierModuleModel = Vtiger_Module_Model::getInstance('SMSNotifier');
|
|
|
|
if(!empty($SMSNotifierModuleModel) && $currentUserModel->hasModulePermission($SMSNotifierModuleModel->getId())) {
|
|
|
|
$massActionLink = array(
|
|
|
|
'linktype' => 'LISTVIEWMASSACTION',
|
|
|
|
'linklabel' => 'LBL_SEND_SMS',
|
|
|
|
'linkurl' => 'javascript:Vtiger_List_Js.triggerSendSms("index.php?module='.$this->getModule()->getName().'&view=MassActionAjax&mode=showSendSMSForm","SMSNotifier");',
|
|
|
|
'linkicon' => ''
|
|
|
|
);
|
|
|
|
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
$currentUser = Users_Record_Model::getCurrentUserModel();
|
|
|
|
$userId = $currentUser->get('id');
|
|
|
|
|
|
|
|
if($userId == 1 || $userId == 17) {
|
|
|
|
$moduleModel = $this->getModule();
|
|
|
|
if($currentUserModel->hasModuleActionPermission($moduleModel->getId(), 'EditView')) {
|
|
|
|
$massActionLink = array(
|
|
|
|
'linktype' => 'LISTVIEWMASSACTION',
|
|
|
|
'linklabel' => 'LBL_TRANSFER_OWNERSHIP',
|
|
|
|
'linkurl' => 'javascript:Vtiger_List_Js.triggerTransferOwnership("index.php?module='.$moduleModel->getName().'&view=MassActionAjax&mode=transferOwnership")',
|
|
|
|
'linkicon' => ''
|
|
|
|
);
|
|
|
|
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $massActionLinks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to get the list of listview links for the module
|
|
|
|
* @param <Array> $linkParams
|
|
|
|
* @return <Array> - Associate array of Link Type to List of Vtiger_Link_Model instances
|
|
|
|
*/
|
|
|
|
function getListViewLinks($linkParams) {
|
|
|
|
$links = parent::getListViewLinks($linkParams);
|
|
|
|
|
|
|
|
$index=0;
|
|
|
|
foreach($links['LISTVIEWBASIC'] as $link) {
|
|
|
|
if($link->linklabel == 'Send SMS') {
|
|
|
|
unset($links['LISTVIEWBASIC'][$index]);
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
return $links;
|
|
|
|
}
|
|
|
|
|
|
|
|
//filter account by default
|
|
|
|
private function customSearch($roleid) {
|
|
|
|
|
|
|
|
$field_value = "all";
|
|
|
|
$fullname = "";
|
|
|
|
$aCondition = ["columnname" => "vtiger_account:account_type:accounttype:Accounts_Type:V", "comparator" => "n", "value" => $field_value];
|
|
|
|
$aCondition2 = [];
|
|
|
|
$aCondition3 = [];
|
|
|
|
|
|
|
|
|
|
|
|
$currentUser = Users_Record_Model::getCurrentUserModel();
|
|
|
|
if(isByWilaya($currentUser->get('id'))) {
|
|
|
|
|
|
|
|
$lieu = $currentUser->get('secteur1_id').','.$currentUser->get('secteur2_id').','.$currentUser->get('secteur3_id').','.$currentUser->get('secteur4_id');
|
|
|
|
|
|
|
|
$industry = "Pharmacie";
|
|
|
|
if(isMedecin($roleid))
|
|
|
|
$industry = "Medecin";
|
|
|
|
$aCondition = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => $industry, "column_condition" => "and"];
|
|
|
|
$aCondition2 = ["columnname" => "vtiger_accountscf:cf_992:cf_992:Accounts_Wilaya:V", "comparator" => "c", "value" => $lieu];
|
|
|
|
$asearchParams = $this->get('search_params');
|
|
|
|
if(empty($asearchParams)) {
|
|
|
|
$searchParams = [[ "columns" => [$aCondition, $aCondition2] ]];
|
|
|
|
$this->set('search_params', $searchParams);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
|
|
|
if(isMedecin($roleid) || isPharma($roleid)) {
|
|
|
|
$field_value = "Medecin";
|
|
|
|
$fullname = $currentUser->get('first_name').' '.$currentUser->get('last_name');
|
|
|
|
$sub = getSubordinateRoleAndUsers($roleid);
|
|
|
|
foreach($sub as $roleid=>$userids) {
|
|
|
|
foreach($userids as $roleid2=>$userids2) {
|
|
|
|
$fullname = $fullname.",".$userids2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$aCondition = ["columnname" => "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V", "comparator" => "c", "value" => $fullname, "column_condition" => "or"];
|
|
|
|
$aCondition2 = ["columnname" => "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V", "comparator" => "c", "value" => $fullname, "column_condition" => "or"];
|
|
|
|
if($this->isVMPharma)
|
|
|
|
$aCondition3 = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => "Pharmacie"];
|
|
|
|
else
|
|
|
|
$aCondition3 = ["columnname" => "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V", "comparator" => "c", "value" => $fullname];
|
|
|
|
|
|
|
|
} else if(isGro($roleid)) {
|
|
|
|
$field_value = "Grossiste";
|
|
|
|
$aCondition = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => $field_value];
|
|
|
|
}
|
|
|
|
|
|
|
|
// update search_params
|
|
|
|
$searchParams = $this->get('search_params');
|
|
|
|
if(empty($searchParams)) {
|
|
|
|
if($aCondition2 != [] && $aCondition3 != []) {
|
|
|
|
$searchParams = [[ "columns" => [$aCondition, $aCondition2, $aCondition3] ]];
|
|
|
|
} else {
|
|
|
|
$searchParams = [[ "columns" => [$aCondition] ]];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$exist = 0;
|
|
|
|
$index = 0;
|
|
|
|
$columns = $searchParams[0]["columns"];
|
|
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
|
|
|
|
if(isByWilaya($currentUser->get('id'))) {
|
|
|
|
if($column["columnname"] == "vtiger_account:account_type:accounttype:Accounts_Type:V") {
|
|
|
|
$column["value"] = $field_value;
|
|
|
|
|
|
|
|
$exist = 1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
|
|
|
|
if(isGro($roleid)) {
|
|
|
|
if($column["columnname"] == "vtiger_account:industry:industry:Accounts_industry:V") {
|
|
|
|
|
|
|
|
if($roleid == 'H4' && ($column["value"] == 'Pharmacie' || $column["value"] == 'Grossiste')) {
|
|
|
|
} else {
|
|
|
|
$column["value"] = $field_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$exist = 1;
|
|
|
|
}
|
|
|
|
} else if(isMedecin($roleid) || isPharma($roleid)) {
|
|
|
|
|
|
|
|
if($column["columnname"] == "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V" || $column["columnname"] == "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V" || $column["columnname"] == "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V") {
|
|
|
|
//$column["value"] = $fullname;
|
|
|
|
$fullnames = split(',', $fullname);
|
|
|
|
$acolumns = split(',', $column["value"]);
|
|
|
|
if (count(array_diff($fullnames, $acolumns)) == 0) {
|
|
|
|
$exist = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if($column["columnname"] == "vtiger_account:account_type:accounttype:Accounts_Type:V") {
|
|
|
|
$column["value"] = $field_value;
|
|
|
|
|
|
|
|
$exist = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$exist && $index < count($columns)) {
|
|
|
|
//if($column["column_condition"] != 'or')
|
|
|
|
$column["column_condition"] = "and";
|
|
|
|
}
|
|
|
|
$columns[$index] = $column;
|
|
|
|
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$exist) {
|
|
|
|
|
|
|
|
if(isByWilaya($currentUser->get('id'))) {
|
|
|
|
array_push($columns, $aCondition, $aCondition2);
|
|
|
|
} else
|
|
|
|
|
|
|
|
if(isMedecin($roleid) || isPharma($roleid)) {
|
|
|
|
$tempColumns = $columns;
|
|
|
|
array_push($columns, $aCondition);
|
|
|
|
foreach ($tempColumns as $column) {
|
|
|
|
array_push($columns, $column);
|
|
|
|
}
|
|
|
|
array_push($columns, $aCondition2);
|
|
|
|
foreach ($tempColumns as $column) {
|
|
|
|
array_push($columns, $column);
|
|
|
|
}
|
|
|
|
array_push($columns, $aCondition3);
|
|
|
|
} else {
|
|
|
|
array_push($columns, $aCondition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$searchParams[0]["columns"] = $columns;
|
|
|
|
}
|
|
|
|
//print_r($searchParams);
|
|
|
|
$this->set('search_params', $searchParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getListViewEntries($pagingModel) {
|
|
|
|
|
|
|
|
$currentUser = Users_Record_Model::getCurrentUserModel();
|
|
|
|
$roleid = $currentUser->get('roleid');
|
|
|
|
//if($roleid != 'H2' && $_GET['viewname'] != 70) {
|
|
|
|
// if($roleid != 'H2' && $roleid != 'H20' && $roleid != 'H26' && $roleid != 'H39' && $_GET['viewname'] != 70) {
|
|
|
|
// $this->customSearch($roleid);
|
|
|
|
// }
|
|
|
|
if($_GET['parent'] != '') {
|
|
|
|
|
|
|
|
$parent = $_GET['parent'];
|
|
|
|
$infousers = explode('user;', $parent);
|
|
|
|
|
|
|
|
if(count($infousers) > 1) {
|
|
|
|
$auser = $infousers[1];
|
|
|
|
|
|
|
|
$aCondition = ["columnname" => "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
|
|
|
$aCondition5 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
|
|
|
$aCondition2 = ["columnname" => "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
|
|
|
$aCondition6 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
|
|
|
if($this->isVMPharma)
|
|
|
|
$aCondition3 = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => "Pharmacie", "column_condition" => "and"];
|
|
|
|
else
|
|
|
|
$aCondition3 = ["columnname" => "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
|
|
|
$aCondition4 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0'];
|
|
|
|
|
|
|
|
$searchParams = [[ "columns" => [$aCondition, $aCondition5, $aCondition2, $aCondition6, $aCondition3, $aCondition4] ]];
|
|
|
|
|
|
|
|
//print_r($searchParams);
|
|
|
|
$this->set('search_params', $searchParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getListViewEntries($pagingModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getListViewCount() {
|
|
|
|
|
|
|
|
$currentUser = Users_Record_Model::getCurrentUserModel();
|
|
|
|
$roleid = $currentUser->get('roleid');
|
|
|
|
//if($roleid != 'H2' && $_GET['viewname'] != 70) {
|
|
|
|
// if($roleid != 'H2' && $roleid != 'H20' && $roleid != 'H26' && $roleid != 'H39' && $_GET['viewname'] != 70) {
|
|
|
|
// $this->customSearch($roleid);
|
|
|
|
// }
|
|
|
|
if($_GET['parent'] != '') {
|
|
|
|
|
|
|
|
$parent = $_GET['parent'];
|
|
|
|
$infousers = explode('user;', $parent);
|
|
|
|
|
|
|
|
if(count($infousers) > 1) {
|
|
|
|
$auser = $infousers[1];
|
|
|
|
|
|
|
|
$aCondition = ["columnname" => "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
|
|
|
$aCondition5 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
|
|
|
$aCondition2 = ["columnname" => "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
|
|
|
$aCondition6 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
|
|
|
if($this->isVMPharma)
|
|
|
|
$aCondition3 = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => "Pharmacie", "column_condition" => "and"];
|
|
|
|
else
|
|
|
|
$aCondition3 = ["columnname" => "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
|
|
|
$aCondition4 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0'];
|
|
|
|
|
|
|
|
$searchParams = [[ "columns" => [$aCondition, $aCondition5, $aCondition2, $aCondition6, $aCondition3, $aCondition4] ]];
|
|
|
|
|
|
|
|
//print_r($searchParams);
|
|
|
|
$this->set('search_params', $searchParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getListViewCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|