//New Functionality Added in Vicidial Dialer

1)	Campaign Caller ID Change [03-03-2023]
	a)	Admin will have a select field for every users to enable caller id change for agent, in user modification page with name 'eti_cli_change_enable_flag';
		field : 
		MYSQL Query for adding this column:
		##########################################################   MYSQL Query ###############################################################################
		ALTER TABLE vicidial_users ADD COLUMN (eti_cli_change_enable_flag enum('Y','N') NOT NULL DEFAULT 'N');
		########################################################################################################################################################

		Add below written code, at the end of the user modification page "$ADD==3", just before submit button
		########################################################################################################################################################
		<div class="col-lg-12 text-center admin_formPart_heading">Additional Functionality Providing to Agent</div>
		<div class="form-group col-sm-3"><label>Enable CLI Change For Agent</label><div class="input-group"><select class="custom-select" name="eti_cli_change_enable_flag" id="eti_cli_change_enable_flag"><option value="YES">YES</option><option value="NO">NO</option><option value="YES" selected="">YES</option></select><div class="input-group-append"><span class="input-group-text"><i onclick="FillAndShowHelpDiv(event, '#users-eti_cli_change_enable_flag')" class="fa fa-duotone fa-question"></i></span></div></div></div>
		########################################################################################################################################################
	b)	Change in mysql query according to new field added. (Table : vicidial_users) {$ADD = [3,4, '4A', '4B']}
	c)	Agent : add related field in mysql according to requirements.(Table : vicidial_users)
	d)	Add the below code to html in index.php for agent, just before 'dialControl' button [Reference : 'You are paused']
		########################################################################################################################################################
		<tr>
			<td style="padding:0px 0px 0px 0px">
				<?php
					if($eti_cli_change_enable_flag == 'YES'){ ?>
						<span id="eti_cli_change_button">
							<div class="ui teal fluid center aligned button" onclick="eti_cli_change_block_function('SHOW', this);">
								Change Campaign CLI
							</div>
						</span>
				<?php	}
				?>
				<span style="background-color:#f1f1f1" id="eti_cli_change_block">
					<select class="ui fluid dropdown" onchange="eti_cli_change_function(this)">
						<option>Select Caller ID</option>
						<?php
						foreach($eti_callerID as $key => $value)
						{ ?>
							<option value="<?php echo $value['did_pattern'];?>" <?php echo($value['id']) ? 'selected' : '' ;?>><?php echo $value['did_pattern'];?></option>
					<?php	}
					?>
					</select>
				</span>
			</td>
		</tr>
		########################################################################################################################################################
	e)	i)Add a function 'eti_cli_change_function' for the select field declared above
		########################################################### Javascript Function ########################################################################
		function eti_cli_change_function(element)
		{
			var eti_agent_selected_caller_id = '<?php echo $eti_agent_selected_caller_id;?>';
			var eti_agent_new_caller_id = $(element).val();
			var confirm_box_text = "You are trying to change Caller ID to "; 
			if(eti_agent_new_caller_id != '')
			{
				confirm_box_text += " '"+eti_agent_new_caller_id+"' ";
			}
			else
			{
				confirm_box_text += "Default Caller ID set by campaign.";
			}

			if(confirm(confirm_box_text) === true)
			{
				$(element).val(eti_agent_new_caller_id);

				$.ajax({
					url : 'eti_agent_custom_api.php',
					data : {user : user, caller_id : eti_agent_new_caller_id},
					method : "POST",
					success:function(response)
					{
						console.log(response);
					}
				});
			}
			else
			{
				$(element).val(eti_agent_selected_caller_id);
			}
		}
		########################################################################################################################################################
		ii) Add an entry in function start_all_refresh() :-
		########################################################################################################################################################
		$("#eti_cli_change_block").hide();

		########################################################################################################################################################
	f)	Add the following code in agent/index.php, at the end of the block [if($auth>0)]
		########################################################################################################################################################
		$stmt = "SELECT caller_id FROM eti_agent_caller_id WHERE user = '".$VD_login."' ";
		$rslt = mysql_to_mysqli($stmt, $link);
		if($rslt)
		{
			if(mysqli_num_rows($rslt) > 0)
			{
				$row = mysqli_fetch_row($rslt);
				$eti_agent_selected_caller_id = $row[0];
			}
			else
			{
				$eti_agent_selected_caller_id = '';
			}
		}

		$stmt = "SELECT d.did_id,d.did_pattern,c.id FROM eti_agent_caller_id_group g INNER JOIN vicidial_inbound_dids d ON d.did_id = g.did_id LEFT JOIN eti_agent_caller_id c ON c.caller_id = d.did_pattern WHERE g.campaign_id = '".$VD_campaign."' ";
		$rslt = mysql_to_mysqli($stmt, $link);
		if(mysqli_num_rows($rslt) > 0)
		{
			$eti_callerID = array();
			while($row = mysqli_fetch_assoc($rslt))
			{
				$eti_callerID[] = $row;
			}
		}
		else
		{
			$eti_callerID = array();
		}
		########################################################################################################################################################
 	g)	MYSQL Queries For creating the above declared tables
 		CREATE TABLE `eti_agent_caller_id` (
		  `id` int(10) NOT NULL AUTO_INCREMENT,
		  `user` varchar(45) NOT NULL,
		  `caller_id` varchar(40) NOT NULL,
		  `create_time_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
		  PRIMARY KEY (`id`)
		);

		CREATE TABLE `eti_agent_caller_id_group` (
		  `id` int(11) NOT NULL AUTO_INCREMENT,
		  `campaign_id` int(11) NOT NULL,
		  `did_id` int(11) NOT NULL,
		  `active_did` tinyint(1) NOT NULL DEFAULT '0',
		  `time_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
		  PRIMARY KEY (`id`)
		);



		CREATE TABLE `eti_agent_caller_id_history` (
		  `id` int(10) NOT NULL AUTO_INCREMENT,
		  `user` varchar(45) NOT NULL,
		  `log` text NOT NULL,
		  `create_time_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
		  PRIMARY KEY (`id`)
		);

	h)	MYSQL Query for add help info for the field created in admin/index.php file
		Query : INSERT INTO help_documentation (help_id, help_title, help_text) VALUES('users-eti_cli_change_enable_flag','CLI Change','This field enable or disable CLI change option for agent, on agent screen. Default is NO.');


*! Note : 
1) copy files from './required_files_for_cli_change' Location and paste them at '/var/lib/asterisk/agi-bin' with -777 Permission
2) Add the following code in carrier in admin. [$ADD == 140000000000]
	################################################################      Carrier     ####################################################################################
	exten => _6632X.,1,AGI(agi://127.0.0.1:4577/call_log)
	exten => _6632X.,n,AGI(eti_callerid.sh,"${CHANNEL}","${CALLERID(ani)}")
	exten => _6632X.,n,Verbose(result is: ${result})
	exten => _6632X.,n,Set(CALLERID(ani)=${result})
	exten => _6632X.,n,Set(CALLERID(num)=${result})
	exten => _6632X.,n,Dial(${DYNAMICM-3266}/${EXTEN:4},,tTo)
	exten => _6632X.,n,Hangup()
	###############################################################    Change it according to your requirements   ##########################################################
