fusionpbx/app/call_block/call_block_cdr_add.php

127 lines
4.2 KiB
PHP

<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2019
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
Call Block is written by Gerrit Visser <gerrit308@gmail.com>
*/
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (!permission_exists('call_block_edit') && !permission_exists('call_block_add')) {
echo "access denied"; exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//action add from cdr
if (is_uuid($_REQUEST["id"])) {
//get the uuid
$xml_cdr_uuid = $_REQUEST["id"];
// get the caller id info from cdr the user chose
$sql = "select caller_id_name, caller_id_number ";
$sql .= "from v_xml_cdr ";
$sql .= "where xml_cdr_uuid = :xml_cdr_uuid ";
$parameters['xml_cdr_uuid'] = $xml_cdr_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
unset ($sql, $parameters);
//create data array
$x = 0;
if (permission_exists('call_block_all')) {
$array['call_block'][$x]['call_block_uuid'] = uuid();
$array['call_block'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
$array['call_block'][$x]['call_block_name'] = trim($row["caller_id_name"]);
$array['call_block'][$x]['call_block_number'] = trim($row["caller_id_number"]);
$array['call_block'][$x]['call_block_count'] = 0;
$array['call_block'][$x]['call_block_action'] = 'reject';
$array['call_block'][$x]['call_block_enabled'] = 'true';
$array['call_block'][$x]['date_added'] = time();
}
if (!permission_exists('call_block_all') && is_array($_SESSION['user']['extension'])) {
foreach ($_SESSION['user']['extension'] as $field) {
if (is_uuid($field['extension_uuid'])) {
$array['call_block'][$x]['call_block_uuid'] = uuid();
$array['call_block'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
$array['call_block'][$x]['extension_uuid'] = $field['extension_uuid'];
$array['call_block'][$x]['call_block_name'] = trim($row["caller_id_name"]);
$array['call_block'][$x]['call_block_number'] = trim($row["caller_id_number"]);
$array['call_block'][$x]['call_block_count'] = 0;
$array['call_block'][$x]['call_block_action'] = 'reject';
$array['call_block'][$x]['call_block_enabled'] = 'true';
$array['call_block'][$x]['date_added'] = time();
}
$x++;
}
}
//ensure call block is enabled in the dialplan
$sql = "select dialplan_uuid from v_dialplans where true ";
$sql .= "and domain_uuid = :domain_uuid ";
$sql .= "and app_uuid = 'b1b31930-d0ee-4395-a891-04df94599f1f' ";
$sql .= "and dialplan_enabled <> 'true' ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters);
if (is_array($rows) && sizeof($rows) != 0) {
foreach ($rows as $index => $row) {
$array['dialplans'][$index]['dialplan_uuid'] = $row['dialplan_uuid'];
$array['dialplans'][$index]['dialplan_enabled'] = 'true';
}
$p = new permissions;
$p->add('dialplan_edit', 'temp');
$database = new database;
$database->save($array);
unset($array);
$p->delete('dialplan_edit', 'temp');
}
//insert call block record
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->save($array);
$response = $database->message;
unset($array);
//add a message
message::add($text['label-add-complete']);
}
//redirect the browser
header("Location: call_block.php");
?>