Fork me on GitHub

Announcement

The oneye project has been discontinued. You might not expect further fixes and support from us. All community related systems are set to read-only mode. Though feel free to download and use oneye as-is or even fork it over at GitHub.

#1 2012-01-13 09:44:30

Steven
Member
From: Near Aix en Provence, France
Registered: 2011-07-19
Posts: 20
Website

Checkboxes, problem

Hi,

I'm stuck (again ;-))

I have an array (variable size) of checkboxes (with some text after them) like this :

				$Doc_AA = new Checkbox(array(
					'name' => 'slot-labocb'.$rowx->id,
					'father' => 'extra_slot_Content',
					'text' => ' ',
					'x' => 10,
					'y' => $y_extra,
					'checked' => $oblio || $chum,
					'enabled' => 1 - $oblio,
				));
				$Doc_AA->show();
    			$Doc_AA->addEvent('onchange','sendMsg('.$checknum.',"slot_calcule",eyeParam("value",document.getElementById("'. $myPid .'_slot-labocb'.$rowx->id.'").checked));');

The result is ok, I get checked in the slot_calcule routine.
However, in this routine I walk all the check boxes of the array to do some calculations, and as a result write a total value in a text box.

Like this :

function gites_on_slot_calcule($params=null) {
	/**************************************************
	Here we do all the re-calculations when a field changes.
	we just do all the fields each time we are signalled
	**************************************************/
	$value = $params['value'][0];
// value is correct for the calling widget !
	$slot_id = $GLOBALS['slot.No']->text;
	$link = gites_mysql_pconnect();
	if ($link == false) return(false);
	
	// lets start with the extras 
	// we walk the tree of globals and add amounts, then write it in the extras field				// we calculate the duration of the slot
	$slo = mysql_query("SELECT DATEDIFF(Arrdate, Depdate) as dif, Adults, Animaux  FROM slot WHERE No = $slot_id");
	$rowS = mysql_fetch_object($slo);
	$days = $rowS->dif;
	$weeks = $days / 7;
	$persons = $rowS->Adults;
	$animals = $rowS->Animaux;
	$som = 0;
	$times = 1;

	$l = strlen('slot-labocb');
	foreach($GLOBALS as $glob) {
		if (substr($glob->name, 0, $l) == "slot-labocb") {  // we have one
			if ($glob->checked == true) {
				$extra_id = substr($glob->name, $l);
				$res = mysql_query("SELECT tarif, par, unite FROM supplement WHERE id = $extra_id");
				$row = mysql_fetch_object($res);													// lets analyse this one, we want an amount and #
																									// things per Time and Hour are not counted
																									// things per unit also (we dont know the # yet !
				if ($row->unite == "Stay" || $row->unite == "Week" || $row->unite == "Day") {
					$times = 1;
					if ($row->unite == "Week") $times = $times * $weeks;
					if ($row->unite == "Day") $times = $times * $days;
					if ($row->par == "Person") $times = $times * $persons;
					if ($row->par == "Animal") $times = $times * $animals;
					$total = $times * $row->tarif;
					$som = $som + $total;
				}
			}		
		varDump($glob->checked);
		}
	}
	$GLOBALS['slot.Autres']->setText($total);

...................... and a lot more here

That works good , BUT ........
The checked values I get for the other check boxes  are wrong.
Of course, I get the original values, not those that where changed by the user.

It's a bit difficult to work with friends here, plus that i am using JS to fire the routine.

The question is :
Is there a way (other then for instance : hold a local file (named $checknum, or something) with all the settings to
keep the check-boxes synchronized between the user and the server ??????

Actually, to eleborate that : Should there not be a way to have an option per widget to just keep it always sync'ed ?
Would eliminate the addFriends thing, and make the whole a lot simpler. You could (to reduce traffic a bit) only sync changed items...
And only for windows that have the focus....
Whatever, juts some thoughts.....


Kindest regards,
Steven


Steven Lobbezoo
[url=http://www.maisons-de-france.com]www.maisons-de-france.com[/url]

Offline

#2 2012-01-13 10:22:11

Steven
Member
From: Near Aix en Provence, France
Registered: 2011-07-19
Posts: 20
Website

Re: Checkboxes, problem

re-hi,

I solved my problem, if you are interested, I changed these lines :

    			$Doc_AA->addEvent('onchange','sendMsg('.$checknum.',"slot_calcule",eyeParam("value",document.getElementById("'. $myPid .'_slot-labocb'.$rowx->id.'").checked + "|'.$rowx->id.'"));');

To give a reference to the check-box to :

function gites_on_slot_calcule($params=null) {
	/**************************************************
	Here we do all the re-calculations when a field changes.
	we just do all the fields each time we are signalled
	**************************************************/
	$tmp = explode("|",$params['value'][0]); 
	$value = $tmp[0];
	$box = "slot-labocb".$tmp[1];
	if ($value == 'true') {
		$GLOBALS[$box]->check();
	} else {
		$GLOBALS[$box]->uncheck();
	}
	$slot_id = $GLOBALS['slot.No']->text;

etc etc....

It's not very nice, but it works good.

Steven


Steven Lobbezoo
[url=http://www.maisons-de-france.com]www.maisons-de-france.com[/url]

Offline

#3 2012-01-16 01:52:52

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: Checkboxes, problem

Hi Steven,

good to know that you've already found a solution.

Actually the friends system is a quite worse part of eyeos 1 / oneye 0.8, but we cannot simply get around it now, sorry sad ...


Best regards,
Lars Knickrehm

The oneye project.

Offline

Board footer

Powered by FluxBB