View file File name : manage-student-ambassador-program-grocery.php Content :<?php session_start(); include("../include/config.php"); include("../include/simpleimage.php"); include("../include/functions.php"); validate_admin(); // Save Data if($_REQUEST['submitForm']=='yes'){ //Get inputs $title=mysqli_real_escape_string($GLOBALS['conn'],$_POST['title']); $obj->query("update $tbl_setting set student_ambassador_grocery = '$title' where id=1"); $_SESSION['sess_msg']='Data updated successfully'; //stores if($_REQUEST["hdnTmpIDs"] != ''){ $stores_arr = explode (",", $_REQUEST["hdnTmpIDs"]); foreach($stores_arr as $indx) { $popUpID = $_REQUEST["hdnPopUpID-" . $indx]; $order = $_REQUEST["hdnOrderNo-" . $indx]; $sec = $_REQUEST["ddlSec-" . $indx]; $store = $_REQUEST["ddlStore-" . $indx]; if($popUpID == "0") { $obj->query("INSERT INTO tbl_student_ambassador (storeid, productid, display_order,type,status) VALUES ($sec, $store, $order,1,1)"); } else { $obj->query("UPDATE tbl_student_ambassador SET storeid = $sec, productid = $store, display_order = $order,type=1,status=1 WHERE id = $popUpID"); } } } //Delete if($_REQUEST["hdnDelIDs"] != ''){ $obj->query("DELETE FROM tbl_student_ambassador WHERE id IN (" . rtrim($_REQUEST["hdnDelIDs"], ',') . ")"); } } // Get Data $sql=$obj->query("select student_ambassador_grocery from $tbl_setting where id=1"); $result=$obj->fetchNextObject($sql); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo SITE_TITLE; ?></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css/admin.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.7.2.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> <style> .clsTemplate { display: none; } span.select2.select2-container { width: 290px !important; margin-left: 16px; } .clsFP_Stores { padding: 0; margin: 0; padding-left: 15px; display: inline-block; } .clsFP_Stores .clsFP_Store { border: 1px solid #c8c8c8; padding: 7px; background-color: #f3f4f6; } .clsFP_Stores .clsFP_Store:not(:last-child) { margin-bottom: 10px; } .clsFP_Stores .clsFP_Store img { display: inline-table; vertical-align: top; width: 70px; height: 70px; background-size: contain; background-repeat: no-repeat; background-position: center center; } .clsFP_Stores .clsFP_Store .cntrls { margin-left: 5px; display: inline-table; vertical-align: top; } .clsFP_Stores .clsFP_Store .cntrls select:not(:first-child) { margin-left: 5px; } .clsFP_Stores .clsFP_Store .cntrls input[type=file]{ display: block; margin-top: 5px; } .clsFP_Stores .clsFP_Store .cntrls a.clsRemoveBtn { margin-top: 5px; display: inline-block; width:18px; height: 18px; background-image: url(../images/del.png); background-repeat: no-repeat; background-size: contain; background-position: center center; } a.clsAddBtn { background-color: #0971a2; color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; border-radius: 5px; text-decoration: none; outline: none; display: inline-block; padding: 3px 5px; } .ui-state-highlight { height: 86px; border: 1px dashed #e5d262 !important; } </style> <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js" defer></script> </head> <body> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <?php include("header.php") ?> <tr> <td align="right" class="paddRtLt70" valign="top"> <table width="99%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="right" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="middle" class="headingbg bodr text14"> <em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>Admin: Manage Student Ambassador Grocery Tab </td> </tr> <tr> <td height="100" align="left" valign="top" bgcolor="#f3f4f6" class="bodr"> <form name="frm" method="POST" enctype="multipart/form-data" action="" onsubmit="return validate(this)"> <input type="hidden" name="submitForm" value="yes" /> <input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" /> <input type="hidden" name="hdnDelIDs" id="hdnDelIDs" value=""> <input type="hidden" name="hdnDelImgs" id="hdnDelImgs" value=""> <input type="hidden" name="hdnTmpIDs" id="hdnTmpIDs" value=""> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td align="center" colspan="2" class="paddRt14 paddBot11"> <font color="#FF0000"><strong><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']='';?></strong></font></td> </tr> <tr> <td width="18%" align="right" class="paddBot11 paddRt14"> </td> <td width="82%" align="left" class="paddBot11"></td> </tr> <tr> <td align="right" class="paddBot11 paddRt14"><strong>Title:</strong></td> <td align="left" class="paddBot11"><input name="title" type="text" id="title" maxlength="100" style="width: 400px;" value="<?php echo stripslashes($result->student_ambassador_grocery);?>" /></td> </tr> <tr> <td align="right" class="paddBot11 paddRt14" style="vertical-align: top;"><strong>Stores:</td> <td align="left" class="paddBot11"> <p>Drag stores to arrange display order.<p> <ol class="clsFP_Stores"> <?php $stores = $obj->query(" SELECT * FROM tbl_student_ambassador where type=1 order by display_order"); $TmpID = 0; while($store = $obj->fetchNextObject($stores)){ ?> <li class="clsFP_Store" id="store-<?php echo $TmpID ?>"> <input type="hidden" name="hdnOrderNo-<?php echo $TmpID ?>" id="hdnOrderNo-<?php echo $TmpID ?>" value="<?php echo $TmpID ?>" class="order"> <input type="hidden" name="hdnPopUpID-<?php echo $TmpID ?>" id="hdnPopUpID-<?php echo $TmpID ?>" value="<?php echo $store->id ?>" class="id"> <input type="hidden" name="hdnOldImg-<?php echo $TmpID ?>" id="hdnOldImg-<?php echo $TmpID ?>" value="" class="old"> <input type="hidden" name="hdnTmpID-<?php echo $TmpID ?>" id="hdnTmpID-<?php echo $TmpID ?>" value="<?php echo $TmpID ?>" class="tmpid"> <div class="cntrls"> <select name="ddlSec-<?php echo $TmpID ?>" class="clsSelSec" onchange="getStores(this);" data-val="<?php echo $store->storeid ?>"> <option value="">Select Store</option> <?php $sections = $obj->query("select storename,z.storeid from tbl_store_zip z join stores s on s.storeid=z.storeid where z.status=1 and s.status=1 and (s.sectionid like '%1,%' || s.sectionid like '%,1%' || s.sectionid=1) and s.skip_store=0 and s.storeid>0 group by storeid order by storeid"); while($section = $obj->fetchNextObject($sections)){ ?> <option value="<?php echo $section->storeid;?>"><?php echo $section->storename;?></option> <?php } ?> </select> <select name="ddlStore-<?php echo $TmpID ?>" class="clsSelStore js-example-basic-single" data-val="<?php echo $store->productid ?>"> <option value="">Select Product</option> <?php $storeid=$store->storeid; $prod=$obj->query("select product_name,p.id,mrp_price,sell_price,size,size_type from tbl_product p join tbl_productprice pp on p.id=pp.product_id where p.status=1 and pp.status=1 and p.storeid='$storeid'"); $number_of_rec=$obj->numRows($prod); ?> <?php if( $number_of_rec==0){?> <option value="" selected>No result find</option> <?php }else{ ?> <?php while($resprod=$obj->fetchNextObject($prod)){?> <option value="<?php echo $resprod->id;?>" <?php if($resprod->id==$store->productid){?>selected<?php } ?>><?php echo $resprod->product_name;?> <?php echo $resprod->size;?><?php echo $resprod->size_type;?> $<?php echo $resprod->sell_price;?></option> <?php } } ?> </select> <a href="javascript:void(0);" class="clsRemoveBtn" onclick="removeStore(this);"></a> </div> </li> <?php $TmpID = $TmpID + 1; } ?> </ol> <br><br> <a href="javascript:void(0);" class="clsAddBtn" onclick="addStore();">+ Add Store</a> </td> </tr> <tr> <td align="right" class="paddRt14 paddBot11"> </td> <td align="left" class="paddBot11"> </td> </tr> <tr> <td width="18%" align="right" class="paddRt14 paddBot11"> </td> <td width="82%" align="left" class="paddBot11"> <input type="submit" name="submit" value="Update" class="submit" onclick="return setData();" border="0"/> </td> </tr> </table> </form> </td> </tr> </table> </td> </tr> </table> </td> </tr> <?php include('footer.php'); ?> </table> <div class="clsTemplate"> <ol id="tempStore"> <li class="clsFP_Store" id="{li_id}" style="display: none;"> <input type="hidden" name="{0}" id="{1}" value="0" class="order"> <input type="hidden" name="{2}" id="{3}" value="0" class="id"> <input type="hidden" name="{4}" id="{5}" value="" class="old"> <input type="hidden" name="{6}" id="{7}" value="{8}" class="tmpid"> <div class="cntrls"> <select name="{sel_sec}" onchange="getStores(this);"> <option value="">Select Store</option> <?php $sections = $obj->query("select storename,z.storeid from tbl_store_zip z join stores s on s.storeid=z.storeid where z.status=1 and s.status=1 and (s.sectionid like '%1,%' || s.sectionid like '%,1%' || s.sectionid=1) and s.skip_store=0 and s.storeid>0 group by storeid order by storeid"); while($section = $obj->fetchNextObject($sections)){?> <option value="<?php echo $section->storeid;?>"><?php echo $section->storename;?></option> <?php } ?> </select> <select name="{sel_store}" class="js-example-basic-single2"> <option value="">Select Product</option> </select> <a href="javascript:void(0);" class="clsRemoveBtn" onclick="removeStore(this);"></a> </div> </li> </div> </div> <script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script> function addStore(){ var id = 1; var stores = $('.clsFP_Stores .clsFP_Store'); if(stores.length > 0) id = parseInt(stores[stores.length - 1].id.substr(6)) + 1; var template = $('#tempStore').html(); template = template.replace('{li_id}', 'store-' + id); template = template.replace('{0}', 'hdnOrderNo-' + id); template = template.replace('{1}', 'hdnOrderNo-' + id); template = template.replace('{2}', 'hdnPopUpID-' + id); template = template.replace('{3}', 'hdnPopUpID-' + id); template = template.replace('{4}', 'hdnOldImg-' + id); template = template.replace('{5}', 'hdnOldImg-' + id); template = template.replace('{6}', 'hdnTmpID-' + id); template = template.replace('{7}', 'hdnTmpID-' + id); template = template.replace('{8}', id); template = template.replace('{sel_sec}', 'ddlSec-' + id); template = template.replace('{sel_store}', 'ddlStore-' + id); $('.clsFP_Stores').append(template); var dvLast = $('.clsFP_Stores .clsFP_Store:last-child'); $(dvLast).slideDown('normal', function () { $(this).find('select')[0].focus(); }); } function getStores(ddl){ var ddlStore = $(ddl).next(); $(ddlStore).find('option:not(:first-child)').remove(); if(ddl.value != ''){ $.ajax({ url:"ajax-stp.php", data:{storeid:ddl.value}, success:function(data){ $(ddlStore).append(data); $('.js-example-basic-single2').select2(); } }) } } function removeStore(lnk){ if(confirm('Remove Product?')){ var parent = $(lnk).closest('.clsFP_Store'); var hdnID = $(parent).find('input[type=hidden]')[1]; if (hdnID != undefined && hdnID.value != '0') $('#hdnDelIDs')[0].value += hdnID.value + ","; var hdnID = $(parent).find('input[type=hidden]')[2]; if (hdnID != undefined && hdnID.value != '0') $('#hdnDelImgs')[0].value += hdnID.value + ","; $(lnk).closest('.clsFP_Store').slideUp('normal', function () { $(this).remove(); }); } } function setImg(fu){ var dvImg = $(fu).parent().parent().find('img')[0]; if (fu.files && fu.files[0]) { var reader = new FileReader(); reader.onload = function (e) { dvImg.style.backgroundImage = "url(" + e.target.result + ")"; } reader.readAsDataURL(fu.files[0]); } else dvImg.style.backgroundImage = "none, url('https://www.quicklly.com/images/no-img.jpg')"; } function validateData(){ try{ var ErrMsg = '' if ($('#title')[0].value == '') { ErrMsg += '- Enter title!\n'; $('#title')[0].style.backgroundColor = '#ffe8e8'; } else $('#title')[0].style.backgroundColor = 'transparent'; var stores = $('.clsFP_Stores .clsFP_Store'); if(stores.length > 0) { var flgSec = false, flgStore = false, flgImg = false; for (var i = 0; i < stores.length; i++) { var ddlSec = $(stores[i]).find('select')[0]; var ddlStore = $(stores[i]).find('select')[1]; var id = $(stores[i]).find('input[type=hidden]')[1]; if (ddlSec.value == '') { if (!flgSec) { flgSec = true; ErrMsg += '- Select section!\n'; } $(ddlSec)[0].style.backgroundColor = '#ffe8e8'; } else $(ddlSec)[0].style.backgroundColor = 'transparent'; if (ddlStore.value == '') { if (!flgStore) { flgStore = true; ErrMsg += '- Select store!\n'; } $(ddlStore)[0].style.backgroundColor = '#ffe8e8'; } else $(ddlStore)[0].style.backgroundColor = 'transparent'; } } if (ErrMsg != '') { alert('Validation Error!\n' + ErrMsg); return false; } else return true; } catch (e) { alert('Validation Failed!\n'); console.error(e.message); return false; } } function setData() { if(validateData()){ $('#hdnTmpIDs')[0].value = ''; var items = $(".clsFP_Stores .clsFP_Store"); for (var i = 0; i < items.length; i++) { var hdnOrderNo = $(items[i]).find('input[type=hidden]')[0]; hdnOrderNo.value = (i + 1); var hdnTmpID = $(items[i]).find('input[type=hidden]')[3]; $('#hdnTmpIDs')[0].value += hdnTmpID.value + ','; } if(hdnTmpIDs.value != '') $('#hdnTmpIDs')[0].value = $('#hdnTmpIDs').val().substr(0, $('#hdnTmpIDs').val().length - 1); if($('#hdnDelIDs').val() != '') $('#hdnDelIDs')[0].value = $('#hdnDelIDs').val().substr(0, $('#hdnDelIDs').val().length - 1); return true; } else return false; } $(".clsFP_Stores").sortable({ placeholder: "ui-state-highlight" }); $(".clsFP_Stores").disableSelection(); setCombo(); function setCombo(){ var secs = $('.clsFP_Stores .clsFP_Store .clsSelSec'); for (var i = 0; i < secs.length; i++) { secs[i].value = secs[i].dataset.val; } var secs = $('.clsFP_Stores .clsFP_Store .clsSelSec'); for (var i = 0; i < secs.length; i++) { secs[i].value = secs[i].dataset.val; } } function setInputFilter(textbox, inputFilter) { ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function (event) { textbox.addEventListener(event, function () { if (inputFilter(this.value)) { this.oldValue = this.value; this.oldSelectionStart = this.selectionStart; this.oldSelectionEnd = this.selectionEnd; } else if (this.hasOwnProperty("oldValue")) { this.value = this.oldValue; this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd); } else { this.value = ""; } }); }); } $(document).ready(function() { $('.js-example-basic-single').select2(); }); </script> </body> </html>