Project

General

Profile

Bug #7980 » telephonylist.php

Enzo Zazzaro, 04/10/2020 11:58 AM

 
1
<?php
2
/**
3
 * @file 		telephonylist.php
4
 * @brief 		Manage List and Upload Leads
5
 * @copyright 	Copyright (c) 2018 GOautodial Inc. 
6
 * @author		Demian Lizandro A. Biscocho
7
 * @author     	Alexander Jim H. Abenoja
8
 *
9
 * @par <b>License</b>:
10
 *  This program is free software: you can redistribute it and/or modify
11
 *  it under the terms of the GNU Affero General Public License as published by
12
 *  the Free Software Foundation, either version 3 of the License, or
13
 *  (at your option) any later version.
14
 *
15
 *  This program is distributed in the hope that it will be useful,
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU Affero General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU Affero General Public License
21
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
**/
23
        ini_set('memory_limit','1024M');
24
        ini_set('upload_max_filesize', '600M');
25
        ini_set('post_max_size', '600M');
26
        ini_set('max_execution_time', 0);
27

    
28
	require_once('./php/UIHandler.php');
29
	require_once('./php/APIHandler.php');
30
	require_once('./php/CRMDefaults.php');
31
        require_once('./php/LanguageHandler.php');
32
        include('./php/Session.php');
33

    
34
	$ui = \creamy\UIHandler::getInstance();
35
	$api = \creamy\APIHandler::getInstance();
36
	$lh = \creamy\LanguageHandler::getInstance();
37
	$user = \creamy\CreamyUser::currentUser();
38

    
39
	$perm = $api->goGetPermissions('list,customfields');
40
	$checkbox_all = $ui->getCheckAll("list");
41
?>
42
<html>
43
    <head>
44
        <meta charset="UTF-8">
45
        <title><?php $lh->translateText('portal_title'); ?> - <?php $lh->translateText("Lists"); ?></title>
46
        <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
47

    
48
        <?php 
49
			print $ui->standardizedThemeCSS(); 
50
			print $ui->creamyThemeCSS();
51
			print $ui->dataTablesTheme();
52
		?>
53

    
54
        <!-- Wizard Form style -->
55
        <link href="css/wizard-form.css" rel="stylesheet" type="text/css" />
56
        <link href="css/style.css" rel="stylesheet" type="text/css" />
57

    
58
        <!-- Datetime picker CSS -->
59
		<link rel="stylesheet" src="js/dashboard/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css">
60

    
61
        <!-- Date Picker JS -->
62
        <script type="text/javascript" src="js/dashboard/eonasdan-bootstrap-datetimepicker/build/js/moment.js"></script>
63
		<script type="text/javascript" src="js/dashboard/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
64
		<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/0.71/jquery.csv-0.71.min.js"></script>
65

    
66
		<style type="text/css">
67
			#progress-wrp {
68
				border: 1px solid #0099CC;
69
				border-radius: 3px;
70
				position: relative;
71
				width: 100%;
72
				height: 30px;
73
				background-color: #367fa9;
74
			}
75
			
76
			#progress-wrp .progress-bar {
77
				border-radius: 3px;
78
				position: absolute;
79
				width: 1%;
80
				height: 100%;
81
				background-color: #00a65a;
82
			  /* background-color: #4CAF50; */
83
			}
84
			
85
			#progress-wrp .status {
86
				top:3px;
87
				left:50%;
88
				position:absolute;
89
				display:inline-block;
90
				color: white;
91
				font-style: bold;
92
				/* color: #000000; */
93
			}
94
		</style>
95

    
96
		<style type="text/css">
97
			.select2-container{
98
				width: 100% !important;
99
			}
100
		</style>
101
    </head>
102

    
103
    <?php print $ui->creamyBody(); ?>
104

    
105
        <div class="wrapper">
106
        <!-- header logo: style can be found in header.less -->
107
		<?php print $ui->creamyHeader($user); ?>
108
            <!-- Left side column. contains the logo and sidebar -->
109
			<?php print $ui->getSidebar($user->getUserId(), $user->getUserName(), $user->getUserRole(), $user->getUserAvatar()); ?>
110

    
111
            <!-- Right side column. Contains the navbar and content of the page -->
112
            <aside class="right-side">
113
                <!-- Content Header (Page header) -->
114
                <section class="content-header">
115
                    <h1>
116
                        <?php $lh->translateText("telephony"); ?>
117
                        <small><?php $lh->translateText("list_management"); ?></small>
118
                    </h1>
119
                    <ol class="breadcrumb">
120
                        <li><a href="./index.php"><i class="fa fa-home"></i> <?php $lh->translateText("home"); ?></a></li>
121
                       <li><?php $lh->translateText("telephony"); ?></li>
122
						<li class="active"><?php $lh->translateText("lists"); ?>
123
                    </ol>
124
                </section>
125

    
126
                <!-- Main content -->
127
                <section class="content">
128
				<?php
