Example #1
0
 public function editRule(Vtiger_Request $request)
 {
     $viewer = $this->getViewer($request);
     $moduleName = $request->getModule();
     $qualifiedModuleName = $request->getModule(false);
     $forModule = $request->get('for_module');
     $ruleId = $request->get('record');
     $moduleModel = Settings_SharingAccess_Module_Model::getInstance($forModule);
     if ($ruleId) {
         $ruleModel = Settings_SharingAccess_Rule_Model::getInstance($moduleModel, $ruleId);
     } else {
         $ruleModel = new Settings_SharingAccess_Rule_Model();
         $ruleModel->setModuleFromInstance($moduleModel);
     }
     $viewer->assign('ALL_RULE_MEMBERS', Settings_SharingAccess_RuleMember_Model::getAll());
     $viewer->assign('ALL_PERMISSIONS', Settings_SharingAccess_Rule_Model::$allPermissions);
     $viewer->assign('MODULE_MODEL', $moduleModel);
     $viewer->assign('RULE_MODEL', $ruleModel);
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
     $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
     echo $viewer->view('EditRule.tpl', $qualifiedModuleName, true);
 }
Example #2
0
 public function save()
 {
     $db = PearDatabase::getInstance();
     $ruleId = $this->getId();
     if (!$ruleId) {
         $ruleId = $db->getUniqueId('vtiger_datashare_module_rel');
         $this->set('shareid', $ruleId);
         $db->pquery("INSERT INTO vtiger_datashare_module_rel(shareid, tabid) VALUES(?,?)", array($ruleId, $this->getModule()->getId()));
     } else {
         $relationTypeComponents = explode('::', $this->get('relationtype'));
         $sourceType = $relationTypeComponents[0];
         $targetType = $relationTypeComponents[1];
         $tableColumnInfo = self::$dataShareTableColArr[$sourceType][$targetType];
         $tableName = $tableColumnInfo['table'];
         $sourceColumnName = $tableColumnInfo['source_id'];
         $targetColumnName = $tableColumnInfo['target_id'];
         $db->pquery("DELETE FROM {$tableName} WHERE shareid=?", array($ruleId));
     }
     $sourceId = $this->get('source_id');
     $sourceIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($sourceId);
     $sourceType = array_search($sourceIdComponents[0], self::$ruleMemberToRelationMapping);
     $targetId = $this->get('target_id');
     $targetIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($targetId);
     $targetType = array_search($targetIdComponents[0], self::$ruleMemberToRelationMapping);
     $tableColumnName = self::$dataShareTableColArr[$sourceType][$targetType];
     $tableName = $tableColumnName['table'];
     $sourceColumnName = $tableColumnName['source_id'];
     $targetColumnName = $tableColumnName['target_id'];
     $this->set('relationtype', implode('::', array($sourceType, $targetType)));
     $permission = $this->get('permission');
     $sql = "INSERT INTO {$tableName} (shareid, {$sourceColumnName}, {$targetColumnName}, permission) VALUES (?,?,?,?)";
     $params = array($ruleId, $sourceIdComponents[1], $targetIdComponents[1], $permission);
     $db->pquery($sql, $params);
     $sql = 'UPDATE vtiger_datashare_module_rel SET relationtype=? WHERE shareid=?';
     $params = array($this->get('relationtype'), $ruleId);
     $db->pquery($sql, $params);
     Settings_SharingAccess_Module_Model::recalculateSharingRules();
 }
Example #3
0
 public function save()
 {
     $db = PearDatabase::getInstance();
     $ruleId = $this->getId();
     if (!$ruleId) {
         $ruleId = $db->getUniqueId('vtiger_datashare_module_rel');
         $this->set('shareid', $ruleId);
         $db->insert('vtiger_datashare_module_rel', ['shareid' => $ruleId, 'tabid' => $this->getModule()->getId()]);
     } else {
         $relationTypeComponents = explode('::', $this->get('relationtype'));
         $sourceType = $relationTypeComponents[0];
         $targetType = $relationTypeComponents[1];
         $tableColumnInfo = self::$dataShareTableColArr[$sourceType][$targetType];
         $tableName = $tableColumnInfo['table'];
         $sourceColumnName = $tableColumnInfo['source_id'];
         $targetColumnName = $tableColumnInfo['target_id'];
         $db->delete($tableName, 'shareid = ?', [$ruleId]);
     }
     $sourceId = $this->get('source_id');
     $sourceIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($sourceId);
     $sourceType = array_search($sourceIdComponents[0], self::$ruleMemberToRelationMapping);
     $targetId = $this->get('target_id');
     $targetIdComponents = Settings_SharingAccess_RuleMember_Model::getIdComponentsFromQualifiedId($targetId);
     $targetType = array_search($targetIdComponents[0], self::$ruleMemberToRelationMapping);
     $tableColumnName = self::$dataShareTableColArr[$sourceType][$targetType];
     $tableName = $tableColumnName['table'];
     $sourceColumnName = $tableColumnName['source_id'];
     $targetColumnName = $tableColumnName['target_id'];
     $this->set('relationtype', implode('::', array($sourceType, $targetType)));
     $db->insert($tableName, ['shareid' => $ruleId, $sourceColumnName => $sourceIdComponents[1], $targetColumnName => $targetIdComponents[1], 'permission' => $this->get('permission')]);
     $db->update('vtiger_datashare_module_rel', ['relationtype' => $this->get('relationtype')], 'shareid = ?', [$ruleId]);
     Settings_SharingAccess_Module_Model::recalculateSharingRules();
 }