Esempio n. 1
0
 /**
  * DataSet Security Delete
  * @return <XiboAPIResponse>
  */
 public function DataSetSecurityDelete()
 {
     // Auth
     if (!$this->user->PageAuth('dataset')) {
         return $this->Error(1, 'Access Denied');
     }
     $dataSetId = $this->GetParam('dataSetId', _INT);
     $auth = $this->user->DataSetAuth($dataSetId, true);
     if (!$auth->modifyPermissions) {
         return $this->Error(1, 'Access Denied');
     }
     $groupId = $this->GetParam('groupId', _INT);
     Kit::ClassLoader('datasetgroupsecurity');
     $security = new DataSetGroupSecurity();
     if (!($results = $security->Unlink($dataSetId, $groupId))) {
         return $this->Error($security->GetErrorNumber(), $security->GetErrorMessage());
     }
     return $this->Respond($this->ReturnId('success', true));
 }
Esempio n. 2
0
 public function Permissions()
 {
     // Check the token
     if (!Kit::CheckToken()) {
         trigger_error('Token does not match', E_USER_ERROR);
     }
     $db =& $this->db;
     $user =& $this->user;
     $response = new ResponseManager();
     Kit::ClassLoader('datasetgroupsecurity');
     $dataSetId = Kit::GetParam('datasetid', _POST, _INT);
     $groupIds = Kit::GetParam('groupids', _POST, _ARRAY);
     $auth = $this->user->DataSetAuth($dataSetId, true);
     if (!$auth->modifyPermissions) {
         trigger_error(__('You do not have permissions to edit this dataset'), E_USER_ERROR);
     }
     // Unlink all
     $security = new DataSetGroupSecurity($db);
     if (!$security->UnlinkAll($dataSetId)) {
         trigger_error(__('Unable to set permissions'));
     }
     // Some assignments for the loop
     $lastGroupId = 0;
     $first = true;
     $view = 0;
     $edit = 0;
     $del = 0;
     // List of groupIds with view, edit and del assignments
     foreach ($groupIds as $groupPermission) {
         $groupPermission = explode('_', $groupPermission);
         $groupId = $groupPermission[0];
         if ($first) {
             // First time through
             $first = false;
             $lastGroupId = $groupId;
         }
         if ($groupId != $lastGroupId) {
             // The groupId has changed, so we need to write the current settings to the db.
             // Link new permissions
             if (!$security->Link($dataSetId, $lastGroupId, $view, $edit, $del)) {
                 trigger_error(__('Unable to set permissions'), E_USER_ERROR);
             }
             // Reset
             $lastGroupId = $groupId;
             $view = 0;
             $edit = 0;
             $del = 0;
         }
         switch ($groupPermission[1]) {
             case 'view':
                 $view = 1;
                 break;
             case 'edit':
                 $edit = 1;
                 break;
             case 'del':
                 $del = 1;
                 break;
         }
     }
     // Need to do the last one
     if (!$first) {
         if (!$security->Link($dataSetId, $lastGroupId, $view, $edit, $del)) {
             trigger_error(__('Unable to set permissions'), E_USER_ERROR);
         }
     }
     $response->SetFormSubmitResponse(__('Permissions Changed'));
     $response->Respond();
 }
Esempio n. 3
0
 /**
  * Delete DataSet
  * @param <type> $dataSetId
  */
 public function Delete($dataSetId)
 {
     try {
         $dbh = PDOConnect::init();
         // Delete the Data
         $data = new DataSetData();
         $data->DeleteAll($dataSetId);
         // Delete security
         $security = new DataSetGroupSecurity($this->db);
         $security->UnlinkAll($dataSetId);
         // Delete columns
         $dataSetObject = new DataSetColumn($this->db);
         if (!$dataSetObject->DeleteAll($dataSetId)) {
             return $this->SetError(25005, __('Cannot delete dataset, columns could not be deleted.'));
         }
         // Delete data set
         $sth = $dbh->prepare('DELETE FROM dataset WHERE DataSetID = :datasetid');
         $sth->execute(array('datasetid' => $dataSetId));
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25005, sprintf(__('Cannot edit dataset %s'), $dataSet));
         }
         return false;
     }
 }
Esempio n. 4
0
 /**
  * Delete DataSet
  * @param <type> $dataSetId
  */
 public function Delete($dataSetId)
 {
     try {
         $dbh = PDOConnect::init();
         // First check to see if we have any data
         $sth = $dbh->prepare('SELECT * FROM `datasetdata` INNER JOIN `datasetcolumn` ON datasetcolumn.DataSetColumnID = datasetdata.DataSetColumnID WHERE datasetcolumn.DataSetID = :datasetid');
         $sth->execute(array('datasetid' => $dataSetId));
         if ($row = $sth->fetch()) {
             return $this->SetError(25005, __('There is data assigned to this data set, cannot delete.'));
         }
         // Delete security
         Kit::ClassLoader('datasetgroupsecurity');
         $security = new DataSetGroupSecurity($this->db);
         $security->UnlinkAll($dataSetId);
         // Delete columns
         $dataSetObject = new DataSetColumn($this->db);
         if (!$dataSetObject->DeleteAll($dataSetId)) {
             return $this->SetError(25005, __('Cannot delete dataset, columns could not be deleted.'));
         }
         // Delete data set
         $sth = $dbh->prepare('DELETE FROM dataset WHERE DataSetID = :datasetid');
         $sth->execute(array('datasetid' => $dataSetId));
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25005, sprintf(__('Cannot edit dataset %s'), $dataSet));
         }
         return false;
     }
 }