129
					if ($perm->list->list_read !== 'N') {
130
						/****
131
						** API to get data of tables
132
						****/
133
						$lists = $api->API_getAllLists();
134
						
135
						//echo "<!--\n";
136
						//var_dump($lists);
137
						//echo "\n-->\n";
138
				?>
139
                	<div class="row">
140
                        <div class="col-lg-9">
141
		                <div class="panel panel-default">
142
							<div class="panel-body">
143
							<legend id="legend_title"><?php $lh->translateText("lists"); ?></legend>
144
								<div role="tabpanel">
145
							
146
									<ul role="tablist" class="nav nav-tabs nav-justified">
147
			
148
									<!-- List panel tabs-->
149
										 <li role="presentation" <?php if(!isset($_GET['dnc_tab']))echo 'class="active"';?>>
150
											<a href="#list_tab" aria-controls="list_tab" role="tab" data-toggle="tab" class="bb0">
151
												<?php $lh->translateText("list"); ?></a>
152
										 </li>
153
									<!-- DNC panel tab -->
154
										 <li role="presentation" <?php if(isset($_GET['dnc_tab']))echo 'class="active"';?>>
155
											<a href="#dnc_tab" aria-controls="dnc_tab" role="tab" data-toggle="tab" class="bb0">
156
												<?php $lh->translateText("dnc"); ?> </a>
157
										 </li>
158
									</ul>
159
									  
160
									<!-- Tab panes-->
161
									<div class="tab-content bg-white">
162
										<!--==== List ====-->
163
										<div id="list_tab" role="tabpanel" class="tab-pane <?php if(!isset($_GET['dnc_tab']))echo 'active'?>">
164
											<table class="display responsive no-wrap table table-striped table-bordered" width="100%" id="table_lists">
165
												<thead>
166
													<tr>
167
													<!--<th style="color: white;">Pic</th>-->
168
													<th><?php $lh->translateText("list_id"); ?></th>
169
													<th><?php $lh->translateText("name"); ?></th>
170
													<th><?php $lh->translateText("status"); ?></th>
171
													<th><?php $lh->translateText("leads_count"); ?></th>
172
													<th><?php $lh->translateText("campaign"); ?></th>
173
													<th><?php $lh->translateText("field"); ?></th>
174
													<?php if ($perm->list->list_delete !== 'N'){ ?>
175
													<th><?php echo $checkbox_all;?></th>
176
													<?php } ?>													
177
													<th><?php $lh->translateText("action"); ?></th>
178
													</tr>
179
												</thead>
180
												<tbody>
181
												<?php
182
												for($i=0;$i < count($lists->list_id);$i++){
183
												// if no entry in user list
184
												
185
												if($lists->active[$i] == "Y"){
186
												$lists->active[$i] = $lh->translationFor("active");
187
												}else{
188
												$lists->active[$i] = $lh->translationFor("inactive");
189
												}
190
												
191
												$action_list = $ui->getUserActionMenuForLists($lists->list_id[$i], $lists->list_name[$i], $perm);
192
												if($lists->list_id[$i] === 998 || $lists->list_id[$i] === 999)
193
													$checkbox = "";
194
												else
195
													$checkbox = '<label for="'.$lists->list_id[$i].'"><div class="checkbox c-checkbox"><label><input name="" class="check_list" id="'.$lists->list_id[$i].'" type="checkbox" value="Y"><span class="fa fa-check"></span> </label></div></label>';
196
												?>
197
												<tr>
198
												<!--<td><avatar username='<?php echo $lists->list_name[$i];?>' :size='36'></avatar></td>-->
199
												<td><strong>
200
													<?php
201
													if (($perm->list->list_update !== 'N' && !preg_match("/^(998|999)$/", $lists->list_id[$i]))) {
202
													?>
203
													<a class='edit-list' data-id='<?php echo $lists->list_id[$i];?>'>
204
													<?php
205
													}
206
													?><?php echo $lists->list_id[$i];?>
207
												</strong></td>
208
												<td><?php echo $lists->list_name[$i];?></td>
209
												<td><?php echo $lists->active[$i];?></td>
210
												<td><?php echo $lists->tally[$i];?></td>
211
												<td><?php echo $lists->campaign_name[$i];?></td>
212
												<td><?php echo $lists->cf_count[$i];?></td>
213
												<?php if ($perm->list->list_delete !== 'N'){ ?>
214
												<td><?php echo $checkbox;?></td>
215
												<?php } ?>												
216
												<td><?php echo $action_list;?></td>
217
												</tr>
218
												<?php
219
												
220
												}
221
												?>
222
												</tbody>
223
											</table>
224
										</div><!-- /.list-tab -->
225
										<!--==== DNC ====-->
226
										<div id="dnc_tab" role="tabpanel" class="tab-pane <?php if(isset($_GET['dnc_tab']))echo 'active'?>">
227
											<table class="display responsive no-wrap table table-striped table-bordered" width="100%" id="table_dnc">
228
												<thead>
229
													<tr>
230
													<th><?php $lh->translateText("phone_number"); ?></th>
231
													<th><?php $lh->translateText("campaign"); ?></th>
232
													<th><?php $lh->translateText("action"); ?></th>
233
													</tr>
234
												</thead>
235
												<tbody>
236
													<tr id="dnc_result">														
237
														<td colspan="3"><center><span id="dnc_error">- - - <?php $lh->translateText("search_filter_dnc");?> - - -</span></center></td>
238
														<td></td>
239
														<td></td>													
240
													</tr>
241
												</tbody>
242
											</table>
243
										</div><!-- /.dnc-tab -->
244
										
245
									</div><!-- /.tab-content -->
246
								</div><!-- /.tab-panel -->
247
							</div><!-- /.body -->
248
						</div><!-- /.panel -->
249
					</div><!-- /.col-lg-9 -->
250

    
251
<?php
252
//if ($perm->list->list_upload !== 'N') {
253
?>
254
	<div class="col-lg-3" id="list_sidebar">
255
	<h3 class="m0 pb-lg"><?php $lh->translateText("upload_import"); ?></h3>
256
		<form action="./php/AddLoadLeads.php" method="POST" enctype="multipart/form-data" id="upload_form" name="upload_form">
257
			<input type="hidden" name="log_user" value="<?=$_SESSION['user']?>" />
258
			<input type="hidden" name="log_group" value="<?=$_SESSION['usergroup']?>" />
259
			<div class="form-group">
260
				<label><?php $lh->translateText("list_id"); ?>:</label>
261
					<div class="form-group">
262
					<!-- <select id="select2-1" class="form-control" name="list_id"> -->
263
						<select id="list_id" class="form-control select2" name="list_id" required>
264
						<option value="" selected disabled></option>
265
						<?php
266
						for($i=0;$i<count($lists->list_id);$i++){
267
						echo '<option value="'.$lists->list_id[$i].'">'.$lists->list_id[$i].' - '.$lists->list_name[$i].'</option>';
268
						}
269
						?>
270
						</select>
271
					</div>
272
				<div class="form-group">
273
					<label><?php $lh->translateText("duplicate_check"); ?> :</label>
274
					<SELECT size="1" NAME="goDupcheck" ID="goDupcheck" TITLE="Duplicate Check - Will check phone numbers on the lead file and cross reference it with all phone numbers on a specific campaign or in all List ID or in the entire system." class="form-control select2">
275
					<OPTION value="DUPBLOCK"><?php $lh->translateText("esclusi_lavorazione"); ?></OPTION>
276
					<OPTION value="DUPLIST"><?php $lh->translateText("check_phones_in_list_id"); ?></OPTION>
277
					<OPTION value="DUPCAMP"><?php $lh->translateText("check_phones_in_campaign-lists"); ?></OPTION>					
278
					<OPTION value="NONE"><?php $lh->translateText("no_duplicate_check"); ?></OPTION>
279
					<?php
280
					// Customization
281
					if(LEADUPLOAD_CHECK_PHONES_IN_SYSTEM === 'y'){
282
					?>
283
					<OPTION value="DUPSYS"><?php $lh->translateText("check_phones_in_system"); ?></OPTION>
284
					<?php }//end customization ?>
285
					</SELECT>
286
				</div>
287
			</div>
288
			
289
			<div class="form-group">
290
                        <label><?php $lh->translateText("lead_mapping"); ?>  </label> &nbsp;&nbsp;
291
                        	<label class="switch">
292
  					<input type="checkbox" id="LeadMapSubmit" name="LeadMapSubmit" value="0" checked />
293
  					<span class="slider round"></span>
294
				</label>
295
			</div>
296
			
297
			<div class="form-group">			
298
			<label><?php $lh->translateText("csv_file"); ?>:</label>
299
			<div class="form-group" id="dvImportSegments">
300
				<div class="input-group">
301
				<input type="text" class="form-control file-name" name="file_name" placeholder="<?php $lh->translateText("csv_file"); ?>" required>
302
				<span class="input-group-btn">
303
				<button type="button" class="btn browse-btn  btn-primary" type="button"><?php $lh->translateText("browse"); ?></button>
304
				</span>
305
				</div>
306
				<input type="file" class="file-box hide" name="file_upload" id="txtFileUpload" accept=".csv">
307
			</div>
308
	
309
			<div id="LeadMappingContainer" class="modal" tabindex="-1" role="dialog" data-keyboard="false" data-backdrop="static">
310
 				<div class="modal-dialog" role="document">
311
    					<div class="modal-content">
312
      						<div class="modal-header">
313
        						<h4 class="modal-title">
314
							<div class="col-sm-12 col-md-8">
315
								<b>ASSOCIA CAMPI</b>
316
							</div>
317
        							<button type="button" class="close" data-dismiss="modal" aria-label="Close">
318
          							<span aria-hidden="true">&times;</span>
319
        							</button>
320
							</h4>
321
      						</div>
322
      						<div class="modal-body">
323
        						<span id="lead_map_data"></span>
324
							<!--<input type="hidden" id="LeadMapSubmit" name="LeadMapSubmit" value="0"/>-->
325
							<span id="lead_map_fields"></span>
326
      						</div>
327
      						<div class="modal-footer">
328
      							<input type="button" id="btnUpload" name="btnUpload" value="<?php $lh->translateText("proceed"); ?>" class="btn btn-primary" onClick="goProgressBar();">
329
						</div>
330
    					</div>
331
  				</div>
332
			</div>
333

    
334
			<div id="goValuesContainer"></div>
335
			</div>
336
			
337
			<!-- Progress bar -->
338
			<div class="form-group">
339
				<div id="progress-wrp">
340
				<div class="progress-bar"></div >
341
				<div class="status">0%</div>
342
				</div>
343
				<div id="output"><!-- error or success results --></div>
344
				<br />
345
				<div>
346
				<div class="alert alert-success" style="display:none;" id="dStatus"> 
347
				<div id="qstatus">  </div>
348
				</div>
349
				</div>
350
			</div>
351
			<!-- End Progress bar -->
352
			
353
			<div class="form-group">
354
			<input type="button" id="btnUpload" name="btnUpload" value="<?php $lh->translateText("update"); ?>" class="btn btn-primary" onClick="goProgressBar();">
355
			<!--										<div class="col-lg-12" style="margin-top: 10px;">
356
			<div class="alert alert-success" style="display:none;" id="dStatus"> 
357
			<div id="qstatus">  </div>
358
			</div>
359
			</div>-->
360
			</div>
361
			
362
			<div id="jMapFieldsdiv">
363
			<span id="jMapFieldsSpan"></span>
364
			</div>
365
		</form>
366
	<?php
367
	if(isset($_GET['message'])){
368
	echo '<div class="col-lg-12" style="margin-top: 10px;">';
369
	if($_GET['message'] == "success"){
370
	echo '<div class="alert alert-success"> <strong>Succes: </strong>'.$_GET['RetMesg']." leads uploaded</div>";
371
	}else{
372
	echo '<div class="alert alert-success"> <strong>Error: </strong>'.$_GET['RetMesg']."</div>";
373
	}
374
	echo '</div>';
375
	}
376
	#var_dump($_GET);
377
	?>
378
	
379
	</div><!-- ./upload leads -->
380
	
381
	<div class="col-lg-3" id="dnc_sidebar" style="display:none;">
382
	<h3 class="m0 pb-lg"><?php $lh->translateText("filter_dnc"); ?></h3>
383
		<div class="form-group">
384
			<label for="search_dnc"><?php $lh->translateText("search"); ?></label>
385
			<div class="has-clear">
386
				<input type="text" placeholder="<?php $lh->translateText("search_phone"); ?>" id="search_dnc" class="form-control mb">
387
				<span class="form-control-clear fa fa-close form-control-feedback"></span>
388
			</div>
389
		</div>
390
		<div class="clearfix">
391
			<button type="button" class="pull-left btn btn-default" id="dnc_search_button"> <?php $lh->translateText("search"); ?></button>
392
		</div>
393
	</div><!-- ./ dnc search -->
394
<?php
395
//}
396
?>
397

    
398
</div>
399
<?php
400
} else {
401
print $ui->calloutErrorMessage($lh->translationFor("you_dont_have_permission"));
402
}
403
?>
404
</section><!-- /.content -->
405
</aside><!-- /.right-side -->
406
<?php print $ui->getRightSidebar($user->getUserId(), $user->getUserName(), $user->getUserAvatar()); ?>
407
</div><!-- ./wrapper -->
408

    
409
<!-- FIXED ACTION BUTTON -->
410
<div class="action-button-circle" data-toggle="modal" data-target="#list-modal" id="list_fab" title="<?php $lh->translateText("list_wizard"); ?>">
411
<?php print $ui->getCircleButton("list_and_call_recording", "plus"); ?>
412
</div>
413
<div class="action-button-circle" data-toggle="modal" data-target="#dnc-modal" id="dnc_fab" style="display:none;" title="<?php $lh->translateText("add_delete_dnc"); ?>">
414
<?php print $ui->getCircleButton("list_and_call_recording", "pencil-square-o"); ?>
415
</div>
416
<?php
417
	$campaign = $api->API_getAllCampaigns();
