Mybb sceditor extra fields - php

I'm trying add extra content to mybb sceditor using three text area fields but it won't allow me to insert content.
I tried to add a function but cant get it working - help is appreciated!
$.sceditor.command.set('hidep', {
_dropDown: function (editor, caller) {
var $content;
$content = $(
'<div>' +
'<div>' +
'<label for="hidep">' + editor._('Amount of gems') + '</label> ' +
'<input type="text" id="hidep" />' +
'</div>' +
'<div>' +
'<label for="des">' + editor._('Content') + '</label> ' +
'<input type="text" id="des" />' +
'</div>' +
'<div>' +
'<label for="destitle">' + editor._('Title') + '</label> ' +
'<input type="text" id="destitle" />' +
'</div>' +
'<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
'</div>'
);
$content.find('.button').on('click', function (e) {
var val = $content.find('#hidep').val(),
description = $content.find('#des').val();
descriptiontitle = $content.find('#destitle').val();
if (val) {
// needed for IE to reset the last range
$(editor).trigger('focus');
if (!editor.getRangeHelper().selectedHtml() || description) {
if (!description)
description = val;
editor.insert('[hide cost="' + val + '" ' + destitle + ']' + description + '[/hide]');
} else
editor.execCommand('createlink', 'mailto:' + val);
}
editor.closeDropDown(true);
e.preventDefault();
});
editor.createDropDown(caller, 'inserthidep', $content.get(0));
},
exec: function (caller) {
$.sceditor.command.get('hidep')._dropDown(this, caller);
}
});
And it should look like this!
[hide cost="50" title="Good Stuff"]This is hidden content[/hide]

Related

Result gives undefined on the front-end in MySQL

I have the following API: api_get.products.php, which should gives me all the products from the database.
When on the front-end and I parse the result, and I try to access the array´s object´s key properties one by one, it gives me undefined for all the properties.
I would like to add that same solution worked fine when data came from a text file. So probably when data comes from MySQL there is a different way to access it?
The echo of $sjResponse, however echo´s the right thing.
[{"productCode":"200","productName":"B","productDescription":null,"quantityInStock":"198","buyPrice":"2.00","image":"img/product-image.1.png"},{"productCode":"1000","productName":"A","productDescription":null,"quantityInStock":"233","buyPrice":"1.00","image":"img/product-image.2.png"}]
What´s wrong?
<?php
try {
// connect to the database
require 'connect.php';
// create a query
$query = $conn->prepare("SELECT * FROM products");
// run the query
$bResult = $query->execute(); // result of this will return true or false
$sajResult = json_encode( $query->fetchAll(PDO::FETCH_ASSOC) ); //fetch the result and turn it into a string
//echo $sajResult;
$sjResponse = $bResult ? $sajResult : '{"status":"error"}'; // means if the query is true or false
echo $sjResponse;
} catch (Exception $e) {
echo "ERROR";
}
?>
Here is the ajax, where everything should be fine, I just parse the response.
function getajProductData() {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if ( this.readyState == 4 && this.status == 200 ) {
ajProductDataFromServer = JSON.parse( this.responseText );
console.log( "Response:" + ajProductDataFromServer );
if ( sessionStorage.getItem('role') === "admin" ) {
//console.log( "PRODUCTS ARE EDITABLE" );
showProductAdmin();
} else if ( sessionStorage.getItem('role') === "user" ) {
//console.log( "PRODUCTS ARE AVAILABLE FOR USER" );
showProduct();
} else {
//console.log( "PRODUCTS AVAILABLE FOR PUBLIC" );
showProduct();
}
}
}
request.open( "GET", "api_get_products.php", true );
request.send();
}
And here is where I try to access the array´s object´s properties one by one. This also worked fine before when the data came from a text file.
/ DISPLAY PRODUCTS for USER / PUBLIC dinamically using a loop and then INSERT into HTML
function showProduct() {
lblProductList.innerHTML = "";
for ( var i = 0; i < ajProductDataFromServer.length; i++ ) {
var lblProduct = '<div class ="lblProduct">' + '' + '<img src="' + ajProductDataFromServer[i].image + '" width="85%" class="lblProductImage" alt="product">' + '' + '' + '<img src="' + ajProductDataFromServer[i].image + '">' + '' + '<h3 class ="lblProductName">' + ajProductDataFromServer[i].name + '</h3>' + '<h3 class ="lblProductPrice">' + 'Price:' + ' ' + ajProductDataFromServer[i].price + '<h3 class ="lblProductQuantity">' + 'Quantity:' + ' ' + ajProductDataFromServer[i].quantity + '</h3>' + '<button class="btnBuyProduct" data-productId="' + ajProductDataFromServer[i].id + '" >' + 'BUY PRODUCT' + '</button>' + '</div>';
lblProductList.insertAdjacentHTML( 'beforeend', lblProduct );
}
}
// DISPLAY PRODUCTS for USER / PUBLIC dinamically using a loop and then INSERT into HTML
function showProduct() {
lblProductList.innerHTML = "";
for ( var i = 0; i < ajProductDataFromServer.length; i++ ) {
var lblProduct = '<div class ="lblProduct">' + '' + '<img src="' + ajProductDataFromServer[i].image + '" width="85%" class="lblProductImage" alt="product">' + '' + '' + '<img src="' + ajProductDataFromServer[i].image + '">' + '' + '<h3 class ="lblProductName">' + ajProductDataFromServer[i].productName + '</h3>' + '<h3 class ="lblProductPrice">' + 'Price:' + ' ' + ajProductDataFromServer[i].buyPrice + '<h3 class ="lblProductQuantity">' + 'Quantity:' + ' ' + ajProductDataFromServer[i].quantityInStock + '</h3>' + '<button class="btnBuyProduct" data-productId="' + ajProductDataFromServer[i].productCode + '" >' + 'BUY PRODUCT' + '</button>' + '</div>';
lblProductList.insertAdjacentHTML( 'beforeend', lblProduct );
}
}

