Phrases - Edit: Add bulk delete of Details, dynamic delete button action. Remove deprecated Detail delete script.

This commit is contained in:
Nate
2020-03-04 07:45:40 -07:00
parent 41801f4b34
commit 82893cbd57
3 changed files with 133 additions and 95 deletions

View File

@@ -40,6 +40,11 @@ if (!class_exists('phrases')) {
private $toggle_field;
private $toggle_values;
/**
* declare public variables
*/
public $phrase_uuid;
/**
* called when the object is created
*/
@@ -158,6 +163,83 @@ if (!class_exists('phrases')) {
}
}
public function delete_details($records) {
//assign private variables
$this->permission_prefix = 'phrase_';
$this->list_page = 'phrase_edit.php?id='.$this->phrase_uuid;
$this->table = 'phrase_details';
$this->uuid_prefix = 'phrase_detail_';
if (permission_exists($this->permission_prefix.'edit')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//filter out unchecked phrases, build the delete array
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array[$this->table][$x]['phrase_uuid'] = $this->phrase_uuid;
$array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
}
}
//get phrase languages
if (is_array($array) && @sizeof($array) != 0) {
$sql = "select phrase_language as lang from v_phrases ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and phrase_uuid = :phrase_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['phrase_uuid'] = $this->phrase_uuid;
$database = new database;
$phrase_language = $database->select($sql, $parameters, 'column');
unset($sql, $parameters, $rows, $row);
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('phrase_detail_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('phrase_detail_delete', 'temp');
//save the xml
save_phrases_xml();
//clear the cache
if ($phrase_language != '') {
$cache = new cache;
$cache->delete("languages:".$phrase_language);
}
}
unset($records, $phrase_language);
}
}
}
/**
* toggle records
*/