418
	
419
	$next_listname = "ListID ".$lists->next_listID;
420
	$datenow = date("j-n-Y");
421
	$next_listdesc = "Auto-generated - ListID - ".$datenow;
422
?>
423
	<div class="modal fade" id="list-modal" tabindex="-1" aria-labelledby="list-modal" >
424
        <div class="modal-dialog" role="document">
425
            <div class="modal-content" style="border-radius:5px;">
426

    
427
				<div class="modal-header">
428
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
429
					<h4 class="modal-title animate-header" id="scripts"><b><?php $lh->translateText("list_wizard"); ?> » <?php $lh->translateText("add_list"); ?></b></h4>
430
				</div>
431
				<div class="modal-body wizard-content">
432

    
433
				<form method="POST" id="create_form" role="form">
434
					<input type="hidden" name="log_user" value="<?=$_SESSION['user']?>" />
435
					<input type="hidden" name="log_group" value="<?=$_SESSION['usergroup']?>" />
436
				<div class="row">
437
				<h4><?php $lh->translateText("list_info"); ?>
438
				   <br>
439
				   <small><?php $lh->translateText("list_details"); ?></small>
440
				</h4>
441
				<fieldset>
442
					<div class="form-group mt">
443
						<label class="col-sm-3 control-label" for="auto_generate"><?php $lh->translateText("auto_generated"); ?>:</label>
444
						<div class="col-sm-9 mb">
445
							<label class="col-sm-3 checkbox-inline c-checkbox" for="auto_generate">
446
								<input type="checkbox" id="auto_generate" checked>
447
								<span class="fa fa-check"></span>
448
							</label>
449
						</div>
450
					</div>
451
					<div class="form-group">
452
						<label class="col-sm-3 control-label" for="add_list_id"><?php $lh->translateText("list_id"); ?>:</label>
453
						<div class="col-sm-9 mb">
454
							<input type="number" class="form-control" name="add_list_id" id="add_list_id" placeholder="<?php $lh->translateText("list_id"); ?>" value="<?php echo $lists->next_listID;?>" minlength="1" maxlength="8" disabled required/>
