diff --git a/app/call_recordings/call_recordings.php b/app/call_recordings/call_recordings.php index 4be7c00af9..2aa121a85c 100644 --- a/app/call_recordings/call_recordings.php +++ b/app/call_recordings/call_recordings.php @@ -1,356 +1,356 @@ - - Portions created by the Initial Developer are Copyright (C) 2018-2024 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - require_once "resources/paging.php"; - -//check permissions - if (permission_exists('call_recording_view')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//add the settings object - $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); - $transcribe_enabled = $settings->get('transcribe', 'enabled', 'false'); - $transcribe_engine = $settings->get('transcribe', 'engine', ''); - -//set additional variables - $search = $_GET["search"] ?? ''; - $show = $_GET["show"] ?? ''; - -//get the http post data - if (!empty($_POST['call_recordings']) && is_array($_POST['call_recordings'])) { - $action = $_POST['action']; - $search = $_POST['search']; - $call_recordings = $_POST['call_recordings']; - } - -//process the http post data by action - if (!empty($action) && is_array($call_recordings) && @sizeof($call_recordings) != 0) { - switch ($action) { - case 'download': - if (permission_exists('call_recording_download')) { - $obj = new call_recordings; - $obj->download($call_recordings); - } - break; - case 'transcribe': - if (permission_exists('call_recording_download')) { - $obj = new call_recordings; - $obj->transcribe($call_recordings); - } - break; - case 'delete': - if (permission_exists('call_recording_delete')) { - $obj = new call_recordings; - $obj->delete($call_recordings); - } - break; - } - - //redirect the user - header('Location: call_recordings.php'.($search != '' ? '?search='.urlencode($search) : null)); - exit; - } - -//get order and order by - $order_by = $_GET["order_by"] ?? ''; - $order = $_GET["order"] ?? ''; - -//add the search string - if (!empty($search)) { - $search = strtolower($_GET["search"]); - } - -//set the time zone - if (!empty($_SESSION['domain']['time_zone']['name'])) { - $time_zone = $_SESSION['domain']['time_zone']['name']; - } - else { - $time_zone = date_default_timezone_get(); - } - $parameters['time_zone'] = $time_zone; - -//get the count - //$sql = "select count(*) "; - //$sql .= "from view_call_recordings "; - //$sql .= "where true "; - //if ($_GET['show'] != "all" || !permission_exists('call_recording_all')) { - // $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; - // $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - //} - //if (isset($search)) { - // $sql .= "and ("; - // $sql .= " lower(call_recording_name) like :search "; - // $sql .= " or lower(call_recording_path) like :search "; - // $sql .= ") "; - // $parameters['search'] = '%'.$search.'%'; - //} - //$database = new database; - //$num_rows = $database->select($sql, $parameters, 'column'); - -//prepare some of the paging values - $rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50; - $page = $_GET['page'] ?? ''; - if (empty($page)) { $page = 0; $_GET['page'] = 0; } - $offset = $rows_per_page * $page; - -//get the list - $sql = "select r.domain_uuid, d.domain_name, r.call_recording_uuid, r.call_direction, "; - $sql .= "r.call_recording_name, r.call_recording_path, r.call_recording_transcription, r.call_recording_length, "; - $sql .= "r.caller_id_name, r.caller_id_number, r.caller_destination, r.destination_number, "; - $sql .= "to_char(timezone(:time_zone, r.call_recording_date), 'DD Mon YYYY') as call_recording_date_formatted, \n"; - $sql .= "to_char(timezone(:time_zone, r.call_recording_date), 'HH12:MI:SS am') as call_recording_time_formatted \n"; - $sql .= "from view_call_recordings as r, v_domains as d "; - //$sql .= "from v_call_recordings as r, v_domains as d "; - $sql .= "where true "; - if ($show != "all" || !permission_exists('call_recording_all')) { - $sql .= "and (r.domain_uuid = :domain_uuid or r.domain_uuid is null) "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - } - $sql .= "and r.domain_uuid = d.domain_uuid "; - if (!empty($search)) { - $sql .= "and ("; - $sql .= " lower(r.call_direction) like :search "; - $sql .= " or lower(r.caller_id_name) like :search "; - $sql .= " or lower(r.caller_id_number) like :search "; - $sql .= " or lower(r.caller_destination) like :search "; - $sql .= " or lower(r.destination_number) like :search "; - $sql .= " or lower(r.call_recording_name) like :search "; - $sql .= " or lower(r.call_recording_path) like :search "; - $sql .= ") "; - $parameters['search'] = '%'.$search.'%'; - } - $sql .= order_by($order_by, $order, 'r.call_recording_date', 'desc'); - $sql .= limit_offset($rows_per_page, $offset); - $database = new database; - $call_recordings = $database->select($sql, $parameters ?? null, 'all'); - unset($sql, $parameters); - -//detect if any transcriptions available - if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && !empty($call_recordings) && is_array($call_recordings)) { - $transcriptions_exists = false; - foreach ($call_recordings as $row) { - if (!empty($row['call_recording_transcription'])) { $transcriptions_exists = true; } - } - } - -//count the results - $result_count = is_array($call_recordings) ? sizeof($call_recordings) : 0; - -//limit the number of results - if (!empty($_SESSION['cdr']['limit']['numeric']) && $_SESSION['cdr']['limit']['numeric'] > 0) { - $num_rows = $_SESSION['cdr']['limit']['numeric']; - } - -//prepare to page the results - $param = "&search=".urlencode($search); - if ($show == "all" && permission_exists('call_recording_all')) { - $param .= "&show=all"; - } - list($paging_controls_mini, $rows_per_page) = paging($num_rows ?? null, $param, $rows_per_page, true, $result_count); //top - list($paging_controls, $rows_per_page) = paging($num_rows ?? null, $param, $rows_per_page, false, $result_count); //bottom - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//include the header - $document['title'] = $text['title-call_recordings']; - require_once "resources/header.php"; - -//show the content - echo "
\n"; - echo "
".$text['title-call_recordings']."
".number_format($result_count)."
\n"; - echo "
\n"; - if (permission_exists('call_recording_download') && !empty($call_recordings)) { - echo button::create(['type'=>'button','label'=>$text['button-download'],'icon'=>$_SESSION['theme']['button_icon_download'],'id'=>'btn_download','name'=>'btn_download','style'=>'display: none;','collapse'=>'hide-xs','onclick'=>"list_action_set('download'); list_form_submit('form_list');"]); - } - if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && !empty($call_recordings)) { - echo button::create(['type'=>'button','label'=>$text['button-transcribe'],'icon'=>'quote-right','id'=>'btn_transcribe','name'=>'btn_transcribe','style'=>'display: none;','collapse'=>'hide-xs','onclick'=>"list_action_set('transcribe'); list_form_submit('form_list');"]); - } - if (permission_exists('call_recording_delete') && !empty($call_recordings)) { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-right: 15px;','collapse'=>'hide-xs','onclick'=>"modal_open('modal-delete','btn_delete');"]); - } - echo "\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - - if (permission_exists('call_recording_delete') && !empty($call_recordings)) { - echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); - } - - echo $text['title_description-call_recordings']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - echo "\n"; - echo "\n"; - $col_count = 8; - if ($show == "all" && permission_exists('call_recording_all')) { - $col_count++; - } - if (permission_exists('call_recording_delete')) { - echo " \n"; - $col_count++; - } - if ($show == "all" && permission_exists('call_recording_all')) { - echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param, "class='hide-sm-dn shrink'"); - } - echo th_order_by('caller_id_name', $text['label-caller_id_name'], $order_by, $order, null, "class='hide-sm-dn'"); - echo th_order_by('caller_id_number', $text['label-caller_id_number'], $order_by, $order, null, "class='pct-15'"); - echo th_order_by('caller_destination', $text['label-caller_destination'], $order_by, $order, null, "class='pct-10 hide-sm-dn'"); - echo th_order_by('destination_number', $text['label-destination_number'], $order_by, $order, null, "class='pct-10'"); - echo th_order_by('call_recording_name', $text['label-call_recording_name'], $order_by, $order, null, "class='pct-20 hide-sm-dn'"); - if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { - echo "\n"; - $col_count++; - } - echo th_order_by('call_recording_length', $text['label-call_recording_length'], $order_by, $order, null, "class='right hide-sm-dn shrink'"); - echo th_order_by('call_recording_date', $text['label-call_recording_date'], $order_by, $order, null, "class='pct-20 center'"); - echo th_order_by('call_direction', $text['label-call_direction'], $order_by, $order, null, "class='hide-sm-dn shrink'"); - if (permission_exists('xml_cdr_details')) { - echo " \n"; - } - echo "\n"; - - if (is_array($call_recordings) && @sizeof($call_recordings) != 0) { - $x = 0; - foreach ($call_recordings as $row) { - //add padding to the call recording length - $call_recording_length_padding = (!empty($row['call_recording_length'])) ? str_pad($row['call_recording_length'], 2, '0', STR_PAD_LEFT) : ''; - - //playback progress bar - if (permission_exists('call_recording_play')) { - echo "".(permission_exists('xml_cdr_details') ? "" : null)."\n"; - echo "\n"; // dummy row to maintain alternating background color - } - if (permission_exists('call_recording_play')) { - $list_row_url = "javascript:recording_play('".escape($row['call_recording_uuid'])."');"; - } - echo "\n"; - if (permission_exists('call_recording_delete')) { - echo " \n"; - } - if ($show == "all" && permission_exists('call_recording_all')) { - echo " \n"; - } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { - echo " \n"; - } - echo " \n"; - echo " \n"; - echo " \n"; - if (permission_exists('xml_cdr_details')) { - echo " \n"; - } - echo "\n"; - if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && !empty($row['call_recording_transcription'])) { - echo "\n"; // dummy row to maintain same background color for transcription row - echo "\n"; - echo " \n"; - echo "\n"; - } - $x++; - } - unset($call_recordings); - } - - echo "
\n"; - echo " \n"; - echo " ".$text['label-recording']." 
\n"; - echo " \n"; - echo " \n"; - echo " ".escape($row['domain_name'])."".escape($row['caller_id_name'])."".escape(format_phone(substr($row['caller_id_number'], 0, 20)))."".escape(format_phone(substr($row['caller_destination'], 0, 20)))."".escape(format_phone(substr($row['destination_number'], 0, 20)))."".escape($row['call_recording_name'])."".($row['call_recording_length'] <= 59 ? '0:' : null).escape($call_recording_length_padding)."".escape($row['call_recording_date_formatted'])." ".escape($row['call_recording_time_formatted'])."".($row['call_direction'] != '' ? escape($text['label-'.$row['call_direction']]) : null)."\n"; - echo button::create(['type'=>'button','title'=>$text['button-view'],'icon'=>$_SESSION['theme']['button_icon_view'],'link'=>PROJECT_PATH.'/app/xml_cdr/xml_cdr_details.php?id='.urlencode($row['call_recording_uuid'])]); - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
".$paging_controls."
\n"; - echo "\n"; - echo "
\n"; - -//include the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2018-2024 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + require_once "resources/paging.php"; + +//check permissions + if (permission_exists('call_recording_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//add the settings object + $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); + $transcribe_enabled = $settings->get('transcribe', 'enabled', 'false'); + $transcribe_engine = $settings->get('transcribe', 'engine', ''); + +//set additional variables + $search = $_GET["search"] ?? ''; + $show = $_GET["show"] ?? ''; + +//get the http post data + if (!empty($_POST['call_recordings']) && is_array($_POST['call_recordings'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $call_recordings = $_POST['call_recordings']; + } + +//process the http post data by action + if (!empty($action) && is_array($call_recordings) && @sizeof($call_recordings) != 0) { + switch ($action) { + case 'download': + if (permission_exists('call_recording_download')) { + $obj = new call_recordings; + $obj->download($call_recordings); + } + break; + case 'transcribe': + if (permission_exists('call_recording_download')) { + $obj = new call_recordings; + $obj->transcribe($call_recordings); + } + break; + case 'delete': + if (permission_exists('call_recording_delete')) { + $obj = new call_recordings; + $obj->delete($call_recordings); + } + break; + } + + //redirect the user + header('Location: call_recordings.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + +//get order and order by + $order_by = $_GET["order_by"] ?? ''; + $order = $_GET["order"] ?? ''; + +//add the search string + if (!empty($search)) { + $search = strtolower($_GET["search"]); + } + +//set the time zone + if (!empty($_SESSION['domain']['time_zone']['name'])) { + $time_zone = $_SESSION['domain']['time_zone']['name']; + } + else { + $time_zone = date_default_timezone_get(); + } + $parameters['time_zone'] = $time_zone; + +//get the count + //$sql = "select count(*) "; + //$sql .= "from view_call_recordings "; + //$sql .= "where true "; + //if ($_GET['show'] != "all" || !permission_exists('call_recording_all')) { + // $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; + // $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + //} + //if (isset($search)) { + // $sql .= "and ("; + // $sql .= " lower(call_recording_name) like :search "; + // $sql .= " or lower(call_recording_path) like :search "; + // $sql .= ") "; + // $parameters['search'] = '%'.$search.'%'; + //} + //$database = new database; + //$num_rows = $database->select($sql, $parameters, 'column'); + +//prepare some of the paging values + $rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50; + $page = $_GET['page'] ?? ''; + if (empty($page)) { $page = 0; $_GET['page'] = 0; } + $offset = $rows_per_page * $page; + +//get the list + $sql = "select r.domain_uuid, d.domain_name, r.call_recording_uuid, r.call_direction, "; + $sql .= "r.call_recording_name, r.call_recording_path, r.call_recording_transcription, r.call_recording_length, "; + $sql .= "r.caller_id_name, r.caller_id_number, r.caller_destination, r.destination_number, "; + $sql .= "to_char(timezone(:time_zone, r.call_recording_date), 'DD Mon YYYY') as call_recording_date_formatted, \n"; + $sql .= "to_char(timezone(:time_zone, r.call_recording_date), 'HH12:MI:SS am') as call_recording_time_formatted \n"; + $sql .= "from view_call_recordings as r, v_domains as d "; + //$sql .= "from v_call_recordings as r, v_domains as d "; + $sql .= "where true "; + if ($show != "all" || !permission_exists('call_recording_all')) { + $sql .= "and (r.domain_uuid = :domain_uuid or r.domain_uuid is null) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + } + $sql .= "and r.domain_uuid = d.domain_uuid "; + if (!empty($search)) { + $sql .= "and ("; + $sql .= " lower(r.call_direction) like :search "; + $sql .= " or lower(r.caller_id_name) like :search "; + $sql .= " or lower(r.caller_id_number) like :search "; + $sql .= " or lower(r.caller_destination) like :search "; + $sql .= " or lower(r.destination_number) like :search "; + $sql .= " or lower(r.call_recording_name) like :search "; + $sql .= " or lower(r.call_recording_path) like :search "; + $sql .= ") "; + $parameters['search'] = '%'.$search.'%'; + } + $sql .= order_by($order_by, $order, 'r.call_recording_date', 'desc'); + $sql .= limit_offset($rows_per_page, $offset); + $database = new database; + $call_recordings = $database->select($sql, $parameters ?? null, 'all'); + unset($sql, $parameters); + +//detect if any transcriptions available + if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && !empty($call_recordings) && is_array($call_recordings)) { + $transcriptions_exists = false; + foreach ($call_recordings as $row) { + if (!empty($row['call_recording_transcription'])) { $transcriptions_exists = true; } + } + } + +//count the results + $result_count = is_array($call_recordings) ? sizeof($call_recordings) : 0; + +//limit the number of results + if (!empty($_SESSION['cdr']['limit']['numeric']) && $_SESSION['cdr']['limit']['numeric'] > 0) { + $num_rows = $_SESSION['cdr']['limit']['numeric']; + } + +//prepare to page the results + $param = "&search=".urlencode($search); + if ($show == "all" && permission_exists('call_recording_all')) { + $param .= "&show=all"; + } + list($paging_controls_mini, $rows_per_page) = paging($num_rows ?? null, $param, $rows_per_page, true, $result_count); //top + list($paging_controls, $rows_per_page) = paging($num_rows ?? null, $param, $rows_per_page, false, $result_count); //bottom + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//include the header + $document['title'] = $text['title-call_recordings']; + require_once "resources/header.php"; + +//show the content + echo "
\n"; + echo "
".$text['title-call_recordings']."
".number_format($result_count)."
\n"; + echo "
\n"; + if (permission_exists('call_recording_download') && !empty($call_recordings)) { + echo button::create(['type'=>'button','label'=>$text['button-download'],'icon'=>$_SESSION['theme']['button_icon_download'],'id'=>'btn_download','name'=>'btn_download','style'=>'display: none;','collapse'=>'hide-xs','onclick'=>"list_action_set('download'); list_form_submit('form_list');"]); + } + if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && !empty($call_recordings)) { + echo button::create(['type'=>'button','label'=>$text['button-transcribe'],'icon'=>'quote-right','id'=>'btn_transcribe','name'=>'btn_transcribe','style'=>'display: none;','collapse'=>'hide-xs','onclick'=>"list_action_set('transcribe'); list_form_submit('form_list');"]); + } + if (permission_exists('call_recording_delete') && !empty($call_recordings)) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-right: 15px;','collapse'=>'hide-xs','onclick'=>"modal_open('modal-delete','btn_delete');"]); + } + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + + if (permission_exists('call_recording_delete') && !empty($call_recordings)) { + echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); + } + + echo $text['title_description-call_recordings']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo "\n"; + echo "\n"; + $col_count = 8; + if ($show == "all" && permission_exists('call_recording_all')) { + $col_count++; + } + if (permission_exists('call_recording_delete')) { + echo " \n"; + $col_count++; + } + if ($show == "all" && permission_exists('call_recording_all')) { + echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param, "class='hide-sm-dn shrink'"); + } + echo th_order_by('caller_id_name', $text['label-caller_id_name'], $order_by, $order, null, "class='hide-sm-dn'"); + echo th_order_by('caller_id_number', $text['label-caller_id_number'], $order_by, $order, null, "class='pct-15'"); + echo th_order_by('caller_destination', $text['label-caller_destination'], $order_by, $order, null, "class='pct-10 hide-sm-dn'"); + echo th_order_by('destination_number', $text['label-destination_number'], $order_by, $order, null, "class='pct-10'"); + echo th_order_by('call_recording_name', $text['label-call_recording_name'], $order_by, $order, null, "class='pct-20 hide-sm-dn'"); + if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { + echo "\n"; + $col_count++; + } + echo th_order_by('call_recording_length', $text['label-call_recording_length'], $order_by, $order, null, "class='right hide-sm-dn shrink'"); + echo th_order_by('call_recording_date', $text['label-call_recording_date'], $order_by, $order, null, "class='pct-20 center'"); + echo th_order_by('call_direction', $text['label-call_direction'], $order_by, $order, null, "class='hide-sm-dn shrink'"); + if (permission_exists('xml_cdr_details')) { + echo " \n"; + } + echo "\n"; + + if (is_array($call_recordings) && @sizeof($call_recordings) != 0) { + $x = 0; + foreach ($call_recordings as $row) { + //add padding to the call recording length + $call_recording_length_padding = (!empty($row['call_recording_length'])) ? str_pad($row['call_recording_length'], 2, '0', STR_PAD_LEFT) : ''; + + //playback progress bar + if (permission_exists('call_recording_play')) { + echo "".(permission_exists('xml_cdr_details') ? "" : null)."\n"; + echo "\n"; // dummy row to maintain alternating background color + } + if (permission_exists('call_recording_play')) { + $list_row_url = "javascript:recording_play('".escape($row['call_recording_uuid'])."');"; + } + echo "\n"; + if (permission_exists('call_recording_delete')) { + echo " \n"; + } + if ($show == "all" && permission_exists('call_recording_all')) { + echo " \n"; + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { + echo " \n"; + } + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('xml_cdr_details')) { + echo " \n"; + } + echo "\n"; + if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && !empty($row['call_recording_transcription'])) { + echo "\n"; // dummy row to maintain same background color for transcription row + echo "\n"; + echo " \n"; + echo "\n"; + } + $x++; + } + unset($call_recordings); + } + + echo "
\n"; + echo " \n"; + echo " ".$text['label-recording']." 
\n"; + echo " \n"; + echo " \n"; + echo " ".escape($row['domain_name'])."".escape($row['caller_id_name'])."".escape(format_phone(substr($row['caller_id_number'], 0, 20)))."".escape(format_phone(substr($row['caller_destination'], 0, 20)))."".escape(format_phone(substr($row['destination_number'], 0, 20)))."".escape($row['call_recording_name'])."".($row['call_recording_length'] <= 59 ? '0:' : null).escape($call_recording_length_padding)."".escape($row['call_recording_date_formatted'])." ".escape($row['call_recording_time_formatted'])."".($row['call_direction'] != '' ? escape($text['label-'.$row['call_direction']]) : null)."\n"; + echo button::create(['type'=>'button','title'=>$text['button-view'],'icon'=>$_SESSION['theme']['button_icon_view'],'link'=>PROJECT_PATH.'/app/xml_cdr/xml_cdr_details.php?id='.urlencode($row['call_recording_uuid'])]); + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; + echo "\n"; + echo "
\n"; + +//include the footer + require_once "resources/footer.php"; + +?> diff --git a/app/call_recordings/download.php b/app/call_recordings/download.php index 01f71feb8a..389e4cfb33 100644 --- a/app/call_recordings/download.php +++ b/app/call_recordings/download.php @@ -1,48 +1,48 @@ - - Portions created by the Initial Developer are Copyright (C) 2016-2020 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permisions - if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//download - if (is_uuid($_GET['id'])) { - $obj = new call_recordings; - $obj->recording_uuid = $_GET['id']; - $obj->binary = isset($_GET['binary']) ? true : false; - $obj->download(); - } - + + Portions created by the Initial Developer are Copyright (C) 2016-2020 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permisions + if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//download + if (is_uuid($_GET['id'])) { + $obj = new call_recordings; + $obj->recording_uuid = $_GET['id']; + $obj->binary = isset($_GET['binary']) ? true : false; + $obj->download(); + } + ?> \ No newline at end of file diff --git a/app/call_recordings/resources/classes/call_recordings.php b/app/call_recordings/resources/classes/call_recordings.php index 4cbf7551c8..feda8ec52b 100644 --- a/app/call_recordings/resources/classes/call_recordings.php +++ b/app/call_recordings/resources/classes/call_recordings.php @@ -1,529 +1,529 @@ - - Portions created by the Initial Developer are Copyright (C) 2018 - 2023 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -/** - * call_recordings class - * - * @method null download - */ -if (!class_exists('call_recordings')) { - class call_recordings { - - /** - * declare the variables - */ - private $app_name; - private $app_uuid; - private $name; - private $table; - private $description_field; - private $location; - public $recording_uuid; - public $binary; - - /** - * called when the object is created - */ - public function __construct() { - //assign the variables - $this->app_name = 'call_recordings'; - $this->app_uuid = '56165644-598d-4ed8-be01-d960bcb8ffed'; - $this->name = 'call_recording'; - $this->table = 'call_recordings'; - $this->description_field = 'call_recording_description'; - $this->location = 'call_recordings.php'; - } - - /** - * delete rows from the database - */ - public function delete($records) { - if (permission_exists($this->name.'_delete')) { - - //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->location); - exit; - } - - //delete multiple records - if (is_array($records) && @sizeof($records) != 0) { - //build the delete array - $x = 0; - foreach ($records as $record) { - //add to the array - if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { - //get the information to delete - $sql = "select call_recording_name, call_recording_path "; - $sql .= "from view_call_recordings "; - $sql .= "where call_recording_uuid = :call_recording_uuid "; - $parameters['call_recording_uuid'] = $record['uuid']; - $database = new database; - $field = $database->select($sql, $parameters, 'row'); - if (is_array($field) && @sizeof($field) != 0) { - //delete the file on the file system - if (file_exists($field['call_recording_path'].'/'.$field['call_recording_name'])) { - unlink($field['call_recording_path'].'/'.$field['call_recording_name']); - } - //build call recording delete array - $array['xml_cdr'][$x]['xml_cdr_uuid'] = $record['uuid']; - $array['xml_cdr'][$x]['record_path'] = null; - $array['xml_cdr'][$x]['record_name'] = null; - $array['xml_cdr'][$x]['record_length'] = null; - //increment the id - $x++; - } - unset($sql, $parameters, $field); - } - } - - //delete the checked rows - if (is_array($array) && @sizeof($array) != 0) { - - //add temporary permissions - $p = new permissions; - $p->add('xml_cdr_edit', 'temp'); - - //remove record_path, record_name and record_length - $database = new database; - $database->app_name = 'xml_cdr'; - $database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848'; - $database->save($array, false); - $message = $database->message; - unset($array); - - //remove the temporary permissions - $p->delete('xml_cdr_edit', 'temp'); - - //set message - message::add($text['message-delete']); - - } - unset($records); - } - } - } - - /** - * transcribe call recordings - */ - public function transcribe($records) { - if (permission_exists($this->name.'_view')) { - //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->location); - exit; - } - - //add the settings object - $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); - $transcribe_enabled = $settings->get('transcribe', 'enabled', 'false'); - $transcribe_engine = $settings->get('transcribe', 'engine', ''); - - //transcribe multiple recordings - if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && is_array($records) && @sizeof($records) != 0) { - //add the transcribe object - $transcribe = new transcribe($settings); - - //build the array - $x = 0; - foreach ($records as $record) { - //add to the array - if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { - - //get the call recording file name and path - $sql = "select call_recording_name, call_recording_path "; - $sql .= "from view_call_recordings "; - $sql .= "where call_recording_uuid = :call_recording_uuid "; - $sql .= "and call_recording_transcription is null "; - $parameters['call_recording_uuid'] = $record['uuid']; - $database = new database; - $field = $database->select($sql, $parameters, 'row'); - if ( - is_array($field) && - @sizeof($field) != 0 && - file_exists($field['call_recording_path'].'/'.$field['call_recording_name']) - ) { - //audio to text - get the transcription from the audio file - $transcribe->audio_path = $field['call_recording_path']; - $transcribe->audio_filename = $field['call_recording_name']; - $record_transcription = $transcribe->transcribe(); - //build call recording data array - if (!empty($record_transcription)) { - $array['xml_cdr'][$x]['xml_cdr_uuid'] = $record['uuid']; - $array['xml_cdr'][$x]['record_transcription'] = $record_transcription; - } - //increment the id - $x++; - } - unset($sql, $parameters, $field); - - } - } - - //update the checked rows - if (is_array($array) && @sizeof($array) != 0) { - - //add temporary permissions - $p = new permissions; - $p->add('xml_cdr_edit', 'temp'); - - //remove record_path, record_name and record_length - $database = new database; - $database->app_name = 'xml_cdr'; - $database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848'; - $database->save($array, false); - $message = $database->message; - unset($array); - - //remove the temporary permissions - $p->delete('xml_cdr_edit', 'temp'); - - //set message - message::add($text['message-audio_transcribed']); - - } - unset($records); - } - } - } - - /** - * download the recordings - */ - public function download($records = null) { - if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { - - //single recording - if (empty($records) || !is_array($records) || @sizeof($records) == 0) { - - //get call recording from database - if (is_uuid($this->recording_uuid)) { - $sql = "select call_recording_name, call_recording_path "; - if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { - $sql = ", call_recording_base64 "; - } - $sql .= "from view_call_recordings "; - $sql .= "where call_recording_uuid = :call_recording_uuid "; - $parameters['call_recording_uuid'] = $this->recording_uuid; - $database = new database; - $row = $database->select($sql, $parameters, 'row'); - if (is_array($row) && @sizeof($row) != 0) { - $call_recording_name = $row['call_recording_name']; - $call_recording_path = $row['call_recording_path']; - if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { - file_put_contents($call_recording_path.'/'.$call_recording_name, base64_decode($row['call_recording_base64'])); - } - } - unset($sql, $parameters, $row); - } - - //build full path - $full_recording_path = $call_recording_path.'/'.$call_recording_name; - - //download the file - if ($full_recording_path != '/' && file_exists($full_recording_path)) { - ob_clean(); - $fd = fopen($full_recording_path, "rb"); - if ($this->binary) { - header("Content-Type: application/force-download"); - header("Content-Type: application/octet-stream"); - header("Content-Type: application/download"); - header("Content-Description: File Transfer"); - } - else { - $file_ext = pathinfo($call_recording_name, PATHINFO_EXTENSION); - switch ($file_ext) { - case "wav" : header("Content-Type: audio/x-wav"); break; - case "mp3" : header("Content-Type: audio/mpeg"); break; - case "ogg" : header("Content-Type: audio/ogg"); break; - } - } - header('Content-Disposition: attachment; filename="'.$call_recording_name.'"'); - header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past - if ($this->binary) { - header("Content-Length: ".filesize($full_recording_path)); - } - ob_clean(); - - //content-range - if (isset($_SERVER['HTTP_RANGE']) && !$this->binary) { - $this->range_download($full_recording_path); - } - - fpassthru($fd); - } - - //if base64, remove temp recording file - if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { - @unlink($full_recording_path); - } - - } - - //multiple recordings - else { - - //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->location); - exit; - } - - //drop unchecked records - foreach ($records as $i => $record) { - if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { - $uuids[] = $record['uuid']; - } - } - unset($records, $record); - - //get data for recordings - if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) { - $sql = "select call_recording_name, call_recording_path "; - if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && $row['call_recording_base64'] != '') { - $sql = ", call_recording_base64 "; - } - $sql .= "from view_call_recordings "; - $sql .= "where call_recording_uuid in ('".implode("','", $uuids)."') "; - $database = new database; - $rows = $database->select($sql, null, 'all'); - if (!empty($rows) && is_array($rows) && @sizeof($rows) != 0) { - foreach ($rows as $row) { - $call_recording_name = $row['call_recording_name']; - $call_recording_path = $row['call_recording_path']; - if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { - file_put_contents($call_recording_path.'/'.$call_recording_name, base64_decode($row['call_recording_base64'])); - } - if (file_exists($call_recording_path.'/'.$call_recording_name)) { - $full_recording_paths[] = $call_recording_path.'/'.$call_recording_name; - } - } - } - unset($sql, $rows, $row); - } - - //compress the recordings - if (!empty($full_recording_paths) && is_array($full_recording_paths) && @sizeof($full_recording_paths) != 0) { - header("Content-Type: application/x-zip"); - header("Content-Description: File Transfer"); - header('Content-Disposition: attachment; filename="call_recordings.zip"'); - header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past - passthru("zip -qj - ".implode(' ', $full_recording_paths)); - } - - - //if base64, remove temp recording file - if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { - foreach ($full_recording_paths as $full_recording_path) { - @unlink($full_recording_path); - } - } - - exit; - - } - - } - - } //method - - /* - * range download method (helps safari play audio sources) - */ - private function range_download($file) { - $fp = @fopen($file, 'rb'); - - $size = filesize($file); // File size - $length = $size; // Content length - $start = 0; // Start byte - $end = $size - 1; // End byte - // Now that we've gotten so far without errors we send the accept range header - /* At the moment we only support single ranges. - * Multiple ranges requires some more work to ensure it works correctly - * and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2 - * - * Multirange support annouces itself with: - * header('Accept-Ranges: bytes'); - * - * Multirange content must be sent with multipart/byteranges mediatype, - * (mediatype = mimetype) - * as well as a boundry header to indicate the various chunks of data. - */ - header("Accept-Ranges: 0-".$length); - // header('Accept-Ranges: bytes'); - // multipart/byteranges - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2 - if (isset($_SERVER['HTTP_RANGE'])) { - - $c_start = $start; - $c_end = $end; - // Extract the range string - list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); - // Make sure the client hasn't sent us a multibyte range - if (strpos($range, ',') !== false) { - // (?) Shoud this be issued here, or should the first - // range be used? Or should the header be ignored and - // we output the whole content? - header('HTTP/1.1 416 Requested Range Not Satisfiable'); - header("Content-Range: bytes $start-$end/$size"); - // (?) Echo some info to the client? - exit; - } - // If the range starts with an '-' we start from the beginning - // If not, we forward the file pointer - // And make sure to get the end byte if spesified - if ($range[0] == '-') { - // The n-number of the last bytes is requested - $c_start = $size - substr($range, 1); - } - else { - $range = explode('-', $range); - $c_start = $range[0]; - $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size; - } - /* Check the range and make sure it's treated according to the specs. - * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html - */ - // End bytes can not be larger than $end. - $c_end = ($c_end > $end) ? $end : $c_end; - // Validate the requested range and return an error if it's not correct. - if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) { - - header('HTTP/1.1 416 Requested Range Not Satisfiable'); - header("Content-Range: bytes $start-$end/$size"); - // (?) Echo some info to the client? - exit; - } - $start = $c_start; - $end = $c_end; - $length = $end - $start + 1; // Calculate new content length - fseek($fp, $start); - header('HTTP/1.1 206 Partial Content'); - } - // Notify the client the byte range we'll be outputting - header("Content-Range: bytes $start-$end/$size"); - header("Content-Length: $length"); - - // Start buffered download - $buffer = 1024 * 8; - while(!feof($fp) && ($p = ftell($fp)) <= $end) { - if ($p + $buffer > $end) { - // In case we're only outputtin a chunk, make sure we don't - // read past the length - $buffer = $end - $p + 1; - } - set_time_limit(0); // Reset time limit for big files - echo fread($fp, $buffer); - flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit. - } - - fclose($fp); - } - - /** - * Called by the maintenance service to clean out old call recordings - * @param settings $settings - * @return void - */ - public static function filesystem_maintenance(settings $settings): void { - //get the database connection object - $database = $settings->database(); - - //get an associative array of domain_uuid => domain_names - $domains = maintenance::get_domains($database); - - //loop over each domain - foreach ($domains as $domain_uuid => $domain_name) { - //get the settings for this domain - $domain_settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]); - - //get the recording location for this domain - $call_recording_location = $domain_settings->get('switch', 'recordings', '/var/lib/freeswitch/storage/recordings') . '/default'; - - //get the retention days for this domain - $retention_days = $domain_settings->get('call_recordings', 'filesystem_retention_days', ''); - - //ensure retention days are not empty - if (!empty($retention_days) && is_numeric($retention_days)) { - $retention_days = intval($retention_days); - - //get list of mp3 and wav files - $mp3_files = glob("$call_recording_location/$domain_name/*/archive/*.mp3"); - $wav_files = glob("$call_recording_location/$domain_name/*/archive/*.wav"); - - //combine to single array - $domain_call_recording_files = array_merge($mp3_files, $wav_files); - - //loop over each call recording mp3 or wav file - foreach ($domain_call_recording_files as $file) { - - //use the maintenance service class helper function to get the modified date and see if it is older - if (maintenance_service::days_since_modified($file) > $retention_days) { - //remove the file when it is older - if (unlink($file)) { - //log success - maintenance_service::log_write(self::class, "Removed $file from call_recordings", $domain_uuid); - } else { - //log failure - maintenance_service::log_write(self::class, "Unable to remove $file", $domain_uuid, maintenance_service::LOG_ERROR); - } - } else { - //file is not older - do nothing - } - } - } - else { - //report the retention days is not set correctly - maintenance_service::log_write(self::class, "Retention days not set or not a valid number", $domain_uuid, maintenance_service::LOG_ERROR); - } - } - } - - } //class -} - -?> + + Portions created by the Initial Developer are Copyright (C) 2018 - 2023 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +/** + * call_recordings class + * + * @method null download + */ +if (!class_exists('call_recordings')) { + class call_recordings { + + /** + * declare the variables + */ + private $app_name; + private $app_uuid; + private $name; + private $table; + private $description_field; + private $location; + public $recording_uuid; + public $binary; + + /** + * called when the object is created + */ + public function __construct() { + //assign the variables + $this->app_name = 'call_recordings'; + $this->app_uuid = '56165644-598d-4ed8-be01-d960bcb8ffed'; + $this->name = 'call_recording'; + $this->table = 'call_recordings'; + $this->description_field = 'call_recording_description'; + $this->location = 'call_recordings.php'; + } + + /** + * delete rows from the database + */ + public function delete($records) { + if (permission_exists($this->name.'_delete')) { + + //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->location); + exit; + } + + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + //build the delete array + $x = 0; + foreach ($records as $record) { + //add to the array + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { + //get the information to delete + $sql = "select call_recording_name, call_recording_path "; + $sql .= "from view_call_recordings "; + $sql .= "where call_recording_uuid = :call_recording_uuid "; + $parameters['call_recording_uuid'] = $record['uuid']; + $database = new database; + $field = $database->select($sql, $parameters, 'row'); + if (is_array($field) && @sizeof($field) != 0) { + //delete the file on the file system + if (file_exists($field['call_recording_path'].'/'.$field['call_recording_name'])) { + unlink($field['call_recording_path'].'/'.$field['call_recording_name']); + } + //build call recording delete array + $array['xml_cdr'][$x]['xml_cdr_uuid'] = $record['uuid']; + $array['xml_cdr'][$x]['record_path'] = null; + $array['xml_cdr'][$x]['record_name'] = null; + $array['xml_cdr'][$x]['record_length'] = null; + //increment the id + $x++; + } + unset($sql, $parameters, $field); + } + } + + //delete the checked rows + if (is_array($array) && @sizeof($array) != 0) { + + //add temporary permissions + $p = new permissions; + $p->add('xml_cdr_edit', 'temp'); + + //remove record_path, record_name and record_length + $database = new database; + $database->app_name = 'xml_cdr'; + $database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848'; + $database->save($array, false); + $message = $database->message; + unset($array); + + //remove the temporary permissions + $p->delete('xml_cdr_edit', 'temp'); + + //set message + message::add($text['message-delete']); + + } + unset($records); + } + } + } + + /** + * transcribe call recordings + */ + public function transcribe($records) { + if (permission_exists($this->name.'_view')) { + //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->location); + exit; + } + + //add the settings object + $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); + $transcribe_enabled = $settings->get('transcribe', 'enabled', 'false'); + $transcribe_engine = $settings->get('transcribe', 'engine', ''); + + //transcribe multiple recordings + if ($transcribe_enabled == 'true' && !empty($transcribe_engine) && is_array($records) && @sizeof($records) != 0) { + //add the transcribe object + $transcribe = new transcribe($settings); + + //build the array + $x = 0; + foreach ($records as $record) { + //add to the array + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { + + //get the call recording file name and path + $sql = "select call_recording_name, call_recording_path "; + $sql .= "from view_call_recordings "; + $sql .= "where call_recording_uuid = :call_recording_uuid "; + $sql .= "and call_recording_transcription is null "; + $parameters['call_recording_uuid'] = $record['uuid']; + $database = new database; + $field = $database->select($sql, $parameters, 'row'); + if ( + is_array($field) && + @sizeof($field) != 0 && + file_exists($field['call_recording_path'].'/'.$field['call_recording_name']) + ) { + //audio to text - get the transcription from the audio file + $transcribe->audio_path = $field['call_recording_path']; + $transcribe->audio_filename = $field['call_recording_name']; + $record_transcription = $transcribe->transcribe(); + //build call recording data array + if (!empty($record_transcription)) { + $array['xml_cdr'][$x]['xml_cdr_uuid'] = $record['uuid']; + $array['xml_cdr'][$x]['record_transcription'] = $record_transcription; + } + //increment the id + $x++; + } + unset($sql, $parameters, $field); + + } + } + + //update the checked rows + if (is_array($array) && @sizeof($array) != 0) { + + //add temporary permissions + $p = new permissions; + $p->add('xml_cdr_edit', 'temp'); + + //remove record_path, record_name and record_length + $database = new database; + $database->app_name = 'xml_cdr'; + $database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848'; + $database->save($array, false); + $message = $database->message; + unset($array); + + //remove the temporary permissions + $p->delete('xml_cdr_edit', 'temp'); + + //set message + message::add($text['message-audio_transcribed']); + + } + unset($records); + } + } + } + + /** + * download the recordings + */ + public function download($records = null) { + if (permission_exists('call_recording_play') || permission_exists('call_recording_download')) { + + //single recording + if (empty($records) || !is_array($records) || @sizeof($records) == 0) { + + //get call recording from database + if (is_uuid($this->recording_uuid)) { + $sql = "select call_recording_name, call_recording_path "; + if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { + $sql = ", call_recording_base64 "; + } + $sql .= "from view_call_recordings "; + $sql .= "where call_recording_uuid = :call_recording_uuid "; + $parameters['call_recording_uuid'] = $this->recording_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($row) && @sizeof($row) != 0) { + $call_recording_name = $row['call_recording_name']; + $call_recording_path = $row['call_recording_path']; + if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { + file_put_contents($call_recording_path.'/'.$call_recording_name, base64_decode($row['call_recording_base64'])); + } + } + unset($sql, $parameters, $row); + } + + //build full path + $full_recording_path = $call_recording_path.'/'.$call_recording_name; + + //download the file + if ($full_recording_path != '/' && file_exists($full_recording_path)) { + ob_clean(); + $fd = fopen($full_recording_path, "rb"); + if ($this->binary) { + header("Content-Type: application/force-download"); + header("Content-Type: application/octet-stream"); + header("Content-Type: application/download"); + header("Content-Description: File Transfer"); + } + else { + $file_ext = pathinfo($call_recording_name, PATHINFO_EXTENSION); + switch ($file_ext) { + case "wav" : header("Content-Type: audio/x-wav"); break; + case "mp3" : header("Content-Type: audio/mpeg"); break; + case "ogg" : header("Content-Type: audio/ogg"); break; + } + } + header('Content-Disposition: attachment; filename="'.$call_recording_name.'"'); + header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past + if ($this->binary) { + header("Content-Length: ".filesize($full_recording_path)); + } + ob_clean(); + + //content-range + if (isset($_SERVER['HTTP_RANGE']) && !$this->binary) { + $this->range_download($full_recording_path); + } + + fpassthru($fd); + } + + //if base64, remove temp recording file + if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { + @unlink($full_recording_path); + } + + } + + //multiple recordings + else { + + //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->location); + exit; + } + + //drop unchecked records + foreach ($records as $i => $record) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { + $uuids[] = $record['uuid']; + } + } + unset($records, $record); + + //get data for recordings + if (!empty($uuids) && is_array($uuids) && @sizeof($uuids) != 0) { + $sql = "select call_recording_name, call_recording_path "; + if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && $row['call_recording_base64'] != '') { + $sql = ", call_recording_base64 "; + } + $sql .= "from view_call_recordings "; + $sql .= "where call_recording_uuid in ('".implode("','", $uuids)."') "; + $database = new database; + $rows = $database->select($sql, null, 'all'); + if (!empty($rows) && is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + $call_recording_name = $row['call_recording_name']; + $call_recording_path = $row['call_recording_path']; + if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { + file_put_contents($call_recording_path.'/'.$call_recording_name, base64_decode($row['call_recording_base64'])); + } + if (file_exists($call_recording_path.'/'.$call_recording_name)) { + $full_recording_paths[] = $call_recording_path.'/'.$call_recording_name; + } + } + } + unset($sql, $rows, $row); + } + + //compress the recordings + if (!empty($full_recording_paths) && is_array($full_recording_paths) && @sizeof($full_recording_paths) != 0) { + header("Content-Type: application/x-zip"); + header("Content-Description: File Transfer"); + header('Content-Disposition: attachment; filename="call_recordings.zip"'); + header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past + passthru("zip -qj - ".implode(' ', $full_recording_paths)); + } + + + //if base64, remove temp recording file + if (!empty($_SESSION['call_recordings']['storage_type']['text']) && $_SESSION['call_recordings']['storage_type']['text'] == 'base64' && !empty($row['call_recording_base64'])) { + foreach ($full_recording_paths as $full_recording_path) { + @unlink($full_recording_path); + } + } + + exit; + + } + + } + + } //method + + /* + * range download method (helps safari play audio sources) + */ + private function range_download($file) { + $fp = @fopen($file, 'rb'); + + $size = filesize($file); // File size + $length = $size; // Content length + $start = 0; // Start byte + $end = $size - 1; // End byte + // Now that we've gotten so far without errors we send the accept range header + /* At the moment we only support single ranges. + * Multiple ranges requires some more work to ensure it works correctly + * and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2 + * + * Multirange support annouces itself with: + * header('Accept-Ranges: bytes'); + * + * Multirange content must be sent with multipart/byteranges mediatype, + * (mediatype = mimetype) + * as well as a boundry header to indicate the various chunks of data. + */ + header("Accept-Ranges: 0-".$length); + // header('Accept-Ranges: bytes'); + // multipart/byteranges + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2 + if (isset($_SERVER['HTTP_RANGE'])) { + + $c_start = $start; + $c_end = $end; + // Extract the range string + list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); + // Make sure the client hasn't sent us a multibyte range + if (strpos($range, ',') !== false) { + // (?) Shoud this be issued here, or should the first + // range be used? Or should the header be ignored and + // we output the whole content? + header('HTTP/1.1 416 Requested Range Not Satisfiable'); + header("Content-Range: bytes $start-$end/$size"); + // (?) Echo some info to the client? + exit; + } + // If the range starts with an '-' we start from the beginning + // If not, we forward the file pointer + // And make sure to get the end byte if spesified + if ($range[0] == '-') { + // The n-number of the last bytes is requested + $c_start = $size - substr($range, 1); + } + else { + $range = explode('-', $range); + $c_start = $range[0]; + $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size; + } + /* Check the range and make sure it's treated according to the specs. + * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html + */ + // End bytes can not be larger than $end. + $c_end = ($c_end > $end) ? $end : $c_end; + // Validate the requested range and return an error if it's not correct. + if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) { + + header('HTTP/1.1 416 Requested Range Not Satisfiable'); + header("Content-Range: bytes $start-$end/$size"); + // (?) Echo some info to the client? + exit; + } + $start = $c_start; + $end = $c_end; + $length = $end - $start + 1; // Calculate new content length + fseek($fp, $start); + header('HTTP/1.1 206 Partial Content'); + } + // Notify the client the byte range we'll be outputting + header("Content-Range: bytes $start-$end/$size"); + header("Content-Length: $length"); + + // Start buffered download + $buffer = 1024 * 8; + while(!feof($fp) && ($p = ftell($fp)) <= $end) { + if ($p + $buffer > $end) { + // In case we're only outputtin a chunk, make sure we don't + // read past the length + $buffer = $end - $p + 1; + } + set_time_limit(0); // Reset time limit for big files + echo fread($fp, $buffer); + flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit. + } + + fclose($fp); + } + + /** + * Called by the maintenance service to clean out old call recordings + * @param settings $settings + * @return void + */ + public static function filesystem_maintenance(settings $settings): void { + //get the database connection object + $database = $settings->database(); + + //get an associative array of domain_uuid => domain_names + $domains = maintenance::get_domains($database); + + //loop over each domain + foreach ($domains as $domain_uuid => $domain_name) { + //get the settings for this domain + $domain_settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]); + + //get the recording location for this domain + $call_recording_location = $domain_settings->get('switch', 'recordings', '/var/lib/freeswitch/storage/recordings') . '/default'; + + //get the retention days for this domain + $retention_days = $domain_settings->get('call_recordings', 'filesystem_retention_days', ''); + + //ensure retention days are not empty + if (!empty($retention_days) && is_numeric($retention_days)) { + $retention_days = intval($retention_days); + + //get list of mp3 and wav files + $mp3_files = glob("$call_recording_location/$domain_name/*/archive/*.mp3"); + $wav_files = glob("$call_recording_location/$domain_name/*/archive/*.wav"); + + //combine to single array + $domain_call_recording_files = array_merge($mp3_files, $wav_files); + + //loop over each call recording mp3 or wav file + foreach ($domain_call_recording_files as $file) { + + //use the maintenance service class helper function to get the modified date and see if it is older + if (maintenance_service::days_since_modified($file) > $retention_days) { + //remove the file when it is older + if (unlink($file)) { + //log success + maintenance_service::log_write(self::class, "Removed $file from call_recordings", $domain_uuid); + } else { + //log failure + maintenance_service::log_write(self::class, "Unable to remove $file", $domain_uuid, maintenance_service::LOG_ERROR); + } + } else { + //file is not older - do nothing + } + } + } + else { + //report the retention days is not set correctly + maintenance_service::log_write(self::class, "Retention days not set or not a valid number", $domain_uuid, maintenance_service::LOG_ERROR); + } + } + } + + } //class +} + +?> diff --git a/app/destinations/destination_imports.php b/app/destinations/destination_imports.php index 673950c879..851326302c 100644 --- a/app/destinations/destination_imports.php +++ b/app/destinations/destination_imports.php @@ -1,1042 +1,1042 @@ - - Portions created by the Initial Developer are Copyright (C) 2018-2024 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('destination_import')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher - if(!function_exists('str_getcsv')) { - function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { - $fp = fopen("php://memory", 'r+'); - fputs($fp, $input); - rewind($fp); - $data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0 - fclose($fp); - return $data; - } - } - -//get the http get values and set them as php variables - $action = $_POST["action"] ?? null; - $from_row = $_POST["from_row"] ?? null; - $delimiter = $_POST["data_delimiter"] ?? null; - $enclosure = $_POST["data_enclosure"] ?? null; - $destination_type = $_POST["destination_type"] ?? null; - $destination_action = $_POST["destination_action"] ?? null; - $destination_context = $_POST["destination_context"] ?? null; - $destination_record = $_POST["destination_record"] ?? null; - -//set the defaults - if (empty($destination_type)) { $destination_type = 'inbound'; } - if (empty($destination_context)) { $destination_context = 'public'; } - if ($destination_type =="outbound" && $destination_context == "public") { $destination_context = $_SESSION['domain_name']; } - if ($destination_type =="outbound" && empty($destination_context)) { $destination_context = $_SESSION['domain_name']; } - if (empty($from_row)) { $from_row = '2'; } - -//save the data to the csv file - if (isset($_POST['data'])) { - $file = $_SESSION['server']['temp']['dir']."/destinations-".$_SESSION['domain_name'].".csv"; - file_put_contents($file, $_POST['data']); - $_SESSION['file'] = $file; - $_SESSION['file_name'] = $_FILES['ulfile']['name']; - } - -//copy the csv file - //$_POST['submit'] == "Upload" && - if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('destination_upload')) { - if ($_POST['type'] == 'csv') { - move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']); - $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']); - //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*'); - unset($_POST['txtCommand']); - $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']; - $_SESSION['file'] = $file; - } - } - -//get the schema - if (!empty($delimiter)) { - //get the first line - $line = fgets(fopen($_SESSION['file'], 'r')); - $line_fields = explode($delimiter, $line); - - //get the schema - $x = 0; - include "app/destinations/app_config.php"; - $i = 0; - foreach ($apps[0]['db'] as $table) { - //get the table name and parent name - $table_name = $table["table"]['name']; - $parent_name = $table["table"]['parent']; - - //remove the v_ table prefix - if (substr($table_name, 0, 2) == 'v_') { - $table_name = substr($table_name, 2); - } - if (substr($parent_name, 0, 2) == 'v_') { - $parent_name = substr($parent_name, 2); - } - - //filter for specific tables and build the schema array - if ($table_name == "destinations") { - $schema[$i]['table'] = $table_name; - $schema[$i]['parent'] = $parent_name; - foreach ($table['fields'] as $row) { - if (empty($row['deprecated']) || (!empty($row['deprecated']) && $row['deprecated'] !== 'true')) { - if (is_array($row['name'])) { - $field_name = $row['name']['text']; - } - else { - $field_name = $row['name']; - } - $schema[$i]['fields'][] = $field_name; - } - } - $i++; - } - } - } - -//get the parent table - function get_parent($schema,$table_name) { - foreach ($schema as $row) { - if ($row['table'] == $table_name) { - return $row['parent']; - } - } - } - -//upload the destination csv - if (file_exists($_SESSION['file'] ?? '') && $action == 'add') { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: destination_imports.php'); - exit; - } - - //user selected fields - $fields = $_POST['fields']; - $domain_uuid = $_POST['domain_uuid']; - $destination_record = $_POST['destination_record']; - $destination_type = $_POST['destination_type']; - $destination_context = $_POST['destination_context']; - $destination_enabled = $_POST['destination_enabled']; - - //set the domain_uuid - $domain_uuid = $_SESSION['domain_uuid']; - - //get the contents of the csv file and convert them into an array - $handle = @fopen($_SESSION['file'], "r"); - if ($handle) { - //pre-set the numbers - $row_id = 0; - $row_number = 1; - - //loop through the array - while (($line = fgets($handle, 4096)) !== false) { - if ($from_row <= $row_number) { - //format the data - $y = 0; - foreach ($fields as $key => $value) { - //get the line - $result = str_getcsv($line, $delimiter, $enclosure); - - //get the table and field name - $field_array = explode(".",$value); - $table_name = $field_array[0] ?? null; - $field_name = $field_array[1] ?? null; - - //get the parent table name - $parent = get_parent($schema, $table_name); - - //remove formatting from the phone number - if ($field_name == "phone_number") { - $result[$key] = preg_replace('{\D}', '', $result[$key]); - } - - //build the data array - if (!empty($table_name)) { - if (empty($parent)) { - $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; - $array[$table_name][$row_id][$field_name] = $result[$key]; - } - else { - $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; - $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; - } - } - - //get the destination_number - if ($key === 'destination_number') { $destination_number = $result[$key]; } - if ($key === 'destination_description') { $destination_description = $result[$key]; } - if ($key === 'destination_app') { $destination_app = $result[$key]; echo "destination_app $destination_app\n"; } - if ($key === 'destination_data') { $destination_data = $result[$key]; echo "destination_data $destination_data\n"; } - } - - //add the actions - foreach ($array['destinations'] as $row) { - - //build the array - if (!empty($row['destination_actions']) && is_json($row['destination_actions'])) { - $destination_actions = $row['destination_actions']; // use json actions - $temp = json_decode($row['destination_actions'], true); - $row['destination_app'] = $temp[array_key_last($temp)]['destination_app']; - $row['destination_data'] = $temp[array_key_last($temp)]['destination_data']; - unset($temp); - } - else if (!empty($row['destination_app']) && !empty($row['destination_data'])) { - $actions[0]['destination_app'] = $row['destination_app']; - $actions[0]['destination_data'] = $row['destination_data']; - $destination_actions = json_encode($actions); - unset($actions); - } - - //get the values - $destination_number = $row['destination_number']; - $destination_app = $row['destination_app']; - $destination_data = $row['destination_data']; - $destination_prefix = $row['destination_prefix']; - $destination_accountcode = $row['destination_accountcode']; - $destination_cid_name_prefix = $row['destination_cid_name_prefix']; - $destination_description = $row['destination_description']; - - //convert the number to a regular expression - if (isset($destination_prefix) && !empty($destination_prefix)) { - $destination_number_regex = string_to_regex($destination_number, $destination_prefix); - } - else { - $destination_number_regex = string_to_regex($destination_number); - } - - //add the additional fields - $dialplan_uuid = uuid(); - $array["destinations"][$row_id]['destination_actions'] = $destination_actions; - $array["destinations"][$row_id]['destination_app'] = $destination_app; - $array["destinations"][$row_id]['destination_data'] = $destination_data; - $array["destinations"][$row_id]['destination_type'] = $destination_type; - $array["destinations"][$row_id]['destination_record'] = $destination_record; - $array["destinations"][$row_id]['destination_context'] = $destination_context; - $array["destinations"][$row_id]['destination_number_regex'] = $destination_number_regex; - $array["destinations"][$row_id]['destination_enabled'] = $destination_enabled; - $array["destinations"][$row_id]['dialplan_uuid'] = $dialplan_uuid; - - //build the dialplan array - $array["dialplans"][$row_id]["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4"; - $array["dialplans"][$row_id]["dialplan_uuid"] = $dialplan_uuid; - $array["dialplans"][$row_id]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_name"] = !empty($dialplan_name) ? $dialplan_name : format_phone($destination_number); - $array["dialplans"][$row_id]["dialplan_number"] = $destination_number; - $array["dialplans"][$row_id]["dialplan_context"] = $destination_context; - $array["dialplans"][$row_id]["dialplan_continue"] = "false"; - $array["dialplans"][$row_id]["dialplan_order"] = "100"; - $array["dialplans"][$row_id]["dialplan_enabled"] = $destination_enabled; - $array["dialplans"][$row_id]["dialplan_description"] = $destination_description; - $dialplan_detail_order = 10; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //set the dialplan detail type - if (!empty($_SESSION['dialplan']['destination']['text'])) { - $dialplan_detail_type = $_SESSION['dialplan']['destination']['text']; - } - else { - $dialplan_detail_type = "destination_number"; - } - - //authorized specific dialplan_detail_type that are safe, sanitize all other values - switch ($dialplan_detail_type) { - case 'destination_number': - break; - case '${sip_to_user}': - break; - case '${sip_req_user}': - break; - default: - $dialplan_detail_type = xml::sanitize($dialplan_detail_type); - } - - //build the xml dialplan - $array["dialplans"][$row_id]["dialplan_xml"] = "\n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - if (!empty($destination_cid_name_prefix)) { - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - } - if (!empty($destination_record)) { - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - } - if (!empty($destination_accountcode)) { - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - } - if (!empty($destination_carrier)) { - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - } - if (!empty($fax_uuid)) { - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - } - if (!empty($destination_data) && $destination_app == 'bridge') { - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - } - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; - $array["dialplans"][$row_id]["dialplan_xml"] .= "\n"; - - //dialplan details - if ($_SESSION['destinations']['dialplan_details']['boolean'] == "true") { - - //check the destination number - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; - if (!empty($_SESSION['dialplan']['destination']['text'])) { - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text']; - } - else { - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number"; - } - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //set the caller id name prefix - if (!empty($destination_cid_name_prefix)) { - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "effective_caller_id_name=".$destination_cid_name_prefix."#\${caller_id_name}"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //enable call recordings - if ($destination_record == "true") { - - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "answer"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = ""; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "record_path=\${recordings_dir}/\${domain_name}/archive/\${strftime(%Y)}/\${strftime(%b)}/\${strftime(%d)}"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "record_name=\${uuid}.\${record_ext}"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //add a variable - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "recording_follow_transfer=true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "record_session"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "\${record_path}/\${record_name}"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "false"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //set the call accountcode - if (!empty($destination_accountcode)) { - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //add hangup_after_bridge and continue_on_fail - if (!empty($destination_data) && $destination_app == 'bridge') { - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "hangup_after_bridge=true"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "continue_on_fail=true"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //set the destination app and data - if (strlen($destination_app) > 0 && !empty($destination_data)) { - $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = $destination_app; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = $destination_data; - $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //set inline to true - if (!empty($action_app) && ($action_app == 'set' || $action_app == 'export')) { - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; - } - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //set the detail id back to 0 - $y = 0; - - } //end if - } //foreach - - //process a chunk of the array - if ($row_id === 1000) { - - //save to the data - $database = new database; - $database->app_name = 'destinations'; - $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; - $database->save($array); - //$message = $database->message; - - //clear the array - unset($array); - - //set the row id back to 0 - $row_id = 0; - } - - } - $row_number++; - $row_id++; - } - fclose($handle); - - //save to the data - if (!empty($array) && is_array($array)) { - $database = new database; - $database->app_name = 'destinations'; - $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; - $database->save($array); - $message = $database->message; - } - - } - - //send the redirect header - header("Location: destinations.php?type=".$destination_type); - exit; - - } - -//upload the destination csv - if (file_exists($_SESSION['file'] ?? '') && $action == 'delete') { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: destination_imports.php'); - exit; - } - - //user selected fields - $fields = $_POST['fields']; - $domain_uuid = $_POST['domain_uuid']; - $destination_type = $_POST['destination_type']; - $destination_context = $_POST['destination_context']; - $destination_enabled = $_POST['destination_enabled']; - - //set the domain_uuid - $domain_uuid = $_SESSION['domain_uuid']; - - //get the contents of the csv file and convert them into an array - $handle = @fopen($_SESSION['file'], "r"); - if ($handle) { - //set the starting identifiers - $row_id = 0; - $dialplan_id = 0; - $row_number = 1; - - //loop through the array - while (($line = fgets($handle, 4096)) !== false) { - if ($from_row <= $row_number) { - - //format the data - $y = 0; - foreach ($fields as $key => $value) { - //get the line - $result = str_getcsv($line, $delimiter, $enclosure); - - //get the table and field name - $field_array = explode(".",$value); - $table_name = $field_array[0]; - $field_name = $field_array[1]; - - //get the parent table name - $parent = get_parent($schema, $table_name); - - //remove formatting from the phone number - if ($field_name == "phone_number") { - $result[$key] = preg_replace('{\D}', '', $result[$key]); - } - - //build the data array - if (!empty($table_name)) { - if (empty($parent)) { - $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; - $array[$table_name][$row_id][$field_name] = $result[$key]; - } - else { - $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; - $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; - } - } - - //get the destination_number - if ($key === 'destination_number') { $destination_number = $result[$key]; } - if ($key === 'destination_uuid') { $destination_uuid = $result[$key]; } - if ($key === 'dialplan_uuid') { $destination_uuid = $result[$key]; } - } - - //delete the destinations - foreach ($array['destinations'] as $row) { - //get the values - $domain_uuid = $row['domain_uuid']; - $destination_number = $row['destination_number']; - - //get the dialplan uuid - if (empty($row['destination_number']) || !is_uuid($row['dialplan_uuid'])) { - $sql = "select * from v_destinations "; - $sql .= "where domain_uuid = :domain_uuid "; - $sql .= "and destination_number = :destination_number; "; - $parameters['domain_uuid'] = $domain_uuid; - $parameters['destination_number'] = $destination_number; - $database = new database; - $destinations = $database->select($sql, $parameters, 'all'); - $row = $destinations[0]; - unset($sql, $parameters); - - //add to the array - //$array['destinations'][$row_id] = $destinations[0]; - $array['destinations'][$row_id]['destination_uuid'] = $destinations[0]['destination_uuid']; - if (!empty($row['dialplan_uuid'])) { - $array['destinations'][$row_id]['dialplan_uuid'] = $destinations[0]['dialplan_uuid']; - //$array['dialplans'][$row_id]['dialplan_uuid'] = $destinations[0]['dialplan_uuid']; - } - } - } - - } - $row_number++; - - //process a chunk of the array - if ($row_id === 1000) { - //delete the destinations - $row_number = 0; - foreach ($array['destinations'] as $row) { - //delete the dialplan - if (is_uuid($row['dialplan_uuid'])) { - $sql = "delete from v_dialplan_details "; - $sql .= "where dialplan_uuid = :dialplan_uuid "; - $parameters['dialplan_uuid'] = $row['dialplan_uuid']; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); - - $sql = "delete from v_dialplans "; - $sql .= "where dialplan_uuid = :dialplan_uuid "; - $parameters['dialplan_uuid'] = $row['dialplan_uuid']; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); - } - - //delete the destinations - if (is_uuid($row['destination_uuid'])) { - $sql = "delete from v_destinations "; - $sql .= "where destination_uuid = :destination_uuid "; - $parameters['destination_uuid'] = $row['destination_uuid']; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); - } - } - - //clear the array - unset($array); - - //set the row id back to 0 - $row_id = 0; - } - - //increment row id - $row_id++; - } - fclose($handle); - - //delete the remaining destinations - if ($row_id < 1000) { - foreach ($array['destinations'] as $row) { - //delete the dialplan - if (is_uuid($row['dialplan_uuid'])) { - $sql = "delete from v_dialplan_details "; - $sql .= "where dialplan_uuid = :dialplan_uuid "; - $parameters['dialplan_uuid'] = $row['dialplan_uuid']; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); - - $sql = "delete from v_dialplans "; - $sql .= "where dialplan_uuid = :dialplan_uuid "; - $parameters['dialplan_uuid'] = $row['dialplan_uuid']; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); - } - - //delete the destinations - if (is_uuid($row['destination_uuid'])) { - $sql = "delete from v_destinations "; - $sql .= "where destination_uuid = :destination_uuid "; - $parameters['destination_uuid'] = $row['destination_uuid']; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); - } - } - } - - //set response - message::add($text['message-delete'], 'positive'); - - //send the redirect header - header("Location: /app/destinations/destinations.php?type=".$destination_type); - exit; - } - } - -//match the column names to the field names - if (!empty($delimiter) && file_exists($_SESSION['file']) && ($action !== 'add' or $action !== 'delete')) { - - //create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - - //include the header - $document['title'] = $text['title-destination_import']; - require_once "resources/header.php"; - - //form to match the fields to the column names - echo "
\n"; - - echo "
\n"; - echo "
".$text['header-destination_import']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'destination_imports.php']); - echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['description-destination_import']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - - if (isset($_SESSION['file_name']) && !empty($_SESSION['file_name'])) { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - } - - //loop through user columns - $x = 0; - foreach ($line_fields as $line_field) { - $line_field = preg_replace('#[^a-zA-Z0-9_]#', '', $line_field); - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - $x++; - } - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - //if (permission_exists('destination_context')) { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - //} - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - if (permission_exists('destination_domain')) { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - } - else { - echo "\n"; - } - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - echo " ".$text['label-file_name']."\n"; - echo "\n"; - echo " ".$_SESSION['file_name']."\n"; - echo "
\n"; - //echo $text['description-file_name']."\n"; - echo "
\n"; - echo $line_field; - echo " \n"; - echo " \n"; - //echo "
\n"; - //echo $text['description-zzz']."\n"; - echo "
\n"; - echo " ".$text['label-destination_type']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-destination_type']."\n"; - echo "
\n"; - echo " ".$text['label-destination_record']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo ($text['description-destination_record'] ?? null)."\n"; - echo "
\n"; - echo " ".$text['label-destination_context']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-destination_context']."\n"; - echo "
\n"; - echo " ".$text['label-actions']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo ($text['description-actions'] ?? null)."\n"; - echo "
\n"; - echo " ".$text['label-domain']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-domain_name']."\n"; - echo "
\n"; - echo " ".$text['label-destination_enabled']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo ($text['description-destination_enabled'] ?? null)."\n"; - echo "
\n"; - echo "
\n"; - echo "

\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - - require_once "resources/footer.php"; - - //normalize the column names - //$line = strtolower($line); - //$line = str_replace("-", "_", $line); - //$line = str_replace($delimiter."title".$delimiter, $delimiter."destination_title".$delimiter, $line); - //$line = str_replace("firstname", "name_given", $line); - //$line = str_replace("lastname", "name_family", $line); - //$line = str_replace("company", "organization", $line); - //$line = str_replace("company", "destination_email", $line); - - //end the script - exit; - } - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//include the header - $document['title'] = $text['title-destination_import']; - require_once "resources/header.php"; - -//show the content - echo "
\n"; - - echo "
\n"; - echo "
".$text['header-destination_import']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'destinations.php']); - echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['description-destination_import']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - if (permission_exists('destination_upload')) { - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - } - - echo "
\n"; - echo " ".$text['label-import_data']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_data']."\n"; - echo "
\n"; - echo " ".$text['label-from_row']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-from_row']."\n"; - echo "
\n"; - echo " ".$text['label-import_delimiter']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_delimiter']."\n"; - echo "
\n"; - echo " ".$text['label-import_enclosure']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_enclosure']."\n"; - echo "
\n"; - echo " ".$text['label-import_file_upload']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo ($text['description-import_file_upload'] ?? null)."\n"; - echo "
\n"; - echo "
\n"; - echo "

"; - - echo "\n"; - echo "\n"; - - echo "
"; - -//include the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2018-2024 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('destination_import')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher + if(!function_exists('str_getcsv')) { + function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { + $fp = fopen("php://memory", 'r+'); + fputs($fp, $input); + rewind($fp); + $data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0 + fclose($fp); + return $data; + } + } + +//get the http get values and set them as php variables + $action = $_POST["action"] ?? null; + $from_row = $_POST["from_row"] ?? null; + $delimiter = $_POST["data_delimiter"] ?? null; + $enclosure = $_POST["data_enclosure"] ?? null; + $destination_type = $_POST["destination_type"] ?? null; + $destination_action = $_POST["destination_action"] ?? null; + $destination_context = $_POST["destination_context"] ?? null; + $destination_record = $_POST["destination_record"] ?? null; + +//set the defaults + if (empty($destination_type)) { $destination_type = 'inbound'; } + if (empty($destination_context)) { $destination_context = 'public'; } + if ($destination_type =="outbound" && $destination_context == "public") { $destination_context = $_SESSION['domain_name']; } + if ($destination_type =="outbound" && empty($destination_context)) { $destination_context = $_SESSION['domain_name']; } + if (empty($from_row)) { $from_row = '2'; } + +//save the data to the csv file + if (isset($_POST['data'])) { + $file = $_SESSION['server']['temp']['dir']."/destinations-".$_SESSION['domain_name'].".csv"; + file_put_contents($file, $_POST['data']); + $_SESSION['file'] = $file; + $_SESSION['file_name'] = $_FILES['ulfile']['name']; + } + +//copy the csv file + //$_POST['submit'] == "Upload" && + if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('destination_upload')) { + if ($_POST['type'] == 'csv') { + move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']); + $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']); + //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*'); + unset($_POST['txtCommand']); + $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']; + $_SESSION['file'] = $file; + } + } + +//get the schema + if (!empty($delimiter)) { + //get the first line + $line = fgets(fopen($_SESSION['file'], 'r')); + $line_fields = explode($delimiter, $line); + + //get the schema + $x = 0; + include "app/destinations/app_config.php"; + $i = 0; + foreach ($apps[0]['db'] as $table) { + //get the table name and parent name + $table_name = $table["table"]['name']; + $parent_name = $table["table"]['parent']; + + //remove the v_ table prefix + if (substr($table_name, 0, 2) == 'v_') { + $table_name = substr($table_name, 2); + } + if (substr($parent_name, 0, 2) == 'v_') { + $parent_name = substr($parent_name, 2); + } + + //filter for specific tables and build the schema array + if ($table_name == "destinations") { + $schema[$i]['table'] = $table_name; + $schema[$i]['parent'] = $parent_name; + foreach ($table['fields'] as $row) { + if (empty($row['deprecated']) || (!empty($row['deprecated']) && $row['deprecated'] !== 'true')) { + if (is_array($row['name'])) { + $field_name = $row['name']['text']; + } + else { + $field_name = $row['name']; + } + $schema[$i]['fields'][] = $field_name; + } + } + $i++; + } + } + } + +//get the parent table + function get_parent($schema,$table_name) { + foreach ($schema as $row) { + if ($row['table'] == $table_name) { + return $row['parent']; + } + } + } + +//upload the destination csv + if (file_exists($_SESSION['file'] ?? '') && $action == 'add') { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: destination_imports.php'); + exit; + } + + //user selected fields + $fields = $_POST['fields']; + $domain_uuid = $_POST['domain_uuid']; + $destination_record = $_POST['destination_record']; + $destination_type = $_POST['destination_type']; + $destination_context = $_POST['destination_context']; + $destination_enabled = $_POST['destination_enabled']; + + //set the domain_uuid + $domain_uuid = $_SESSION['domain_uuid']; + + //get the contents of the csv file and convert them into an array + $handle = @fopen($_SESSION['file'], "r"); + if ($handle) { + //pre-set the numbers + $row_id = 0; + $row_number = 1; + + //loop through the array + while (($line = fgets($handle, 4096)) !== false) { + if ($from_row <= $row_number) { + //format the data + $y = 0; + foreach ($fields as $key => $value) { + //get the line + $result = str_getcsv($line, $delimiter, $enclosure); + + //get the table and field name + $field_array = explode(".",$value); + $table_name = $field_array[0] ?? null; + $field_name = $field_array[1] ?? null; + + //get the parent table name + $parent = get_parent($schema, $table_name); + + //remove formatting from the phone number + if ($field_name == "phone_number") { + $result[$key] = preg_replace('{\D}', '', $result[$key]); + } + + //build the data array + if (!empty($table_name)) { + if (empty($parent)) { + $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; + $array[$table_name][$row_id][$field_name] = $result[$key]; + } + else { + $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; + $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; + } + } + + //get the destination_number + if ($key === 'destination_number') { $destination_number = $result[$key]; } + if ($key === 'destination_description') { $destination_description = $result[$key]; } + if ($key === 'destination_app') { $destination_app = $result[$key]; echo "destination_app $destination_app\n"; } + if ($key === 'destination_data') { $destination_data = $result[$key]; echo "destination_data $destination_data\n"; } + } + + //add the actions + foreach ($array['destinations'] as $row) { + + //build the array + if (!empty($row['destination_actions']) && is_json($row['destination_actions'])) { + $destination_actions = $row['destination_actions']; // use json actions + $temp = json_decode($row['destination_actions'], true); + $row['destination_app'] = $temp[array_key_last($temp)]['destination_app']; + $row['destination_data'] = $temp[array_key_last($temp)]['destination_data']; + unset($temp); + } + else if (!empty($row['destination_app']) && !empty($row['destination_data'])) { + $actions[0]['destination_app'] = $row['destination_app']; + $actions[0]['destination_data'] = $row['destination_data']; + $destination_actions = json_encode($actions); + unset($actions); + } + + //get the values + $destination_number = $row['destination_number']; + $destination_app = $row['destination_app']; + $destination_data = $row['destination_data']; + $destination_prefix = $row['destination_prefix']; + $destination_accountcode = $row['destination_accountcode']; + $destination_cid_name_prefix = $row['destination_cid_name_prefix']; + $destination_description = $row['destination_description']; + + //convert the number to a regular expression + if (isset($destination_prefix) && !empty($destination_prefix)) { + $destination_number_regex = string_to_regex($destination_number, $destination_prefix); + } + else { + $destination_number_regex = string_to_regex($destination_number); + } + + //add the additional fields + $dialplan_uuid = uuid(); + $array["destinations"][$row_id]['destination_actions'] = $destination_actions; + $array["destinations"][$row_id]['destination_app'] = $destination_app; + $array["destinations"][$row_id]['destination_data'] = $destination_data; + $array["destinations"][$row_id]['destination_type'] = $destination_type; + $array["destinations"][$row_id]['destination_record'] = $destination_record; + $array["destinations"][$row_id]['destination_context'] = $destination_context; + $array["destinations"][$row_id]['destination_number_regex'] = $destination_number_regex; + $array["destinations"][$row_id]['destination_enabled'] = $destination_enabled; + $array["destinations"][$row_id]['dialplan_uuid'] = $dialplan_uuid; + + //build the dialplan array + $array["dialplans"][$row_id]["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4"; + $array["dialplans"][$row_id]["dialplan_uuid"] = $dialplan_uuid; + $array["dialplans"][$row_id]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_name"] = !empty($dialplan_name) ? $dialplan_name : format_phone($destination_number); + $array["dialplans"][$row_id]["dialplan_number"] = $destination_number; + $array["dialplans"][$row_id]["dialplan_context"] = $destination_context; + $array["dialplans"][$row_id]["dialplan_continue"] = "false"; + $array["dialplans"][$row_id]["dialplan_order"] = "100"; + $array["dialplans"][$row_id]["dialplan_enabled"] = $destination_enabled; + $array["dialplans"][$row_id]["dialplan_description"] = $destination_description; + $dialplan_detail_order = 10; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //set the dialplan detail type + if (!empty($_SESSION['dialplan']['destination']['text'])) { + $dialplan_detail_type = $_SESSION['dialplan']['destination']['text']; + } + else { + $dialplan_detail_type = "destination_number"; + } + + //authorized specific dialplan_detail_type that are safe, sanitize all other values + switch ($dialplan_detail_type) { + case 'destination_number': + break; + case '${sip_to_user}': + break; + case '${sip_req_user}': + break; + default: + $dialplan_detail_type = xml::sanitize($dialplan_detail_type); + } + + //build the xml dialplan + $array["dialplans"][$row_id]["dialplan_xml"] = "\n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + if (!empty($destination_cid_name_prefix)) { + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + } + if (!empty($destination_record)) { + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + } + if (!empty($destination_accountcode)) { + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + } + if (!empty($destination_carrier)) { + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + } + if (!empty($fax_uuid)) { + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + } + if (!empty($destination_data) && $destination_app == 'bridge') { + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + } + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= " \n"; + $array["dialplans"][$row_id]["dialplan_xml"] .= "\n"; + + //dialplan details + if ($_SESSION['destinations']['dialplan_details']['boolean'] == "true") { + + //check the destination number + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; + if (!empty($_SESSION['dialplan']['destination']['text'])) { + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text']; + } + else { + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number"; + } + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //set the caller id name prefix + if (!empty($destination_cid_name_prefix)) { + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "effective_caller_id_name=".$destination_cid_name_prefix."#\${caller_id_name}"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //enable call recordings + if ($destination_record == "true") { + + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "answer"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = ""; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "record_path=\${recordings_dir}/\${domain_name}/archive/\${strftime(%Y)}/\${strftime(%b)}/\${strftime(%d)}"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "record_name=\${uuid}.\${record_ext}"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //add a variable + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "recording_follow_transfer=true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "record_session"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "\${record_path}/\${record_name}"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_inline"] = "false"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //set the call accountcode + if (!empty($destination_accountcode)) { + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //add hangup_after_bridge and continue_on_fail + if (!empty($destination_data) && $destination_app == 'bridge') { + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "hangup_after_bridge=true"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = "continue_on_fail=true"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //set the destination app and data + if (strlen($destination_app) > 0 && !empty($destination_data)) { + $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_type"] = $destination_app; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_data"] = $destination_data; + $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //set inline to true + if (!empty($action_app) && ($action_app == 'set' || $action_app == 'export')) { + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; + } + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //set the detail id back to 0 + $y = 0; + + } //end if + } //foreach + + //process a chunk of the array + if ($row_id === 1000) { + + //save to the data + $database = new database; + $database->app_name = 'destinations'; + $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; + $database->save($array); + //$message = $database->message; + + //clear the array + unset($array); + + //set the row id back to 0 + $row_id = 0; + } + + } + $row_number++; + $row_id++; + } + fclose($handle); + + //save to the data + if (!empty($array) && is_array($array)) { + $database = new database; + $database->app_name = 'destinations'; + $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; + $database->save($array); + $message = $database->message; + } + + } + + //send the redirect header + header("Location: destinations.php?type=".$destination_type); + exit; + + } + +//upload the destination csv + if (file_exists($_SESSION['file'] ?? '') && $action == 'delete') { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: destination_imports.php'); + exit; + } + + //user selected fields + $fields = $_POST['fields']; + $domain_uuid = $_POST['domain_uuid']; + $destination_type = $_POST['destination_type']; + $destination_context = $_POST['destination_context']; + $destination_enabled = $_POST['destination_enabled']; + + //set the domain_uuid + $domain_uuid = $_SESSION['domain_uuid']; + + //get the contents of the csv file and convert them into an array + $handle = @fopen($_SESSION['file'], "r"); + if ($handle) { + //set the starting identifiers + $row_id = 0; + $dialplan_id = 0; + $row_number = 1; + + //loop through the array + while (($line = fgets($handle, 4096)) !== false) { + if ($from_row <= $row_number) { + + //format the data + $y = 0; + foreach ($fields as $key => $value) { + //get the line + $result = str_getcsv($line, $delimiter, $enclosure); + + //get the table and field name + $field_array = explode(".",$value); + $table_name = $field_array[0]; + $field_name = $field_array[1]; + + //get the parent table name + $parent = get_parent($schema, $table_name); + + //remove formatting from the phone number + if ($field_name == "phone_number") { + $result[$key] = preg_replace('{\D}', '', $result[$key]); + } + + //build the data array + if (!empty($table_name)) { + if (empty($parent)) { + $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; + $array[$table_name][$row_id][$field_name] = $result[$key]; + } + else { + $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; + $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; + } + } + + //get the destination_number + if ($key === 'destination_number') { $destination_number = $result[$key]; } + if ($key === 'destination_uuid') { $destination_uuid = $result[$key]; } + if ($key === 'dialplan_uuid') { $destination_uuid = $result[$key]; } + } + + //delete the destinations + foreach ($array['destinations'] as $row) { + //get the values + $domain_uuid = $row['domain_uuid']; + $destination_number = $row['destination_number']; + + //get the dialplan uuid + if (empty($row['destination_number']) || !is_uuid($row['dialplan_uuid'])) { + $sql = "select * from v_destinations "; + $sql .= "where domain_uuid = :domain_uuid "; + $sql .= "and destination_number = :destination_number; "; + $parameters['domain_uuid'] = $domain_uuid; + $parameters['destination_number'] = $destination_number; + $database = new database; + $destinations = $database->select($sql, $parameters, 'all'); + $row = $destinations[0]; + unset($sql, $parameters); + + //add to the array + //$array['destinations'][$row_id] = $destinations[0]; + $array['destinations'][$row_id]['destination_uuid'] = $destinations[0]['destination_uuid']; + if (!empty($row['dialplan_uuid'])) { + $array['destinations'][$row_id]['dialplan_uuid'] = $destinations[0]['dialplan_uuid']; + //$array['dialplans'][$row_id]['dialplan_uuid'] = $destinations[0]['dialplan_uuid']; + } + } + } + + } + $row_number++; + + //process a chunk of the array + if ($row_id === 1000) { + //delete the destinations + $row_number = 0; + foreach ($array['destinations'] as $row) { + //delete the dialplan + if (is_uuid($row['dialplan_uuid'])) { + $sql = "delete from v_dialplan_details "; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $row['dialplan_uuid']; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); + + $sql = "delete from v_dialplans "; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $row['dialplan_uuid']; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); + } + + //delete the destinations + if (is_uuid($row['destination_uuid'])) { + $sql = "delete from v_destinations "; + $sql .= "where destination_uuid = :destination_uuid "; + $parameters['destination_uuid'] = $row['destination_uuid']; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); + } + } + + //clear the array + unset($array); + + //set the row id back to 0 + $row_id = 0; + } + + //increment row id + $row_id++; + } + fclose($handle); + + //delete the remaining destinations + if ($row_id < 1000) { + foreach ($array['destinations'] as $row) { + //delete the dialplan + if (is_uuid($row['dialplan_uuid'])) { + $sql = "delete from v_dialplan_details "; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $row['dialplan_uuid']; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); + + $sql = "delete from v_dialplans "; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + $parameters['dialplan_uuid'] = $row['dialplan_uuid']; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); + } + + //delete the destinations + if (is_uuid($row['destination_uuid'])) { + $sql = "delete from v_destinations "; + $sql .= "where destination_uuid = :destination_uuid "; + $parameters['destination_uuid'] = $row['destination_uuid']; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); + } + } + } + + //set response + message::add($text['message-delete'], 'positive'); + + //send the redirect header + header("Location: /app/destinations/destinations.php?type=".$destination_type); + exit; + } + } + +//match the column names to the field names + if (!empty($delimiter) && file_exists($_SESSION['file']) && ($action !== 'add' or $action !== 'delete')) { + + //create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + + //include the header + $document['title'] = $text['title-destination_import']; + require_once "resources/header.php"; + + //form to match the fields to the column names + echo "
\n"; + + echo "
\n"; + echo "
".$text['header-destination_import']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'destination_imports.php']); + echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-destination_import']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + + if (isset($_SESSION['file_name']) && !empty($_SESSION['file_name'])) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + + //loop through user columns + $x = 0; + foreach ($line_fields as $line_field) { + $line_field = preg_replace('#[^a-zA-Z0-9_]#', '', $line_field); + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + $x++; + } + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + //if (permission_exists('destination_context')) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + //} + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + if (permission_exists('destination_domain')) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + else { + echo "\n"; + } + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo " ".$text['label-file_name']."\n"; + echo "\n"; + echo " ".$_SESSION['file_name']."\n"; + echo "
\n"; + //echo $text['description-file_name']."\n"; + echo "
\n"; + echo $line_field; + echo " \n"; + echo " \n"; + //echo "
\n"; + //echo $text['description-zzz']."\n"; + echo "
\n"; + echo " ".$text['label-destination_type']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-destination_type']."\n"; + echo "
\n"; + echo " ".$text['label-destination_record']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo ($text['description-destination_record'] ?? null)."\n"; + echo "
\n"; + echo " ".$text['label-destination_context']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-destination_context']."\n"; + echo "
\n"; + echo " ".$text['label-actions']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo ($text['description-actions'] ?? null)."\n"; + echo "
\n"; + echo " ".$text['label-domain']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-domain_name']."\n"; + echo "
\n"; + echo " ".$text['label-destination_enabled']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo ($text['description-destination_enabled'] ?? null)."\n"; + echo "
\n"; + echo "
\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + + require_once "resources/footer.php"; + + //normalize the column names + //$line = strtolower($line); + //$line = str_replace("-", "_", $line); + //$line = str_replace($delimiter."title".$delimiter, $delimiter."destination_title".$delimiter, $line); + //$line = str_replace("firstname", "name_given", $line); + //$line = str_replace("lastname", "name_family", $line); + //$line = str_replace("company", "organization", $line); + //$line = str_replace("company", "destination_email", $line); + + //end the script + exit; + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//include the header + $document['title'] = $text['title-destination_import']; + require_once "resources/header.php"; + +//show the content + echo "
\n"; + + echo "
\n"; + echo "
".$text['header-destination_import']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'destinations.php']); + echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-destination_import']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + if (permission_exists('destination_upload')) { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + + echo "
\n"; + echo " ".$text['label-import_data']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_data']."\n"; + echo "
\n"; + echo " ".$text['label-from_row']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-from_row']."\n"; + echo "
\n"; + echo " ".$text['label-import_delimiter']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_delimiter']."\n"; + echo "
\n"; + echo " ".$text['label-import_enclosure']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_enclosure']."\n"; + echo "
\n"; + echo " ".$text['label-import_file_upload']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo ($text['description-import_file_upload'] ?? null)."\n"; + echo "
\n"; + echo "
\n"; + echo "

"; + + echo "\n"; + echo "\n"; + + echo "
"; + +//include the footer + require_once "resources/footer.php"; + +?> diff --git a/app/extension_settings/extension_setting_edit.php b/app/extension_settings/extension_setting_edit.php index 86e66bc7e7..11fcb3d3b5 100644 --- a/app/extension_settings/extension_setting_edit.php +++ b/app/extension_settings/extension_setting_edit.php @@ -1,384 +1,384 @@ - - Portions created by the Initial Developer are Copyright (C) 2021-2023 - the Initial Developer. All Rights Reserved. -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('extension_setting_add') || permission_exists('extension_setting_edit')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//set the defaults - $extension_uuid = ''; - $extension_setting_uuid = ''; - $extension_setting_name = ''; - $extension_setting_value = ''; - $extension_setting_description = ''; - -//action add or update - if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { - $action = "update"; - $extension_setting_uuid = $_REQUEST["id"]; - $id = $_REQUEST["id"]; - } - else { - $action = "add"; - } - -//get the extension id - if (!empty($_REQUEST["extension_setting_uuid"]) && is_uuid($_REQUEST["extension_setting_uuid"])) { - $extension_setting_uuid = $_REQUEST["extension_setting_uuid"]; - } - if (!empty($_REQUEST["extension_uuid"]) && is_uuid($_REQUEST["extension_uuid"])) { - $extension_uuid = $_REQUEST["extension_uuid"]; - } - -//get http post variables and set them to php variables - if (!empty($_POST)) { - $domain_uuid = $_POST["domain_uuid"] ?? null; - $extension_setting_type = $_POST["extension_setting_type"]; - $extension_setting_name = $_POST["extension_setting_name"]; - $extension_setting_value = $_POST["extension_setting_value"]; - $extension_setting_enabled = $_POST["extension_setting_enabled"] ?? 'false'; - $extension_setting_description = $_POST["extension_setting_description"]; - } - -//process the user data and save it to the database - if (!empty($_POST) && empty($_POST["persistformvar"])) { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: extension_settings.php?id='.$extension_uuid); - exit; - } - - //process the http post data by submitted action - if (!empty($_POST['action'])) { - - //prepare the array(s) - //send the array to the database class - switch ($_POST['action']) { - case 'copy': - if (permission_exists('extension_setting_add')) { - $obj = new database; - $obj->copy($array); - } - break; - case 'delete': - if (permission_exists('extension_setting_delete')) { - $obj = new database; - $obj->delete($array); - } - break; - case 'toggle': - if (permission_exists('extension_setting_update')) { - $obj = new database; - $obj->toggle($array); - } - break; - } - - //redirect the user - if (in_array($_POST['action'], array('copy', 'delete', 'toggle')) && is_uuid($id) && is_uuid($extension_uuid)) { - header('Location: extension_setting_edit.php?id='.$id.'&extension_uuid='.$extension_uuid); - exit; - } - } - - //check for all required data - $msg = ''; - //if (empty($domain_uuid)) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } - if (empty($extension_setting_type)) { $msg .= $text['message-required']." ".$text['label-extension_setting_type']."
\n"; } - if (empty($extension_setting_name)) { $msg .= $text['message-required']." ".$text['label-extension_setting_name']."
\n"; } - //if (empty($extension_setting_value)) { $msg .= $text['message-required']." ".$text['label-extension_setting_value']."
\n"; } - if (empty($extension_setting_enabled)) { $msg .= $text['message-required']." ".$text['label-extension_setting_enabled']."
\n"; } - //if (empty($extension_setting_description)) { $msg .= $text['message-required']." ".$text['label-extension_setting_description']."
\n"; } - if (!empty($msg) && empty($_POST["persistformvar"])) { - require_once "resources/header.php"; - require_once "resources/persist_form_var.php"; - echo "
\n"; - echo "
\n"; - echo $msg."
"; - echo "
\n"; - persistformvar($_POST); - echo "
\n"; - require_once "resources/footer.php"; - return; - } - - //add the extension_setting_uuid - if (empty($extension_setting_uuid)) { - $extension_setting_uuid = uuid(); - } - - //prepare the array - $array['extension_settings'][0]['extension_setting_uuid'] = $extension_setting_uuid; - $array['extension_settings'][0]['extension_uuid'] = $extension_uuid; - $array['extension_settings'][0]['domain_uuid'] = $_SESSION['domain_uuid']; - //$array['extension_settings'][0]['domain_uuid'] = $domain_uuid; - $array['extension_settings'][0]['extension_setting_type'] = $extension_setting_type; - $array['extension_settings'][0]['extension_setting_name'] = $extension_setting_name; - $array['extension_settings'][0]['extension_setting_value'] = $extension_setting_value; - $array['extension_settings'][0]['extension_setting_enabled'] = $extension_setting_enabled; - $array['extension_settings'][0]['extension_setting_description'] = $extension_setting_description; - - //save the data - $database = new database; - $database->app_name = 'extension settings'; - $database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd'; - $database->save($array); - - //clear the cache - $sql = "select extension, number_alias, user_context from v_extensions "; - $sql .= "where extension_uuid = :extension_uuid "; - $parameters['extension_uuid'] = $extension_uuid; - $database = new database; - $extension = $database->select($sql, $parameters, 'row'); - $cache = new cache; - $cache->delete("directory:".$extension["extension"]."@".$extension["user_context"]); - $cache->delete("directory:".$extension["number_alias"]."@".$extension["user_context"]); - - //redirect the user - if (isset($action)) { - if ($action == "add") { - $_SESSION["message"] = $text['message-add']; - } - if ($action == "update") { - $_SESSION["message"] = $text['message-update']; - } - //header('Location: extension_settings.php'); - header('Location: extension_setting_edit.php?id='.urlencode($extension_setting_uuid).'&extension_uuid='.$extension_uuid); - return; - } - } - -//pre-populate the form - if (!empty($_GET) && empty($_POST["persistformvar"])) { - $sql = "select "; - //$sql .= "extension_uuid, "; - //$sql .= "domain_uuid, "; - $sql .= "extension_setting_uuid, "; - $sql .= "extension_setting_type, "; - $sql .= "extension_setting_name, "; - $sql .= "extension_setting_value, "; - $sql .= "cast(extension_setting_enabled as text), "; - $sql .= "extension_setting_description "; - $sql .= "from v_extension_settings "; - $sql .= "where extension_setting_uuid = :extension_setting_uuid "; - //$sql .= "and domain_uuid = :domain_uuid "; - //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $parameters['extension_setting_uuid'] = $extension_setting_uuid ?? ''; - $database = new database; - $row = $database->select($sql, $parameters, 'row'); - if (!empty($row)) { - if (!empty($row["extension_uuid"]) && is_uuid($row["extension_uuid"])) { - $extension_uuid = $row["extension_uuid"]; - } - //$domain_uuid = $row["domain_uuid"]; - $extension_setting_type = $row["extension_setting_type"]; - $extension_setting_name = $row["extension_setting_name"]; - $extension_setting_value = $row["extension_setting_value"]; - $extension_setting_enabled = $row["extension_setting_enabled"]; - $extension_setting_description = $row["extension_setting_description"]; - } - unset($sql, $parameters, $row); - } - -//set the defaults - if (empty($extension_setting_enabled)) { $extension_setting_enabled = 'true'; } - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//show the header - $document['title'] = $text['title-extension_setting']; - require_once "resources/header.php"; - -//show the content - echo "
\n"; - echo "\n"; - - echo "
\n"; - echo "
".$text['title-extension_setting']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'extension_settings.php?id='.$extension_uuid]); - if ($action == 'update') { - if (permission_exists('_add')) { - echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); - } - if (permission_exists('_delete')) { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); - } - } - echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['title_description-extension_settings']."\n"; - echo "

\n"; - - if ($action == 'update') { - if (permission_exists('extension_setting_add')) { - echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]); - } - if (permission_exists('extension_setting_delete')) { - echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]); - } - } - - echo "
\n"; - echo "\n"; - - //echo "\n"; - //echo "\n"; - //echo "\n"; - //echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - //echo " ".$text['label-domain_uuid']."\n"; - //echo "\n"; - //echo " \n"; - //echo "
\n"; - //echo $text['description-domain_uuid']."\n"; - //echo "
\n"; - echo " ".$text['label-extension_setting_type']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-extension_setting_type']."\n"; - echo "
\n"; - echo " ".$text['label-extension_setting_name']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-extension_setting_name']."\n"; - echo "
\n"; - echo " ".$text['label-extension_setting_value']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-extension_setting_value']."\n"; - echo "
\n"; - echo " ".$text['label-extension_setting_enabled']."\n"; - echo "\n"; - if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') { - echo " \n"; - } - else { - echo " \n"; - } - echo "
\n"; - echo $text['description-extension_setting_enabled']."\n"; - echo "
\n"; - echo " ".$text['label-extension_setting_description']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-extension_setting_description']."\n"; - echo "
\n"; - echo "
\n"; - echo "

\n"; - - echo "\n"; - echo "\n"; - - echo "
"; - -//include the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2021-2023 + the Initial Developer. All Rights Reserved. +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('extension_setting_add') || permission_exists('extension_setting_edit')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set the defaults + $extension_uuid = ''; + $extension_setting_uuid = ''; + $extension_setting_name = ''; + $extension_setting_value = ''; + $extension_setting_description = ''; + +//action add or update + if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { + $action = "update"; + $extension_setting_uuid = $_REQUEST["id"]; + $id = $_REQUEST["id"]; + } + else { + $action = "add"; + } + +//get the extension id + if (!empty($_REQUEST["extension_setting_uuid"]) && is_uuid($_REQUEST["extension_setting_uuid"])) { + $extension_setting_uuid = $_REQUEST["extension_setting_uuid"]; + } + if (!empty($_REQUEST["extension_uuid"]) && is_uuid($_REQUEST["extension_uuid"])) { + $extension_uuid = $_REQUEST["extension_uuid"]; + } + +//get http post variables and set them to php variables + if (!empty($_POST)) { + $domain_uuid = $_POST["domain_uuid"] ?? null; + $extension_setting_type = $_POST["extension_setting_type"]; + $extension_setting_name = $_POST["extension_setting_name"]; + $extension_setting_value = $_POST["extension_setting_value"]; + $extension_setting_enabled = $_POST["extension_setting_enabled"] ?? 'false'; + $extension_setting_description = $_POST["extension_setting_description"]; + } + +//process the user data and save it to the database + if (!empty($_POST) && empty($_POST["persistformvar"])) { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: extension_settings.php?id='.$extension_uuid); + exit; + } + + //process the http post data by submitted action + if (!empty($_POST['action'])) { + + //prepare the array(s) + //send the array to the database class + switch ($_POST['action']) { + case 'copy': + if (permission_exists('extension_setting_add')) { + $obj = new database; + $obj->copy($array); + } + break; + case 'delete': + if (permission_exists('extension_setting_delete')) { + $obj = new database; + $obj->delete($array); + } + break; + case 'toggle': + if (permission_exists('extension_setting_update')) { + $obj = new database; + $obj->toggle($array); + } + break; + } + + //redirect the user + if (in_array($_POST['action'], array('copy', 'delete', 'toggle')) && is_uuid($id) && is_uuid($extension_uuid)) { + header('Location: extension_setting_edit.php?id='.$id.'&extension_uuid='.$extension_uuid); + exit; + } + } + + //check for all required data + $msg = ''; + //if (empty($domain_uuid)) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } + if (empty($extension_setting_type)) { $msg .= $text['message-required']." ".$text['label-extension_setting_type']."
\n"; } + if (empty($extension_setting_name)) { $msg .= $text['message-required']." ".$text['label-extension_setting_name']."
\n"; } + //if (empty($extension_setting_value)) { $msg .= $text['message-required']." ".$text['label-extension_setting_value']."
\n"; } + if (empty($extension_setting_enabled)) { $msg .= $text['message-required']." ".$text['label-extension_setting_enabled']."
\n"; } + //if (empty($extension_setting_description)) { $msg .= $text['message-required']." ".$text['label-extension_setting_description']."
\n"; } + if (!empty($msg) && empty($_POST["persistformvar"])) { + require_once "resources/header.php"; + require_once "resources/persist_form_var.php"; + echo "
\n"; + echo "
\n"; + echo $msg."
"; + echo "
\n"; + persistformvar($_POST); + echo "
\n"; + require_once "resources/footer.php"; + return; + } + + //add the extension_setting_uuid + if (empty($extension_setting_uuid)) { + $extension_setting_uuid = uuid(); + } + + //prepare the array + $array['extension_settings'][0]['extension_setting_uuid'] = $extension_setting_uuid; + $array['extension_settings'][0]['extension_uuid'] = $extension_uuid; + $array['extension_settings'][0]['domain_uuid'] = $_SESSION['domain_uuid']; + //$array['extension_settings'][0]['domain_uuid'] = $domain_uuid; + $array['extension_settings'][0]['extension_setting_type'] = $extension_setting_type; + $array['extension_settings'][0]['extension_setting_name'] = $extension_setting_name; + $array['extension_settings'][0]['extension_setting_value'] = $extension_setting_value; + $array['extension_settings'][0]['extension_setting_enabled'] = $extension_setting_enabled; + $array['extension_settings'][0]['extension_setting_description'] = $extension_setting_description; + + //save the data + $database = new database; + $database->app_name = 'extension settings'; + $database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd'; + $database->save($array); + + //clear the cache + $sql = "select extension, number_alias, user_context from v_extensions "; + $sql .= "where extension_uuid = :extension_uuid "; + $parameters['extension_uuid'] = $extension_uuid; + $database = new database; + $extension = $database->select($sql, $parameters, 'row'); + $cache = new cache; + $cache->delete("directory:".$extension["extension"]."@".$extension["user_context"]); + $cache->delete("directory:".$extension["number_alias"]."@".$extension["user_context"]); + + //redirect the user + if (isset($action)) { + if ($action == "add") { + $_SESSION["message"] = $text['message-add']; + } + if ($action == "update") { + $_SESSION["message"] = $text['message-update']; + } + //header('Location: extension_settings.php'); + header('Location: extension_setting_edit.php?id='.urlencode($extension_setting_uuid).'&extension_uuid='.$extension_uuid); + return; + } + } + +//pre-populate the form + if (!empty($_GET) && empty($_POST["persistformvar"])) { + $sql = "select "; + //$sql .= "extension_uuid, "; + //$sql .= "domain_uuid, "; + $sql .= "extension_setting_uuid, "; + $sql .= "extension_setting_type, "; + $sql .= "extension_setting_name, "; + $sql .= "extension_setting_value, "; + $sql .= "cast(extension_setting_enabled as text), "; + $sql .= "extension_setting_description "; + $sql .= "from v_extension_settings "; + $sql .= "where extension_setting_uuid = :extension_setting_uuid "; + //$sql .= "and domain_uuid = :domain_uuid "; + //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['extension_setting_uuid'] = $extension_setting_uuid ?? ''; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (!empty($row)) { + if (!empty($row["extension_uuid"]) && is_uuid($row["extension_uuid"])) { + $extension_uuid = $row["extension_uuid"]; + } + //$domain_uuid = $row["domain_uuid"]; + $extension_setting_type = $row["extension_setting_type"]; + $extension_setting_name = $row["extension_setting_name"]; + $extension_setting_value = $row["extension_setting_value"]; + $extension_setting_enabled = $row["extension_setting_enabled"]; + $extension_setting_description = $row["extension_setting_description"]; + } + unset($sql, $parameters, $row); + } + +//set the defaults + if (empty($extension_setting_enabled)) { $extension_setting_enabled = 'true'; } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//show the header + $document['title'] = $text['title-extension_setting']; + require_once "resources/header.php"; + +//show the content + echo "
\n"; + echo "\n"; + + echo "
\n"; + echo "
".$text['title-extension_setting']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'extension_settings.php?id='.$extension_uuid]); + if ($action == 'update') { + if (permission_exists('_add')) { + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); + } + if (permission_exists('_delete')) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); + } + } + echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['title_description-extension_settings']."\n"; + echo "

\n"; + + if ($action == 'update') { + if (permission_exists('extension_setting_add')) { + echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]); + } + if (permission_exists('extension_setting_delete')) { + echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]); + } + } + + echo "
\n"; + echo "\n"; + + //echo "\n"; + //echo "\n"; + //echo "\n"; + //echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + //echo " ".$text['label-domain_uuid']."\n"; + //echo "\n"; + //echo " \n"; + //echo "
\n"; + //echo $text['description-domain_uuid']."\n"; + //echo "
\n"; + echo " ".$text['label-extension_setting_type']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-extension_setting_type']."\n"; + echo "
\n"; + echo " ".$text['label-extension_setting_name']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-extension_setting_name']."\n"; + echo "
\n"; + echo " ".$text['label-extension_setting_value']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-extension_setting_value']."\n"; + echo "
\n"; + echo " ".$text['label-extension_setting_enabled']."\n"; + echo "\n"; + if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') { + echo " \n"; + } + else { + echo " \n"; + } + echo "
\n"; + echo $text['description-extension_setting_enabled']."\n"; + echo "
\n"; + echo " ".$text['label-extension_setting_description']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-extension_setting_description']."\n"; + echo "
\n"; + echo "
\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + + echo "
"; + +//include the footer + require_once "resources/footer.php"; + +?> diff --git a/app/extension_settings/extension_settings.php b/app/extension_settings/extension_settings.php index 46c51f0b58..0b6d568ae8 100644 --- a/app/extension_settings/extension_settings.php +++ b/app/extension_settings/extension_settings.php @@ -1,334 +1,334 @@ - - Portions created by the Initial Developer are Copyright (C) 2021-2023 - the Initial Developer. All Rights Reserved. -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('extension_setting_view')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//set the defaults - $search = ''; - $paging_controls = ''; - $id = ''; - -//set from session variables - $list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false'; - -//get the http post data - if (!empty($_POST['extension_settings'])) { - $action = $_POST['action']; - $search = $_POST['search']; - $extension_settings = $_POST['extension_settings']; - } - -//action add or update - if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { - $extension_uuid = $_REQUEST["id"]; - } - -//process the http post data by action - if (!empty($action) && !empty($extension_settings)) { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: extension_settings.php'); - exit; - } - - //prepare the database object - $obj = new extension_settings; - - //send the array to the database class - switch ($action) { - case 'copy': - if (permission_exists('extension_setting_add')) { - $obj->copy($extension_settings); - } - break; - case 'toggle': - if (permission_exists('extension_setting_edit')) { - $obj->toggle($extension_settings); - } - break; - case 'delete': - if (permission_exists('extension_setting_delete')) { - $obj->extension_uuid = $extension_uuid; - $obj->delete($extension_settings); - } - break; - } - - //redirect the user - header('Location: extension_settings.php?id='.urlencode($extension_uuid).'&'.($search != '' ? '?search='.urlencode($search) : null)); - exit; - } - -//get order and order by - $order_by = $_GET["order_by"] ?? ''; - $order = $_GET["order"] ?? ''; - -//add the search - if (isset($_GET["search"])) { - $search = strtolower($_GET["search"]); - } - -//get the count - $sql = "select count(extension_setting_uuid) "; - $sql .= "from v_extension_settings "; - $sql .= "where extension_uuid = :extension_uuid "; - if (isset($search)) { - $sql .= "and ("; - $sql .= " lower(extension_setting_type) like :search "; - $sql .= " or lower(extension_setting_name) like :search "; - $sql .= " or lower(extension_setting_description) like :search "; - $sql .= ") "; - $parameters['search'] = '%'.$search.'%'; - } - else { - $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; - if (isset($sql_search)) { - $sql .= "and ".$sql_search; - } - $parameters['domain_uuid'] = $domain_uuid; - } - $parameters['extension_uuid'] = $extension_uuid; - $database = new database; - $num_rows = $database->select($sql, $parameters, 'column'); - unset($sql, $parameters); - -//get the list - $sql = "select "; - //$sql .= "d.domain_name, "; - $sql .= "extension_setting_uuid, "; - $sql .= "extension_setting_type, "; - $sql .= "extension_setting_name, "; - $sql .= "extension_setting_value, "; - $sql .= "cast(extension_setting_enabled as text), "; - $sql .= "extension_setting_description "; - $sql .= "from v_extension_settings as e "; - //$sql .= ",v_domains as d "; - $sql .= "where extension_uuid = :extension_uuid "; - $sql .= "and (e.domain_uuid = :domain_uuid or e.domain_uuid is null) "; - //$sql .= "and d.domain_uuid = e.domain_uuid "; - if (isset($_GET["search"])) { - $sql .= "and ("; - $sql .= " lower(extension_setting_type) like :search "; - $sql .= " or lower(extension_setting_name) like :search "; - $sql .= " or lower(extension_setting_description) like :search "; - $sql .= ") "; - $parameters['search'] = '%'.$search.'%'; - } - - $sql .= order_by($order_by, $order, 'extension_setting_type', 'asc'); - $sql .= limit_offset($rows_per_page ?? null, $offset ?? null); - $parameters['extension_uuid'] = $extension_uuid; - $parameters['domain_uuid'] = $domain_uuid; - $database = new database; - $extension_settings = $database->select($sql, $parameters, 'all'); - unset($sql, $parameters); - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//additional includes - $document['title'] = $text['title-extension_settings']; - require_once "resources/header.php"; - -//show the content - echo "
\n"; - echo "
".$text['title-extension_settings']."
".number_format($num_rows)."
\n"; - echo "
\n"; - - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_add','name'=>'btn_add','style'=>'margin-right: 15px;','link'=>'/app/extensions/extension_edit.php?id='.$extension_uuid]); - - if (permission_exists('extension_setting_add')) { - echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'extension_setting_edit.php?extension_uuid='.$extension_uuid]); - } - if (permission_exists('extension_setting_add') && $extension_settings) { - echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); - } - if (permission_exists('extension_setting_edit') && $extension_settings) { - echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); - } - if (permission_exists('extension_setting_delete') && $extension_settings) { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); - } - echo "\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - - if (permission_exists('extension_setting_add') && $extension_settings) { - echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); - } - if (permission_exists('extension_setting_edit') && $extension_settings) { - echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); - } - if (permission_exists('extension_setting_delete') && $extension_settings) { - echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); - } - - echo $text['title_description-extension_settings']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - echo "\n"; - if (!empty($extension_settings)) { - //define the variable - $previous_extension_setting_type = ''; - - //set the initial value - $x = 0; - - //show the extension settings - foreach ($extension_settings as $row) { - $extension_setting_type = $row['extension_setting_type']; - $extension_setting_type = strtolower($extension_setting_type); - - $label_extension_setting_type = $row['extension_setting_type']; - $label_extension_setting_type = str_replace("_", " ", $label_extension_setting_type); - $label_extension_setting_type = str_replace("-", " ", $label_extension_setting_type); - $label_extension_setting_type = ucwords($label_extension_setting_type); - - if ($previous_extension_setting_type !== $row['extension_setting_type']) { - echo " "; - echo " \n"; - echo " "; - echo " "; - echo " \n"; - echo " "; - echo "\n"; - if (permission_exists('extension_setting_add') || permission_exists('extension_setting_edit') || permission_exists('extension_setting_delete')) { - echo " \n"; - } - //if ($_GET['show'] == 'all' && permission_exists('extension_setting_all')) { - // echo th_order_by('domain_name', $text['label-domain'], $order_by, $order); - //} - - //echo th_order_by('extension_setting_type', $text['label-extension_setting_type'], $order_by, $order); - //echo th_order_by('extension_setting_name', $text['label-extension_setting_name'], $order_by, $order); - //echo th_order_by('extension_setting_value', $text['label-extension_setting_value'], $order_by, $order); - //echo th_order_by('extension_setting_enabled', $text['label-extension_setting_enabled'], $order_by, $order, null, "class='center'"); - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - - echo " \n"; - if (permission_exists('extension_setting_edit') && $list_row_edit_button == 'true') { - echo " \n"; - } - echo "\n"; - - } - if (permission_exists('extension_setting_edit')) { - $list_row_url = "extension_setting_edit.php?id=".urlencode($row['extension_setting_uuid'])."&extension_uuid=".urlencode($extension_uuid); - } - echo "\n"; - if (permission_exists('extension_setting_add') || permission_exists('extension_setting_edit') || permission_exists('extension_setting_delete')) { - echo " \n"; - } - //if ($_GET['show'] == 'all' && permission_exists('extension_setting_all')) { - // echo " \n"; - //} - echo " \n"; - echo " \n"; - echo " \n"; - if (permission_exists('extension_setting_edit')) { - echo " \n"; - echo " \n"; - if (permission_exists('extension_setting_edit') && $list_row_edit_button == 'true') { - echo " \n"; - } - echo "\n"; - - //set the previous category - $previous_extension_setting_type = $row['extension_setting_type']; - $x++; - } - unset($extension_settings); - } - - echo "
 
".escape($label_extension_setting_type)."
\n"; - echo " \n"; - echo " ".$text['label-extension_setting_type']."".$text['label-extension_setting_name']."".$text['label-extension_setting_value']."".$text['label-extension_setting_enabled']."".$text['label-extension_setting_description']." 
\n"; - echo " \n"; - echo " \n"; - echo " ".escape($row['domain_name'])."".escape($row['extension_setting_type'])."".escape($row['extension_setting_name'])."".escape($row['extension_setting_value'])."\n"; - echo $text['label-'.$row['extension_setting_enabled']]; - } - echo " ".escape($row['extension_setting_description'])."\n"; - echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo "
".$paging_controls."
\n"; - echo "\n"; - echo "\n"; - echo "
\n"; - -//include the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2021-2023 + the Initial Developer. All Rights Reserved. +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('extension_setting_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set the defaults + $search = ''; + $paging_controls = ''; + $id = ''; + +//set from session variables + $list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false'; + +//get the http post data + if (!empty($_POST['extension_settings'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $extension_settings = $_POST['extension_settings']; + } + +//action add or update + if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { + $extension_uuid = $_REQUEST["id"]; + } + +//process the http post data by action + if (!empty($action) && !empty($extension_settings)) { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: extension_settings.php'); + exit; + } + + //prepare the database object + $obj = new extension_settings; + + //send the array to the database class + switch ($action) { + case 'copy': + if (permission_exists('extension_setting_add')) { + $obj->copy($extension_settings); + } + break; + case 'toggle': + if (permission_exists('extension_setting_edit')) { + $obj->toggle($extension_settings); + } + break; + case 'delete': + if (permission_exists('extension_setting_delete')) { + $obj->extension_uuid = $extension_uuid; + $obj->delete($extension_settings); + } + break; + } + + //redirect the user + header('Location: extension_settings.php?id='.urlencode($extension_uuid).'&'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + +//get order and order by + $order_by = $_GET["order_by"] ?? ''; + $order = $_GET["order"] ?? ''; + +//add the search + if (isset($_GET["search"])) { + $search = strtolower($_GET["search"]); + } + +//get the count + $sql = "select count(extension_setting_uuid) "; + $sql .= "from v_extension_settings "; + $sql .= "where extension_uuid = :extension_uuid "; + if (isset($search)) { + $sql .= "and ("; + $sql .= " lower(extension_setting_type) like :search "; + $sql .= " or lower(extension_setting_name) like :search "; + $sql .= " or lower(extension_setting_description) like :search "; + $sql .= ") "; + $parameters['search'] = '%'.$search.'%'; + } + else { + $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; + if (isset($sql_search)) { + $sql .= "and ".$sql_search; + } + $parameters['domain_uuid'] = $domain_uuid; + } + $parameters['extension_uuid'] = $extension_uuid; + $database = new database; + $num_rows = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + +//get the list + $sql = "select "; + //$sql .= "d.domain_name, "; + $sql .= "extension_setting_uuid, "; + $sql .= "extension_setting_type, "; + $sql .= "extension_setting_name, "; + $sql .= "extension_setting_value, "; + $sql .= "cast(extension_setting_enabled as text), "; + $sql .= "extension_setting_description "; + $sql .= "from v_extension_settings as e "; + //$sql .= ",v_domains as d "; + $sql .= "where extension_uuid = :extension_uuid "; + $sql .= "and (e.domain_uuid = :domain_uuid or e.domain_uuid is null) "; + //$sql .= "and d.domain_uuid = e.domain_uuid "; + if (isset($_GET["search"])) { + $sql .= "and ("; + $sql .= " lower(extension_setting_type) like :search "; + $sql .= " or lower(extension_setting_name) like :search "; + $sql .= " or lower(extension_setting_description) like :search "; + $sql .= ") "; + $parameters['search'] = '%'.$search.'%'; + } + + $sql .= order_by($order_by, $order, 'extension_setting_type', 'asc'); + $sql .= limit_offset($rows_per_page ?? null, $offset ?? null); + $parameters['extension_uuid'] = $extension_uuid; + $parameters['domain_uuid'] = $domain_uuid; + $database = new database; + $extension_settings = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//additional includes + $document['title'] = $text['title-extension_settings']; + require_once "resources/header.php"; + +//show the content + echo "
\n"; + echo "
".$text['title-extension_settings']."
".number_format($num_rows)."
\n"; + echo "
\n"; + + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_add','name'=>'btn_add','style'=>'margin-right: 15px;','link'=>'/app/extensions/extension_edit.php?id='.$extension_uuid]); + + if (permission_exists('extension_setting_add')) { + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'extension_setting_edit.php?extension_uuid='.$extension_uuid]); + } + if (permission_exists('extension_setting_add') && $extension_settings) { + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); + } + if (permission_exists('extension_setting_edit') && $extension_settings) { + echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); + } + if (permission_exists('extension_setting_delete') && $extension_settings) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); + } + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + + if (permission_exists('extension_setting_add') && $extension_settings) { + echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); + } + if (permission_exists('extension_setting_edit') && $extension_settings) { + echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); + } + if (permission_exists('extension_setting_delete') && $extension_settings) { + echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); + } + + echo $text['title_description-extension_settings']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo "\n"; + if (!empty($extension_settings)) { + //define the variable + $previous_extension_setting_type = ''; + + //set the initial value + $x = 0; + + //show the extension settings + foreach ($extension_settings as $row) { + $extension_setting_type = $row['extension_setting_type']; + $extension_setting_type = strtolower($extension_setting_type); + + $label_extension_setting_type = $row['extension_setting_type']; + $label_extension_setting_type = str_replace("_", " ", $label_extension_setting_type); + $label_extension_setting_type = str_replace("-", " ", $label_extension_setting_type); + $label_extension_setting_type = ucwords($label_extension_setting_type); + + if ($previous_extension_setting_type !== $row['extension_setting_type']) { + echo " "; + echo " \n"; + echo " "; + echo " "; + echo " \n"; + echo " "; + echo "\n"; + if (permission_exists('extension_setting_add') || permission_exists('extension_setting_edit') || permission_exists('extension_setting_delete')) { + echo " \n"; + } + //if ($_GET['show'] == 'all' && permission_exists('extension_setting_all')) { + // echo th_order_by('domain_name', $text['label-domain'], $order_by, $order); + //} + + //echo th_order_by('extension_setting_type', $text['label-extension_setting_type'], $order_by, $order); + //echo th_order_by('extension_setting_name', $text['label-extension_setting_name'], $order_by, $order); + //echo th_order_by('extension_setting_value', $text['label-extension_setting_value'], $order_by, $order); + //echo th_order_by('extension_setting_enabled', $text['label-extension_setting_enabled'], $order_by, $order, null, "class='center'"); + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + if (permission_exists('extension_setting_edit') && $list_row_edit_button == 'true') { + echo " \n"; + } + echo "\n"; + + } + if (permission_exists('extension_setting_edit')) { + $list_row_url = "extension_setting_edit.php?id=".urlencode($row['extension_setting_uuid'])."&extension_uuid=".urlencode($extension_uuid); + } + echo "\n"; + if (permission_exists('extension_setting_add') || permission_exists('extension_setting_edit') || permission_exists('extension_setting_delete')) { + echo " \n"; + } + //if ($_GET['show'] == 'all' && permission_exists('extension_setting_all')) { + // echo " \n"; + //} + echo " \n"; + echo " \n"; + echo " \n"; + if (permission_exists('extension_setting_edit')) { + echo " \n"; + echo " \n"; + if (permission_exists('extension_setting_edit') && $list_row_edit_button == 'true') { + echo " \n"; + } + echo "\n"; + + //set the previous category + $previous_extension_setting_type = $row['extension_setting_type']; + $x++; + } + unset($extension_settings); + } + + echo "
 
".escape($label_extension_setting_type)."
\n"; + echo " \n"; + echo " ".$text['label-extension_setting_type']."".$text['label-extension_setting_name']."".$text['label-extension_setting_value']."".$text['label-extension_setting_enabled']."".$text['label-extension_setting_description']." 
\n"; + echo " \n"; + echo " \n"; + echo " ".escape($row['domain_name'])."".escape($row['extension_setting_type'])."".escape($row['extension_setting_name'])."".escape($row['extension_setting_value'])."\n"; + echo $text['label-'.$row['extension_setting_enabled']]; + } + echo " ".escape($row['extension_setting_description'])."\n"; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo "
".$paging_controls."
\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + +//include the footer + require_once "resources/footer.php"; + +?> diff --git a/app/extensions/extension_imports.php b/app/extensions/extension_imports.php index 47562ae405..6b27a718aa 100644 --- a/app/extensions/extension_imports.php +++ b/app/extensions/extension_imports.php @@ -1,464 +1,464 @@ - - Portions created by the Initial Developer are Copyright (C) 2018-2020 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('extension_import')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//initialize the database object - $database = new database; - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher - if (!function_exists('str_getcsv')) { - function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { - $fp = fopen("php://memory", 'r+'); - fputs($fp, $input); - rewind($fp); - $data = fgetcsv($fp, null, $delimiter, $enclosure, $escape); - fclose($fp); - return $data; - } - } - -//get the http get values and set them as php variables - $action = $_POST["action"] ?? null; - $from_row = $_POST["from_row"] ?? null; - $delimiter = $_POST["data_delimiter"] ?? null; - $enclosure = $_POST["data_enclosure"] ?? null; - -//save the data to the csv file - if (isset($_POST['data'])) { - $file = $_SESSION['server']['temp']['dir']."/extensions-".$_SESSION['domain_name'].".csv"; - file_put_contents($file, $_POST['data']); - $_SESSION['file'] = $file; - } - -//copy the csv file - //$_POST['submit'] == "Upload" && - if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('extension_import')) { - if ($_POST['type'] == 'csv') { - move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']); - $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']); - //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*'); - unset($_POST['txtCommand']); - $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']; - $_SESSION['file'] = $file; - } - } - -//get the schema - if (!empty($delimiter)) { - //get the first line - $line = fgets(fopen($_SESSION['file'], 'r')); - $line_fields = explode($delimiter, $line); - - //get the schema - $x = 0; - include "app/extensions/app_config.php"; - $i = 0; - foreach ($apps[0]['db'] as $table) { - //get the table name and parent name - $table_name = $table["table"]['name']; - $parent_name = $table["table"]['parent']; - - //remove the v_ table prefix - if (substr($table_name, 0, 2) == 'v_') { - $table_name = substr($table_name, 2); - } - if (substr($parent_name, 0, 2) == 'v_') { - $parent_name = substr($parent_name, 2); - } - - //filter for specific tables and build the schema array - if ($table_name == "extensions") { - $schema[$i]['table'] = $table_name; - $schema[$i]['parent'] = $parent_name; - foreach ($table['fields'] as $row) { - if (empty($row['deprecated']) || $row['deprecated'] !== 'true') { - if (is_array($row['name'])) { - $field_name = $row['name']['text']; - } - else { - $field_name = $row['name']; - } - $schema[$i]['fields'][] = $field_name; - } - } - $i++; - } - } - - $i++; - $schema[$i]['table'] = 'extension_users'; - $schema[$i]['parent'] = 'extensions'; - $schema[$i]['fields'][] = 'username'; - } - -//match the column names to the field names - if (!empty($delimiter) && file_exists($_SESSION['file']) && $action != 'import') { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: extension_imports.php'); - exit; - } - - //create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - - //include header - $document['title'] = $text['title-extension_import']; - require_once "resources/header.php"; - - //form to match the fields to the column names - echo "
\n"; - - echo "
\n"; - echo "
".$text['header-extension_import']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'extension_imports.php']); - echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['description-import']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - - //loop through user columns - $x = 0; - foreach ($line_fields as $line_field) { - $line_field = preg_replace('#[^a-zA-Z0-9_]#', '', $line_field); - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - $x++; - } - - echo "
\n"; - //echo " ".$text['label-zzz']."\n"; - echo $line_field; - echo " \n"; - echo " \n"; - //echo "
\n"; - //echo $text['description-zzz']."\n"; - echo "
\n"; - echo "
\n"; - echo "

\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - - require_once "resources/footer.php"; - - //normalize the column names - //$line = strtolower($line); - //$line = str_replace("-", "_", $line); - //$line = str_replace($delimiter."title".$delimiter, $delimiter."contact_title".$delimiter, $line); - //$line = str_replace("firstname", "name_given", $line); - //$line = str_replace("lastname", "name_family", $line); - //$line = str_replace("company", "organization", $line); - //$line = str_replace("company", "contact_email", $line); - - //end the script - exit; - } - -//get the parent table - function get_parent($schema,$table_name) { - foreach ($schema as $row) { - if ($row['table'] == $table_name) { - return $row['parent']; - } - } - } - -//upload the csv - if (file_exists($_SESSION['file'] ?? '') && $action == 'import') { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: extension_imports.php'); - exit; - } - - //user selected fields - $fields = $_POST['fields']; - - //set the domain_uuid - $domain_uuid = $_SESSION['domain_uuid']; - - //get the users - $sql = "select * from v_users where domain_uuid = :domain_uuid "; - $parameters['domain_uuid'] = $domain_uuid; - $users = $database->select($sql, $parameters, 'all'); - unset($sql, $parameters); - - //get the contents of the csv file and convert them into an array - $handle = @fopen($_SESSION['file'], "r"); - if ($handle) { - //set the starting identifiers - $row_id = 0; - $row_number = 1; - - //loop through the array - while (($line = fgets($handle, 4096)) !== false) { - if ($from_row <= $row_number) { - //format the data - $y = 0; - foreach ($fields as $key => $value) { - //get the line - $result = str_getcsv($line, $delimiter, $enclosure); - - //get the table and field name - $field_array = explode(".",$value); - $table_name = $field_array[0]; - $field_name = $field_array[1] ?? null; - //echo "value: $value
\n"; - //echo "table_name: $table_name
\n"; - //echo "field_name: $field_name
\n"; - - //get the parent table name - $parent = get_parent($schema, $table_name); - - //remove formatting from the phone number - if ($field_name == "phone_number") { - $result[$key] = preg_replace('{\D}', '', $result[$key]); - } - - //set various fields to lower case - if (in_array($field_name, array('enabled','directory_visible','directory_exten_visible','call_screen_enabled','user_record','do_not_disturb','forward_all_enabled','forward_busy_enabled','forward_no_answer_enabled','forward_user_not_registered_enabled'))) { - $result[$key] = strtolower($result[$key]); - } - - //build the data array - if (!empty($table_name)) { - if (empty($parent)) { - $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; - $array[$table_name][$row_id][$field_name] = $result[$key]; - } - elseif ($field_name != "username") { - $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; - $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; - } - - if ($field_name == "username") { - foreach ($users as $field) { - if ($field['username'] == $result[$key]) { - //$array[$parent][$row_id]['extension_users'][$y]['cextension_user_uuid'] = uuid(); - $array[$parent][$row_id]['extension_users'][$y]['domain_uuid'] = $domain_uuid; - //$array[$parent][$row_id]['extension_users'] = $row['extension_uuid']; - $array[$parent][$row_id]['extension_users'][$y]['user_uuid'] = $field['user_uuid']; - } - } - } - } - } - - //process a chunk of the array - if ($row_id === 1000) { - - //save to the data - $database->app_name = 'extensions'; - $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; - $database->save($array); - - //clear the array - unset($array); - - //set the row id back to 0 - $row_id = 0; - } - - } //if ($from_row <= $row_number) - $row_number++; - $row_id++; - } //end while - fclose($handle); - - //save to the data - if (!empty($array) && is_array($array)) { - $database->app_name = 'extensions'; - $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; - $database->save($array); - unset($array); - } - - //send the redirect header - header("Location: extensions.php"); - exit; - } - } - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//include the header - $document['title'] = $text['title-extension_import']; - require_once "resources/header.php"; - -//show content - echo "
\n"; - echo "
\n"; - echo "
".$text['header-extension_import']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'extensions.php']); - echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['description-import']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - echo " ".$text['label-import_data']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_data']."\n"; - echo "
\n"; - echo " ".$text['label-from_row']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-from_row']."\n"; - echo "
\n"; - echo " ".$text['label-import_delimiter']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_delimiter']."\n"; - echo "
\n"; - echo " ".$text['label-import_enclosure']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_enclosure']."\n"; - echo "
\n"; - echo " ".$text['label-import_file_upload']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "

"; - - echo "\n"; - echo "\n"; - - echo "
"; - -//include the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2018-2020 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('extension_import')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//initialize the database object + $database = new database; + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduct the functionality but requirs PHP 5.1.0 or higher + if (!function_exists('str_getcsv')) { + function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { + $fp = fopen("php://memory", 'r+'); + fputs($fp, $input); + rewind($fp); + $data = fgetcsv($fp, null, $delimiter, $enclosure, $escape); + fclose($fp); + return $data; + } + } + +//get the http get values and set them as php variables + $action = $_POST["action"] ?? null; + $from_row = $_POST["from_row"] ?? null; + $delimiter = $_POST["data_delimiter"] ?? null; + $enclosure = $_POST["data_enclosure"] ?? null; + +//save the data to the csv file + if (isset($_POST['data'])) { + $file = $_SESSION['server']['temp']['dir']."/extensions-".$_SESSION['domain_name'].".csv"; + file_put_contents($file, $_POST['data']); + $_SESSION['file'] = $file; + } + +//copy the csv file + //$_POST['submit'] == "Upload" && + if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('extension_import')) { + if ($_POST['type'] == 'csv') { + move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']); + $save_msg = "Uploaded file to ".$_SESSION['server']['temp']['dir']."/". htmlentities($_FILES['ulfile']['name']); + //system('chmod -R 744 '.$_SESSION['server']['temp']['dir'].'*'); + unset($_POST['txtCommand']); + $file = $_SESSION['server']['temp']['dir'].'/'.$_FILES['ulfile']['name']; + $_SESSION['file'] = $file; + } + } + +//get the schema + if (!empty($delimiter)) { + //get the first line + $line = fgets(fopen($_SESSION['file'], 'r')); + $line_fields = explode($delimiter, $line); + + //get the schema + $x = 0; + include "app/extensions/app_config.php"; + $i = 0; + foreach ($apps[0]['db'] as $table) { + //get the table name and parent name + $table_name = $table["table"]['name']; + $parent_name = $table["table"]['parent']; + + //remove the v_ table prefix + if (substr($table_name, 0, 2) == 'v_') { + $table_name = substr($table_name, 2); + } + if (substr($parent_name, 0, 2) == 'v_') { + $parent_name = substr($parent_name, 2); + } + + //filter for specific tables and build the schema array + if ($table_name == "extensions") { + $schema[$i]['table'] = $table_name; + $schema[$i]['parent'] = $parent_name; + foreach ($table['fields'] as $row) { + if (empty($row['deprecated']) || $row['deprecated'] !== 'true') { + if (is_array($row['name'])) { + $field_name = $row['name']['text']; + } + else { + $field_name = $row['name']; + } + $schema[$i]['fields'][] = $field_name; + } + } + $i++; + } + } + + $i++; + $schema[$i]['table'] = 'extension_users'; + $schema[$i]['parent'] = 'extensions'; + $schema[$i]['fields'][] = 'username'; + } + +//match the column names to the field names + if (!empty($delimiter) && file_exists($_SESSION['file']) && $action != 'import') { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: extension_imports.php'); + exit; + } + + //create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + + //include header + $document['title'] = $text['title-extension_import']; + require_once "resources/header.php"; + + //form to match the fields to the column names + echo "
\n"; + + echo "
\n"; + echo "
".$text['header-extension_import']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'extension_imports.php']); + echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-import']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + + //loop through user columns + $x = 0; + foreach ($line_fields as $line_field) { + $line_field = preg_replace('#[^a-zA-Z0-9_]#', '', $line_field); + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + $x++; + } + + echo "
\n"; + //echo " ".$text['label-zzz']."\n"; + echo $line_field; + echo " \n"; + echo " \n"; + //echo "
\n"; + //echo $text['description-zzz']."\n"; + echo "
\n"; + echo "
\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + + require_once "resources/footer.php"; + + //normalize the column names + //$line = strtolower($line); + //$line = str_replace("-", "_", $line); + //$line = str_replace($delimiter."title".$delimiter, $delimiter."contact_title".$delimiter, $line); + //$line = str_replace("firstname", "name_given", $line); + //$line = str_replace("lastname", "name_family", $line); + //$line = str_replace("company", "organization", $line); + //$line = str_replace("company", "contact_email", $line); + + //end the script + exit; + } + +//get the parent table + function get_parent($schema,$table_name) { + foreach ($schema as $row) { + if ($row['table'] == $table_name) { + return $row['parent']; + } + } + } + +//upload the csv + if (file_exists($_SESSION['file'] ?? '') && $action == 'import') { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: extension_imports.php'); + exit; + } + + //user selected fields + $fields = $_POST['fields']; + + //set the domain_uuid + $domain_uuid = $_SESSION['domain_uuid']; + + //get the users + $sql = "select * from v_users where domain_uuid = :domain_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + $users = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + + //get the contents of the csv file and convert them into an array + $handle = @fopen($_SESSION['file'], "r"); + if ($handle) { + //set the starting identifiers + $row_id = 0; + $row_number = 1; + + //loop through the array + while (($line = fgets($handle, 4096)) !== false) { + if ($from_row <= $row_number) { + //format the data + $y = 0; + foreach ($fields as $key => $value) { + //get the line + $result = str_getcsv($line, $delimiter, $enclosure); + + //get the table and field name + $field_array = explode(".",$value); + $table_name = $field_array[0]; + $field_name = $field_array[1] ?? null; + //echo "value: $value
\n"; + //echo "table_name: $table_name
\n"; + //echo "field_name: $field_name
\n"; + + //get the parent table name + $parent = get_parent($schema, $table_name); + + //remove formatting from the phone number + if ($field_name == "phone_number") { + $result[$key] = preg_replace('{\D}', '', $result[$key]); + } + + //set various fields to lower case + if (in_array($field_name, array('enabled','directory_visible','directory_exten_visible','call_screen_enabled','user_record','do_not_disturb','forward_all_enabled','forward_busy_enabled','forward_no_answer_enabled','forward_user_not_registered_enabled'))) { + $result[$key] = strtolower($result[$key]); + } + + //build the data array + if (!empty($table_name)) { + if (empty($parent)) { + $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; + $array[$table_name][$row_id][$field_name] = $result[$key]; + } + elseif ($field_name != "username") { + $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; + $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; + } + + if ($field_name == "username") { + foreach ($users as $field) { + if ($field['username'] == $result[$key]) { + //$array[$parent][$row_id]['extension_users'][$y]['cextension_user_uuid'] = uuid(); + $array[$parent][$row_id]['extension_users'][$y]['domain_uuid'] = $domain_uuid; + //$array[$parent][$row_id]['extension_users'] = $row['extension_uuid']; + $array[$parent][$row_id]['extension_users'][$y]['user_uuid'] = $field['user_uuid']; + } + } + } + } + } + + //process a chunk of the array + if ($row_id === 1000) { + + //save to the data + $database->app_name = 'extensions'; + $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; + $database->save($array); + + //clear the array + unset($array); + + //set the row id back to 0 + $row_id = 0; + } + + } //if ($from_row <= $row_number) + $row_number++; + $row_id++; + } //end while + fclose($handle); + + //save to the data + if (!empty($array) && is_array($array)) { + $database->app_name = 'extensions'; + $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; + $database->save($array); + unset($array); + } + + //send the redirect header + header("Location: extensions.php"); + exit; + } + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//include the header + $document['title'] = $text['title-extension_import']; + require_once "resources/header.php"; + +//show content + echo "
\n"; + echo "
\n"; + echo "
".$text['header-extension_import']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'extensions.php']); + echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-import']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo " ".$text['label-import_data']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_data']."\n"; + echo "
\n"; + echo " ".$text['label-from_row']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-from_row']."\n"; + echo "
\n"; + echo " ".$text['label-import_delimiter']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_delimiter']."\n"; + echo "
\n"; + echo " ".$text['label-import_enclosure']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_enclosure']."\n"; + echo "
\n"; + echo " ".$text['label-import_file_upload']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "

"; + + echo "\n"; + echo "\n"; + + echo "
"; + +//include the footer + require_once "resources/footer.php"; + +?> diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 58285d03db..aaf1ec413b 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -1,1030 +1,1030 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2024 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane - Luis Daniel Lucio Quiroz - Tony Fernandez -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - require_once "resources/paging.php"; - -//check permisions - if (permission_exists('xml_cdr_view')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//set permissions - $permission = array(); - $permission['xml_cdr_view'] = permission_exists('xml_cdr_view'); - $permission['xml_cdr_search_extension'] = permission_exists('xml_cdr_search_extension'); - $permission['xml_cdr_delete'] = permission_exists('xml_cdr_delete'); - $permission['xml_cdr_domain'] = permission_exists('xml_cdr_domain'); - $permission['xml_cdr_search_call_center_queues'] = permission_exists('xml_cdr_search_call_center_queues'); - $permission['xml_cdr_statistics'] = permission_exists('xml_cdr_statistics'); - $permission['xml_cdr_archive'] = permission_exists('xml_cdr_archive'); - $permission['xml_cdr_all'] = permission_exists('xml_cdr_all'); - $permission['xml_cdr_export'] = permission_exists('xml_cdr_export'); - $permission['xml_cdr_export_csv'] = permission_exists('xml_cdr_export_csv'); - $permission['xml_cdr_export_pdf'] = permission_exists('xml_cdr_export_pdf'); - $permission['xml_cdr_search'] = permission_exists('xml_cdr_search'); - $permission['xml_cdr_search_direction'] = permission_exists('xml_cdr_search_direction'); - $permission['xml_cdr_b_leg'] = permission_exists('xml_cdr_b_leg'); - $permission['xml_cdr_search_status'] = permission_exists('xml_cdr_search_status'); - $permission['xml_cdr_search_caller_id'] = permission_exists('xml_cdr_search_caller_id'); - $permission['xml_cdr_search_start_range'] = permission_exists('xml_cdr_search_start_range'); - $permission['xml_cdr_search_duration'] = permission_exists('xml_cdr_search_duration'); - $permission['xml_cdr_search_caller_destination'] = permission_exists('xml_cdr_search_caller_destination'); - $permission['xml_cdr_search_destination'] = permission_exists('xml_cdr_search_destination'); - $permission['xml_cdr_codecs'] = permission_exists('xml_cdr_codecs'); - $permission['xml_cdr_search_tta'] = permission_exists('xml_cdr_search_tta'); - $permission['xml_cdr_search_hangup_cause'] = permission_exists('xml_cdr_search_hangup_cause'); - $permission['xml_cdr_search_recording'] = permission_exists('xml_cdr_search_recording'); - $permission['xml_cdr_search_order'] = permission_exists('xml_cdr_search_order'); - $permission['xml_cdr_extension'] = permission_exists('xml_cdr_extension'); - $permission['xml_cdr_caller_id_name'] = permission_exists('xml_cdr_caller_id_name'); - $permission['xml_cdr_caller_id_number'] = permission_exists('xml_cdr_caller_id_number'); - $permission['xml_cdr_caller_destination'] = permission_exists('xml_cdr_caller_destination'); - $permission['xml_cdr_destination'] = permission_exists('xml_cdr_destination'); - $permission['xml_cdr_start'] = permission_exists('xml_cdr_start'); - $permission['xml_cdr_tta'] = permission_exists('xml_cdr_tta'); - $permission['xml_cdr_duration'] = permission_exists('xml_cdr_duration'); - $permission['xml_cdr_pdd'] = permission_exists('xml_cdr_pdd'); - $permission['xml_cdr_mos'] = permission_exists('xml_cdr_mos'); - $permission['xml_cdr_hangup_cause'] = permission_exists('xml_cdr_hangup_cause'); - $permission['xml_cdr_custom_fields'] = permission_exists('xml_cdr_custom_fields'); - $permission['xml_cdr_search_advanced'] = permission_exists('xml_cdr_search_advanced'); - $permission['xml_cdr_direction'] = permission_exists('xml_cdr_direction'); - $permission['xml_cdr_recording'] = permission_exists('xml_cdr_recording'); - $permission['xml_cdr_recording_play'] = permission_exists('xml_cdr_recording_play'); - $permission['xml_cdr_recording_download'] = permission_exists('xml_cdr_recording_download'); - $permission['xml_cdr_account_code'] = permission_exists('xml_cdr_account_code'); - $permission['xml_cdr_status'] = permission_exists('xml_cdr_status'); - $permission['xml_cdr_details'] = permission_exists('xml_cdr_details'); - $permission['xml_cdr_lose_race'] = permission_exists('xml_cdr_lose_race'); - $permission['xml_cdr_cc_agent_leg'] = permission_exists('xml_cdr_cc_agent_leg'); - $permission['xml_cdr_cc_side'] = permission_exists('xml_cdr_cc_side'); - $permission['xml_cdr_call_center_queues'] = permission_exists('xml_cdr_call_center_queues'); - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//set defaults - $archive_request = false; - $action = ''; - $xml_cdrs = []; - $paging_controls_mini = ''; - $paging_controls = null; - $order_by = ""; - $read_codec = ''; - $write_codec = ''; - if (!isset($_REQUEST['show'])) { - //set to show only this domain - $_REQUEST['show'] = 'domain'; - } - -//get posted data - if (!$archive_request && isset($_POST['xml_cdrs']) && is_array($_POST['xml_cdrs'])) { - $action = $_POST['action'] ?? ''; - $xml_cdrs = $_POST['xml_cdrs'] ?? []; - } - -//process the http post data by action - if (!$archive_request && $action != '' && count($xml_cdrs) > 0) { - switch ($action) { - case 'delete': - if ($permission['xml_cdr_delete']) { - $obj = new xml_cdr; - $obj->delete($xml_cdrs); - } - break; - } - - header('Location: xml_cdr.php'); - exit; - } - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//get the extensions - if ($permission['xml_cdr_search_extension']) { - $sql = "select extension_uuid, extension, number_alias from v_extensions "; - $sql .= "where domain_uuid = :domain_uuid "; - if (!$permission['xml_cdr_domain'] && is_array($extension_uuids) && @sizeof($extension_uuids != 0)) { - $sql .= "and extension_uuid in ('".implode("','",$extension_uuids)."') "; //only show the user their extensions - } - $sql .= "order by extension asc, number_alias asc "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; - $extensions = $database->select($sql, $parameters, 'all'); - } - -//get the call center queues - if ($permission['xml_cdr_search_call_center_queues']) { - $sql = "select call_center_queue_uuid, queue_name, queue_extension from v_call_center_queues "; - $sql .= "where domain_uuid = :domain_uuid "; - $sql .= "order by queue_extension asc "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; - $call_center_queues = $database->select($sql, $parameters, 'all'); - } - -//include the header - if ($archive_request) { - $document['title'] = $text['title-call_detail_records_archive']; - } - else { - $document['title'] = $text['title-call_detail_records']; - } - require_once "resources/header.php"; - -//xml cdr include - $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - require_once "xml_cdr_inc.php"; - -//javascript function: send_cmd - echo "\n"; - -//javascript to toggle export select box - echo ""; - -//show the content - echo "
\n"; - echo "
"; - if ($archive_request) { - echo "".$text['title-call_detail_records_archive'].""; - } - else { - echo "".$text['title-call_detail_records'].""; - } - echo "
\n"; - echo "
\n"; - if (!$archive_request) { - if ($permission['xml_cdr_statistics']) { - echo button::create(['type'=>'button','label'=>$text['button-statistics'],'icon'=>'chart-area','link'=>'xml_cdr_statistics.php']); - } - if ($permission['xml_cdr_archive']) { - echo button::create(['type'=>'button','label'=>$text['button-archive'],'icon'=>'archive','link'=>'xml_cdr_archive.php'.($_REQUEST['show'] == 'all' ? '?show=all' : null)]); - } - } - echo "
\n"; - if ($archive_request) { - echo " \n"; - } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - if ($permission['xml_cdr_all'] && $_REQUEST['show'] == 'all') { - echo " \n"; - } - if (isset($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field'])) { - foreach ($_SESSION['cdr']['field'] as $field) { - $array = explode(",", $field); - $field_name = $array[count($array) - 1]; - if (isset($_REQUEST[$field_name])) { - echo " \n"; - } - } - } - if (isset($order_by)) { - echo " \n"; - echo " \n"; - } - if ($archive_request) { - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'link'=>'xml_cdr.php']); - } - echo button::create(['type'=>'button','label'=>$text['button-refresh'],'icon'=>'sync-alt','style'=>'margin-left: 15px;','onclick'=>'location.reload(true);']); - if (isset($_GET['status']) && $_GET['status'] != 'missed') { - echo button::create(['type'=>'button','label'=>$text['button-missed'],'icon'=>'phone-slash','link'=>'?status=missed']); - } - - if ($permission['xml_cdr_export']) { - echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'onclick'=>"toggle_select('export_format'); this.blur();"]); - echo ""; - } - if (!$archive_request && $permission['xml_cdr_delete']) { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); - } - if ($permission['xml_cdr_all'] && $_REQUEST['show'] !== 'all') { - echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']); - } - if ($paging_controls_mini != '') { - echo "".$paging_controls_mini.""; - } - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
\n"; - - if (!$archive_request && $permission['xml_cdr_delete']) { - echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); - } - - echo $text['description']."   ".$text['description_search']."\n"; - echo "

\n"; - -//basic search of call detail records - if ($permission['xml_cdr_search']) { - echo "
\n"; - - echo "
\n"; - echo "
\n"; - - if ($permission['xml_cdr_search_direction']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-direction']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - if ($permission['xml_cdr_b_leg']){ - echo " \n"; - } - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_status']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-status']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_extension']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-extension']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - unset($sql, $parameters, $extensions, $row, $selected); - } - if ($permission['xml_cdr_search_caller_id']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-caller_id']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_start_range']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-start_range']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_duration']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-duration']." (".$text['label-seconds'].")\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_caller_destination']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-caller_destination']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_destination']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-destination']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_codecs']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-codecs']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_tta']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-tta']." (".$text['label-seconds'].")\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - - if ($permission['xml_cdr_search_hangup_cause']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-hangup_cause']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_recording']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-recording']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - } - if ($permission['xml_cdr_search_order']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-order']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - - if ($permission['xml_cdr_search_call_center_queues']) { - echo "
\n"; - echo "
\n"; - echo " ".$text['label-call_center_queue']."\n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - unset($sql, $parameters, $call_center_queues, $row, $selected); - } - } - - echo "
\n"; - - button::$collapse = false; - echo "
"; - if ($permission['xml_cdr_all'] && $_REQUEST['show'] == 'all') { - echo "\n"; - } - if (!$archive_request && $permission['xml_cdr_search_advanced']) { - echo button::create(['type'=>'button','label'=>$text['button-advanced_search'],'icon'=>'tools','link'=>"xml_cdr_search.php".($_REQUEST['show'] == 'all' ? '?show=all' : null),'style'=>'margin-right: 15px;']); - } - echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','link'=>($archive_request ? 'xml_cdr_archive.php' : 'xml_cdr.php')]); - echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_save','name'=>'submit']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - echo "
"; - } - -//mod paging parameters for inclusion in column sort heading links - $param = substr($param, 1); //remove leading '&' - $param = substr($param, 0, strrpos($param, '&order_by=')); //remove trailing order by - -//show the results - echo "
\n"; - echo "\n"; - - echo "
\n"; - echo "\n"; - echo "\n"; - $col_count = 0; - if (!$archive_request && $permission['xml_cdr_delete']) { - echo " \n"; - $col_count++; - } - -//column headings - if ($permission['xml_cdr_direction']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_extension']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_all'] && $_REQUEST['show'] == "all") { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_caller_id_name']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_caller_id_number']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_caller_destination']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_destination']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_recording'] && ($permission['xml_cdr_recording_play'] || $permission['xml_cdr_recording_download'])) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_account_code']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_custom_fields']) { - if (isset($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field']) && @sizeof($_SESSION['cdr']['field'])) { - foreach ($_SESSION['cdr']['field'] as $field) { - $array = explode(",", $field); - $field_name = end($array); - $field_label = ucwords(str_replace("_", " ", $field_name)); - $field_label = str_replace("Sip", "SIP", $field_label); - if ($field_name != "destination_number") { - echo "\n"; - $col_count++; - } - } - } - } - if ($permission['xml_cdr_start']) { - echo "\n"; - echo "\n"; - $col_count += 2; - } - if ($permission['xml_cdr_codecs']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_tta']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_pdd']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_mos']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_duration']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_status']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_hangup_cause']) { - echo "\n"; - $col_count++; - } - if ($permission['xml_cdr_details']) { - echo "\n"; - } - echo "\n"; - -//show results - if (is_array($result)) { - - //determine if theme images exist - $theme_image_path = $_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/"; - $theme_cdr_images_exist = ( - file_exists($theme_image_path."icon_cdr_inbound_answered.png") && - file_exists($theme_image_path."icon_cdr_inbound_no_answer.png") && - file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") && - file_exists($theme_image_path."icon_cdr_inbound_missed.png") && - file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") && - file_exists($theme_image_path."icon_cdr_inbound_busy.png") && - file_exists($theme_image_path."icon_cdr_inbound_failed.png") && - file_exists($theme_image_path."icon_cdr_outbound_answered.png") && - file_exists($theme_image_path."icon_cdr_outbound_no_answer.png") && - file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") && - file_exists($theme_image_path."icon_cdr_outbound_busy.png") && - file_exists($theme_image_path."icon_cdr_outbound_failed.png") && - file_exists($theme_image_path."icon_cdr_local_answered.png") && - file_exists($theme_image_path."icon_cdr_local_no_answer.png") && - file_exists($theme_image_path."icon_cdr_local_voicemail.png") && - file_exists($theme_image_path."icon_cdr_local_cancelled.png") && - file_exists($theme_image_path."icon_cdr_local_busy.png") && - file_exists($theme_image_path."icon_cdr_local_failed.png") - ) ? true : false; - - //simplify the variables - $outbound_caller_id_name = $_SESSION['user']['extension'][0]['outbound_caller_id_name'] ?? ''; - $outbound_caller_id_number = $_SESSION['user']['extension'][0]['outbound_caller_id_number'] ?? ''; - $user_extension = $_SESSION['user']['extension'][0]['user'] ?? ''; - - //loop through the results - $x = 0; - foreach ($result as $index => $row) { - - //set the status - $status = $row['status']; - if (empty($row['status'])) { - //define an array of failed hangup causes - $failed_array = array( - "CALL_REJECTED", - "CHAN_NOT_IMPLEMENTED", - "DESTINATION_OUT_OF_ORDER", - "EXCHANGE_ROUTING_ERROR", - "INCOMPATIBLE_DESTINATION", - "INVALID_NUMBER_FORMAT", - "MANDATORY_IE_MISSING", - "NETWORK_OUT_OF_ORDER", - "NORMAL_TEMPORARY_FAILURE", - "NORMAL_UNSPECIFIED", - "NO_ROUTE_DESTINATION", - "RECOVERY_ON_TIMER_EXPIRE", - "REQUESTED_CHAN_UNAVAIL", - "SUBSCRIBER_ABSENT", - "SYSTEM_SHUTDOWN", - "UNALLOCATED_NUMBER" - ); - - //determine the call status - if ($row['billsec'] > 0) { - $status = 'answered'; - } - if ($row['hangup_cause'] == 'NO_ANSWER') { - $status = 'no_answer'; - } - if ($row['missed_call'] == '1') { - $status = 'missed'; - } - if (substr($row['destination_number'], 0, 3) == '*99') { - $status = 'voicemail'; - } - if ($row['hangup_cause'] == 'ORIGINATOR_CANCEL') { - $status = 'cancelled'; - } - if ($row['hangup_cause'] == 'USER_BUSY') { - $status = 'busy'; - } - if (in_array($row['hangup_cause'], $failed_array)) { - $status = 'failed'; - } - } - - //clear previous variables - unset($record_path, $record_name); - - //get the hangup cause - $hangup_cause = $row['hangup_cause']; - $hangup_cause = str_replace("_", " ", $hangup_cause); - $hangup_cause = strtolower($hangup_cause); - $hangup_cause = ucwords($hangup_cause); - - //get the duration if null use 0 - $duration = $row['duration'] ?? 0; - - //determine recording properties - if (!empty($row['record_path']) && !empty($row['record_name']) && $permission['xml_cdr_recording'] && ($permission['xml_cdr_recording_play'] || $permission['xml_cdr_recording_download'])) { - $record_path = $row['record_path']; - $record_name = $row['record_name']; - //$record_name = strtolower(pathinfo($tmp_name, PATHINFO_BASENAME)); - $record_extension = pathinfo($record_name, PATHINFO_EXTENSION); - switch ($record_extension) { - case "wav" : $record_type = "audio/wav"; break; - case "mp3" : $record_type = "audio/mpeg"; break; - case "ogg" : $record_type = "audio/ogg"; break; - } - } - - //set an empty content variable - $content = ''; - - //recording playback - if ($permission['xml_cdr_recording_play']) { - $content .= "\n"; - $content .= "\n"; // dummy row to maintain alternating background color - } - if ($permission['xml_cdr_details']) { - $list_row_url = "xml_cdr_details.php?id=".urlencode($row['xml_cdr_uuid']).($_REQUEST['show'] ? "&show=all" : null); - } - $content .= "\n"; - if (!$archive_request && $permission['xml_cdr_delete']) { - $content .= " \n"; - } - - //determine call result and appropriate icon - if ($permission['xml_cdr_direction']) { - $content .= "\n"; - } - //extension - if ($permission['xml_cdr_extension']) { - $content .= " \n"; - } - //domain name - if ($permission['xml_cdr_all'] && $_REQUEST['show'] == "all") { - $content .= " \n"; - } - //caller id name - if ($permission['xml_cdr_caller_id_name']) { - $content .= " \n"; - } - //source - if ($permission['xml_cdr_caller_id_number']) { - $content .= " \n"; - } - //caller destination - if ($permission['xml_cdr_caller_destination']) { - $content .= " \n"; - } - //destination - if ($permission['xml_cdr_destination']) { - $content .= " \n"; - } - //recording - if ($permission['xml_cdr_recording'] && ($permission['xml_cdr_recording_play'] || $permission['xml_cdr_recording_download'])) { - if (!empty($record_path) || !empty($record_name)) { - $content .= " \n"; - } - else { - $content .= " \n"; - } - } - //account code - if ($permission['xml_cdr_account_code']) { - $content .= " \n"; - } - //custom cdr fields - if ($permission['xml_cdr_custom_fields']) { - if (!empty($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field'])) { - foreach ($_SESSION['cdr']['field'] as $field) { - $array = explode(",", $field); - $field_name = $array[count($array) - 1]; - if ($field_name != "destination_number") { - $content .= " \n"; - } - } - } - } - //start - if ($permission['xml_cdr_start']) { - $content .= " \n"; - $content .= " \n"; - } - //codec - if ($permission['xml_cdr_codecs']) { - $content .= " \n"; - } - //tta (time to answer) - if ($permission['xml_cdr_tta']) { - $content .= " \n"; - } - //pdd (post dial delay) - if ($permission['xml_cdr_pdd']) { - $content .= " \n"; - } - //mos (mean opinion score) - if ($permission['xml_cdr_mos']) { - if(!empty($row['rtp_audio_in_mos']) && is_numeric($row['rtp_audio_in_mos'])) { - $title = " title='".$text['label-mos_score-'.round($row['rtp_audio_in_mos'])]."'"; - $value = $row['rtp_audio_in_mos']; - } - $content .= " \n"; - } - //duration - if ($permission['xml_cdr_duration']) { - $content .= " \n"; - } - //call result/status - if ($permission['xml_cdr_status']) { - $content .= " \n"; - } - //hangup cause - if ($permission['xml_cdr_hangup_cause']) { - $content .= " \n"; - } - $content .= "\n"; - //show the leg b only to those with the permission - if ($row['leg'] == 'a') { - echo $content; - } - else if ($row['leg'] == 'b' && $permission['xml_cdr_b_leg']) { - echo $content; - } - unset($content); - - $x++; - } - unset($sql, $result, $row_count); - } - - echo "
\n"; - echo " \n"; - echo "  ".$text['label-extension']."".$text['label-domain']."".$text['label-caller_id_name']."".$text['label-caller_id_number']."".$text['label-caller_destination']."".$text['label-destination']."".$text['label-recording']."".$text['label-accountcode']."".$field_label."".$text['label-date']."".$text['label-time']."".$text['label-codecs']."".$text['label-tta']."".$text['label-pdd']."".$text['label-mos']."".$text['label-duration']."".$text['label-status']."".$text['label-hangup_cause']." 
\n"; - $content .= " \n"; - $content .= " \n"; - $content .= " \n"; - if ($theme_cdr_images_exist) { - if (!empty($row['direction'])) { - $image_name = "icon_cdr_" . $row['direction'] . "_" . $status; - if ($row['leg'] == 'b') { - $image_name .= '_b'; - } - $image_name .= ".png"; - if (file_exists($theme_image_path.$image_name)) { - $content .= "\n"; - } - else { $content .= " "; } - } - } - else { $content .= " "; } - $content .= "".$row['extension']." ".escape($row['extension_name'])."".$row['domain_name']."".escape($row['caller_id_name'])." ".escape($row[$field_name])."".$row['start_date_formatted']."".$row['start_time_formatted']."".($row['read_codec'] ?? '').' / '.($row['write_codec'] ?? '')."".(!empty($row['tta']) && $row['tta'] >= 0 ? $row['tta']."s" : " ")."".number_format(escape($row['pdd_ms'])/1000,2)."s".($value ?? '')."".gmdate("G:i:s", $duration)."".escape($text['label-'.$status] ?? '')."".escape($hangup_cause)."
\n"; - echo "
\n"; - echo "
\n"; - echo "
".$paging_controls."
\n"; - echo "\n"; - echo "
\n"; - -//store last search/sort query parameters in session - $_SESSION['xml_cdr']['last_query'] = $_SERVER["QUERY_STRING"]; - -//show the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2008-2024 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + Luis Daniel Lucio Quiroz + Tony Fernandez +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + require_once "resources/paging.php"; + +//check permisions + if (permission_exists('xml_cdr_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//set permissions + $permission = array(); + $permission['xml_cdr_view'] = permission_exists('xml_cdr_view'); + $permission['xml_cdr_search_extension'] = permission_exists('xml_cdr_search_extension'); + $permission['xml_cdr_delete'] = permission_exists('xml_cdr_delete'); + $permission['xml_cdr_domain'] = permission_exists('xml_cdr_domain'); + $permission['xml_cdr_search_call_center_queues'] = permission_exists('xml_cdr_search_call_center_queues'); + $permission['xml_cdr_statistics'] = permission_exists('xml_cdr_statistics'); + $permission['xml_cdr_archive'] = permission_exists('xml_cdr_archive'); + $permission['xml_cdr_all'] = permission_exists('xml_cdr_all'); + $permission['xml_cdr_export'] = permission_exists('xml_cdr_export'); + $permission['xml_cdr_export_csv'] = permission_exists('xml_cdr_export_csv'); + $permission['xml_cdr_export_pdf'] = permission_exists('xml_cdr_export_pdf'); + $permission['xml_cdr_search'] = permission_exists('xml_cdr_search'); + $permission['xml_cdr_search_direction'] = permission_exists('xml_cdr_search_direction'); + $permission['xml_cdr_b_leg'] = permission_exists('xml_cdr_b_leg'); + $permission['xml_cdr_search_status'] = permission_exists('xml_cdr_search_status'); + $permission['xml_cdr_search_caller_id'] = permission_exists('xml_cdr_search_caller_id'); + $permission['xml_cdr_search_start_range'] = permission_exists('xml_cdr_search_start_range'); + $permission['xml_cdr_search_duration'] = permission_exists('xml_cdr_search_duration'); + $permission['xml_cdr_search_caller_destination'] = permission_exists('xml_cdr_search_caller_destination'); + $permission['xml_cdr_search_destination'] = permission_exists('xml_cdr_search_destination'); + $permission['xml_cdr_codecs'] = permission_exists('xml_cdr_codecs'); + $permission['xml_cdr_search_tta'] = permission_exists('xml_cdr_search_tta'); + $permission['xml_cdr_search_hangup_cause'] = permission_exists('xml_cdr_search_hangup_cause'); + $permission['xml_cdr_search_recording'] = permission_exists('xml_cdr_search_recording'); + $permission['xml_cdr_search_order'] = permission_exists('xml_cdr_search_order'); + $permission['xml_cdr_extension'] = permission_exists('xml_cdr_extension'); + $permission['xml_cdr_caller_id_name'] = permission_exists('xml_cdr_caller_id_name'); + $permission['xml_cdr_caller_id_number'] = permission_exists('xml_cdr_caller_id_number'); + $permission['xml_cdr_caller_destination'] = permission_exists('xml_cdr_caller_destination'); + $permission['xml_cdr_destination'] = permission_exists('xml_cdr_destination'); + $permission['xml_cdr_start'] = permission_exists('xml_cdr_start'); + $permission['xml_cdr_tta'] = permission_exists('xml_cdr_tta'); + $permission['xml_cdr_duration'] = permission_exists('xml_cdr_duration'); + $permission['xml_cdr_pdd'] = permission_exists('xml_cdr_pdd'); + $permission['xml_cdr_mos'] = permission_exists('xml_cdr_mos'); + $permission['xml_cdr_hangup_cause'] = permission_exists('xml_cdr_hangup_cause'); + $permission['xml_cdr_custom_fields'] = permission_exists('xml_cdr_custom_fields'); + $permission['xml_cdr_search_advanced'] = permission_exists('xml_cdr_search_advanced'); + $permission['xml_cdr_direction'] = permission_exists('xml_cdr_direction'); + $permission['xml_cdr_recording'] = permission_exists('xml_cdr_recording'); + $permission['xml_cdr_recording_play'] = permission_exists('xml_cdr_recording_play'); + $permission['xml_cdr_recording_download'] = permission_exists('xml_cdr_recording_download'); + $permission['xml_cdr_account_code'] = permission_exists('xml_cdr_account_code'); + $permission['xml_cdr_status'] = permission_exists('xml_cdr_status'); + $permission['xml_cdr_details'] = permission_exists('xml_cdr_details'); + $permission['xml_cdr_lose_race'] = permission_exists('xml_cdr_lose_race'); + $permission['xml_cdr_cc_agent_leg'] = permission_exists('xml_cdr_cc_agent_leg'); + $permission['xml_cdr_cc_side'] = permission_exists('xml_cdr_cc_side'); + $permission['xml_cdr_call_center_queues'] = permission_exists('xml_cdr_call_center_queues'); + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set defaults + $archive_request = false; + $action = ''; + $xml_cdrs = []; + $paging_controls_mini = ''; + $paging_controls = null; + $order_by = ""; + $read_codec = ''; + $write_codec = ''; + if (!isset($_REQUEST['show'])) { + //set to show only this domain + $_REQUEST['show'] = 'domain'; + } + +//get posted data + if (!$archive_request && isset($_POST['xml_cdrs']) && is_array($_POST['xml_cdrs'])) { + $action = $_POST['action'] ?? ''; + $xml_cdrs = $_POST['xml_cdrs'] ?? []; + } + +//process the http post data by action + if (!$archive_request && $action != '' && count($xml_cdrs) > 0) { + switch ($action) { + case 'delete': + if ($permission['xml_cdr_delete']) { + $obj = new xml_cdr; + $obj->delete($xml_cdrs); + } + break; + } + + header('Location: xml_cdr.php'); + exit; + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//get the extensions + if ($permission['xml_cdr_search_extension']) { + $sql = "select extension_uuid, extension, number_alias from v_extensions "; + $sql .= "where domain_uuid = :domain_uuid "; + if (!$permission['xml_cdr_domain'] && is_array($extension_uuids) && @sizeof($extension_uuids != 0)) { + $sql .= "and extension_uuid in ('".implode("','",$extension_uuids)."') "; //only show the user their extensions + } + $sql .= "order by extension asc, number_alias asc "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $extensions = $database->select($sql, $parameters, 'all'); + } + +//get the call center queues + if ($permission['xml_cdr_search_call_center_queues']) { + $sql = "select call_center_queue_uuid, queue_name, queue_extension from v_call_center_queues "; + $sql .= "where domain_uuid = :domain_uuid "; + $sql .= "order by queue_extension asc "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $call_center_queues = $database->select($sql, $parameters, 'all'); + } + +//include the header + if ($archive_request) { + $document['title'] = $text['title-call_detail_records_archive']; + } + else { + $document['title'] = $text['title-call_detail_records']; + } + require_once "resources/header.php"; + +//xml cdr include + $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + require_once "xml_cdr_inc.php"; + +//javascript function: send_cmd + echo "\n"; + +//javascript to toggle export select box + echo ""; + +//show the content + echo "
\n"; + echo "
"; + if ($archive_request) { + echo "".$text['title-call_detail_records_archive'].""; + } + else { + echo "".$text['title-call_detail_records'].""; + } + echo "
\n"; + echo "
\n"; + if (!$archive_request) { + if ($permission['xml_cdr_statistics']) { + echo button::create(['type'=>'button','label'=>$text['button-statistics'],'icon'=>'chart-area','link'=>'xml_cdr_statistics.php']); + } + if ($permission['xml_cdr_archive']) { + echo button::create(['type'=>'button','label'=>$text['button-archive'],'icon'=>'archive','link'=>'xml_cdr_archive.php'.($_REQUEST['show'] == 'all' ? '?show=all' : null)]); + } + } + echo "
\n"; + if ($archive_request) { + echo " \n"; + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + if ($permission['xml_cdr_all'] && $_REQUEST['show'] == 'all') { + echo " \n"; + } + if (isset($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field'])) { + foreach ($_SESSION['cdr']['field'] as $field) { + $array = explode(",", $field); + $field_name = $array[count($array) - 1]; + if (isset($_REQUEST[$field_name])) { + echo " \n"; + } + } + } + if (isset($order_by)) { + echo " \n"; + echo " \n"; + } + if ($archive_request) { + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'link'=>'xml_cdr.php']); + } + echo button::create(['type'=>'button','label'=>$text['button-refresh'],'icon'=>'sync-alt','style'=>'margin-left: 15px;','onclick'=>'location.reload(true);']); + if (isset($_GET['status']) && $_GET['status'] != 'missed') { + echo button::create(['type'=>'button','label'=>$text['button-missed'],'icon'=>'phone-slash','link'=>'?status=missed']); + } + + if ($permission['xml_cdr_export']) { + echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'onclick'=>"toggle_select('export_format'); this.blur();"]); + echo ""; + } + if (!$archive_request && $permission['xml_cdr_delete']) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); + } + if ($permission['xml_cdr_all'] && $_REQUEST['show'] !== 'all') { + echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']); + } + if ($paging_controls_mini != '') { + echo "".$paging_controls_mini.""; + } + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + + if (!$archive_request && $permission['xml_cdr_delete']) { + echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); + } + + echo $text['description']."   ".$text['description_search']."\n"; + echo "

