Jump to content

ForgottenCat

Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by ForgottenCat

  1. Nevermind, i was stupid. Problem was html form formatting. solution: give each form a different id and submit id.
  2. Hi@all, i seem to have run myself in some kind of dead-end. I am trying to realize a local beverage-booking interface for some friends. Goal is to run it on a local server, and everyone with an account and access to the wifi can "buy" stuff. this part works just fine via $form = $modules->get("InputfieldForm"); and $user->wallet = $user->wallet - $cost; $user->setAndSave('wallet',$user->wallet); The Main interface will be a tablet, some kind of "Mainuser" (!=Admin), that has Access to "buy" all Stuff as any User. I added 2 extensions to the user template: a field to store the account balance and a profields:table to log all the interactions. I failed at 2 approches so far and will be thankfull for either a thrid approch or the correction of one of mine. 1st try: generate the same form for each user foreach ($users->find("roles=standart") as $guy){ code for form } then try to get the data to each individual user with if($form->getErrors()) { $out .= $form->render(); } else { $booking = $guy->user_log->makeBlankItem(); //create new row $page->of(false); // turn off cache creation $booking->date = date('D, d M Y H:i:s'); //create date and time of transaction $booking->guthaben_vor = $guthaben_vor; //log wallet before transaction $booking->guthaben_nach = $guthaben_nach; //log wallet after transaction $booking->preis = $preis/100; //log cost $booking->getrank = $getrank; //log name $guy->user_log->add($buchung); //apply log $guy->save('user_log'); //save log $guy->of(true); //reenable cache $out .= "<p>gebucht.</p>"; //success message $out .= "Guthaben: " . $guy->guthaben . "€"; //display actual wallet $out .= $form->render(); //redisplay the form. } When i dont try to append the data to the users logfile, this does somehow work, but it changes the value of the wallet (account balance) for every user by the desired amount. I dont really get why. 2nd attempt (stupid): just paste a bunch of hyperlinks, that call a specific template, that force-logins the specific user, waits for a booking/purcharse then loggs it off again and loggs in the "mainuser" (=Tablet). Problem: I need some kind of timeout to make sure, that the User is logged off after a set time (yet to be defined), and the "Mainuser" aka Tablet user is force-logged in afterwards. I could only find clues on how to define gernal login timeouts for all accounts or specific accounts by name (not dynamic so useless for me). Thats why i define this as a stupid workaround since all users would be logged off after some set time. Here is the pathetic Code i could write so far: <?php $out = ''; // create a new form $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'buchen'); //create new radio field (getränke) $field = $modules->get("InputfieldRadios"); //fieldtype $field->label = "Auswahl"; //label above $field->attr("id+name","auswahl"); //for callback foreach ($pages->get('/getranke/')->children as $getrank) { $field->addOption($getrank->preis*100 . "|!|" . $getrank->title, $getrank->title); //value, lable. value to decypher later on. preis in cents } $form->append($field); // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Buchen"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); // here is a good point for extra/custom validation and manipulate fields if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { $gebucht = explode("|!|",$form->get("auswahl")->value); //get string from choice $preis = intval($gebucht[0]); //get cost from choice $getrank = $gebucht[1]; // get name from choice $guthaben_vor = $user->guthaben; //get wallet before transaction $user->guthaben = $user->guthaben - $preis/100; //calculate new wallet $user->setAndSave('guthaben',$user->guthaben); //save current wallet $guthaben_nach = $user->guthaben; //set walalet after transaction //set logfile $buchung = $user->user_log->makeBlankItem(); //create new row $page->of(false); // turn off cache creation $buchung->date = date('D, d M Y H:i:s'); //create date and time of transaction $buchung->guthaben_vor = $guthaben_vor; //log wallet before transaction $buchung->guthaben_nach = $guthaben_nach; //log wallet after transaction $buchung->preis = $preis/100; //log cost $buchung->getrank = $getrank; //log name $buchung->menge = 1;//PLACEHOLDER FOR NOW $buchung->kommentar = 'Normale Buchung'; //log comment. PLACEHOLDER for now $user->user_log->add($buchung); //apply log $user->save('user_log'); //save log $page->of(true);//reenable cache $out .= "<p>gebucht.</p>"; //success message $out .= "Guthaben: " . $user->guthaben . "€"; //display actual wallet $out .= $form->render(); //redisplay the form. } } else { // render out form without processing $out .= $form->render(); } echo $out; ?> Got Problems with the same code copy-pasted and replacing $user with the foreach as $something. Best regards, Fox
  3. Perfect! i will try this asap and share the result. Thank you for the advice, but sadly i need to create tabs without limitation to the number of tabs. Thats why horizontal Tabs are no option imhoo, plus the tabs size will be +- 1/4 or 1/5 of the site.... php is more a try and error thing for me than real understanding as css is. Since i work with bootstrap, i wanted to keep it simple and let the responsive part up to bootstrap itself since i had bad experiences with putting someone elses or even my code inbetween -> php is the best option for me. anyways: thank you both for the quick replys (seems like the community is as awesome as PW itself )
  4. Hi there, I am new to processwire, but (after hating the new) i begun to love it after some hours of reding, missunderstanding leading to realizing the beauty and simplicity of the CMS. For my Project, i want to implement a left-Tabbed Navigation for some Items, but the Navigation Items will be bigger than normal. For that reason, i cannot simply make the left-tabbed nav a top-tabbed nav on mobile devices. I came up with the Idea to make it a accordion-like listing of the Items, where you would be clicking one item, then below it, the content of that item expands and so on. The HTML and CSS for that purpose is not the problem; the problem is: How can i define a "hook" to two different templates depending on the viewport of the current user? I am thinking of something like if viewport>720px {include('./workshops_desktop.php')}; else {include('./workshops_mobile.php')}; Since i am new, i could have missed one or more posts in this amazing board, if so please forgive me but give me the link to the thread helping me. Also excuse my language since i am no native speaker. Looking foreward for help in any way, Fox [ForgottenCat] PS: Because im new to PW, i use the newest version provided (did not have the time to let any version get old)
×
×
  • Create New...