455
						</div>
456
					</div>
457
					<div class="form-group">
458
						<label class="col-sm-3 control-label" for="list_name"><?php $lh->translateText("list_name"); ?>:</label>
459
						<div class="col-sm-9 mb">
460
							<input type="text" class="form-control" name="list_name" id="list_name" placeholder="<?php $lh->translateText("list_name"); ?>" value="<?php echo $next_listname;?>" maxlength="30" required/>
461
						</div>
462
					</div>
463
					<div class="form-group">
464
						<label class="col-sm-3 control-label" for="list_desc"><?php $lh->translateText("list_description"); ?>:</label>
465
						<div class="col-sm-9 mb">
466
							<input type="text" class="form-control" name="list_desc" id="list_desc" placeholder="<?php $lh->translateText("list_description"); ?>"  value="<?php echo $next_listdesc;?>" maxlength="255" />
467
						</div>
468
					</div>
469
					<div class="form-group">
470
						<label class="col-sm-3 control-label" for="campaign_select"><?php $lh->translateText("campaign"); ?>: </label>
471
						<div class="col-sm-9 mb">
472
							<select name="campaign_select" class="form-control">
473
								<?php
474
								echo '<option value="">'.$lh->translationFor("-none-").'</option>';
475
									for($i=0; $i < count($campaign->campaign_id);$i++){
476
										echo "<option value='".$campaign->campaign_id[$i]."'> ".$campaign->campaign_name[$i]." </option>";
477
									}
478
								?>
479
							</select>
480
						</div>
481
					</div>
482
					<div class="form-group">
483
						<label class="col-sm-3 control-label" for="status"><?php $lh->translateText("active"); ?>: </label>
484
						<div class="col-sm-9 mb">
485
							<select name="status" class="form-control">
486
								<option value="Y" selected><?php $lh->translateText("go_yes"); ?></option>
487
								<option value="N" ><?php $lh->translateText("go_no"); ?></option>
488
							</select>
489
						</div>
490
					</div>
491
				</fieldset>
492
				</div>
493
				</form>
494

    
495
				</div> <!-- end of modal body -->
496
			</div>
497
		</div>
498
	</div><!-- end of modal -->
499

    
500
	<div id="modal_custom_field_copy" class="modal fade" role="dialog">
501
		<div class="modal-dialog" role="document">
502
			<div class="modal-content">
503
				<div class="modal-header">
504
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
505
					<h4 class="modal-title"><?php $lh->translateText("copy_custom_wizard"); ?></h4>
506
				</div>
507
				<div class="modal-body">
508
					<form id="copy_cf_form" class="form-horizontal" style="margin-top: 10px;">
509
						<input type="hidden" name="log_user" value="<?=$_SESSION['user']?>" />
510
						<input type="hidden" name="log_group" value="<?=$_SESSION['usergroup']?>" />
511
						<div class="form-group">
512
							<label class="control-label col-lg-4"><?php $lh->translateText("copy_from_list_id"); ?>:</label>
513
							<div class="col-lg-8">
514
								<input type="hidden" class="form-control list-from" value="" name="list_from">
515
								<input type="text" class="form-control list-from-label" value="" readonly>
516
							</div>
517
						</div>
518
						<div class="form-group">
519
							<label class="control-label col-lg-4"><?php $lh->translateText("copy_to_list_id"); ?>:</label>
520
							<div class="col-lg-8">
521
								<select class="form-control select2" name="list_to">
522
									<?php for($i=0;$i < count($lists->list_id);$i++){ ?>
523
										<option value="<?php echo $lists->list_id[$i]; ?>"><?php echo $lists->list_id[$i].' - '.$lists->list_name[$i];?></option>
524
									<?php } ?>
525
								</select>
526
							</div>
527
						</div>
528
						<div class="form-group">
529
							<label class="control-label col-lg-4"><?php $lh->translateText("copy_option"); ?>:</label>
530
							<div class="col-lg-8">
531
								<select class="form-control select2" name="copy_option">
532
									<option value="APPEND"><?php $lh->translateText("append"); ?></option>
533
									<option value="UPDATE"><?php $lh->translateText("UPDATE"); ?></option>
534
									<option value="REPLACE"><?php $lh->translateText("replace"); ?></option>
535
								</select>
536
							</div>
537
						</div>
538
					</form>
539
				</div>
540
				<div class="modal-footer">
541
					<button type="button" class="btn btn-default" data-dismiss="modal"><?php $lh->translateText("close"); ?></button>
542
					<button type="button" class="btn btn-success btn-copy-cf" data-dismiss="modal"><?php $lh->translateText("copy"); ?></button>
543
				</div>
544
			</div><!-- /.modal-content -->
545
		</div><!-- /.modal-dialog -->
546
	</div><!-- /.modal -->
547
	<!-- End of modal -->
548
	
549
	<!-- Modal -->
550
	<div id="dnc-modal" class="modal fade" role="dialog">
551
	  <div class="modal-dialog">
552
	    <!-- Modal content-->
553
	    <div class="modal-content">
554
	      <div class="modal-header">
555
	        <button type="button" class="close" data-dismiss="modal">&times;</button>
556
	        <h4 class="modal-title"><b><?php $lh->translateText("add_delete_dnc"); ?></b></h4>
557
	      </div>
558
	      <div class="modal-body">
559
			<form id="dnc_form">
560
				<input type="hidden" name="session_user" value="<?php echo $_SESSION['user'];?>">
561
				<div class="form-group mt">
562
					<label class="col-md-3 control-label"><?php $lh->translateText("list"); ?>:</label>
563
					<div class="col-md-9 mb">
564
						<select id="campaign_id" class="form-control select2" name="campaign_id" required>
565
							<option value="INTERNAL"><?php $lh->translateText("internal_dnc"); ?></option>
566
							<?php
567
								for($i=0;$i<count($campaign->campaign_id);$i++){
568
									echo '<option value="'.$campaign->campaign_id[$i].'">'.$campaign->campaign_id[$i].' - '.$campaign->campaign_name[$i].'</option>';
569
								}
570
							?>
571
						</select>
572
					</div>
573
				</div>
574
				<div class="form-group mt">
575
					<label class="col-md-3 control-label"><?php $lh->translateText("phone_number"); ?>:</label>
576
					<div class="col-md-9 mb">
577
						<textarea rows="15" cols="17" name="phone_numbers" id="phone_numbers" style="resize:none"></textarea><br/>
578
						<small class="text-danger"><?php $lh->translateText("limit25_per_submit"); ?></small>
579
					</div>
580
				</div>
581
				<div class="form-group mt">
582
					<label class="col-md-3 control-label"><?php $lh->translateText("add_delete_dnc"); ?>:</label>
583
					<div class="col-md-4">
584
						<select id="stageDNC" class="form-control" name="stageDNC" required>
585
							<option value="ADD"><?php $lh->translateText("ADD"); ?> DNC LIST</option>
586
							<option value="DELETE"><?php $lh->translateText("DELETE"); ?> DNC LIST</option>