\n"; + +//basic search of call detail records + if ($permission['xml_cdr_search']) { + echo "
\n"; + + echo "
\n"; + echo "
\n"; + + if ($permission['xml_cdr_search_direction']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-direction']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + if ($permission['xml_cdr_b_leg']){ + echo " \n"; + } + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_status']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-status']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_extension']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-extension']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + unset($sql, $parameters, $extensions, $row, $selected); + } + if ($permission['xml_cdr_search_caller_id']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-caller_id']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_start_range']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-start_range']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_duration']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-duration']." (".$text['label-seconds'].")\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_caller_destination']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-caller_destination']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_destination']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-destination']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_codecs']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-codecs']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_tta']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-tta']." (".$text['label-seconds'].")\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + + if ($permission['xml_cdr_search_hangup_cause']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-hangup_cause']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_recording']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-recording']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + } + if ($permission['xml_cdr_search_order']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-order']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + + if ($permission['xml_cdr_search_call_center_queues']) { + echo "
\n"; + echo "
\n"; + echo " ".$text['label-call_center_queue']."\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + unset($sql, $parameters, $call_center_queues, $row, $selected); + } + } + + echo "
\n"; + + button::$collapse = false; + echo "
"; + if ($permission['xml_cdr_all'] && $_REQUEST['show'] == 'all') { + echo "\n"; + } + if (!$archive_request && $permission['xml_cdr_search_advanced']) { + echo button::create(['type'=>'button','label'=>$text['button-advanced_search'],'icon'=>'tools','link'=>"xml_cdr_search.php".($_REQUEST['show'] == 'all' ? '?show=all' : null),'style'=>'margin-right: 15px;']); + } + echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','link'=>($archive_request ? 'xml_cdr_archive.php' : 'xml_cdr.php')]); + echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_save','name'=>'submit']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
"; + } + +//mod paging parameters for inclusion in column sort heading links + $param = substr($param, 1); //remove leading '&' + $param = substr($param, 0, strrpos($param, '&order_by=')); //remove trailing order by + +//show the results + echo "
\n"; + echo "\n"; + + echo "
\n"; + echo "\n"; + echo "\n"; + $col_count = 0; + if (!$archive_request && $permission['xml_cdr_delete']) { + echo " \n"; + $col_count++; + } + +//column headings + if ($permission['xml_cdr_direction']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_extension']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_all'] && $_REQUEST['show'] == "all") { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_caller_id_name']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_caller_id_number']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_caller_destination']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_destination']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_recording'] && ($permission['xml_cdr_recording_play'] || $permission['xml_cdr_recording_download'])) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_account_code']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_custom_fields']) { + if (isset($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field']) && @sizeof($_SESSION['cdr']['field'])) { + foreach ($_SESSION['cdr']['field'] as $field) { + $array = explode(",", $field); + $field_name = end($array); + $field_label = ucwords(str_replace("_", " ", $field_name)); + $field_label = str_replace("Sip", "SIP", $field_label); + if ($field_name != "destination_number") { + echo "\n"; + $col_count++; + } + } + } + } + if ($permission['xml_cdr_start']) { + echo "\n"; + echo "\n"; + $col_count += 2; + } + if ($permission['xml_cdr_codecs']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_tta']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_pdd']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_mos']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_duration']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_status']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_hangup_cause']) { + echo "\n"; + $col_count++; + } + if ($permission['xml_cdr_details']) { + echo "\n"; + } + echo "\n"; + +//show results + if (is_array($result)) { + + //determine if theme images exist + $theme_image_path = $_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/"; + $theme_cdr_images_exist = ( + file_exists($theme_image_path."icon_cdr_inbound_answered.png") && + file_exists($theme_image_path."icon_cdr_inbound_no_answer.png") && + file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") && + file_exists($theme_image_path."icon_cdr_inbound_missed.png") && + file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") && + file_exists($theme_image_path."icon_cdr_inbound_busy.png") && + file_exists($theme_image_path."icon_cdr_inbound_failed.png") && + file_exists($theme_image_path."icon_cdr_outbound_answered.png") && + file_exists($theme_image_path."icon_cdr_outbound_no_answer.png") && + file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") && + file_exists($theme_image_path."icon_cdr_outbound_busy.png") && + file_exists($theme_image_path."icon_cdr_outbound_failed.png") && + file_exists($theme_image_path."icon_cdr_local_answered.png") && + file_exists($theme_image_path."icon_cdr_local_no_answer.png") && + file_exists($theme_image_path."icon_cdr_local_voicemail.png") && + file_exists($theme_image_path."icon_cdr_local_cancelled.png") && + file_exists($theme_image_path."icon_cdr_local_busy.png") && + file_exists($theme_image_path."icon_cdr_local_failed.png") + ) ? true : false; + + //simplify the variables + $outbound_caller_id_name = $_SESSION['user']['extension'][0]['outbound_caller_id_name'] ?? ''; + $outbound_caller_id_number = $_SESSION['user']['extension'][0]['outbound_caller_id_number'] ?? ''; + $user_extension = $_SESSION['user']['extension'][0]['user'] ?? ''; + + //loop through the results + $x = 0; + foreach ($result as $index => $row) { + + //set the status + $status = $row['status']; + if (empty($row['status'])) { + //define an array of failed hangup causes + $failed_array = array( + "CALL_REJECTED", + "CHAN_NOT_IMPLEMENTED", + "DESTINATION_OUT_OF_ORDER", + "EXCHANGE_ROUTING_ERROR", + "INCOMPATIBLE_DESTINATION", + "INVALID_NUMBER_FORMAT", + "MANDATORY_IE_MISSING", + "NETWORK_OUT_OF_ORDER", + "NORMAL_TEMPORARY_FAILURE", + "NORMAL_UNSPECIFIED", + "NO_ROUTE_DESTINATION", + "RECOVERY_ON_TIMER_EXPIRE", + "REQUESTED_CHAN_UNAVAIL", + "SUBSCRIBER_ABSENT", + "SYSTEM_SHUTDOWN", + "UNALLOCATED_NUMBER" + ); + + //determine the call status + if ($row['billsec'] > 0) { + $status = 'answered'; + } + if ($row['hangup_cause'] == 'NO_ANSWER') { + $status = 'no_answer'; + } + if ($row['missed_call'] == '1') { + $status = 'missed'; + } + if (substr($row['destination_number'], 0, 3) == '*99') { + $status = 'voicemail'; + } + if ($row['hangup_cause'] == 'ORIGINATOR_CANCEL') { + $status = 'cancelled'; + } + if ($row['hangup_cause'] == 'USER_BUSY') { + $status = 'busy'; + } + if (in_array($row['hangup_cause'], $failed_array)) { + $status = 'failed'; + } + } + + //clear previous variables + unset($record_path, $record_name); + + //get the hangup cause + $hangup_cause = $row['hangup_cause']; + $hangup_cause = str_replace("_", " ", $hangup_cause); + $hangup_cause = strtolower($hangup_cause); + $hangup_cause = ucwords($hangup_cause); + + //get the duration if null use 0 + $duration = $row['duration'] ?? 0; + + //determine recording properties + if (!empty($row['record_path']) && !empty($row['record_name']) && $permission['xml_cdr_recording'] && ($permission['xml_cdr_recording_play'] || $permission['xml_cdr_recording_download'])) { + $record_path = $row['record_path']; + $record_name = $row['record_name']; + //$record_name = strtolower(pathinfo($tmp_name, PATHINFO_BASENAME)); + $record_extension = pathinfo($record_name, PATHINFO_EXTENSION); + switch ($record_extension) { + case "wav" : $record_type = "audio/wav"; break; + case "mp3" : $record_type = "audio/mpeg"; break; + case "ogg" : $record_type = "audio/ogg"; break; + } + } + + //set an empty content variable + $content = ''; + + //recording playback + if ($permission['xml_cdr_recording_play']) { + $content .= "\n"; + $content .= "\n"; // dummy row to maintain alternating background color + } + if ($permission['xml_cdr_details']) { + $list_row_url = "xml_cdr_details.php?id=".urlencode($row['xml_cdr_uuid']).($_REQUEST['show'] ? "&show=all" : null); + } + $content .= "\n"; + if (!$archive_request && $permission['xml_cdr_delete']) { + $content .= " \n"; + } + + //determine call result and appropriate icon + if ($permission['xml_cdr_direction']) { + $content .= "\n"; + } + //extension + if ($permission['xml_cdr_extension']) { + $content .= " \n"; + } + //domain name + if ($permission['xml_cdr_all'] && $_REQUEST['show'] == "all") { + $content .= " \n"; + } + //caller id name + if ($permission['xml_cdr_caller_id_name']) { + $content .= " \n"; + } + //source + if ($permission['xml_cdr_caller_id_number']) { + $content .= " \n"; + } + //caller destination + if ($permission['xml_cdr_caller_destination']) { + $content .= " \n"; + } + //destination + if ($permission['xml_cdr_destination']) { + $content .= " \n"; + } + //recording + if ($permission['xml_cdr_recording'] && ($permission['xml_cdr_recording_play'] || $permission['xml_cdr_recording_download'])) { + if (!empty($record_path) || !empty($record_name)) { + $content .= " \n"; + } + else { + $content .= " \n"; + } + } + //account code + if ($permission['xml_cdr_account_code']) { + $content .= " \n"; + } + //custom cdr fields + if ($permission['xml_cdr_custom_fields']) { + if (!empty($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field'])) { + foreach ($_SESSION['cdr']['field'] as $field) { + $array = explode(",", $field); + $field_name = $array[count($array) - 1]; + if ($field_name != "destination_number") { + $content .= " \n"; + } + } + } + } + //start + if ($permission['xml_cdr_start']) { + $content .= " \n"; + $content .= " \n"; + } + //codec + if ($permission['xml_cdr_codecs']) { + $content .= " \n"; + } + //tta (time to answer) + if ($permission['xml_cdr_tta']) { + $content .= " \n"; + } + //pdd (post dial delay) + if ($permission['xml_cdr_pdd']) { + $content .= " \n"; + } + //mos (mean opinion score) + if ($permission['xml_cdr_mos']) { + if(!empty($row['rtp_audio_in_mos']) && is_numeric($row['rtp_audio_in_mos'])) { + $title = " title='".$text['label-mos_score-'.round($row['rtp_audio_in_mos'])]."'"; + $value = $row['rtp_audio_in_mos']; + } + $content .= " \n"; + } + //duration + if ($permission['xml_cdr_duration']) { + $content .= " \n"; + } + //call result/status + if ($permission['xml_cdr_status']) { + $content .= " \n"; + } + //hangup cause + if ($permission['xml_cdr_hangup_cause']) { + $content .= " \n"; + } + $content .= "\n"; + //show the leg b only to those with the permission + if ($row['leg'] == 'a') { + echo $content; + } + else if ($row['leg'] == 'b' && $permission['xml_cdr_b_leg']) { + echo $content; + } + unset($content); + + $x++; + } + unset($sql, $result, $row_count); + } + + echo "
\n"; + echo " \n"; + echo "  ".$text['label-extension']."".$text['label-domain']."".$text['label-caller_id_name']."".$text['label-caller_id_number']."".$text['label-caller_destination']."".$text['label-destination']."".$text['label-recording']."".$text['label-accountcode']."".$field_label."".$text['label-date']."".$text['label-time']."".$text['label-codecs']."".$text['label-tta']."".$text['label-pdd']."".$text['label-mos']."".$text['label-duration']."".$text['label-status']."".$text['label-hangup_cause']." 
\n"; + $content .= " \n"; + $content .= " \n"; + $content .= " \n"; + if ($theme_cdr_images_exist) { + if (!empty($row['direction'])) { + $image_name = "icon_cdr_" . $row['direction'] . "_" . $status; + if ($row['leg'] == 'b') { + $image_name .= '_b'; + } + $image_name .= ".png"; + if (file_exists($theme_image_path.$image_name)) { + $content .= "\n"; + } + else { $content .= " "; } + } + } + else { $content .= " "; } + $content .= "".$row['extension']." ".escape($row['extension_name'])."".$row['domain_name']."".escape($row['caller_id_name'])." ".escape($row[$field_name])."".$row['start_date_formatted']."".$row['start_time_formatted']."".($row['read_codec'] ?? '').' / '.($row['write_codec'] ?? '')."".(!empty($row['tta']) && $row['tta'] >= 0 ? $row['tta']."s" : " ")."".number_format(escape($row['pdd_ms'])/1000,2)."s".($value ?? '')."".gmdate("G:i:s", $duration)."".escape($text['label-'.$status] ?? '')."".escape($hangup_cause)."
\n"; + echo "
\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; + echo "\n"; + echo "
\n"; + +//store last search/sort query parameters in session + $_SESSION['xml_cdr']['last_query'] = $_SERVER["QUERY_STRING"]; + +//show the footer + require_once "resources/footer.php"; + +?> diff --git a/core/menu/menu_edit.php b/core/menu/menu_edit.php index 2a24bc44fd..224d335298 100644 --- a/core/menu/menu_edit.php +++ b/core/menu/menu_edit.php @@ -1,236 +1,236 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2023 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('menu_add') || permission_exists('menu_edit')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//connect to the database - $database = new database; - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//action add or update - if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { - $action = "update"; - $menu_uuid = $_REQUEST["id"]; - } - else { - $action = "add"; - } - -//get http post variables and set them to php variables - if (!empty($_POST) && count($_POST) > 0) { - $menu_uuid = $_POST["menu_uuid"] ?? null; - $menu_name = $_POST["menu_name"]; - $menu_language = $_POST["menu_language"]; - $menu_description = $_POST["menu_description"]; - } - -//process the http post - if (count($_POST) > 0 && empty($_POST["persistformvar"])) { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: menu.php'); - exit; - } - - //check for all required data - $msg = ''; - if (empty($menu_name)) { $msg .= $text['message-required'].$text['label-name']."
\n"; } - if (empty($menu_language)) { $msg .= $text['message-required'].$text['label-language']."
\n"; } - //if (empty($menu_description)) { $msg .= $text['message-required'].$text['label-description']."
\n"; } - if (!empty($msg) && empty($_POST["persistformvar"])) { - require_once "resources/header.php"; - require_once "resources/persist_form_var.php"; - echo "
\n"; - echo "
\n"; - echo $msg."
"; - echo "
\n"; - persistformvar($_POST); - echo "
\n"; - require_once "resources/footer.php"; - return; - } - - //add or update the database - if (empty($_POST["persistformvar"])) { - if ($action == "add") { - //create a new unique id - $menu_uuid = uuid(); - - //start a new menu - $array['menus'][0]['menu_uuid'] = $menu_uuid; - $array['menus'][0]['menu_name'] = $menu_name; - $array['menus'][0]['menu_language'] = $menu_language; - $array['menus'][0]['menu_description'] = $menu_description; - $database->app_name = 'menu'; - $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; - $database->save($array); - unset($array); - - //redirect the user back to the main menu - message::add($text['message-add']); - header("Location: menu.php"); - return; - } //if ($action == "add") - - if ($action == "update") { - //update the menu - $array['menus'][0]['menu_uuid'] = $menu_uuid; - $array['menus'][0]['menu_name'] = $menu_name; - $array['menus'][0]['menu_language'] = $menu_language; - $array['menus'][0]['menu_description'] = $menu_description; - $database->app_name = 'menu'; - $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; - $database->save($array); - unset($array); - - //redirect the user back to the main menu - message::add($text['message-update']); - header("Location: menu.php"); - return; - } - } - } - -//pre-populate the form - if (count($_GET) > 0 && is_uuid($_GET["id"]) && empty($_POST["persistformvar"])) { - $menu_uuid = $_GET["id"]; - $sql = "select * from v_menus "; - $sql .= "where menu_uuid = :menu_uuid "; - $parameters['menu_uuid'] = $menu_uuid; - $row = $database->select($sql, $parameters, 'row'); - if (!empty($row)) { - $menu_uuid = $row["menu_uuid"]; - $menu_name = $row["menu_name"]; - $menu_language = $row["menu_language"]; - $menu_description = $row["menu_description"]; - } - unset($sql, $parameters, $row); - } - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//show the header - $document['title'] = $text['title-menu']; - require_once "resources/header.php"; - -//show the content - echo "
\n"; - - echo "
\n"; - echo "
".$text['header-menu']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','link'=>'menu.php']); - echo button::create(['type'=>'button','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'collapse'=>'hide-xs','style'=>'margin-left: 15px;','link'=>'menu_reload.php?menu_uuid='.urlencode($menu_uuid ?? '').'&menu_language='.urlencode($menu_language ?? '')]); - if (permission_exists('menu_restore') && $action == "update") { - echo button::create(['type'=>'button','label'=>$text['button-restore_default'],'icon'=>'undo-alt','collapse'=>'hide-xs','onclick'=>"modal_open('modal-restore','btn_restore');"]); - } - echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - if (permission_exists('menu_restore') && $action == "update") { - echo modal::create(['id'=>'modal-restore','type'=>'confirmation','message'=>$text['confirm-restore'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_restore','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>'menu_restore_default.php?menu_uuid='.urlencode($menu_uuid).'&menu_language='.urlencode($menu_language),'onclick'=>'modal_close();'])]); - } - - echo $text['description-menu']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - echo " ".$text['label-name']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo "\n"; - echo $text['description-name']."
\n"; - echo " ".$text['label-language']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-language']."\n"; - echo "
\n"; - echo " ".$text['label-description']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-description']."\n"; - echo "
"; - echo "
"; - echo "
"; - - if ($action == "update") { - echo "\n"; - } - echo "\n"; - - echo "
"; - -//show the menu items - if ($action == "update") { - require_once "core/menu/menu_item_list.php"; - } - -//include the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2008-2023 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('menu_add') || permission_exists('menu_edit')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//connect to the database + $database = new database; + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//action add or update + if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { + $action = "update"; + $menu_uuid = $_REQUEST["id"]; + } + else { + $action = "add"; + } + +//get http post variables and set them to php variables + if (!empty($_POST) && count($_POST) > 0) { + $menu_uuid = $_POST["menu_uuid"] ?? null; + $menu_name = $_POST["menu_name"]; + $menu_language = $_POST["menu_language"]; + $menu_description = $_POST["menu_description"]; + } + +//process the http post + if (count($_POST) > 0 && empty($_POST["persistformvar"])) { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: menu.php'); + exit; + } + + //check for all required data + $msg = ''; + if (empty($menu_name)) { $msg .= $text['message-required'].$text['label-name']."
\n"; } + if (empty($menu_language)) { $msg .= $text['message-required'].$text['label-language']."
\n"; } + //if (empty($menu_description)) { $msg .= $text['message-required'].$text['label-description']."
\n"; } + if (!empty($msg) && empty($_POST["persistformvar"])) { + require_once "resources/header.php"; + require_once "resources/persist_form_var.php"; + echo "
\n"; + echo "
\n"; + echo $msg."
"; + echo "
\n"; + persistformvar($_POST); + echo "
\n"; + require_once "resources/footer.php"; + return; + } + + //add or update the database + if (empty($_POST["persistformvar"])) { + if ($action == "add") { + //create a new unique id + $menu_uuid = uuid(); + + //start a new menu + $array['menus'][0]['menu_uuid'] = $menu_uuid; + $array['menus'][0]['menu_name'] = $menu_name; + $array['menus'][0]['menu_language'] = $menu_language; + $array['menus'][0]['menu_description'] = $menu_description; + $database->app_name = 'menu'; + $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; + $database->save($array); + unset($array); + + //redirect the user back to the main menu + message::add($text['message-add']); + header("Location: menu.php"); + return; + } //if ($action == "add") + + if ($action == "update") { + //update the menu + $array['menus'][0]['menu_uuid'] = $menu_uuid; + $array['menus'][0]['menu_name'] = $menu_name; + $array['menus'][0]['menu_language'] = $menu_language; + $array['menus'][0]['menu_description'] = $menu_description; + $database->app_name = 'menu'; + $database->app_uuid = 'f4b3b3d2-6287-489c-2a00-64529e46f2d7'; + $database->save($array); + unset($array); + + //redirect the user back to the main menu + message::add($text['message-update']); + header("Location: menu.php"); + return; + } + } + } + +//pre-populate the form + if (count($_GET) > 0 && is_uuid($_GET["id"]) && empty($_POST["persistformvar"])) { + $menu_uuid = $_GET["id"]; + $sql = "select * from v_menus "; + $sql .= "where menu_uuid = :menu_uuid "; + $parameters['menu_uuid'] = $menu_uuid; + $row = $database->select($sql, $parameters, 'row'); + if (!empty($row)) { + $menu_uuid = $row["menu_uuid"]; + $menu_name = $row["menu_name"]; + $menu_language = $row["menu_language"]; + $menu_description = $row["menu_description"]; + } + unset($sql, $parameters, $row); + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//show the header + $document['title'] = $text['title-menu']; + require_once "resources/header.php"; + +//show the content + echo "
\n"; + + echo "
\n"; + echo "
".$text['header-menu']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','link'=>'menu.php']); + echo button::create(['type'=>'button','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'collapse'=>'hide-xs','style'=>'margin-left: 15px;','link'=>'menu_reload.php?menu_uuid='.urlencode($menu_uuid ?? '').'&menu_language='.urlencode($menu_language ?? '')]); + if (permission_exists('menu_restore') && $action == "update") { + echo button::create(['type'=>'button','label'=>$text['button-restore_default'],'icon'=>'undo-alt','collapse'=>'hide-xs','onclick'=>"modal_open('modal-restore','btn_restore');"]); + } + echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + if (permission_exists('menu_restore') && $action == "update") { + echo modal::create(['id'=>'modal-restore','type'=>'confirmation','message'=>$text['confirm-restore'],'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_restore','style'=>'float: right; margin-left: 15px;','collapse'=>'never','link'=>'menu_restore_default.php?menu_uuid='.urlencode($menu_uuid).'&menu_language='.urlencode($menu_language),'onclick'=>'modal_close();'])]); + } + + echo $text['description-menu']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo " ".$text['label-name']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "\n"; + echo $text['description-name']."
\n"; + echo " ".$text['label-language']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-language']."\n"; + echo "
\n"; + echo " ".$text['label-description']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-description']."\n"; + echo "
"; + echo "
"; + echo "
"; + + if ($action == "update") { + echo "\n"; + } + echo "\n"; + + echo "
"; + +//show the menu items + if ($action == "update") { + require_once "core/menu/menu_item_list.php"; + } + +//include the footer + require_once "resources/footer.php"; + +?> diff --git a/core/user_logs/app_config.php b/core/user_logs/app_config.php index dabc76a7b1..4dd25c541d 100644 --- a/core/user_logs/app_config.php +++ b/core/user_logs/app_config.php @@ -1,115 +1,115 @@ - + diff --git a/core/user_logs/resources/classes/user_logs.php b/core/user_logs/resources/classes/user_logs.php index fc74e7742f..9d95409c44 100644 --- a/core/user_logs/resources/classes/user_logs.php +++ b/core/user_logs/resources/classes/user_logs.php @@ -1,156 +1,156 @@ - - Portions created by the Initial Developer are Copyright (C) 2019-2024 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -/** - * user_logs class - * - * @method null delete - * @method null toggle - * @method null copy - */ -if (!class_exists('user_logs')) { - class user_logs { - - /** - * declare the variables - */ - private $app_name; - private $app_uuid; - private $name; - private $table; - private $toggle_field; - private $toggle_values; - private $location; - - /** - * called when the object is created - */ - public function __construct() { - //assign the variables - $this->app_name = 'user_logs'; - $this->app_uuid = '582a13cf-7d75-4ea3-b2d9-60914352d76e'; - $this->name = 'user_log'; - $this->table = 'user_logs'; - $this->toggle_field = ''; - $this->toggle_values = ['true','false']; - $this->location = 'user_logs.php'; - } - - /** - * add user_logs - */ - public static function add($result) { - - //prepare the array - $array = []; - $array['user_logs'][0]["timestamp"] = 'now()'; - $array['user_logs'][0]["domain_uuid"] = $result['domain_uuid']; - $array['user_logs'][0]["user_uuid"] = $result['user_uuid']; - $array['user_logs'][0]["username"] = $result['username']; - $array['user_logs'][0]["hostname"] = gethostname(); - $array['user_logs'][0]["type"] = 'login'; - $array['user_logs'][0]["remote_address"] = $_SERVER['REMOTE_ADDR']; - $array['user_logs'][0]["user_agent"] = $_SERVER['HTTP_USER_AGENT']; - $array['user_logs'][0]["session_id"] = session_id(); - $array['user_logs'][0]["type"] = 'login'; - if ($result["authorized"] == "true") { - $array['user_logs'][0]["result"] = 'success'; - } - else { - $array['user_logs'][0]["result"] = 'failure'; - } - - //add the dialplan permission - $p = new permissions; - $p->add("user_log_add", 'temp'); - - //save to the data - $database = new database; - $database->app_name = 'authentication'; - $database->app_uuid = 'a8a12918-69a4-4ece-a1ae-3932be0e41f1'; - if (strlen($user_log_uuid ?? '')>0) - $database->uuid($user_log_uuid); - $database->save($array, false); - $message = $database->message; - - //remove the temporary permission - $p->delete("user_log_add", 'temp'); - } - - /** - * delete rows from the database - */ - public function delete($records) { - if (permission_exists($this->name.'_delete')) { - - //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->location); - exit; - } - - //delete multiple records - if (is_array($records) && @sizeof($records) != 0) { - //build the delete array - $x = 0; - foreach ($records as $record) { - //add to the array - if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { - $array[$this->table][$x][$this->name.'_uuid'] = $record['uuid']; - $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid']; - } - - //increment the id - $x++; - } - - //delete the checked rows - if (is_array($array) && @sizeof($array) != 0) { - //execute delete - $database = new database; - $database->app_name = $this->app_name; - $database->app_uuid = $this->app_uuid; - $database->delete($array); - unset($array); - - //set message - message::add($text['message-delete']); - } - unset($records); - } - } - } - - } -} - -?> + + Portions created by the Initial Developer are Copyright (C) 2019-2024 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +/** + * user_logs class + * + * @method null delete + * @method null toggle + * @method null copy + */ +if (!class_exists('user_logs')) { + class user_logs { + + /** + * declare the variables + */ + private $app_name; + private $app_uuid; + private $name; + private $table; + private $toggle_field; + private $toggle_values; + private $location; + + /** + * called when the object is created + */ + public function __construct() { + //assign the variables + $this->app_name = 'user_logs'; + $this->app_uuid = '582a13cf-7d75-4ea3-b2d9-60914352d76e'; + $this->name = 'user_log'; + $this->table = 'user_logs'; + $this->toggle_field = ''; + $this->toggle_values = ['true','false']; + $this->location = 'user_logs.php'; + } + + /** + * add user_logs + */ + public static function add($result) { + + //prepare the array + $array = []; + $array['user_logs'][0]["timestamp"] = 'now()'; + $array['user_logs'][0]["domain_uuid"] = $result['domain_uuid']; + $array['user_logs'][0]["user_uuid"] = $result['user_uuid']; + $array['user_logs'][0]["username"] = $result['username']; + $array['user_logs'][0]["hostname"] = gethostname(); + $array['user_logs'][0]["type"] = 'login'; + $array['user_logs'][0]["remote_address"] = $_SERVER['REMOTE_ADDR']; + $array['user_logs'][0]["user_agent"] = $_SERVER['HTTP_USER_AGENT']; + $array['user_logs'][0]["session_id"] = session_id(); + $array['user_logs'][0]["type"] = 'login'; + if ($result["authorized"] == "true") { + $array['user_logs'][0]["result"] = 'success'; + } + else { + $array['user_logs'][0]["result"] = 'failure'; + } + + //add the dialplan permission + $p = new permissions; + $p->add("user_log_add", 'temp'); + + //save to the data + $database = new database; + $database->app_name = 'authentication'; + $database->app_uuid = 'a8a12918-69a4-4ece-a1ae-3932be0e41f1'; + if (strlen($user_log_uuid ?? '')>0) + $database->uuid($user_log_uuid); + $database->save($array, false); + $message = $database->message; + + //remove the temporary permission + $p->delete("user_log_add", 'temp'); + } + + /** + * delete rows from the database + */ + public function delete($records) { + if (permission_exists($this->name.'_delete')) { + + //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->location); + exit; + } + + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + //build the delete array + $x = 0; + foreach ($records as $record) { + //add to the array + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $array[$this->table][$x][$this->name.'_uuid'] = $record['uuid']; + $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid']; + } + + //increment the id + $x++; + } + + //delete the checked rows + if (is_array($array) && @sizeof($array) != 0) { + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //set message + message::add($text['message-delete']); + } + unset($records); + } + } + } + + } +} + +?> diff --git a/core/user_logs/user_log_edit.php b/core/user_logs/user_log_edit.php index 1afa5cd34a..3bd27af63a 100644 --- a/core/user_logs/user_log_edit.php +++ b/core/user_logs/user_log_edit.php @@ -1,214 +1,214 @@ -get(); - -//get the uuid - $user_log_uuid = $_GET['id']; - -//pre-populate the form - if (!empty($_GET) && is_array($_GET) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) { - $sql = "select * from v_user_logs "; - $sql .= "where user_log_uuid = :user_log_uuid "; - //$sql .= "and domain_uuid = :domain_uuid "; - //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $parameters['user_log_uuid'] = $user_log_uuid; - $database = new database; - $row = $database->select($sql, $parameters, 'row'); - if (is_array($row) && @sizeof($row) != 0) { - $domain_uuid = $row["domain_uuid"]; - $timestamp = $row["timestamp"]; - $user_uuid = $row["user_uuid"]; - $username = $row["username"]; - $type = $row["type"]; - $result = $row["result"]; - $remote_address = $row["remote_address"]; - $user_agent = $row["user_agent"]; - } - unset($sql, $parameters, $row); - } - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//show the header - $document['title'] = $text['title-user_log']; - require_once "resources/header.php"; - -//get the users - $sql = "SELECT user_uuid, username FROM v_users "; - $sql .= "WHERE domain_uuid = :domain_uuid "; - $sql .= "ORDER by username asc "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; - $users = $database->execute($sql, $parameters, 'all'); - unset ($sql, $parameters); - -//show the content - echo "
\n"; - echo "\n"; - - echo "
\n"; - echo "
".$text['title-user_log']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'user_logs.php']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['title_description-user_logs']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - echo " ".$text['label-domain_uuid']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-domain_uuid']."\n"; - echo "
\n"; - echo " ".$text['label-timestamp']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-timestamp']."\n"; - echo "
\n"; - echo " ".$text['label-user_uuid']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-user_uuid']."\n"; - echo "
\n"; - echo " ".$text['label-username']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-username']."\n"; - echo "
\n"; - echo " ".$text['label-type']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-type']."\n"; - echo "
\n"; - echo " ".$text['label-result']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-result']."\n"; - echo "
\n"; - echo " ".$text['label-remote_address']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-remote_address']."\n"; - echo "
\n"; - echo " ".$text['label-user_agent']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-user_agent']."\n"; - echo "
"; - echo "
"; - echo "

