@@ -253,13 +253,12 @@ function insertIntoCrmEntity($module, $fileid = '')
253
253
$ description_val = from_html ($ this ->column_fields ['description ' ], ($ insertion_mode == 'edit ' ) ? true : false );
254
254
$ attention_val = from_html ($ this ->column_fields ['attention ' ], ($ insertion_mode == 'edit ' ) ? true : false );
255
255
$ was_read = ($ this ->column_fields ['was_read ' ] == 'on ' ) ? true : false ;
256
- $ inheritsharing = ($ this ->column_fields ['inheritsharing ' ] == 'on ' ) ? true : false ;
257
256
checkFileAccessForInclusion ('user_privileges/user_privileges_ ' . $ current_user ->id . '.php ' );
258
257
require ('user_privileges/user_privileges_ ' . $ current_user ->id . '.php ' );
259
258
$ tabid = getTabid ($ module );
260
259
if ($ is_admin == true || $ profileGlobalPermission [1 ] == 0 || $ profileGlobalPermission [2 ] == 0 ) {
261
- $ sql = "update vtiger_crmentity set smownerid=?,modifiedby=?,description=?,attention=?, modifiedtime=?, was_read=?, inheritsharing=? where crmid=? " ;
262
- $ params = array ($ ownerid , $ current_user ->id , $ description_val , $ attention_val , $ adb ->formatDate ($ date_var , true ), $ was_read , $ inheritsharing , $ this ->id );
260
+ $ sql = "update vtiger_crmentity set smownerid=?,modifiedby=?,description=?,attention=?, modifiedtime=?, was_read=? where crmid=? " ;
261
+ $ params = array ($ ownerid , $ current_user ->id , $ description_val , $ attention_val , $ adb ->formatDate ($ date_var , true ), $ was_read , $ this ->id );
263
262
} else {
264
263
$ profileList = getCurrentUserProfileList ();
265
264
$ perm_qry = "SELECT columnname FROM vtiger_field INNER JOIN vtiger_profile2field ON vtiger_profile2field.fieldid = vtiger_field.fieldid INNER JOIN vtiger_def_org_field ON vtiger_def_org_field.fieldid = vtiger_field.fieldid WHERE vtiger_field.tabid = ? AND vtiger_profile2field.visible = 0 AND vtiger_profile2field.readonly = 0 AND vtiger_profile2field.profileid IN ( " . generateQuestionMarks ($ profileList ) . ") AND vtiger_def_org_field.visible = 0 and vtiger_field.tablename='vtiger_crmentity' and vtiger_field.presence in (0,2); " ;
@@ -269,8 +268,8 @@ function insertIntoCrmEntity($module, $fileid = '')
269
268
$ columname [] = $ adb ->query_result ($ perm_result , $ i , "columnname " );
270
269
}
271
270
if (is_array ($ columname ) && in_array ("description " , $ columname )) {
272
- $ sql = "update vtiger_crmentity set smownerid=?,modifiedby=?,description=?, attention=?, modifiedtime=?,was_read=?, inheritsharing=? where crmid=? " ;
273
- $ params = array ($ ownerid , $ current_user ->id , $ description_val , $ attention_val , $ adb ->formatDate ($ date_var , true ), $ was_read , $ inheritsharing , $ this ->id );
271
+ $ sql = "update vtiger_crmentity set smownerid=?,modifiedby=?,description=?, attention=?, modifiedtime=?,was_read=? where crmid=? " ;
272
+ $ params = array ($ ownerid , $ current_user ->id , $ description_val , $ attention_val , $ adb ->formatDate ($ date_var , true ), $ was_read , $ this ->id );
274
273
} else {
275
274
$ sql = "update vtiger_crmentity set smownerid=?,modifiedby=?, modifiedtime=? where crmid=? " ;
276
275
$ params = array ($ ownerid , $ current_user ->id , $ adb ->formatDate ($ date_var , true ), $ this ->id );
@@ -290,7 +289,6 @@ function insertIntoCrmEntity($module, $fileid = '')
290
289
// Customization
291
290
$ created_date_var = $ adb ->formatDate ($ date_var , true );
292
291
$ modified_date_var = $ adb ->formatDate ($ date_var , true );
293
- $ inheritsharing = ($ this ->column_fields ['inheritsharing ' ] == 'on ' ) ? true : false ;
294
292
// Preserve the timestamp
295
293
if (self ::isBulkSaveMode ()) {
296
294
if (!empty ($ this ->column_fields ['createdtime ' ]))
@@ -301,8 +299,8 @@ function insertIntoCrmEntity($module, $fileid = '')
301
299
302
300
$ description_val = from_html ($ this ->column_fields ['description ' ], ($ insertion_mode == 'edit ' ) ? true : false );
303
301
$ attention_val = from_html ($ this ->column_fields ['attention ' ], ($ insertion_mode == 'edit ' ) ? true : false );
304
- $ sql = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,attention,modifiedby,createdtime,modifiedtime,inheritsharing ) values(?, ?,?,?,?,?,?,?,?,?) " ;
305
- $ params = array ($ current_id , $ current_user ->id , $ ownerid , $ module , $ description_val , $ attention_val , $ current_user ->id , $ created_date_var , $ modified_date_var, $ inheritsharing );
302
+ $ sql = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,attention,modifiedby,createdtime,modifiedtime) values(?,?,?,?,?,?,?,?,?) " ;
303
+ $ params = array ($ current_id , $ current_user ->id , $ ownerid , $ module , $ description_val , $ attention_val , $ current_user ->id , $ created_date_var , $ modified_date_var );
306
304
$ adb ->pquery ($ sql , $ params );
307
305
308
306
$ this ->column_fields ['createdtime ' ] = $ created_date_var ;
@@ -474,6 +472,13 @@ function insertIntoEntityTable($table_name, $module, $fileid = '')
474
472
$ field_list = $ this ->column_fields [$ fieldname ];
475
473
}
476
474
$ fldvalue = $ field_list ;
475
+ } elseif (in_array ($ uitype , [303 , 304 ])) {
476
+ if (is_array ($ this ->column_fields [$ fieldname ])) {
477
+ $ field_list = implode (', ' , $ this ->column_fields [$ fieldname ]);
478
+ } else {
479
+ $ field_list = $ this ->column_fields [$ fieldname ];
480
+ }
481
+ $ fldvalue = $ field_list ;
477
482
} elseif ($ uitype == 5 || $ uitype == 6 || $ uitype == 23 ) {
478
483
//Added to avoid function call getDBInsertDateValue in ajax save
479
484
if (isset ($ current_user ->date_format ) && !$ ajaxSave ) {
@@ -538,6 +543,7 @@ function insertIntoEntityTable($table_name, $module, $fileid = '')
538
543
else {
539
544
$ fldvalue = '' ;
540
545
}
546
+
541
547
if ($ fldvalue == '' ) {
542
548
$ fldvalue = $ this ->get_column_value ($ columname , $ fldvalue , $ fieldname , $ uitype , $ datatype );
543
549
}
@@ -778,11 +784,11 @@ function retrieve_entity_info($record, $module)
778
784
$ result = $ adb ->pquery ($ sql , $ params );
779
785
780
786
if (!$ result || $ adb ->num_rows ($ result ) < 1 ) {
781
- throw new Exception ($ app_strings ['LBL_RECORD_NOT_FOUND ' ] . ': ' . $ record . ' ' . $ module , -1 );
787
+ throw new AppException ($ app_strings ['LBL_RECORD_NOT_FOUND ' ] . ': ' . $ record . ' ' . $ module , -1 );
782
788
} else {
783
789
$ resultrow = $ adb ->query_result_rowdata ($ result );
784
790
if (!empty ($ resultrow ['deleted ' ])) {
785
- throw new Exception ($ app_strings ['LBL_RECORD_DELETE ' ] . ': ' . $ record . ' ' . $ module , 1 );
791
+ throw new AppException ($ app_strings ['LBL_RECORD_DELETE ' ] . ': ' . $ record . ' ' . $ module , 1 );
786
792
;
787
793
}
788
794
foreach ($ cachedModuleFields as $ fieldinfo ) {
@@ -1156,24 +1162,23 @@ function unlinkDependencies($module, $id)
1156
1162
{
1157
1163
$ log = vglobal ('log ' );
1158
1164
1159
- $ fieldRes = $ this ->db ->pquery ('SELECT tabid, tablename, columnname FROM vtiger_field WHERE fieldid IN (
1160
- SELECT fieldid FROM vtiger_fieldmodulerel WHERE relmodule=?) ' , array ( $ module) );
1161
- $ numOfFields = $ this -> db -> num_rows ( $ fieldRes );
1162
- for ($ i = 0 ; $ i < $ numOfFields ; $ i ++ ) {
1163
- $ tabId = $ this -> db -> query_result ( $ fieldRes , $ i , 'tabid ' ) ;
1164
- $ tableName = $ this -> db -> query_result ( $ fieldRes , $ i , 'tablename ' ) ;
1165
- $ columnName = $ this -> db -> query_result ( $ fieldRes , $ i , 'columnname ' ) ;
1165
+ $ result = $ this ->db ->pquery ('SELECT tabid, tablename, columnname FROM vtiger_field WHERE fieldid IN (
1166
+ SELECT fieldid FROM vtiger_fieldmodulerel WHERE relmodule=?) ' , [ $ module] );
1167
+
1168
+ while ($ row = $ this -> db -> fetch_array ( $ result ) ) {
1169
+ $ tabId = $ row [ 'tabid ' ] ;
1170
+ $ tableName = $ row [ 'tablename ' ] ;
1171
+ $ columnName = $ row [ 'columnname ' ] ;
1166
1172
1167
1173
$ relatedModule = vtlib_getModuleNameById ($ tabId );
1168
1174
$ focusObj = CRMEntity::getInstance ($ relatedModule );
1169
1175
1170
1176
//Backup Field Relations for the deleted entity
1171
- $ targetTableColumn = $ focusObj ->table_index ;
1177
+ $ targetTableColumn = $ focusObj ->tab_name_index [ $ tableName ] ;
1172
1178
//While deleting product record the $targetTableColumn should 'id'.
1173
1179
if ($ tableName == 'vtiger_inventoryproductrel ' ) {
1174
1180
$ targetTableColumn = 'id ' ;
1175
1181
}
1176
-
1177
1182
$ relQuery = "SELECT $ targetTableColumn FROM $ tableName WHERE $ columnName=? " ;
1178
1183
$ relResult = $ this ->db ->pquery ($ relQuery , array ($ id ));
1179
1184
$ numOfRelRecords = $ this ->db ->num_rows ($ relResult );
@@ -2391,7 +2396,7 @@ function getUserAccessConditionsQuery($module, $user)
2391
2396
return $ query ;
2392
2397
}
2393
2398
2394
- function getUserAccessConditionsQuerySR ($ module , $ current_user = false )
2399
+ function getUserAccessConditionsQuerySR ($ module , $ current_user = false , $ relatedRecord = false )
2395
2400
{
2396
2401
if ($ current_user == false )
2397
2402
$ current_user = vglobal ('current_user ' );
@@ -2403,6 +2408,25 @@ function getUserAccessConditionsQuerySR($module, $current_user = false)
2403
2408
$ query = '' ;
2404
2409
$ tabId = getTabid ($ module );
2405
2410
2411
+ if ($ relatedRecord ) {
2412
+ $ role = getRoleInformation ($ current_user ->roleid );
2413
+ if ($ role ['listrelatedrecord ' ] != 0 ) {
2414
+ $ rparentRecord = Users_Privileges_Model::getParentRecord ($ relatedRecord , false , $ role ['listrelatedrecord ' ]);
2415
+ if ($ rparentRecord ) {
2416
+ $ relatedRecord = $ rparentRecord ;
2417
+ }
2418
+
2419
+ $ recordMetaData = Vtiger_Functions::getCRMRecordMetadata ($ relatedRecord );
2420
+ $ recordPermission = Users_Privileges_Model::isPermitted ($ recordMetaData ['setype ' ], 'DetailView ' , $ relatedRecord );
2421
+ if (!$ recordPermission ) {
2422
+ throw new AppException ('LBL_PERMISSION_DENIED ' );
2423
+ }
2424
+ if ($ recordMetaData ['smownerid ' ] == $ current_user ->id ) {
2425
+ return '' ;
2426
+ }
2427
+ }
2428
+ }
2429
+
2406
2430
if ($ is_admin == false && $ profileGlobalPermission [1 ] == 1 && $ profileGlobalPermission [2 ] == 1 && $ defaultOrgSharingPermission [$ tabId ] == 3 ) {
2407
2431
$ securityParameter = $ this ->getUserAccessConditionsQuery ($ module , $ current_user );
2408
2432
foreach (array_merge ([$ current_user ->id ], $ current_user_groups ) as $ id ) {
0 commit comments