587
						</select>
588
					</div>
589
				</div>
590
			</form>
591
	      </div>
592
		  
593
	      <div class="modal-footer">
594
			<button type="button" class="btn btn-primary" id="submit_dnc"><?php $lh->translateText("submit"); ?></button>
595
	        <button type="button" class="btn btn-default" data-dismiss="modal"><?php $lh->translateText("close"); ?></button>
596
	      </div>
597
	    </div>
598
	    <!-- End of modal content -->
599
	  </div>
600
	</div>
601
	
602
	<?php print $ui->standardizedThemeJS();?>
603
	<!-- JQUERY STEPS-->
604
	<script src="js/dashboard/js/jquery.steps/build/jquery.steps.js"></script>
605
		
606
	<script type="text/javascript">
607
		$(document).ready(function() {
608
			var list_create = <?php echo ($perm->list->list_create !== "N" ? 1 : 0 ) ?>;
609
			var list_read 	= <?php echo ($perm->list->list_create !== "N" ? 1 : 0 ) ?>;
610
			var list_update = <?php echo ($perm->list->list_create !== "N" ? 1 : 0 ) ?>;			
611
			var list_delete = <?php echo ($perm->list->list_delete !== "N" ? 1 : 0 ) ?>;
612
			var list_upload = <?php echo ($perm->list->list_upload !== "N" ? 1 : 0 ) ?>;
613

    
614
			if (list_create != 1) {
615
				$("#list_fab").attr("disabled", true);
616
				$("#list_fab").attr("hidden", true);
617
			} else {
618
				$("#list_fab").attr("disabled", false);
619
				$("#list_fab").attr("hidden", false);			
620
			}
621
			if (list_upload != 1) {
622
				//console.log(list_upload);
623
				$("#list_sidebar").find("select, textarea, input, .browse-btn").each(function() {
624
					//console.log($(this).attr('name'));
625
					$(this).attr("disabled", true);
626
				});
627
			} else {
628
				//console.log(list_upload);
629
				$("#list_sidebar").find("select, textarea, input, .browse-btn").each(function() {
630
					//console.log($(this).attr('name'));
631
					$(this).attr("disabled", false);
632
				});			
633
			}
634

    
635
				
636
			// on tab change, change sidebar
637
			$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
638
				var target = $(e.target).attr("href"); // activated tab
639
				
640
				if(target == "#list_tab"){
641
					$("#list_sidebar").show();
642
					$("#list_fab").show();
643
					$("#dnc_sidebar").hide();
644
					$("#dnc_fab").hide();
645
					$("#legend_title").text("Lists");
646
				}
647
				if(target == "#dnc_tab"){
648
					$("#dnc_sidebar").show();
649
					$("#dnc_fab").show();
650
					$("#list_sidebar").hide();
651
					$("#list_fab").hide();
652
					$("#legend_title").text("DNC");
653
				}
654
			});
655
			
656
			$('body').on('keypress', '#search_dnc', function(args) {
657
				if (args.keyCode == 13) {
658
					$("#dnc_search_button").click();
659
					return false;
660
				}
661
			});
662
			
663
			// initialize datatable
664
			$('#table_lists').DataTable({
665
				destroy: true,
666
				responsive: true,
667
				select: true,
668
				stateSave: true,
669
				drawCallback:function(settings) {
670
					var pagination = $(this).closest('.dataTables_wrapper').find('.dataTables_paginate');
671
					pagination.toggle(this.api().page.info().pages > 1);
672
				},
673
				columnDefs:[
674
					<?php if($perm->list->list_delete !== 'N'){?>
675
						{ width: "8%", targets: 7 },
676
						{ width: "5%", targets: 6 },
677
						{ width: "5%", targets: 0 },						
678
						{ searchable: false, targets: [ 6, 7 ] },
679
						{ sortable: false, targets: [ 6, 7 ] },
680
					<?php }else{ ?>
681
						{ width: "10%", targets: 6 },
682
						{ width: "5%", targets: 0 },					
683
						{ searchable: false, targets: 6 },
684
						{ sortable: false, targets: 6 },
685
					<?php } ?>
686
					{ targets: -1, className: "dt-body-right" }
687
				]
688
			});
689
			
690
			$('#table_dnc').DataTable({
691
				destroy: true,
692
				responsive: true,
693
				drawCallback:function(settings) {
694
					var pagination = $(this).closest('.dataTables_wrapper').find('.dataTables_paginate');
695
					pagination.toggle(this.api().page.info().pages > 1);
696
				},
697
				columnDefs:[
698
					{ searchable: false, targets: 2 },
699
					{ sortable: false, targets: 2 },
700
					{ targets: -1, className: "dt-body-right" }
701
				]									
702
			});			
703
				
704
			// add list
705
			if (list_create == 1) {
706
				//console.log(list_create);
707
				var form = $("#create_form"); // init form wizard
708

    
709
				form.validate({
710
					errorPlacement: function errorPlacement(error, element) { element.after(error); }
711
				});
712
				
713
				form.children("div").steps({
714
					headerTag: "h4",
715
					bodyTag: "fieldset",
716
					transitionEffect: "slideLeft",
717
					onStepChanging: function (event, currentIndex, newIndex)
718
					{
719
						// Allways allow step back to the previous step even if the current step is not valid!
720
						if (currentIndex > newIndex) {
721
							return true;
722
						}
723
	
724
						// Clean up if user went backward before
725
						if (currentIndex < newIndex)
726
						{
727
							// To remove error styles
728
							$(".body:eq(" + newIndex + ") label.error", form).remove();
729
							$(".body:eq(" + newIndex + ") .error", form).removeClass("error");
730
						}
731
	
732
						form.validate().settings.ignore = "";
733
						return form.valid();
734
					},
735
					onFinishing: function (){
736
						form.validate().settings.ignore = "";
737
						return form.valid();
738
					},
739
					onFinished: function (){
740
						$('#finish').text("<?php $lh->translateText("loading"); ?>");
741
						$('#finish').attr("disabled", true);
742
						$('#add_list_id').attr("disabled", false);
743
						// Submit form via ajax
744
						$.ajax({
745
							url: "./php/AddList.php",
746
							type: 'POST',
747
							data: $('#create_form').serialize(),
748
							success: function(data) {
749
								console.log(data);
750
								$('#finish').text("<?php $lh->translateText("submit"); ?>");
751
								$('#finish').attr("disabled", false);
752
								if (data == 1) {
753
									swal({title: "<?php $lh->translateText("add_list_success"); ?>",text: "<?php $lh->translateText("add_list_success"); ?>",type: "success"},function(){window.location.href = 'telephonylist.php';});
754
								} else {
755
									sweetAlert("<?php $lh->translateText("oups"); ?>", "<?php $lh->translateText("something_went_wrong"); ?>", "error");
756
								}
757
							}
758
						});
759
					}
760
				});
761
			}
762

    
763
			// edit
