Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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.
************************************************************************************/
include_once('vtlib/Vtiger/Utils.php');
/**
* Provides API to work with vtiger CRM Profile
* @package vtlib
*/
class Vtiger_Profile {
var $id;
var $name;
var $desc;
public function save() {
if (!$this->id) {
$this->create();
} else {
$this->update();
}
}
private function create() {
global $adb;
$this->id = $adb->getUniqueID('vtiger_profile');
$sql = "INSERT INTO vtiger_profile (profileid, profilename, description)
VALUES (?,?,?)";
$binds = array($this->id, $this->name, $this->desc);
$adb->pquery($sql, $binds);
$sql = "INSERT INTO vtiger_profile2field (profileid, tabid, fieldid, visible, readonly)
SELECT ?, tabid, fieldid, 0, 0
FROM vtiger_field";
$binds = array($this->id);
$adb->pquery($sql, $binds);
$sql = "INSERT INTO vtiger_profile2tab (profileid, tabid, permissions)
SELECT ?, tabid, 0
FROM vtiger_tab";
$binds = array($this->id);
$adb->pquery($sql, $binds);
$sql = "INSERT INTO vtiger_profile2standardpermissions (profileid, tabid, Operation, permissions)
SELECT ?, tabid, actionid, 0
FROM vtiger_actionmapping, vtiger_tab

Satish
committed
WHERE actionname IN ('Save', 'CreateView', 'EditView', 'Delete', 'index', 'DetailView') AND isentitytype = 1";
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
$binds = array($this->id);
$adb->pquery($sql, $binds);
self::log("Initializing profile permissions ... DONE");
}
private function update() {
throw new Exception("Not implemented");
}
/**
* Helper function to log messages
* @param String Message to log
* @param Boolean true appends linebreak, false to avoid it
* @access private
*/
static function log($message, $delimit=true) {
Vtiger_Utils::Log($message, $delimit);
}
/**
* Initialize profile setup for Field
* @param Vtiger_Field Instance of the field
* @access private
*/
static function initForField($fieldInstance) {
global $adb;
// Allow field access to all
$adb->pquery("INSERT INTO vtiger_def_org_field (tabid, fieldid, visible, readonly) VALUES(?,?,?,?)",
Array($fieldInstance->getModuleId(), $fieldInstance->id, '0', '0'));
$profileids = self::getAllIds();
foreach($profileids as $profileid) {
$adb->pquery("INSERT INTO vtiger_profile2field (profileid, tabid, fieldid, visible, readonly) VALUES(?,?,?,?,?)",
Array($profileid, $fieldInstance->getModuleId(), $fieldInstance->id, '0', '0'));
}
}
/**
* Delete profile information related with field.
* @param Vtiger_Field Instance of the field
* @access private
*/
static function deleteForField($fieldInstance) {
global $adb;
$adb->pquery("DELETE FROM vtiger_def_org_field WHERE fieldid=?", Array($fieldInstance->id));
$adb->pquery("DELETE FROM vtiger_profile2field WHERE fieldid=?", Array($fieldInstance->id));
}
/**
* Get all the existing profile ids
* @access private
*/
static function getAllIds() {
global $adb;
$profileids = Array();
$result = $adb->pquery('SELECT profileid FROM vtiger_profile', array());
for($index = 0; $index < $adb->num_rows($result); ++$index) {
$profileids[] = $adb->query_result($result, $index, 'profileid');
}
return $profileids;
}
/**
* Initialize profile setup for the module
* @param Vtiger_Module Instance of module
* @access private
*/
static function initForModule($moduleInstance) {
global $adb;
$actionids = Array();

Satish
committed
$result = $adb->pquery("SELECT actionid from vtiger_actionmapping WHERE actionname IN (?,?,?,?,?,?)", array('Save','EditView','CreateView','Delete','index','DetailView'));
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* NOTE: Other actionname (actionid >= 5) is considered as utility (tools) for a profile.
* Gather all the actionid for associating to profile.
*/
for($index = 0; $index < $adb->num_rows($result); ++$index) {
$actionids[] = $adb->query_result($result, $index, 'actionid');
}
$profileids = self::getAllIds();
foreach($profileids as $profileid) {
$adb->pquery("INSERT INTO vtiger_profile2tab (profileid, tabid, permissions) VALUES (?,?,?)",
Array($profileid, $moduleInstance->id, 0));
if($moduleInstance->isentitytype) {
foreach($actionids as $actionid) {
$adb->pquery(
"INSERT INTO vtiger_profile2standardpermissions (profileid, tabid, Operation, permissions) VALUES(?,?,?,?)",
Array($profileid, $moduleInstance->id, $actionid, 0));
}
}
}
self::log("Initializing module permissions ... DONE");
}
/**
* Delete profile setup of the module
* @param Vtiger_Module Instance of module
* @access private
*/
static function deleteForModule($moduleInstance) {
global $adb;
$adb->pquery("DELETE FROM vtiger_profile2tab WHERE tabid=?", Array($moduleInstance->id));
$adb->pquery("DELETE FROM vtiger_profile2standardpermissions WHERE tabid=?", Array($moduleInstance->id));
}
}
?>