Display radio buttons and checkbox for certain items CodeIgniter

I am new to Codeigniter framework. I have a scenario where I have to display radio box and checkbox based on the database value 0 or 1. If the value is 0 then the radio buttons should appear for the particular items and if the value is 1 then display items with the checkboxes so the user can select multiple items. How can I accomplish this task? Right now, I am able to display all items only with checkboxes.
I have added new field in database with the name of multi_select. Here I am saving items with the value of 0 and 1.
Here is my code.
$(document).on('click', '.add_cart_modal', function (e) {
$('.item_attr_div_model').empty();
var it_val = $(this).attr('value');
$data = 'item_id=' + it_val;
var rest_id = $("#restid-" + it_val).val();
$url = '<?= base_url() ?>main/get_item_attributes';
$.ajax({
url: $url,
type: "POST",
dataType: 'json',
data: $data,
success: function (data) {
if (data.item_options != null && data.group_attrib == '1') {
var item_group_data = '';
$.each(data.item_options, function (key, item) {
var item_attrib = '';
if (item.attributes != null) {
$.each(item.attributes, function (key, it_attrbues) {
item_attrib += '<div class="col-lg-4" style="margin-top: 10px;">' +
'<div class="checkbox">' +
'<input id="' + it_attrbues.name + '" type="checkbox" value="' + it_attrbues.id + '" class="options_ids" name="options[]" style="margin-right:5px">' +
if (item.attributes != null) {
item_group_data += + item.group_name +
'' + item_attrib +;
}
});
var item_attr_display =
'<input name="item_id" id="attr_item_id" type="hidden" value="' + data.item_id + '" >' +
'<input name="item_name" id="attr_item_name" type="hidden" value="' + data.item_name + '" >' +
'<input name="item_price" id="attr_item_price" type="hidden" value="' + data.item_price + '" >' +
'<input name="rest_id" id="attr_rest_id" type="hidden" value="' + rest_id + '" >' +
data.item_name + data.item_description + Price +
data.item_price + item_group_data;
$('.item_attr_div_model').append(item_attr_display);
$('#add_cart_modal').modal('show');
} else {
var attribute_ids = '';
post_array =
{
"item_id": $("#id-" + it_val).val(),
"item_name": $('#name-' + it_val).val(),
"item_qty": $("#qty-" + it_val).val(),
"item_price": $("#price-" + it_val).val(),
"rest_id": $("#restid-" + it_val).val(),
"attribute_ids": attribute_ids
}
$.post(base_url + "main/add_item_to_cart", post_array,
function (data) {
var res = jQuery.parseJSON(data);
update_cart_items(res.cart_view, res.total_cost, res.items_count);
$('.whole_div').hide();
});
}
}
});
});
How can I read 0 and 1 value from database for particular items and display radio or checkbox based on their value?
Change your $.each function as follow
$.each(item.attributes, function (key, it_attrbues) {
var ty = 'radio';
if(it_attrbues.multi_select == '1') //if the value is 1 then it will pass checkbox
{
ty = 'checkbox';
}
item_attrib += '<div class="col-lg-4" style="margin-top: 10px;">' +
'<div class="checkbox">' +
'<input id="' + it_attrbues.name +
'" type="'+ty+'" value="' + it_attrbues.id + '" class="options_ids" name="options[]" style="margin-right:5px">' +
'<label style="padding-left: 25px;" class="label-radio oswald-font bold font22"for="' + it_attrbues.name + '">' + it_attrbues.name + ' (' + it_attrbues.price + ')</label>' +
'</div>' +
'</div>';
});

How to replace the whole item inside the id div using Pusher php and javascript

I want to replace the whole item inside the id div instead of adding it.I am not familliar with javascript/ajax/jquery and i dont know which file i will edit.
This is the sample code given by pusher.com in activity-stream tutorial
$(function() {
var pusher = new Pusher('pusher key');
var channel = pusher.subscribe('site-activity');
var streamer = new PusherActivityStreamer(channel, '#replace_item');
});
html id that will replace all item inside the div
<div id="replace_item">ITEMS</div>
This is the javascript function
function PusherActivityStreamer(activityChannel, ulSelector, options) {
var self = this;
this._email = null;
options = options || {};
this.settings = $.extend({
maxItems: 10
}, options);
this._activityChannel = activityChannel;
this._activityList = $(ulSelector);
this._activityChannel.bind('activity', function(activity) {
self._handleActivity.call(self, activity, activity.type);
});
this._activityChannel.bind('page-load', function(activity) {
self._handleActivity.call(self, activity, 'page-load');
});
this._activityChannel.bind('test-event', function(activity) {
self._handleActivity.call(self, activity, 'test-event');
});
this._activityChannel.bind('scroll', function(activity) {
self._handleActivity.call(self, activity, 'scroll');
});
this._activityChannel.bind('like', function(activity) {
self._handleActivity.call(self, activity, 'like');
});
this._itemCount = 0;
};
PusherActivityStreamer.prototype._handleActivity = function(activity, eventType) {
var self = this;
++this._itemCount;
var activityItem = PusherActivityStreamer._buildListItem(activity);
activityItem.addClass(eventType);
activityItem.hide();
this._activityList.prepend(activityItem);
activityItem.slideDown('slow');
if(this._itemCount > this.settings.maxItems) {
this._activityList.find('li:last-child').fadeOut(function(){
$(this).remove();
--self._itemCount;
});
}
};
PusherActivityStreamer.prototype.sendActivity = function(activityType, activityData) {
var data = {
activity_type: activityType,
activity_data: activityData
};
if(this._email) {
data.email = this._email;
}
$.ajax({
url: 'php/trigger_activity.php', // PHP
// url: '/trigger_activity', // Node.js
data: data
})
};
PusherActivityStreamer._buildListItem = function(activity) {
var li = $('<li class="activity"></li>');
li.attr('data-activity-id', activity.id);
var item = $('<div class="stream-item-content"></div>');
li.append(item);
var imageInfo = activity.actor.image;
var image = $('<div class="image">' +
'<img src="' + imageInfo.url + '" width="' + imageInfo.width + '" height="' + imageInfo.height + '" />' +
'</div>');
item.append(image);
var content = $('<div class="content"></div>');
item.append(content);
var user = $('<div class="activity-row">' +
'<span class="user-name">' +
'<a class="screen-name" title="' + activity.actor.displayName + '">' + activity.actor.displayName + '</a>' +
//'<span class="full-name">' + activity.actor.displayName + '</span>' +
'</span>' +
'</div>');
content.append(user);
var message = $('<div class="activity-row">' +
'<div class="text">' + activity.body + '</div>' +
'</div>');
content.append(message);
var time = $('<div class="activity-row">' +
'<a href="' + activity.link + '" class="timestamp">' +
'<span title="' + activity.published + '">' + PusherActivityStreamer._timeToDescription(activity.published) + '</span>' +
'</a>' +
'<span class="activity-actions">' +
'<span class="tweet-action action-favorite">' +
'<span><i></i><b>Like</b></span>' +
'</span>' +
'</span>' +
'</div>');
content.append(time);
return li;
};
If you want to replace the entire div instead of adding things to it, I think this will work.
Change
this._activityList.prepend(activityItem);
for
this._activityList.empty();
this._activityList.prepend(activityItem);
".prepend" adds the activityItem to the top of the div as you know, but ".empty()" will clear everything previously in the div before you do this.

How Do I generate table columns dynamically after ajax?

I am using jQuery (1.9.1) with jQuery Mobile (1.3.0). I am having trouble with the Reflow table in JQM. When I AJAX to get my JSON data from a script to add more rows to my table, the reflow table headings are not generated after I trigger a refresh and create on the table. Here is my code:
HTML/PHP
'<table data-role="table" id="itemTable" data-mode="reflow" class="ui-responsive table-stroke" style="display:table;">' .
'<thead>' .
'<tr>' .
'<th data-priority="1">Location</th>' .
'<th>Name</th>' .
'<th data-priority="3">Barcode</th>' .
'<th data-priority="4">Needed</th>' .
'<th data-priority="5">Scanned</th>' .
'</tr>' .
'</thead>' .
'<tbody>' .
$tableData .
'</tbody>' .
'</table>' .
JavaScript
$('.getOrder, .getStoreOrder').on('vclick', function(e) {
e.preventDefault();
var sel = this;
var theLink = $(this).attr('href');
if (activeOrder === true) {
return false;
}
$.ajax({
url: 'ajax.php',
data: {
pa: ($(sel).hasClass('getStoreOrder') ? 'store' : '') + 'order'
},
dataType: 'json',
beforeSend: function() {
$.mobile.showPageLoadingMsg();
$('#itemTable tbody').html('');
$('#leftPanel ul li').not(':first-child').remove();
},
success: function(data) {
testVar = data;
var i;
for (i=0; i <= data.length -1; i++) {
$('#itemTable tbody').append( '' +
'<tr id="item' + (i+1) + '">' +
'<td><span>' + data[i].Location + '</span></td>' +
'<td><a onclick="showImageOverlay(\'' + data[i].Image + '\');">' + data[i].Name + '</a></td>' +
'<td>' + data[i].Barcode + '</td>' +
'<td>' + data[i].Qty + '</td>' +
'<td>0</td>' +
'</tr>' +
'');
$('#leftPanel ul').append( '' +
'<li>' +
'<a href="#item' + (i+1) + '" class="itemLink" onclick="changeItem(\'item' + (i+1) + '\')">' +
'Item ' + (i+1) +
'</a>' +
'</li>' +
'');
}
$('#itemTable').trigger('refresh');
$('#itemTable').trigger('create');
$('#leftPanel #leftUl').listview('refresh');
},
complete: function() {
$('#rightPanel', '.ui-page-active').panel('close');
$.mobile.hidePageLoadingMsg();
//pageChange(theLink);
}
});
});
The AJAX does succeed and add my rows to the table how I want them to. My question is how do I trigger JQM to add the reflow column names.
I know that I can use <b class="ui-table-cell-label">Column Name</b> to my row appends to add the column names but I want it done dynamically so I don't have to change the jQuery when I change my HTML.
Thank you.
In my opinion its preferable to do like this: $('#tableContainer').load('revisedTable.php?json=yourJsonString');
That way you're doing the table layout in php rather than javascript.
Figured it out. Turns out that jQuery Mobile version 1.3.0 does not have a proper .table('refresh') method implemented. I solved this by upgrading to jQuery Mobile version 1.3.1 which has the proper method I needed.

Need to pass PHP array to Javascript function

Based on several other threads here I think what I'm looking for is json_encode(), though I don't really understand how the output can be used by my JavaScript function. What I'm trying to do is allow users to add additional select lists as needed and have those select options populated from a PHP function that I use to create the initial select list. Here's my JavaScript at the moment:
<script type="text/javascript">
var assigneeCounter = <?php print checkdata("assignee_count", $formvalues, "1"); ?>;
function addInput(fieldlabel, inputclasses, inputCounter, fieldtype = 'input', selectoptions = false){
window[inputCounter]++;
var cleanlabel = fieldlabel.replace(/[^a-zA-Z 0-9]+/g,'');
var cleanlabel = cleanlabel.replace(/\s+/g, '_').toLowerCase();
var newdiv = document.createElement('div');
newdiv.id = cleanlabel + window[inputCounter];
if (fieldtype == 'input') {
newdiv.innerHTML = '<div class="form-item"><label for="' + cleanlabel + '_' + window[inputCounter] + '">' + fieldlabel + ' #' + window[inputCounter] + '</label><input type="text" name="' + cleanlabel + '_' + window[inputCounter] + '" id="' + cleanlabel + '_' + window[inputCounter] + '" value="" class="' + inputclasses + '"><span class="space">Remove</span>';
}
else if (fieldtype == 'select') {
alert(selectoptions);
newdiv.innerHTML = '<div class="form-item"><label for="' + cleanlabel + '_' + window[inputCounter] + '">' + fieldlabel + ' #' + window[inputCounter] + '</label><select name="' + cleanlabel + '_' + window[inputCounter] + '" id="' + cleanlabel + '_' + window[inputCounter] + '" class="' + inputclasses + '">
<span class="space">Remove</span>';
}
document.getElementById(cleanlabel + "_additions").appendChild(newdiv);
document.getElementById(cleanlabel + "_count").value = window[inputCounter];
}
function removeInput(fieldlabel, inputCounter, fieldID){
var element = document.getElementById(fieldlabel + fieldID);
document.getElementById(fieldlabel + "_additions").removeChild(element);
window[inputCounter]--;
document.getElementById(fieldlabel + "_count").value = window[inputCounter];
}
</script>
I'm calling the function in HTML like so:
<div id="assignee_additions"></div>
<p>Add Another Assignee</p>
When I set the value of "fieldtype" to input it works great and creates another input field as expected. The remove function does its job too. But what I really need is a select field, not an input field and that's where my lack of JavaScript knowledge is killing me.
Also, if anyone seems to think that jQuery is a better option here, I'm certainly open to that as well but I don't know that any better than I do traditional JavaScript.
Thanks in advance!
You can create your JSON in a different php file. Then, from your javascript function, you can use an AJAX call to retrieve generated JSON.
I believe you want to json_encode values and keys for <option> tags, right? So, after successful AJAX call, decode your JSON and for each value build a new option.
Rough code in jQuery can look like this:
$.ajax({
url: 'giveMeJSON.php',
dataType: 'json',
success: function(data){
$.each(data.options, function(index){
$('<option>').val($(this).value).text($(this).text).appendTo($('#select_id'));
}
}
})
Read about $.ajax and AJAX.

Categories