764
			if (list_update == 1) {
765
				$(document).on('click','.edit-list',function() {
766
					var url = './edittelephonylist.php';
767
					var id = $(this).attr('data-id');
768
					//alert(extenid);
769
					var form = $('<form action="' + url + '" method="post"><input type="hidden" name="modifyid" value="'+id+'" /></form>');
770
					$('body').append(form);  // This line is not necessary
771
					
772
					$(form).submit();
773
				});
774
			}
775
				
776
			if (list_read == 1) {
777
				$(document).on('click','.download-list',function() {
778
					var url = 'php/ExportList.php';
779
					var id = $(this).attr('data-id');
780
					console.log(id);
781
					var form = $('<form action="' + url + '" method="post"><input type="hidden" name="listid" value="'+id+'" /></form>');
782
					$('body').append(form);  // This line is not necessary
783
					$(form).submit();
784
				});
785
			}
786

    
787
			// delete
788
			if (list_delete == 1) {
789
				console.log(list_delete);
790
				$(document).on('click','.delete-list',function() {
791
					var listid = [];
792
					listid.push($(this).attr('data-id'));
793
					console.log(listid);
794
					swal({
795
						title: "<?php $lh->translateText("are_you_sure"); ?>?",
796
						text: "<?php $lh->translateText("action_cannot_be_undone"); ?>.",
797
						type: "warning",
798
						showCancelButton: true,
799
						confirmButtonColor: "#DD6B55",
800
						confirmButtonText: "<?php $lh->translateText("confirm_list_delete"); ?>!",
801
						cancelButtonText: "<?php $lh->translateText("cancel_please"); ?>!",
802
						closeOnConfirm: false,
803
						closeOnCancel: false
804
						},
805
						function(isConfirm){
806
							if (isConfirm) {
807
								$.ajax({
808
									url: "./php/DeleteList.php",
809
									type: 'POST',
810
									data: {
811
										listid: listid
812
									},
813
									success: function(data) {
814
									console.log(data);
815
										if(data == 1){
816
											swal({title: "<?php $lh->translateText("delete_list_success"); ?>",text: "<?php $lh->translateText("delete_list_success_msg"); ?>",type: "success"},function(){window.location.href = 'telephonylist.php';});
817
										}else{
818
											sweetAlert("<?php $lh->translateText("oups"); ?>", "<?php $lh->translateText("something_went_wrong"); ?>!", "error");
819
										}
820
									}
821
								});
822

    
823
							} else {
824
								swal("<?php $lh->translateText("cancelled"); ?>", "<?php $lh->translateText("cancel_msg"); ?>", "error");
825
							}
826
						}
827
					);
828
				});
829
				
830
				$(document).on('click','.delete-multiple-list',function() {
831
				var arr = $('input:checkbox.check_list').filter(':checked').map(function () {
832
					return this.id;
833
				}).get();
834
				console.log(arr);
835
				swal({
836
						title: "<?php $lh->translateText("are_you_sure"); ?>",
837
						text: "<?php $lh->translateText("action_cannot_be_undone"); ?>.",
838
						type: "warning",
839
						showCancelButton: true,
840
						confirmButtonColor: "#DD6B55",
841
						confirmButtonText: "<?php $lh->translateText("delete_multiple_list"); ?>!",
842
						cancelButtonText: "<?php $lh->translateText("cancel_please"); ?>!",
843
						closeOnConfirm: false,
844
						closeOnCancel: false
845
					},
846
						function(isConfirm){
847
							if (isConfirm) {
848
								$.ajax({
849
									url: "./php/DeleteList.php",
850
									type: 'POST',
851
									data: {
852
										listid: arr
853
									},
854
									success: function(data) {
855
									console.log(data);
856
										if(data == 1){
857
											swal({title: "<?php $lh->translateText("delete_list_success"); ?>",text: "<?php $lh->translateText("delete_list_success_msg"); ?>!",type: "success"},function(){window.location.href = 'telephonylist.php';});
858
										}else{
859
											sweetAlert("<?php $lh->translateText("oups"); ?>", "<?php $lh->translateText("something_went_wrong"); ?>! "+data, "error");
860
										}
861
									}
862
								});
863
							} else {
864
									swal("Cancelled", "<?php $lh->translateText("cancel_msg"); ?>", "error");
865
							}
866
						}
867
					);
868
				});
869
			}
870
					
871
			if (list_read == 1) {
872
				$(document).on('click', '.copy-custom-fields', function(){
873
					var list_id = $(this).data('id');
874
					var list_name = $(this).data('name');
875

    
876
					$('.list-from').val(list_id);
877
					$('.list-from-label').val(list_id + ' - ' + list_name);
878
					$('#modal_custom_field_copy').modal('show');
879
				});
880

    
881
				$(document).on('click', '.btn-copy-cf', function(){
882
					var form_data = new FormData($("#copy_cf_form")[0]);
883
					swal({
884
						title: "<?php $lh->translateText("are_you_sure"); ?>",
885
						text: "<?php $lh->translateText("action_cannot_be_undone"); ?>.",
886
						type: "warning",
887
						showCancelButton: true,
888
						confirmButtonColor: "#DD6B55",
889
						confirmButtonText: "<?php $lh->translateText("yes_copy_custom_fields"); ?>",
890
						cancelButtonText: "<?php $lh->translateText("cancel_please"); ?>",
891
						closeOnConfirm: false,
892
						closeOnCancel: false
893
						},
894
						function(isConfirm){
895
							if (isConfirm) {
896
								$.ajax({
897
									url: "./php/CopyCustomFields.php",
898
									type: 'POST',
899
									data: form_data,
900
									// dataType: 'json',
901
									cache: false,
902
									contentType: false,
903
									processData: false,
904
									success: function(data) {
905
										// console.log(data);
906
										if(data == "success"){
907
											swal({
908
													title: "<?php $lh->translateText("success"); ?>",
909
													text: "<?php $lh->translateText("custom_fields_copied"); ?>",
910
													type: "success"
911
												},
912
												function(){
913
													location.reload();
914
													$(".preloader").fadeIn();
915
												}
916
											);
917
										}else{
918
												sweetAlert("<?php $lh->translateText("oups"); ?>", "<?php $lh->translateText("something_went_wrong"); ?>! "+ data, "error");
919
										}
920
									}
921
								});
922
							} else {
923
							swal("<?php $lh->translateText("cancelled"); ?>", "<?php $lh->translateText("cancel_msg"); ?>", "error");
924
							}
925
						}
926
					);
927
				});
928
			}
929
					
930
			$(document).on('click', '#auto_generate', function(){
931
			// alert( this.value ); // or $(this).val()
932
				if($('#auto_generate').is(":checked")){
933
					$('#add_list_id').val("<?php echo $next_list;?>");
934
					$('#list_name').val("<?php echo $next_listname;?>");
935
					$('#list_desc').val("<?php echo $next_listdesc;?>");
936
					$('#add_list_id').prop("disabled", true);
937
				}
938
				if(!$('#auto_generate').is(":checked")){
939
					$('#add_list_id').val("");
940
					$('#list_name').val("");
941
					$('#list_desc').val("");
942
					$('#add_list_id').prop("disabled", false);
943
				}
944
			});