"; - - echo "\n"; - - echo "
"; - -//include the footer - require_once "resources/footer.php"; - +get(); + +//get the uuid + $user_log_uuid = $_GET['id']; + +//pre-populate the form + if (!empty($_GET) && is_array($_GET) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true")) { + $sql = "select * from v_user_logs "; + $sql .= "where user_log_uuid = :user_log_uuid "; + //$sql .= "and domain_uuid = :domain_uuid "; + //$parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $parameters['user_log_uuid'] = $user_log_uuid; + $database = new database; + $row = $database->select($sql, $parameters, 'row'); + if (is_array($row) && @sizeof($row) != 0) { + $domain_uuid = $row["domain_uuid"]; + $timestamp = $row["timestamp"]; + $user_uuid = $row["user_uuid"]; + $username = $row["username"]; + $type = $row["type"]; + $result = $row["result"]; + $remote_address = $row["remote_address"]; + $user_agent = $row["user_agent"]; + } + unset($sql, $parameters, $row); + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//show the header + $document['title'] = $text['title-user_log']; + require_once "resources/header.php"; + +//get the users + $sql = "SELECT user_uuid, username FROM v_users "; + $sql .= "WHERE domain_uuid = :domain_uuid "; + $sql .= "ORDER by username asc "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $users = $database->execute($sql, $parameters, 'all'); + unset ($sql, $parameters); + +//show the content + echo "
\n"; + echo "\n"; + + echo "
\n"; + echo "
".$text['title-user_log']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','collapse'=>'hide-xs','style'=>'margin-right: 15px;','link'=>'user_logs.php']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['title_description-user_logs']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo " ".$text['label-domain_uuid']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-domain_uuid']."\n"; + echo "
\n"; + echo " ".$text['label-timestamp']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-timestamp']."\n"; + echo "
\n"; + echo " ".$text['label-user_uuid']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-user_uuid']."\n"; + echo "
\n"; + echo " ".$text['label-username']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-username']."\n"; + echo "
\n"; + echo " ".$text['label-type']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-type']."\n"; + echo "
\n"; + echo " ".$text['label-result']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-result']."\n"; + echo "
\n"; + echo " ".$text['label-remote_address']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-remote_address']."\n"; + echo "
\n"; + echo " ".$text['label-user_agent']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-user_agent']."\n"; + echo "
"; + echo "
"; + echo "

"; + + echo "\n"; + + echo "
"; + +//include the footer + require_once "resources/footer.php"; + ?> \ No newline at end of file diff --git a/core/users/user_imports.php b/core/users/user_imports.php index 88549447f4..69fd3cfbe6 100644 --- a/core/users/user_imports.php +++ b/core/users/user_imports.php @@ -1,506 +1,506 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2023 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane -*/ - -//includes files - require_once dirname(__DIR__, 2) . "/resources/require.php"; - require_once "resources/check_auth.php"; - -//check permissions - if (permission_exists('user_import')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//connect to the database - $database = new database; - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduce the functionality but requires PHP 5.1.0 or higher - if (!function_exists('str_getcsv')) { - function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { - $fp = fopen("php://memory", 'r+'); - fputs($fp, $input); - rewind($fp); - $data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0 - fclose($fp); - return $data; - } - } - -//get the http get values and set them as php variables - $action = $_POST["action"] ?? ''; - $from_row = $_POST["from_row"] ?? ''; - $delimiter = $_POST["data_delimiter"] ?? ''; - $enclosure = $_POST["data_enclosure"] ?? ''; - -//save the data to the csv file - if (isset($_POST['data'])) { - $file = $_SESSION['server']['temp']['dir'].'/users-'.$_SESSION['domain_name'].'.csv'; - if (file_put_contents($file, $_POST['data'])) { - $_SESSION['file'] = $file; - } - } - -//copy the csv file - //$_POST['submit'] == "Upload" && - if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('user_import')) { - if (!empty($_POST['type']) && $_POST['type'] == 'csv') { - $file = $_SESSION['server']['temp']['dir'].'/users-'.$_SESSION['domain_name'].'.csv'; - if (move_uploaded_file($_FILES['ulfile']['tmp_name'], $file)) { - $_SESSION['file'] = $file; - } - } - } - -//get the schema - if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '')) { - //get the first line - $line = fgets(fopen($_SESSION['file'], 'r')); - $line_fields = explode($delimiter, $line); - - //get the schema - $x = 0; - include ("core/users/app_config.php"); - $i = 0; - foreach ($apps[0]['db'] as $table) { - //get the table name and parent name - if (is_array($table["table"]['name'])) { - $table_name = $table["table"]['name']['text']; - } - else { - $table_name = $table["table"]['name']; - } - $parent_name = $table["table"]['parent']; - - //remove the v_ table prefix - if (substr($table_name, 0, 2) == 'v_') { - $table_name = substr($table_name, 2); - } - if (substr($parent_name, 0, 2) == 'v_') { - $parent_name = substr($parent_name, 2); - } - - //filter for specific tables and build the schema array - if ($table_name == "users") { - $schema[$i]['table'] = $table_name; - $schema[$i]['parent'] = $parent_name; - foreach($table['fields'] as $row) { - $row['deprecated'] = $row['deprecated'] ?? ''; - if ($row['deprecated'] !== 'true') { - if (is_array($row['name'])) { - $field_name = $row['name']['text']; - } - else { - $field_name = $row['name']; - } - $schema[$i]['fields'][] = $field_name; - } - } - $i++; - } - } - $schema[$i]['table'] = 'user_groups'; - $schema[$i]['parent'] = 'users'; - $schema[$i]['fields'][] = 'group_name'; - - //debug info - //view_array($schema); - } - -//match the column names to the field names - if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '') && $action != 'import') { - - //create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - - //include header - $document['title'] = $text['title-user_import']; - require_once "resources/header.php"; - - //form to match the fields to the column names - echo "
\n"; - - echo "
\n"; - echo "
".$text['header-user_import']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'user_imports.php']); - echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['description-import']."\n"; - echo "

\n"; - - echo "
\n"; - echo "\n"; - - //loop through user columns - $x = 0; - foreach ($line_fields as $line_field) { - $line_field = preg_replace('#[^a-zA-Z0-9_]#', '', $line_field); - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; - $x++; - } - - echo "
\n"; - //echo " ".$text['label-zzz']."\n"; - echo $line_field; - echo " \n"; - echo " \n"; - //echo "
\n"; - //echo $text['description-zzz']."\n"; - echo "
\n"; - echo "
\n"; - echo "

\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
\n"; - - require_once "resources/footer.php"; - - //normalize the column names - //$line = strtolower($line); - //$line = str_replace("-", "_", $line); - //$line = str_replace($delimiter."title".$delimiter, $delimiter."contact_title".$delimiter, $line); - //$line = str_replace("firstname", "name_given", $line); - //$line = str_replace("lastname", "name_family", $line); - //$line = str_replace("company", "organization", $line); - //$line = str_replace("company", "contact_email", $line); - - //end the script - exit; - } - -//get the parent table - function get_parent($schema,$table_name) { - foreach ($schema as $row) { - if ($row['table'] == $table_name) { - return $row['parent']; - } - } - } - -//upload the csv - if (file_exists($_SESSION['file'] ?? '') && $action == 'import') { - - //validate the token - $token = new token; - if (!$token->validate($_SERVER['PHP_SELF'])) { - message::add($text['message-invalid_token'],'negative'); - header('Location: users.php'); - exit; - } - - //form to match the fields to the column names - //$document['title'] = $text['title-user_import']; - //require_once "resources/header.php"; - - //user selected fields - $fields = $_POST['fields']; - - //set the domain_uuid - $domain_uuid = $_SESSION['domain_uuid']; - - - //get the groups - $sql = "select * from v_groups where domain_uuid is null "; - $groups = $database->select($sql, null, 'all'); - unset($sql); - - //get the contents of the csv file and convert them into an array - $handle = @fopen($_SESSION['file'], "r"); - if ($handle) { - //set the starting identifiers - $row_id = 0; - $row_number = 1; - - //loop through the array - while (($line = fgets($handle, 4096)) !== false) { - if ($from_row <= $row_number) { - //get the user_uuid - $user_uuid = uuid(); - - //format the data - $y = 0; - foreach ($fields as $key => $value) { - - //get the line - $result = str_getcsv($line, $delimiter, $enclosure); - - //get the table and field name - $field_array = explode(".",$value); - $table_name = $field_array[0]; - $field_name = $field_array[1]; - //echo "value: $value
\n"; - //echo "table_name: $table_name
\n"; - //echo "field_name: $field_name
\n"; - - //get the parent table name - $parent = get_parent($schema, $table_name); - - //clean the phone number - //if ($field_name == "phone") { - // $result[$key] = preg_replace('{\D}', '', $result[$key]); - //} - - //build the data array - if (!empty($table_name)) { - if (empty($parent)) { - $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; - $array[$table_name][$row_id][$field_name] = $result[$key]; - } - else { - if ($field_name != "group_name") { - $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; - $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; - } - } - - if ($field_name == "group_name") { - $group_name = ''; - foreach ($groups as $field) { - if ($field['group_name'] == $result[$key]) { - $group_name = $field['group_name']; - $array['user_groups'][$row_id]['user_group_uuid'] = uuid(); - $array['user_groups'][$row_id]['domain_uuid'] = $domain_uuid; - $array['user_groups'][$row_id]['group_name'] = $field['group_name']; - $array['user_groups'][$row_id]['group_uuid'] = $field['group_uuid']; - $array['user_groups'][$row_id]['user_uuid'] = $user_uuid; - } - } - - //remove superadmin if not the correct permission - if ($group_name == 'superadmin') { - if (!permission_exists('group_domain')) { - unset($array['user_groups'][$row_id]); - } - } - } - } - } - - //set the password hash cost - $options = array('cost' => 10); - - //set the hash the user password - $password = $array['users'][$row_id]['password']; - $array['users'][$row_id]['password'] = password_hash($password, PASSWORD_DEFAULT, $options); - - //set the user_uuid - $array['users'][$row_id]['user_uuid'] = $user_uuid; - - //debug - //echo "
\n";
-								//print_r($array);
-								//echo "
\n"; - //exit; - - //process a chunk of the array - if ($row_id === 1000) { - - //save to the data - $database->app_name = 'users'; - $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; - $database->save($array); - //$message = $database->message; - - //clear the array - unset($array); - - //set the row id back to 0 - $row_id = 0; - } - - } //if ($from_row <= $row_id) - $row_number++; - $row_id++; - } //end while - fclose($handle); - - //debug info - //echo "
\n";
-					//print_r($array);
-					//echo "
\n"; - //exit; - - //save to the data - if (!empty($array)) { - $database->app_name = 'users'; - $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; - $database->save($array); - //$message = $database->message; - unset($array); - } - - //send the redirect header - header("Location: users.php"); - return; - } - } - -//create token - $object = new token; - $token = $object->create($_SERVER['PHP_SELF']); - -//include the header - $document['title'] = $text['title-user_import']; - require_once "resources/header.php"; - -//show content - echo "
\n"; - - echo "
\n"; - echo "
".$text['header-user_import']."
\n"; - echo "
\n"; - echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'users.php']); - echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); - echo "
\n"; - echo "
\n"; - echo "
\n"; - - echo $text['description-import']."\n"; - echo "

\n"; - - - echo "
\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['label-import_data']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_data']."\n"; - echo "
\n"; - echo " ".$text['label-from_row']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-from_row']."\n"; - echo "
\n"; - echo " ".$text['label-import_delimiter']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_delimiter']."\n"; - echo "
\n"; - echo " ".$text['label-import_enclosure']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo $text['description-import_enclosure']."\n"; - echo "
\n"; - echo " ".$text['label-import_file_upload']."\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo "  \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo "
"; - echo "

"; - -//include the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2008-2023 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes files + require_once dirname(__DIR__, 2) . "/resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('user_import')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//connect to the database + $database = new database; + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//built in str_getcsv requires PHP 5.3 or higher, this function can be used to reproduce the functionality but requires PHP 5.1.0 or higher + if (!function_exists('str_getcsv')) { + function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") { + $fp = fopen("php://memory", 'r+'); + fputs($fp, $input); + rewind($fp); + $data = fgetcsv($fp, null, $delimiter, $enclosure); // $escape only got added in 5.3.0 + fclose($fp); + return $data; + } + } + +//get the http get values and set them as php variables + $action = $_POST["action"] ?? ''; + $from_row = $_POST["from_row"] ?? ''; + $delimiter = $_POST["data_delimiter"] ?? ''; + $enclosure = $_POST["data_enclosure"] ?? ''; + +//save the data to the csv file + if (isset($_POST['data'])) { + $file = $_SESSION['server']['temp']['dir'].'/users-'.$_SESSION['domain_name'].'.csv'; + if (file_put_contents($file, $_POST['data'])) { + $_SESSION['file'] = $file; + } + } + +//copy the csv file + //$_POST['submit'] == "Upload" && + if (!empty($_FILES['ulfile']['tmp_name']) && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('user_import')) { + if (!empty($_POST['type']) && $_POST['type'] == 'csv') { + $file = $_SESSION['server']['temp']['dir'].'/users-'.$_SESSION['domain_name'].'.csv'; + if (move_uploaded_file($_FILES['ulfile']['tmp_name'], $file)) { + $_SESSION['file'] = $file; + } + } + } + +//get the schema + if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '')) { + //get the first line + $line = fgets(fopen($_SESSION['file'], 'r')); + $line_fields = explode($delimiter, $line); + + //get the schema + $x = 0; + include ("core/users/app_config.php"); + $i = 0; + foreach ($apps[0]['db'] as $table) { + //get the table name and parent name + if (is_array($table["table"]['name'])) { + $table_name = $table["table"]['name']['text']; + } + else { + $table_name = $table["table"]['name']; + } + $parent_name = $table["table"]['parent']; + + //remove the v_ table prefix + if (substr($table_name, 0, 2) == 'v_') { + $table_name = substr($table_name, 2); + } + if (substr($parent_name, 0, 2) == 'v_') { + $parent_name = substr($parent_name, 2); + } + + //filter for specific tables and build the schema array + if ($table_name == "users") { + $schema[$i]['table'] = $table_name; + $schema[$i]['parent'] = $parent_name; + foreach($table['fields'] as $row) { + $row['deprecated'] = $row['deprecated'] ?? ''; + if ($row['deprecated'] !== 'true') { + if (is_array($row['name'])) { + $field_name = $row['name']['text']; + } + else { + $field_name = $row['name']; + } + $schema[$i]['fields'][] = $field_name; + } + } + $i++; + } + } + $schema[$i]['table'] = 'user_groups'; + $schema[$i]['parent'] = 'users'; + $schema[$i]['fields'][] = 'group_name'; + + //debug info + //view_array($schema); + } + +//match the column names to the field names + if (!empty($delimiter) && file_exists($_SESSION['file'] ?? '') && $action != 'import') { + + //create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + + //include header + $document['title'] = $text['title-user_import']; + require_once "resources/header.php"; + + //form to match the fields to the column names + echo "
\n"; + + echo "
\n"; + echo "
".$text['header-user_import']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'user_imports.php']); + echo button::create(['type'=>'submit','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'id'=>'btn_save']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-import']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + + //loop through user columns + $x = 0; + foreach ($line_fields as $line_field) { + $line_field = preg_replace('#[^a-zA-Z0-9_]#', '', $line_field); + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + $x++; + } + + echo "
\n"; + //echo " ".$text['label-zzz']."\n"; + echo $line_field; + echo " \n"; + echo " \n"; + //echo "
\n"; + //echo $text['description-zzz']."\n"; + echo "
\n"; + echo "
\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + + require_once "resources/footer.php"; + + //normalize the column names + //$line = strtolower($line); + //$line = str_replace("-", "_", $line); + //$line = str_replace($delimiter."title".$delimiter, $delimiter."contact_title".$delimiter, $line); + //$line = str_replace("firstname", "name_given", $line); + //$line = str_replace("lastname", "name_family", $line); + //$line = str_replace("company", "organization", $line); + //$line = str_replace("company", "contact_email", $line); + + //end the script + exit; + } + +//get the parent table + function get_parent($schema,$table_name) { + foreach ($schema as $row) { + if ($row['table'] == $table_name) { + return $row['parent']; + } + } + } + +//upload the csv + if (file_exists($_SESSION['file'] ?? '') && $action == 'import') { + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: users.php'); + exit; + } + + //form to match the fields to the column names + //$document['title'] = $text['title-user_import']; + //require_once "resources/header.php"; + + //user selected fields + $fields = $_POST['fields']; + + //set the domain_uuid + $domain_uuid = $_SESSION['domain_uuid']; + + + //get the groups + $sql = "select * from v_groups where domain_uuid is null "; + $groups = $database->select($sql, null, 'all'); + unset($sql); + + //get the contents of the csv file and convert them into an array + $handle = @fopen($_SESSION['file'], "r"); + if ($handle) { + //set the starting identifiers + $row_id = 0; + $row_number = 1; + + //loop through the array + while (($line = fgets($handle, 4096)) !== false) { + if ($from_row <= $row_number) { + //get the user_uuid + $user_uuid = uuid(); + + //format the data + $y = 0; + foreach ($fields as $key => $value) { + + //get the line + $result = str_getcsv($line, $delimiter, $enclosure); + + //get the table and field name + $field_array = explode(".",$value); + $table_name = $field_array[0]; + $field_name = $field_array[1]; + //echo "value: $value
\n"; + //echo "table_name: $table_name
\n"; + //echo "field_name: $field_name
\n"; + + //get the parent table name + $parent = get_parent($schema, $table_name); + + //clean the phone number + //if ($field_name == "phone") { + // $result[$key] = preg_replace('{\D}', '', $result[$key]); + //} + + //build the data array + if (!empty($table_name)) { + if (empty($parent)) { + $array[$table_name][$row_id]['domain_uuid'] = $domain_uuid; + $array[$table_name][$row_id][$field_name] = $result[$key]; + } + else { + if ($field_name != "group_name") { + $array[$parent][$row_id][$table_name][$y]['domain_uuid'] = $domain_uuid; + $array[$parent][$row_id][$table_name][$y][$field_name] = $result[$key]; + } + } + + if ($field_name == "group_name") { + $group_name = ''; + foreach ($groups as $field) { + if ($field['group_name'] == $result[$key]) { + $group_name = $field['group_name']; + $array['user_groups'][$row_id]['user_group_uuid'] = uuid(); + $array['user_groups'][$row_id]['domain_uuid'] = $domain_uuid; + $array['user_groups'][$row_id]['group_name'] = $field['group_name']; + $array['user_groups'][$row_id]['group_uuid'] = $field['group_uuid']; + $array['user_groups'][$row_id]['user_uuid'] = $user_uuid; + } + } + + //remove superadmin if not the correct permission + if ($group_name == 'superadmin') { + if (!permission_exists('group_domain')) { + unset($array['user_groups'][$row_id]); + } + } + } + } + } + + //set the password hash cost + $options = array('cost' => 10); + + //set the hash the user password + $password = $array['users'][$row_id]['password']; + $array['users'][$row_id]['password'] = password_hash($password, PASSWORD_DEFAULT, $options); + + //set the user_uuid + $array['users'][$row_id]['user_uuid'] = $user_uuid; + + //debug + //echo "
\n";
+								//print_r($array);
+								//echo "
\n"; + //exit; + + //process a chunk of the array + if ($row_id === 1000) { + + //save to the data + $database->app_name = 'users'; + $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; + $database->save($array); + //$message = $database->message; + + //clear the array + unset($array); + + //set the row id back to 0 + $row_id = 0; + } + + } //if ($from_row <= $row_id) + $row_number++; + $row_id++; + } //end while + fclose($handle); + + //debug info + //echo "
\n";
+					//print_r($array);
+					//echo "
\n"; + //exit; + + //save to the data + if (!empty($array)) { + $database->app_name = 'users'; + $database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e'; + $database->save($array); + //$message = $database->message; + unset($array); + } + + //send the redirect header + header("Location: users.php"); + return; + } + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//include the header + $document['title'] = $text['title-user_import']; + require_once "resources/header.php"; + +//show content + echo "
\n"; + + echo "
\n"; + echo "
".$text['header-user_import']."
\n"; + echo "
\n"; + echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'users.php']); + echo button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>$_SESSION['theme']['button_icon_upload'],'id'=>'btn_save']); + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-import']."\n"; + echo "

\n"; + + + echo "
\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-import_data']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_data']."\n"; + echo "
\n"; + echo " ".$text['label-from_row']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-from_row']."\n"; + echo "
\n"; + echo " ".$text['label-import_delimiter']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_delimiter']."\n"; + echo "
\n"; + echo " ".$text['label-import_enclosure']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-import_enclosure']."\n"; + echo "
\n"; + echo " ".$text['label-import_file_upload']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo "  \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo "
"; + echo "

"; + +//include the footer + require_once "resources/footer.php"; + +?>