| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) |
| 3 |
exit; |
| 4 |
|
| 5 |
global $wpdb; |
| 6 |
$_GET = stripslashes_deep($_GET); |
| 7 |
$xyz_ips_message =$search_name_db=$search_name= ''; |
| 8 |
|
| 9 |
if(isset($_GET['xyz_ips_msg'])){ |
| 10 |
$xyz_ips_message = intval($_GET['xyz_ips_msg']); |
| 11 |
} |
| 12 |
if($_POST) |
| 13 |
{ |
| 14 |
if(isset($_POST['search'])) |
| 15 |
{ |
| 16 |
if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'snipp-manage_') ){ |
| 17 |
wp_nonce_ays( 'snipp-manage_' ); |
| 18 |
exit; |
| 19 |
} |
| 20 |
} |
| 21 |
if(isset($_POST['textFieldButton2'])) |
| 22 |
{ |
| 23 |
if(!isset($_REQUEST['_wpnonce'])||!wp_verify_nonce($_REQUEST['_wpnonce'],'bulk_actions_ips') ){ |
| 24 |
wp_nonce_ays( 'bulk_actions_ips' ); |
| 25 |
exit; |
| 26 |
} |
| 27 |
} |
| 28 |
if (isset($_POST['apply_ips_bulk_actions'])){ |
| 29 |
if (isset($_POST['ips_bulk_actions_snippet'])){ |
| 30 |
$ips_bulk_actions_snippet=$_POST['ips_bulk_actions_snippet']; |
| 31 |
if (isset($_POST['xyz_ips_snippet_ids'])) |
| 32 |
$xyz_ips_snippet_ids = $_POST['xyz_ips_snippet_ids']; |
| 33 |
$xyz_ips_pageno = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1; |
| 34 |
if (empty($xyz_ips_snippet_ids)) |
| 35 |
{ |
| 36 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=8&pagenum='.$xyz_ips_pageno)); |
| 37 |
exit(); |
| 38 |
} |
| 39 |
if ($ips_bulk_actions_snippet==2)//bulk-delete |
| 40 |
{ |
| 41 |
foreach ($xyz_ips_snippet_ids as $snippet_id) |
| 42 |
{ |
| 43 |
$wpdb->query($wpdb->prepare( 'DELETE FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE id=%d',$snippet_id)) ; |
| 44 |
} |
| 45 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=3&pagenum='.$xyz_ips_pageno)); |
| 46 |
exit(); |
| 47 |
} |
| 48 |
elseif ($ips_bulk_actions_snippet==0)//bulk-Deactivate |
| 49 |
{ |
| 50 |
foreach ($xyz_ips_snippet_ids as $xyz_ips_snippetId) |
| 51 |
$wpdb->update($wpdb->prefix.'xyz_ips_short_code', array('status'=>2), array('id'=>$xyz_ips_snippetId)); |
| 52 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=4&pagenum='.$xyz_ips_pageno)); |
| 53 |
exit(); |
| 54 |
} |
| 55 |
elseif ($ips_bulk_actions_snippet==1)//bulk-activate |
| 56 |
{ |
| 57 |
foreach ($xyz_ips_snippet_ids as $xyz_ips_snippetId) |
| 58 |
$wpdb->update($wpdb->prefix.'xyz_ips_short_code', array('status'=>1), array('id'=>$xyz_ips_snippetId)); |
| 59 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=4&pagenum='.$xyz_ips_pageno)); |
| 60 |
exit(); |
| 61 |
} |
| 62 |
elseif ($ips_bulk_actions_snippet==-1)//no action selected |
| 63 |
{ |
| 64 |
header("Location:".admin_url('admin.php?page=insert-php-code-snippet-manage&xyz_ips_msg=7&pagenum='.$xyz_ips_pageno)); |
| 65 |
exit(); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
if($xyz_ips_message == 1){ |
| 73 |
|
| 74 |
?> |
| 75 |
<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> |
| 76 |
PHP Snippet successfully added. <span |
| 77 |
id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 78 |
</div> |
| 79 |
<?php |
| 80 |
|
| 81 |
} |
| 82 |
if($xyz_ips_message == 2){ |
| 83 |
|
| 84 |
?> |
| 85 |
<div class="xyz_system_notice_area_style0" id="xyz_system_notice_area"> |
| 86 |
PHP Snippet not found. <span |
| 87 |
id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 88 |
</div> |
| 89 |
<?php |
| 90 |
|
| 91 |
} |
| 92 |
if($xyz_ips_message == 3){ |
| 93 |
|
| 94 |
?> |
| 95 |
<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> |
| 96 |
PHP Snippet successfully deleted. <span |
| 97 |
id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 98 |
</div> |
| 99 |
<?php |
| 100 |
|
| 101 |
} |
| 102 |
if($xyz_ips_message == 4){ |
| 103 |
|
| 104 |
?> |
| 105 |
<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> |
| 106 |
PHP Snippet status successfully changed. <span |
| 107 |
id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 108 |
</div> |
| 109 |
<?php |
| 110 |
|
| 111 |
} |
| 112 |
if($xyz_ips_message == 5){ |
| 113 |
|
| 114 |
?> |
| 115 |
<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> |
| 116 |
PHP Snippet successfully updated. <span |
| 117 |
id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 118 |
</div> |
| 119 |
<?php |
| 120 |
|
| 121 |
} |
| 122 |
if($xyz_ips_message == 7) |
| 123 |
{ |
| 124 |
?> |
| 125 |
<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> |
| 126 |
Please select an action to apply. |
| 127 |
<span id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 128 |
</div> |
| 129 |
<?php |
| 130 |
} |
| 131 |
if($xyz_ips_message == 8) |
| 132 |
{ |
| 133 |
?> |
| 134 |
<div class="xyz_system_notice_area_style1" id="xyz_system_notice_area"> |
| 135 |
Please select at least one snippet to perform this action. |
| 136 |
<span id="xyz_system_notice_area_dismiss">Dismiss</span> |
| 137 |
</div> |
| 138 |
<?php |
| 139 |
} |
| 140 |
?> |
| 141 |
<div > |
| 142 |
|
| 143 |
|
| 144 |
<form method="post"> |
| 145 |
<?php wp_nonce_field( 'bulk_actions_ips');?> |
| 146 |
<fieldset |
| 147 |
style="width: 99%; border: 1px solid #F7F7F7; padding: 10px 0px;"> |
| 148 |
<legend><h3>PHP Code Snippets</h3></legend> |
| 149 |
<?php |
| 150 |
global $wpdb; |
| 151 |
$pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1; |
| 152 |
$limit = get_option('xyz_ips_limit'); |
| 153 |
$offset = ( $pagenum - 1 ) * $limit; |
| 154 |
|
| 155 |
|
| 156 |
$field=get_option('xyz_ips_sort_field_name'); |
| 157 |
$order=get_option('xyz_ips_sort_order'); |
| 158 |
if(isset($_POST['snippet_name'])) |
| 159 |
{ |
| 160 |
$search_name=sanitize_text_field($_POST['snippet_name']); |
| 161 |
$search_name_db=esc_sql($search_name); |
| 162 |
} |
| 163 |
|
| 164 |
$entries = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE title like '%".$search_name_db."%'"." ORDER BY $field $order LIMIT $offset,$limit" ); |
| 165 |
|
| 166 |
|
| 167 |
?> |
| 168 |
<input id="xyz_ips_submit_ips" |
| 169 |
style="cursor: pointer; margin-bottom:10px; margin-left:8px;" type="button" |
| 170 |
name="textFieldButton2" value="Add New PHP Code Snippet" |
| 171 |
onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-add');?>"'> |
| 172 |
<br> |
| 173 |
<span style="padding-left: 6px;color:#21759B;">With Selected : </span> |
| 174 |
<select name="ips_bulk_actions_snippet" id="ips_bulk_actions_snippet" style="width:130px;height:29px;"> |
| 175 |
<option value="-1">Bulk Actions</option> |
| 176 |
<option value="0">Deactivate</option> |
| 177 |
<option value="1">Activate</option> |
| 178 |
<option value="2">Delete</option> |
| 179 |
</select> |
| 180 |
<input type="submit" title="Apply" name="apply_ips_bulk_actions" value="Apply" style="color:#21759B;cursor:pointer;padding: 5px;background:linear-gradient(to top, #ECECEC, #F9F9F9) repeat scroll 0 0 #F1F1F1;border: 2px solid #DFDFDF;"> |
| 181 |
</form> |
| 182 |
|
| 183 |
|
| 184 |
<form name="manage_snippets" action="" method="post"> |
| 185 |
<?php wp_nonce_field('snipp-manage_');?> |
| 186 |
<div class="xyz_ips_search_div" style="float:right;"> |
| 187 |
<table class="xyz_ips_search_div_table" style="width:100%;"> |
| 188 |
<tr> |
| 189 |
<input type="text" name="snippet_name" value= "<?php if(isset($search_name)){echo esc_attr($search_name);}?>" placeholder="Search" > |
| 190 |
<input type="submit" name="search" value="Go" /> |
| 191 |
</tr> |
| 192 |
</table> |
| 193 |
</div> |
| 194 |
</form> |
| 195 |
|
| 196 |
<table class="widefat" style="width: 99%; margin: 0 auto; border-bottom:none;"> |
| 197 |
<thead> |
| 198 |
<tr> |
| 199 |
<th scope="col" width="3%"><input type="checkbox" id="chkAllSnippets" /></th> |
| 200 |
<th scope="col" >Tracking Name</th> |
| 201 |
<th scope="col" >Snippet Short Code</th> |
| 202 |
<th scope="col" >Status</th> |
| 203 |
<th scope="col" colspan="4" style="text-align: center;">Action</th> |
| 204 |
</tr> |
| 205 |
</thead> |
| 206 |
<tbody> |
| 207 |
<?php |
| 208 |
if( !empty($entries) )//if( count($entries)>0 ) |
| 209 |
{ |
| 210 |
$count=1; |
| 211 |
$class = ''; |
| 212 |
foreach( $entries as $entry ) { |
| 213 |
$class = ( $count % 2 == 0 ) ? ' class="alternate"' : ''; |
| 214 |
$snippetId=intval($entry->id); |
| 215 |
?> |
| 216 |
<tr <?php echo $class; ?>> |
| 217 |
<td style="vertical-align: middle !important;padding-left: 18px;"> |
| 218 |
<input type="checkbox" class="chk" value="<?php echo $snippetId; ?>" name="xyz_ips_snippet_ids[]" id="xyz_ips_snippet_ids" /> |
| 219 |
</td> |
| 220 |
<td id="xyz_ips_vAlign"><?php |
| 221 |
echo esc_html($entry->title); |
| 222 |
?></td> |
| 223 |
<td id="xyz_ips_vAlign"><?php |
| 224 |
if($entry->status == 2){echo 'NA';} |
| 225 |
else |
| 226 |
echo '[xyz-ips snippet="'.esc_html($entry->title).'"]'; |
| 227 |
?></td> |
| 228 |
<td id="xyz_ips_vAlign"> |
| 229 |
<?php |
| 230 |
if($entry->status == 2){ |
| 231 |
echo "Inactive"; |
| 232 |
}elseif ($entry->status == 1){ |
| 233 |
echo "Active"; |
| 234 |
} |
| 235 |
|
| 236 |
?> |
| 237 |
</td> |
| 238 |
<?php |
| 239 |
if($entry->status == 2){ |
| 240 |
$stat1 = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=1&pageno='.$pagenum); |
| 241 |
?> |
| 242 |
<td style="text-align: center;"><a |
| 243 |
href='<?php echo wp_nonce_url($stat1,'ips-pstat_'.$snippetId); ?>'><img |
| 244 |
id="xyz_ips_img" title="Activate" |
| 245 |
src="<?php echo plugins_url('images/activate.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>"> |
| 246 |
</a> |
| 247 |
</td> |
| 248 |
<?php |
| 249 |
}elseif ($entry->status == 1){ |
| 250 |
$stat2 = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-status&snippetId='.$snippetId.'&status=2&pageno='.$pagenum); |
| 251 |
?> |
| 252 |
<td style="text-align: center;"><a |
| 253 |
href='<?php echo wp_nonce_url($stat2,'ips-pstat_'.$snippetId); ?>'><img |
| 254 |
id="xyz_ips_img" title="Deactivate" |
| 255 |
src="<?php echo plugins_url('images/pause.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>"> |
| 256 |
</a> |
| 257 |
</td> |
| 258 |
<?php |
| 259 |
} |
| 260 |
|
| 261 |
?> |
| 262 |
|
| 263 |
<td style="text-align: center;"><a |
| 264 |
href='<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-edit&snippetId='.$snippetId.'&pageno='.$pagenum); ?>'><img |
| 265 |
id="xyz_ips_img" title="Edit Snippet" |
| 266 |
src="<?php echo plugins_url('images/edit.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>"> |
| 267 |
</a> |
| 268 |
</td> |
| 269 |
|
| 270 |
<?php $delurl = admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-delete&snippetId='.$snippetId.'&pageno='.$pagenum);?> |
| 271 |
<td style="text-align: center;" ><a |
| 272 |
href='<?php echo wp_nonce_url($delurl,'ips-pdel_'.$snippetId); ?>' |
| 273 |
onclick="javascript: return confirm('Please click \'OK\' to confirm ');"><img |
| 274 |
id="xyz_ips_img" title="Delete Snippet" |
| 275 |
src="<?php echo plugins_url('images/delete.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>"> |
| 276 |
</a></td> |
| 277 |
|
| 278 |
<?php |
| 279 |
$page_url =xyz_ips_get_link_by_slug('xyz-ics-preview-page'); |
| 280 |
$page_url =add_query_arg( 'preview', 'true', $page_url ); |
| 281 |
$page_url =add_query_arg( 'snippetId', $snippetId, $page_url ); |
| 282 |
$prewurl =esc_url($page_url); |
| 283 |
?> |
| 284 |
<td style="text-align: center;" > |
| 285 |
<a href='<?php echo $prewurl;?>' target="_blank"> |
| 286 |
<img id="xyz_ips_img" title="Preview" src="<?php echo plugins_url('images/preview.png',XYZ_INSERT_PHP_PLUGIN_FILE)?>"> |
| 287 |
</a> |
| 288 |
</td> |
| 289 |
</tr> |
| 290 |
<?php |
| 291 |
$count++; |
| 292 |
} |
| 293 |
} else { ?> |
| 294 |
<tr> |
| 295 |
<td colspan="7" >PHP Code Snippets not found</td> |
| 296 |
</tr> |
| 297 |
<?php } ?> |
| 298 |
</tbody> |
| 299 |
</table> |
| 300 |
|
| 301 |
<input id="xyz_ips_submit_ips" |
| 302 |
style="cursor: pointer; margin-top:10px;margin-left:8px;" type="button" |
| 303 |
name="textFieldButton2" value="Add New PHP Code Snippet" |
| 304 |
onClick='document.location.href="<?php echo admin_url('admin.php?page=insert-php-code-snippet-manage&action=snippet-add');?>"'> |
| 305 |
|
| 306 |
<?php |
| 307 |
$total = $wpdb->get_var( "SELECT COUNT(`id`) FROM ".$wpdb->prefix."xyz_ips_short_code" ); |
| 308 |
$num_of_pages = ceil( $total / $limit ); |
| 309 |
|
| 310 |
$page_links = paginate_links( array( |
| 311 |
'base' => add_query_arg( 'pagenum','%#%'), |
| 312 |
'format' => '', |
| 313 |
'prev_text' => '«', |
| 314 |
'next_text' => '»', |
| 315 |
'total' => $num_of_pages, |
| 316 |
'current' => $pagenum |
| 317 |
) ); |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
if ( $page_links ) { |
| 322 |
echo '<div class="tablenav" style="width:99%"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>'; |
| 323 |
} |
| 324 |
|
| 325 |
?> |
| 326 |
|
| 327 |
</fieldset> |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
</div> |
| 332 |
<script type="text/javascript"> |
| 333 |
jQuery(document).ready(function(){ |
| 334 |
jQuery("#chkAllSnippets").click(function(){ |
| 335 |
jQuery(".chk").prop("checked",jQuery("#chkAllSnippets").prop("checked")); |
| 336 |
}); |
| 337 |
}); |
| 338 |
</script> |
| 339 |
|