945

    
946
			//initialize single selecting
947
			$('#select2-1').select2({ theme: 'bootstrap' });
948
			$.fn.select2.defaults.set( "theme", "bootstrap" );
949

    
950

    
951
			$('.browse-btn').click(function(){
952
				$('.file-box').click();
953
			});
954

    
955
			$('.file-box').change(function(){
956
				var myFile = $(this).prop('files');
957
				var Filename = myFile[0].name;
958

    
959
				$('.file-name').val(Filename);
960
				console.log($(this).val());
961
			});
962

    
963
			// DNC Search
964
			if (list_read == 1) {
965
				$(document).on('click','#dnc_search_button',function() {
966
				//init_contacts_table.destroy();
967
					if ($('#search_dnc').val() != "") {
968
						$('#dnc_search_button').text("<?php $lh->translateText("searching"); ?>");
969
						$('#dnc_search_button').attr("disabled", true);
970
					} else {
971
						$('#dnc_search_button').text("<?php $lh->translateText("search"); ?>");
972
						$('#dnc_search_button').attr("disabled", false);
973
					}
974
					
975
					$.ajax({
976
						url: "search_dnc.php",
977
						type: 'POST',
978
						data: {
979
							search_dnc : $('#search_dnc').val()
980
						},
981
						success: function(data) {
982
							$('#dnc_search_button').text("<?php $lh->translateText("search"); ?>");
983
							$('#dnc_search_button').attr("disabled", false);
984
							//console.log(data);
985
							if (data != "") {
986
								$('#table_dnc').html(data);
987
								$('#table_dnc').DataTable({
988
									destroy: true,
989
									responsive: true,
990
									drawCallback:function(settings) {
991
										var pagination = $(this).closest('.dataTables_wrapper').find('.dataTables_paginate');
992
										pagination.toggle(this.api().page.info().pages > 1);
993
									},
994
									columnDefs:[
995
										//{ width: "16%", targets: 7 },
996
										{ searchable: false, targets: 2 },
997
										{ sortable: false, targets: 2 },
998
										{ targets: -1, className: "dt-body-right" }
999
									]									
1000
								});
1001
								$('#dnc_error').html("");
1002
							} else {
1003
								$('#dnc_error').text("<?php $lh->translateText("no_results"); ?>");
1004
							}
1005
						}
1006
					});
1007
				});
1008
			
1009
				// DNC Submit
1010
				$(document).on('click','#submit_dnc',function() {
1011
					$('#submit_dnc').text("<?php $lh->translateText("submitting"); ?>");
1012
					$('#submit_dnc').attr("disabled", true);
1013
					var stageDNC = $('#stageDNC option:selected').val();
1014
					console.log(stageDNC);
1015
					if ($('#phone_numbers').val() !== ''){
1016
						$.ajax({
1017
							url: "php/ActionDNC.php",
1018
							type: 'POST',
1019
							data: $('#dnc_form').serialize(),
1020
							//type: 'json',
1021
							success: function(data) {
1022
								console.log(data);
1023
								$('#submit_dnc').text("<?php $lh->translateText("add_delete_dnc"); ?>");
1024
								$('#submit_dnc').attr("disabled", false);										
1025
								
1026
								if (data == 1) {
1027
									if (stageDNC == "ADD") {
1028
										swal({title: "<?php $lh->translateText("added_new"); ?> DNC", text: "<?php $lh->translateText("add_dnc"); ?>", type: "success"},function(){window.location.href = 'telephonylist.php?dnc_tab';});
1029
									}
1030
									if (stageDNC == "DELETE") {
1031
										swal({title: "<?php $lh->translateText("deleted"); ?> DNC", text: "<?php $lh->translateText("delete_dnc"); ?>", type: "success"},function(){window.location.href = 'telephonylist.php?dnc_tab';});
1032
									}								
1033
								} else {
1034
									if (data == 10116) {
1035
										sweetAlert("<?php echo $lh->translateText("oups"); ?>", "<?php echo $lh->translateText("dnc_already_exist"); ?>", "error");
1036
									}		
1037
									if (data == 10117) {
1038
										sweetAlert("<?php echo $lh->translateText("oups"); ?>", "<?php echo $lh->translateText("dnc_do_not_exist"); ?>", "error");
1039
									}									
1040
								}
1041
								
1042
							}
1043
						});
1044
					} else {
1045
						$('#submit_dnc').text("<?php $lh->translateText("submit"); ?>");
1046
						$('#submit_dnc').attr("disabled", false);
1047
						swal("<?php $lh->translateText("dnc_incomplete"); ?>", "<?php $lh->translateText("dnc_incomplete_msg"); ?>", "error");
1048
					}
1049
					
1050
				});
1051
			}
1052
				
1053
			// Delete DNC
1054
			if (list_delete == 1) {				
1055
				$(document).on('click','.delete-dnc',function() {
1056
					var phone_number = $(this).data('id');
1057
					var campaign = $(this).data('campaign');
1058
					
1059
					$.ajax({
1060
						url: "php/ActionDNC.php",
1061
						type: 'POST',
1062
						data: {
1063
							phone_numbers : phone_number,
1064
							campaign_id : campaign,
1065
							stageDNC : "DELETE"
1066
						},
1067
						//type: 'json',
1068
						success: function(data) {
1069
							console.log(data);
1070
							
1071
							if (data == 1) {
1072
								swal({title: "<?php $lh->translateText("deleted"); ?> DNC", text: "<?php $lh->translateText("delete_dnc"); ?>", type: "success"},function(){window.location.href = 'telephonylist.php?dnc_tab';});								
1073
								$("#dnc_sidebar").show();
1074
								$("#dnc_fab").show();
1075
								$("#list_sidebar").hide();
1076
								$("#list_fab").hide();
1077
								$("#legend_title").text("DNC");								
1078
							} else {
1079
								if (data == 10116) {
1080
									sweetAlert("<?php echo $lh->translateText("oups"); ?>", "<?php echo $lh->translateText("dnc_already_exist"); ?>", "error");
1081
								}		
1082
								if (data == 10117) {
1083
									sweetAlert("<?php echo $lh->translateText("oups"); ?>", "<?php echo $lh->translateText("dnc_do_not_exist"); ?>", "error");
1084
								}									
1085
							}
1086
						}
1087
					});
1088
				});
1089
			}
1090
			
1091
			$('#phone_numbers').keypress(function(event){
1092
				if((event.ctrlKey === false && ((event.which < 48 || event.which > 57) && event.which !== 13 && event.which !== 8)) && (event.keyCode !== 9 && event.keyCode !== 46 && (event.keyCode < 37 || event.keyCode > 40)))
1093
				return false;
1094
			});
1095
			
1096
			var lines = 25;
1097
			
1098
			$('#phone_numbers').keydown(function(e) {
1099
				newLines = $(this).val().split("\n").length;
1100
			
1101
				if(e.keyCode == 13 && newLines >= lines) {
1102
					return false;
1103
				}
1104
			});
