I am trying to manipulate my buttons in CJuidialog. I want to have a submit button inside my dialog. I have a checkbox "default" where if it is checked, check data from the database. I have a list of employees, where I input their data. Whenever the employee already have a schedule it will display a popup that says. You already have a schedule. do you wish to continue? Then, in my cjuidialog. I have an "OK" button and "CANCEL". If the user clicks ok. It will submit the form and find the same employee and change its default "1" to "0".
So that the new form will be the default and the previous one will be just a regular schedule.
For example:
there is a fk_user = 1 , default = 1 , from= 07/07/13 , to = 07/10/13 , schedule = 5 data in the database. Then I create another form which is fk_user = 1 , default = 1, from = 10/10/13 , to = 12/12/13 , schedule = 6,There is already a default for fk_user 1. It will display a popup where it says "You already have a schedule. do you wish to continue? ". If the user clicks "OK" the new data will be fk_user = 1 , default = 1, from = 10/10/13 , to = 12/12/13 , schedule = 6 and the previous will be fk_user = 1 , default = 0 , from= 07/07/13 , to = 07/10/13 , schedule = 5 the previous data becomes 0.
I have been trying this for the past days, and it is the only problem for my system to be completed. can anyone help me with these?
I dont know if I will still use the ajax submit button here, I had research over the net, but I cant find documentation about this.
I started with this.
public function actionCreate()
{
$model=new EmpSched;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['EmpSched']))
//$fk_user= $model->fk_user;
$model->attributes=$_POST['EmpSched'];
if($model->default==1){
$record = EmpSched::model()->findAllByAttributes(array('fk_user' => $model->fk_user,'default'=>array('1')));
var_dump($record);
if($record==false){
($model->save());
$this->redirect(array('view','id'=>$model->id_empsched));
}else{
$this->renderPartial('popup');
}
}else{
($model->save());
$this->redirect(array('view','id'=>$model->id_empsched));
}
}
$this->render('create',array(
'model'=>$model,
'emp'=> new CActiveDataProvider('schedule'),
));
}
popup.php
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'popup-form',
'enableAjaxValidation'=>true,
)); ?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'mydialog',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Michael',
'autoOpen'=>true,
'modal'=>true,
'width'=>300,
'height'=>300,
'buttons' => array(
'OK'=>'js:function(){
//$(this).dialog("close")
}',
'CANCEL'=>'js:function(){$(this).dialog("close")}'),
),
));
echo 'Another default schedule is already using. Do you want to set current schedule as default? ';
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
<?php $this->endWidget();?>
Why do you need to make this change before save?
I would do this on save and use the modal only for advertisement.
Like this:
public function actionCreate()
{
$model=new EmpSched;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['EmpSched']))
//$fk_user= $model->fk_user;
$model->attributes=$_POST['EmpSched'];
if($model->validate()){
if($model->default==1){
EmpSched::model()->updateAll(array('default'=>0),'fk_user=:fk_user',array(':fk_user' => $model->fk_user);
}
if($model->save(false)){
$this->redirect(array('view','id'=>$model->id_empsched));
}
}
}
$this->render('create',array(
'model'=>$model,
'emp'=> new CActiveDataProvider('schedule'),
));
}
Related
Basically I can't get a redirect to work for a number of reasons the way I'd like to so I'm wanting to add a function that will run on the /my-account/ page to see if the current user ordered product A or B in the last 10 seconds (would have completed status, using autocomplete order plugin) and if so redirect them to a custom thank you page specified in the function.
I'm finding alot of functions to pull recent orders, but I'm not sure if I'm going in the right direction. How in 3.0 do I get the timestamp and product id of the users most recent order? Is there a hook to tie this to the /my-account/ page or will I need to hack a javascript/php work around?
How about to run the code directly after the purchase?
You check which product it was (and more checks if you need) and then redirect to the custom thankyou page.
add_action( 'woocommerce_thankyou', 'my_custom_code' );
function my_custom_code( $order_id ) {
// Lets grab the order
$order = wc_get_order( $order_id );
// do stuff
}
Here's what I ended up doing:
added a custom column to the 'Orders' table of the 'My Account' page
that included order ID (used filter to add the column - SKU - and
then updated the logic in the orders.php page to add the product ID
to the SKU column.
function new_orders_columns( $columns = array() ) {
$columns['product-name'] = __( 'SKU', 'Text Domain' );
return $columns;
}
add_filter( 'woocommerce_account_orders_columns', 'new_orders_columns' );
added a jQuery script (echoed with php via shortcode added to the 'My
Account' page) that would pull the current date, the datetime
attribute from the date column and the product ID text from the SKU
column from the first row - ie most recent order
used Javascript to find the difference between the current time and
the order time and convert that number to seconds
added a conditional redirect based on the value of that time
difference being less than 10 (seconds) and that product id was a
specific id
function mycustomorder_redirect() {
if (is_user_logged_in()) {
date_default_timezone_set('America/New_York');
$time_now = date( 'c' );
echo '<script>jQuery("document").ready(function() {
//
//Get most recent order datetime
var lastorder_td = jQuery("td.woocommerce-orders-table__cell-order-date:eq(0) time").attr("datetime");
//
//Get most recent order product id
var product_check = jQuery("td.woocommerce-orders-table__cell-product-name:eq(0)").text();
//
//Remove whitespace
product_check = product_check.replace(/(^\s+|\s+$)/g,"");
//
//Get current datetime
var current_wrap = "' . $time_now . '";
//
//Remove +00:00 or -00:00
lastorder_td = lastorder_td.substring(0, lastorder_td.length - 6);
current_wrap = current_wrap.substring(0, current_wrap.length - 6);
//
//Convert to javascript date
var column_a = new Date(current_wrap);
var column_b = new Date(lastorder_td);
//
//Find time difference
var dif = column_a - column_b;
//
//Convert to seconds
var seconds_toredirect = dif / 1000;
//
//Add redirect
if (seconds_toredirect < 10 && (product_check == 1 || product_check == 2)) {
window.location.replace("https://exampleurl.com/page/");
}
});
</script>';
}
}
add_shortcode( 'order-custom', 'mycustomorder_redirect' );
Let's say there are 3 links:
http://example.com/1
http://example.com/2
http://example.com/3
How would I go about creating a rotational based redirect system?
Here's how it would work:
The user opens up http://example.com and then gets redirected to http://example.com/1
The URL http://example.com/1 (that the user gets redirected to is stored in a text file with the URL as the value of the text file)
When another user visits http://example.com, rather than getting redirected to http://example.com/1, he would get redirected to http://example.com/2. The code should know to redirect to http://example.com/2 rather than /1 as /1 is stored in the text file. After the user is redirected, the value of the text file changes from .../1 to .../2.
Same thing happens for when the next user visits but gets forwarded to .../3.
Fourth user gets redirected to .../1
And so on
<?php
$link[0] = array('link' => 'http://example.com/1', 'percent' => 33);
$link[1] = array('link' => 'http://example.com/2', 'percent' => 33);
$link[2] = array('link' => 'http://example.com/3', 'percent' => 33);
$percent_arr = array();
foreach($link as $k => $_l) {
$percent_arr = array_merge($percent_arr, array_fill(0, $_l['percent'], $k));
}
$random_key = $percent_arr[mt_rand(0,count($percent_arr)-1)];
$redirectlink = $link[$random_key]['link'];
?>
Click to redirect
I am currently using this code but it doesn't provide me with what is needed.
If you are using a database with your script, I would recomend using timestamps:
You create a table with 3 columns, id siteurl lastvisit.
Create a query which gets the site which was visited the longest ago.
When the user enters your site, he gets redirected to where he belongs. The timestamp of the site gets updated.
If you don't have a database, just use .txt's.
If I understand your text right, you don't need weighted routing, so
just store the index of the next route in your text file and rotate it on every call.
Read file:
$link[0] = array('link' => 'http://example.com/1');
$link[1] = array('link' => 'http://example.com/2');
$link[2] = array('link' => 'http://example.com/3');
$next = intval(file_get_contents('next.txt')); // $next -> 0
$redirectTo = $link[$next];
Now rotate and write file:
$next = ($next === 2) ? 0 : next +1;
file_put_contents('next.txt', $next);
//redirect ...
I am echoing out a form (foreach) from my filemaker records which will result in the items ID, Name, a Checkbox and then an image.
In my understanding i will have to use classes or the elements will all have the same id.
My Code;
foreach($result->getRecords() as $record){
$id = $record->getField('Record_ID_PHP');
$name = $record->getField('DB_Name');
$pic = $record->getField('Photo_Path');
echo '"'.$id.'"<br>';
echo $name.'<br>';
echo '<input type="checkbox" class="check" value="Invoices/Photos/RC_Data_FMS/Invoices_db/Photos/'.$pic.'">';
echo '<div class="pics">';
echo '<img style="width:200px;" src="Invoices/Photos/RC_Data_FMS/Invoices_db/Photos/'.$pic.'"><br>';
echo '<hr>';
echo '</div>';
}
Which results in a page full of the records, a checkbox and the relating image.
I wish to only show these images when the checkbox is checked but cannot find a solution, i have tried many jquery scripts, to no avail.
The images will then populate the next page as a pdf to be printed.
I am hoping not to have to grab the checkbox's values as an array to then use the get method with 100's of if statements but cant see another way ?
The jquery ive used.
$(document).ready(function () {
$('.pics').hide();
$('.check').click(function () {
$('pics').show;
});
$('.pics').hide;
});
and
$(function() {
$(".check").click(function(e) {
e.preventDefault();
$('.pics').hide();
$('.pics').show();
});
});
Plus many similar alternatives.
Is there something obvious i am missing ?
Query to filemaker method;
I have changed the path field to a calculated value which works great, thank you, although with 1000's of records, i would need lots of php code to echo the checkbox's to the website and lots more to be able to edit them from the website.
I have done this previously with the value held within the checkbox in filemaker.
$sesame = $print->getField('Allergens::Allergens[11]'); if ($sesame == "Sesame") { $sesame = "checked" ;} else if ($sesame !== "Sesame") {$sesame = "" ;}
This displays the checkbox synced with filemaker.
if ($_POST['Sesame'] == 'Sesame'){ $a_sesame = 'Sesame';} else { $a_sesame = 'No Sesame'; }
This is sent as a variable to my script.
if($a_sesame == "Sesame"){$contains_sesame = "Yes";} else { $contains_sesame = "No";}
This grabs the new value from the form.
Which all work great, but then i am writing a script in filemaker too to enable the to and from of the different names for each checkbox state.
which is for this part 120 lines long, this is a sample which i have to repeat for each repetition of this field.
Set Variable [ $sesame; Value:GetValue ( Get ( ScriptParameter ) ; 11 ) ]
If [ $sesame = "Sesame" ]
Set Field [ Allergens::Allergens[11]; "Sesame" ] Commit Records/Requests
[ Skip data entry validation; No dialog ]
Else If [ $sesame = "No Sesame" ]
Clear [ Allergens::Allergens[11] ] [ Select ]
Commit Records/Requests
[ Skip data entry validation; No dialog ]
Refresh Window
[ Flush cached join results; Flush cached external data ]
End If
This would be far too large to write for so many records, just for these 14 fields used 120 in filemaker and 400 plus in the php.
I am not 100% sure what you are trying to do but this should work. First add an extra div that closes input and div pics like below.
foreach($result->getRecords() as $record){
$id = $record->getField('Record_ID_PHP');
$name = $record->getField('DB_Name');
$pic = $record->getField('Photo_Path');
echo <<<TEXT
'{$id}'<br>
{$name}<br>
<div>
<input type='checkbox' class='check' value='Invoices/Photos/RC_Data_FMS/Invoices_db/Photos/{$pic}'>
<div class='pics'>
<img style='width: 200px;' src='Invoices/Photos/RC_Data_FMS/Invoices_db/Photos/{$pic}'><br>
<hr>
</div>
</div>
TEXT;
}
then change your java to this
$(document).ready(function() {
$(".pics").hide();
$(".check").click(function() {
$(this).siblings().toggle();
});
});
well I hope this helps
Another alternative would be to set up a simple calculated container field in FileMaker, with a calculated value of:
If ( checkbox; imageField )
This would only pass the image when the checkbox was ticked for a record. This should be faster than handling this in JavaScript, since you'd be limiting the number of images being sent over the wire.
Note: For performance, you might try this with this calculated container field stored and unstored. I suspect stored v unstored should make little difference, in which case I'd suggest leaving this unstored to minimize disk space consumed.
You can use the toggle()function:
$(function() {
$('.pics').hide();
$(".check").is(':checked',function(e) {
e.preventDefault();
$('.pics').toggle();
});
});
My client needs to make an operation on products custom options.
Using Magento CE, I create a product, and give it some custom options from within the built-in left hand side menu in "Manage products" > "Add new product", such as "mm" (millimeters) and "mt" (meters)
This product will have both radio options and a textbot input.
Let's say we have
Base price: 0
MM:
Radio option A which costs 0,9
Radio option B which costs 1,2
Radio option C which costs 2,3
MT:
Textbox value = unknown yet
Let's say user chooses Radio option B and enters 10 in the textfield
Price should be updates as such:
1,2 * 10 + 0
Which is
radio value cost * textbox value + base price
Is there any way to tell the code to take the value of the radio button, multiply it for the value of the textbox and sum it all to the base price?
Where could I look to see the current behavior of a product's custom options?
EDIT
I saw that whenever a value is selected, the reloadPrice() function is called.
I thought to check if both inputs are radio and text, then get the value of the text and multiply it for the value of the radio.
Is that right? Can you point me better?
This helps me, I hope this will also helps you
initialize : function(config){
this.config = config;
this.reloadPrice();
document.observe("dom:loaded", this.reloadPrice.bind(this));
},
reloadPrice : function(){
price = new Number();
config = this.config;
skipIds = [];
skipIds = [];
relatedword = [];
relatedvalue = [];
relatedid = [];
counter_each=0;
counter=1;
first=0;
areaValue=1;
submitbutton=true;
$$('body .product-custom-option').each(function(element){
var optionId = 0;
element.name.sub(/[0-9]+/, function(match){
optionId = match[0];
});
if (this.config[optionId]) {
if (element.type == 'checkbox' || element.type == 'radio')
{
if (element.checked)
{
if (config[optionId][element.getValue()])
{
<?php if(Mage::getVersion() >= 1.7): ?>
price += parseFloat(config[optionId][element.getValue()].price);
<?php else: ?>
price += parseFloat(this.config[optionId][selectOption.value]);
<?php endif; ?>
}
}
}
}
reloadPrice() does not update product price at server level. One way to do this product price update is by implementing checkout_cart_product_add_after event.
Do you custom logic at client level with javascript in detail page. Assign this value to some hidden variable under the form product_addtocart_form. A better way is to save to session to reduce client side vulnerabilities or you can find your own better way. Or Implement your login only in Observer method. Whatever you find secure.
Rewrite the class Mage_Checkout_Model_Cart to modify as,
public function addProduct($productInfo, $requestInfo=null)
{
...
Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product,'request_data'=>$request));
...
}
In your yourmodule/etc/config.xml:
<config>
...
<frontend>
...
<events>
<checkout_cart_product_add_after>
<observers>
<unique_name>
<class>modulename/observer</class>
<method>customPrice</method>
</unique_name>
</observers>
</checkout_cart_product_add_after>
</events>
...
</frontend>
...
</config>
And then create an Observer class at yourmodule/Model/Observer.php
class <namespace>_<modulename>_Model_Observer
{
public function customPrice(Varien_Event_Observer $observer)
{
// Get the quote item
$item = $observer->getQuoteItem();
$request=$observer->getRequestData();
// Ensure we have the parent item, if it has one
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
// Load the custom price
$price = "custom price logic";//whatever from your hidden value or by some other mean.
// Set the custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
}
}
For more information check here
So I have an .aspx page. In this grid I'm adding a bunch of controls. The first control however is an ExtObject, not one of our preset VB.NET controls. When I go to access the value on the backend for this field with this code:
form.AndOr.getValue()
It doesn't work. I really have no idea what is wrong. Basically, the radio button value isn't saving when I save the rest of the stuff. So I tried to add code to do it. It was just defaulted to 'And' each time. Below is a snippet of code from the actual asp.net grid. Any ideas?
With .Item(2)
.Ref = "../Payee2"
.LabelWidth = 90
With .AddFieldSet("Payee 2")
.AddControl(New Forms.Control("", "../PayeeId")).Hidden = True
.AddControl(New Forms.Control("", "../AddressId")).Hidden = True
.AddExtObject("{xtype:'radiogroup', ref:'../AndOr', defaults:{name:'rdo-payee2'}, width:120, items:[{boxLabel:'And', checked:true, inputValue:'and'},{boxLabel:'Or', inputValue:'or'}]}")
Dim ddlPayee2 As New Controls.ComboBox("", "../PayeePreInfo2", "Payee")
With ddlPayee2
.ForceSelection = True
.TypeAhead = False
.EmptyText = "Select Payee Details"
.ValueField = "AddressId"
.XTemplate = "applicantTemplate"
.ClientStore = "applicantAddressStore"
.AddListener(Akcelerant.Framework.WebControls.Controls.EventType.Select, "function(){prefillPayee('PAYEE2');}")
End With
.AddControl(ddlPayee2)
With .AddControl(New Forms.Control("", "../FirstName", "First Name", ""))
.Validate.MaxLength = 50
.ReadOnly = EditControl.IsFieldReadOnly(10483, True)
End With
With .AddControl(New Forms.Control("", "../LastName", "Last Name", ""))
.Validate.MaxLength = 50
.ReadOnly = EditControl.IsFieldReadOnly(10484, True)
End With
The error it throws is this:
Stack overflow at line: 16736
edit:
reverted some changes back and everything saves EXCEPT that value into the DB.
go to add this line to the javascript save function
if (form.AndOr.getValue() == 'and') {
payeeRec.set('IsPayee2RequiredToSign', 1);
} else {
payeeRec.set('IsPayee2RequiredToSign', 0);
}
and i get this error:
form.AndOr is not defined
Does the Ext ref: mean something different than my controls and how I access them?
Added a ref to the item of checkWin.
Then the ref to the radio value became
checkWin.Payee2.AndOr.getValue()
With that it can recognize the control on the form.