public function save($item_id, $table, $total_backups = 5) { if (!PHPWS_DB::isTable($table)) { return FALSE; } $backupTable = Backup::getBackupTable($table); if (PHPWS_Error::isError($backupTable)) { return $backupTable; } $db = new PHPWS_DB($table); $db->addWhere('id', $item_id); $source_row = $db->select('row'); $db2 = new PHPWS_DB($backupTable); $db2->addWhere('backup_id', $source_row['id']); $db2->addOrder('backup_order'); $past_rows = $db2->select(); $past_row_count = count($past_rows); if (empty($past_rows) || $past_row_count < $total_backups) { $db2->reset(); $source_row['backup_id'] = $source_row['id']; unset($source_row['id']); $source_row['backup_order'] = $past_row_count + 1; $db2->addValue($source_row); $result = $db2->insert(); } else { $db2->delete(); $db2->reset(); unset($past_rows[0]); $source_row['backup_id'] = $source_row['id']; unset($source_row['id']); $past_rows[] = $source_row; foreach ($past_rows as $key => $row) { $row['backup_order'] = $key; $db2->addValue($row); $db2->insert(); $db2->resetValues(); } } }
public function savePermissions() { if (!$this->id) { return false; } $db = new PHPWS_DB('phpws_key'); $db->addValue('restricted', $this->restricted); if (PHPWS_Error::logIfError($db->saveObject($this))) { return false; } $view_db = new PHPWS_DB('phpws_key_view'); $view_db->addWhere('key_id', $this->id); $result = $view_db->delete(); if (PHPWS_Error::isError($result)) { return $result; } $edit_db = new PHPWS_DB('phpws_key_edit'); $edit_db->addWhere('key_id', $this->id); $result = $edit_db->delete(); if (PHPWS_Error::isError($result)) { return $result; } // we don't care if restricted is 0 because everyone can view // we don't care if it is KEY_LOGGED_RESTRICTED either because // just checking log status covers it if ($this->restricted == KEY_GROUP_RESTRICTED) { if (!empty($this->_view_groups) && is_array($this->_view_groups)) { $view_db->reset(); $this->_view_groups = array_unique($this->_view_groups); foreach ($this->_view_groups as $group_id) { $view_db->resetValues(); $view_db->addValue('key_id', $this->id); $view_db->addValue('group_id', $group_id); PHPWS_Error::logIfError($view_db->insert()); } } } if (!empty($this->_edit_groups) && is_array($this->_edit_groups)) { $edit_db->reset(); $this->_edit_groups = array_unique($this->_edit_groups); foreach ($this->_edit_groups as $group_id) { $edit_db->resetValues(); $edit_db->addValue('key_id', $this->id); $edit_db->addValue('group_id', $group_id); PHPWS_Error::logIfError($edit_db->insert()); } } return true; }
public function save() { $db = new PHPWS_DB('users_groups'); $result = $db->saveObject($this); $members = $this->getMembers(); if (isset($members)) { $this->dropAllMembers(); $db = new PHPWS_DB('users_members'); foreach ($members as $member) { $db->addValue('group_id', $this->getId()); $db->addValue('member_id', $member); PHPWS_Error::logIfError($db->insert()); $db->resetValues(); } } }