1105

    
1106
			$('#phone_numbers').blur(function() {
1107
				this.value = this.value.replace('/[^0-9\r\n]/g','');
1108
			});
1109
			
1110
			if (window.location.href.indexOf("dnc_tab") > -1) {
1111
				$("#dnc_sidebar").show();
1112
				$("#dnc_fab").show();
1113
				$("#list_sidebar").hide();
1114
				$("#list_fab").hide();
1115
				$("#legend_title").text("DNC");						
1116
			}			
1117
			
1118
			// RESET LEAD MAPPING CONTAINER ON CLOSE
1119
			$('#LeadMappingContainer').on('hidden.bs.modal', function () {
1120
				$('#LeadMapSubmit').val(0);
1121
				$('#lead_map_data').html("");
1122
				$('#lead_map_fields').html("");
1123
			});			
1124
	
1125
		});
1126
		
1127
		// Progress bar function
1128
		function goProgressBar() {
1129
			
1130
			var formData = new FormData($('#upload_form')[0]);
1131
			var progress_bar_id 		= '#progress-wrp'; //ID of an element for response output
1132
			var percent = 0;
1133
			
1134
			var result_output 			= '#output'; //ID of an element for response output
1135
			var my_form_id 				= '#upload_form'; //ID of an element for response output
1136
			var submit_btn  = $(this).find("input[type=button]"); //btnUpload
1137

    
1138
			formData.append('tax_file', $('input[type=file]')[0].files);
1139
			
1140
			$.ajax({
1141
				url : "./php/AddLoadLeads.php",
1142
				type: "POST",
1143
				data : formData,
1144
				contentType: false,
1145
				cache: false,
1146
				processData:false,
1147
				maxChunkSize: 1000000000,
1148
				maxRetries: 100000000,
1149
				retryTimeout: 5000000000,
1150
				timeout: 0,
1151
				xhr: function(){
1152
					//upload Progress
1153
					var xhr = $.ajaxSettings.xhr();
1154
					if (xhr.upload) {
1155
						xhr.upload.addEventListener('progress', function(event) {
1156
							
1157
							var position = event.loaded || event.position;
1158
							var total = event.total;
1159
							if (event.lengthComputable) {
1160
								percent = Math.ceil(position / total * 100);
1161
							}
1162
							
1163
							//update progressbar
1164
							$(progress_bar_id +" .progress-bar").css("width", + percent +"%");
1165
							$(progress_bar_id + " .status").text(percent +"%");
1166
							//$(progress_bar_id + " .status").innerHTML = percent + '%';
1167
							
1168
							if(percent === 100) {
1169
								
1170
								//$('#dStatus').css("display", "block");
1171
								//$('#dStatus').css("color", "#4CAF50");
1172
								//$('#qstatus').text("File Uploaded Successfully. Please wait for the TOTAL of leads uploaded.(Do not refresh the page)");
1173
								//$('#qstatus').text("Data Processing. Please Wait.");
1174
								//sweetAlert("Oops...", "Something went wrong!", "error");
1175
								
1176
								//var uploadMsgTotal = "Total Leads Uploaded: "+res;
1177
				
1178
								swal({
1179
									title: "<?php $lh->translateText('csv_upload_complete'); ?>",
1180
									text: "<?php $lh->translateText('data_processing'); ?>",
1181
									type: "info",
1182
									showCancelButton: false,
1183
									closeOnConfirm: false
1184
								});
1185
								
1186
							}
1187
							
1188
						}, true);
1189
						
1190
					}
1191
					return xhr;
1192
				},
1193
				mimeType:"multipart/form-data",
1194
				statusCode: {
1195
					503: function(responseObject, textStatus, errorThrown) {
1196
				            // Service Unavailable (503)
1197
				            // This code will be executed if the server returns a 503 response
1198
					    //alert(responseObject + textStatus);
1199
					    //$.ajax(this);
1200
					    upload_timeout(JSON.stringify(textStatus));
1201
					    return;
1202
				        }
1203
				}
1204
			}).done(function(res){
1205
				//console.log(res);
1206
				var data = jQuery.parseJSON(res);
1207
				
1208
					<?php
1209
						//if(LEADUPLOAD_LEAD_MAPPING === "y"){ // IF LEAD MAPPING IS ENABLED
1210
					?>
1211
						if($('#LeadMapSubmit').val() === "0" && $('#LeadMapSubmit').is(':checked')){
1212
							lead_mapping(res);
1213
						} else {
1214
							upload_alert(data.result, data.msg);						
1215
						}
1216
					<?php
1217
						/*}else{
1218
					?>
1219
						upload_success(uploadMsgTotal);
1220
					<?php
1221
						}*/
1222
					?>	
1223
			});								
1224
		}//function end
1225
		
1226
		function upload_alert(res, msg){
1227
		 if(res === "success")
1228
			var uploadMsgTotal = msg;
1229
		 else
1230
			var uploadMsgTotal = msg;
1231
		 swal({
1232
                      title: "<?php $lh->translateText('data_processing_complete'); ?>",
1233
                      text: uploadMsgTotal,
1234
                      type: res
1235
                      },
1236
                      function(){
1237
                      location.reload();
1238
                      $(".preloader").fadeIn();
1239
                    }
1240
                 );
1241
		}
1242

    
1243
		function upload_timeout(uploadMsg){
1244
                                swal({
1245
                      title: "<?php $lh->translateText('Request Timeout'); ?>",
1246
                      text: uploadMsg,
1247
                      type: "error"
1248
                    }
1249
                 );
1250
                }
1251

    
1252
		function lead_mapping(res){
1253
			var obj = JSON.parse(res);
1254
			var data = obj.data;
1255
			var sf = obj.standard_fields;
1256
			var cf = obj.custom_fields;
1257
			//console.log( obj );
1258
			if(cf[0] !== "")
1259
				var all = sf.concat(cf);
1260
			else
1261
				var all = sf;
1262
			var i;
1263
			console.log(cf[0]);	
1264
			console.log(all.length);	
1265
			for(i = 0; i < all.length;i++){
1266
				$('#lead_map_data').append('<div class="form-group"><label>'+all[i]+'</label><span id="span_'+all[i]+'"></span></span></div>');
1267
				$('<input>').attr({type: 'hidden',name: 'map_fields[]', value: all[i]}).appendTo('#lead_map_fields');
1268
				var sel = $('<select name="map_data[]" class="form-control select2">').appendTo('#span_'+all[i]);
1269
				sel.append($("<option>").attr('value',".").text("NONE"));
1270
				for(x=0; x < data.length;x++){
1271
					//if(data[i] === data[x])
1272
					//sel.append($("<option>").attr('value',x).text(data[x]).prop('selected', true));
1273
					//else
1274
					sel.append($("<option>").attr('value',x).text(data[x]));
1275
				}
1276
			}
1277
			$('#LeadMapSubmit').val("1");
1278
			swal.close();
1279
			$('#LeadMappingContainer').modal('show');
1280
		}
1281
			
1282
	</script>
1283
	<?php print $ui->creamyFooter();?>
1284
    </body>
1285
</html>
(1-1/3) Go to top