Jump to content

Juergen

Members
  • Posts

    1,423
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Juergen

  1. Works perfect!!!!!! This is exactly the way that I want. Thanx. PDO is new to me - I have to take a look.
  2. Thanks Adrian, I included the code and it works. Yes you are right, this is not the "last visit", it is the current visit. Unfortunately the query doesnt output all logins of the user which are stored in the column "login_timestamp". So it is not possible to grab the second position "last visit".
  3. For everyone who also wants to use the Login history module from Teppo (http://modules.processwire.com/modules/process-login-history/), here is my attempt to make a sql query to output the date and time of the last visit on a frontend template. $query = $db->query("SELECT login_timestamp FROM process_login_history WHERE username='{$user->name}' AND login_was_successful=1 ORDER BY login_timestamp DESC"); $lastvisit = $query->fetch_row(); echo $lastvisit[0]; This will give you an output for the last successful login like this: 2015-05-08 16:40:59 It calls the table "process_login_history" from the module. The dates of the logins are stored in the column "login_timestamp". If the login was successful or not is stored in the column "login_was_successful" and has the value "1" for a successful login. The username is stored in the column "username". I dont know if the code is the best but it works. If someone has an improvement, please post it here. Best regards
  4. Adrian, thank you so much for your efforts. I havent seen that there is also a module available. This seems the best approach to me because it stores both (frontend and backend) logins. The other possibilities only show frontend logins. Thanks!!!!!
  5. I have tried the code above, but it always stores the date and time of the present login (the current date and time) and do not shows the last login date and time. The code is inside the user frontend profile template. $username = $user->name; wire()->addHookAfter("Session::login", function(HookEvent $event) { $person->of(false); $name = $event->arguments('$username'); $name = $this->wire('sanitizer')->username($username); $person = wire('users')->get($username); $last = $person->last_page_load; $person->last_page_load = date('Y-m-d H:i:s'); $person->save(); }); I have never worked with hooks and therefore its quite difficult to me to figure out. What I want to achieve: If a user logs out (or maybe logs in) then the date and time of the logout (or login) will be stored in a userfield called "last_page_load". If the user logs in the next time, the date and time of the last visit will be displayed in his user profile on the frontend.
  6. Sorry, I dont need to save the checkbox status after redirect, because the redirect only take place if the form has no errors. So all correct data will be submitted via the form and will be stored in the database before the redirect starts. No need to keep the checkbox state alive. [CLOSED]
  7. hello @ all, today I am struggeling with the following problem: I have a checkbox field in a frontend user profile form. <input name="delete" type="checkbox"> Delete profile image If the user clicks the checkbox the profile image will be deleted after submission. In the same form there is also a select drop down field for the language where the user can change his prefered language (German or English). After saving the user will be redirected to the english page with these lines of code. if ($newuserlanguage) {//if language has changed $languageurl = $page->localUrl($newuserlanguage); //get url for the new language $session->redirect($languageurl); //redirect to the new page } This piece of code will be executed POST after submitting the form and works as expected. The user will be redirected to the new page after submit. PROBLEM: The redirect leads to that the checkbox value is always empty - in other words the checkbox status (checked or unchecked) will not be stored if a redirect is present. If I remove the redirect code it will work as expected. I am not a PHP-Pro so I have no idea how I can fix this problem. Has anyone an idea how to handle checkboxes and redirects. I dont want to store values in a cookie if there could be another way. I have tried it to store it in a session but I cannot get it to work. Best regards Jürgen
  8. I found the solution: you have to include $user->userimage->removeAll(); // wirearray before this line of code $user->userimage = $upload_path . $files[0]; This removes the image array in a first step and then loads the new image in the database.
  9. But for what is the API call "setOverwrite(true)" ? It must be possible to overwrite the existing image by uploading a new image without deleting the old manually. In backend it works perfectly. Only one image is allowed: setMaxFiles(1) If I upload a new one then delete (overwrite) the old on and store the new: setOverwrite(true) This seems logical to me
  10. Oh thats new to me - Thanx for the hint
  11. hello @ all, I have tried to use a code that i found in the forum to make a single image upload on the frontend. The problem is that it stores multiple images instead of deleting the old and storing the new. My aim is to offer subscribers to add/change their profile image in the frontend. Here is the code that I use from the post that I have found: <?php $upload_path = $config->paths->assets . "files/avatar_uploads/"; $f = new WireUpload('userimage'); $f->setMaxFiles(1); $f->setMaxFileSize(1*1024*1024); $f->setOverwrite(true); $f->setDestinationPath($upload_path); $f->setValidExtensions(array('jpg', 'jpeg', 'png', 'gif')); if($input->post->form_submit) { if(!is_dir($upload_path)) { if(!wireMkdir($upload_path)) throw new WireException("No upload path!"); } $files = $f->execute(); if ($f->getErrors()) { foreach($files as $filename) @unlink($upload_path . $filename); foreach($f->getErrors() as $e) echo $e; } else { //$u = $users->get($user); //$u = $user->name; //Save the photo to the avatar field $user->of(false); $user->userimage->removeAll(); // wirearray (line added by @horst: explanation is three posts beneath) $user->userimage = $upload_path . $files[0]; $user->save(); $user->of(true); @unlink($upload_path . $files[0]); } } ?> <form class="forum-form" accept-charset="utf-8" action="./" method="post" enctype="multipart/form-data" > <input type="file" id="attach" name="userimage" accept="image/jpg,image/jpeg,image/gif,image/png" /> <input type="submit" name="form_submit" value="Submit"/> </form> $f->setMaxFiles(1); so it is set to 1 file $f->setOverwrite(true); so it should overwrite the existing image Every time I upload a new image it will be added instead of deleting the old. So I have more than one image displayed in the backend area. If I upload the image in the backend it works as expected. I use the latest dev version of PW. Has anyone an idea why MaxFiles and setOverwrite will be ignored? This ist the array output if I use var_dump: object(Pageimages)#729 (2) { ["count"]=> int(2) ["items"]=> array(2) { ["chrysanthemum.jpg"]=> string(17) "chrysanthemum.jpg" ["desert.jpg"]=> string(10) "desert.jpg" } } Best regards Jürgen
  12. Thanks Lostkobrakai this was a mistake, I am switching between Joomla and Processwire and therefore I wrote TinyMCE. I will check out the link you provided. Thanx
  13. Hello @ all I use the Tiny MCE editor and I want to remove some of the settings for the tables. The editor offers some attributes which are obsolent (f.e. width and height). It also offers to change the paddings or to show a border around the tables or to change the alignment. I want to disable all of them because customers are always irritated and I use CSS to make all the tables look like the same. Has someone dealed with the same problem and has found a way to disable this settings in the editor? Best regards Jürgen
  14. Today I had to output notes in a form at the frontend. This little code snippets show you how it can be done via the API: 1) One language site: $notesofmyfield = $page->fields->get("myfield")->notes; echo $notesofmyfield; 2) On a multilanguage site if ($user->language->name != 'default') { $notes = "notes{$user->language}"; } else { $notes = 'notes'; } $notesofmyfield = $page->fields->get("myfield")->$notes; echo $notesofmyfield; Happy coding!!
  15. I have changed the image settings from "auto" to "single element (null if empty)" and now it works. Thanks for your efforts
  16. $userimage = $user->userimage->first() and $userimage = $user->userimage return both the same array with var_dump: object(Pageimages)#656 (2) { ["count"]=> int(1) ["items"]=> array(1) { ["bewerbungklein-1.jpg"]=> string(20) "bewerbungklein-1.jpg" } } Strange behaviour because if the image is in a page template like $pageimage = $page->userimage this will work.
  17. Hello @ all, I added a profil image to the user template in the backend. Unfortunately I am not able to resize the image in frontend. $img = $image->size($x, $y) This function doesnt work for images which are stored in the user template. Here is the complete code $userimage = $user->userimage; if ($userimage){ $options = array( 'quality' => 90, 'upscaling' => false, 'cropping' => 'north' ); $img = $userimage->size(80, 100, $options); echo '<img src="'.$img.'"/> } I always got this error: Error: Exception: Method Pageimages::size does not exist or is not callable in this context (in /home/.sites/24/site1275/web/wire/core/Wire.php line 350) Imagefield setup: Number of allowed images = 1 Format = auto Is it not possible if I call an image from the user? Thanks for your answeres
  18. Yes that was the problem (Hint: This code is for multilingual site): You have to insert the following code to get the values in different languages: if ($user->language->name != 'default') { $title = "title{$user->language}"; $value = "value{$user->language}"; } else { $title = 'title'; $value = 'value'; } Then you can start to create the options for the select $storedgender = $user->YOUROPTIONFIELDNAME->id; $genderoptionstag = ""; //make select for gender options $genderoptions = $fieldtypes->get('FieldtypeOptions')->getOptions('YOUROPTIONFIELDNAME'); foreach($genderoptions as $option) { $genderid = $option->id; $gendervalue = $option->$value; $gendertitle = $option->$title; if ($storedgender == $genderid) { $genderstatus = " selected"; } else { $genderstatus = ""; } $genderoptionstag .= "<option$genderstatus value='$genderid'>$gendertitle</option>"; }; //here you can output the option tags wherever you want (in my case in the user frontend form) echo $genderoptionstag;
  19. Hello at all, I have added a select field with the option field type where the user can select the gender (mister or miss) to the user template. On the frontend the user has a profile page with a form where he can update his user data (if he/she is logged in). On the frontend form I call the gender option field in this way: //grab stored gender from DB $storedgender = $user->usergender; //make select for gender options $genderoptions = $fieldtypes->get('FieldtypeOptions')->getOptions('usergender'); foreach($genderoptions as $option) { $genderid = $option->id; $gendervalue = $option->$value; $gendertitle = $option->$title; $genderselected = ""; if ($storedgender == $genderid) { $genderstatus = " selected"; } $genderoptions .= "<option$genderselected value='$option->id'>$option->title</option>"; }; //here you can output the option tags wherever you want (in my case in the user frontend form) echo $genderoptions; This renders the output in the way that I want but..... Problem: The comparison between the stored user gender (e.g. mister with the value 1) and the genderstatus "selected" doesnt work and I dont know why $genderselected = ""; if ($storedgender == $genderid) { $genderstatus = " selected"; } //this kind of comparison doesnt set the selected status correctly It always put the status "selected" to the first option in the foreach statement independent of the stored user gender. I cant figure out what the problem could be ? Has anyone an idea? I've been trying for some time to find a solution, but I can not find one. Best regards Jürgen
  20. Why dont you check the image with an if statement? if($page->img){ $header_image = $page->img->size(800,250)->URL; } Or am I misunderstand your question?
  21. Its done: https://processwire.com/talk/topic/2074-module-page-edit-field-permission/page-2
  22. Be careful: break site if using with 2.5.25 in my case. Take a look at https://processwire.com/talk/topic/9565-upgrade-from-2524-to-2525-broke-the-site/#entry92025
  23. Thats true but it worked quite well until this update. Anyway! My recommendation: Be careful if you use this module with wire version 2.5.25 - it brokes the site in my case
  24. After uninstalling the PageEditPermission module the upgrade works as expected. I made the update and after that I reinstall the module once more. The error appear once more. I dont need this module at the moment, but this module causes the error. So it seems that it is not compatible with the latest version at the moment
  25. Hello Horst, I have looked into that before I have posted this topic, but I couldnt find the reason on line 8 and 69. <?php /** * Provides the implementation for the PageEditFieldPermission::getModuleConfigInputfields method * */ function PageEditFieldPermissionConfig(array $data) { $inputfields = new InputfieldWrapper(); $f = wire('modules')->get('InputfieldMarkup'); $f->label = 'How to use this module'; $f->attr('name', '_instructions'); $config = wire('config'); $f->value = <<< _OUT <p> To use, create a <a href='{$config->urls->admin}access/permissions/'>new permission</a> and name it <b>page-edit-[field]</b>, replacing [field] with the name of the field you want to limit access to. <em>Better yet, use the tool below to create them for you and save some time.</em> </p> <p> Once your page-edit-[field] permission(s) exist, <a href='{$config->urls->admin}access/roles/'>add them to any roles</a> that you want to have edit access to the field. Roles that have edit access to a page, but do not have the required page-edit-[field] permission will not be able to see or modify the [field] in the page editor. </p> <p>Note that none of this applies to users with the superuser role, as they always have access to edit everything.</p> _OUT; $createPermissions = wire('input')->post->_create_permissions; if($createPermissions) foreach($createPermissions as $name) { $name = wire('sanitizer')->pageName($name); $permission = wire('permissions')->add("page-edit-$name"); $permission->title = "Access to edit the '$name' field"; $permission->save(); wire('modules')->message("Added permission: $permission->name"); } $inputfields->add($f); $f = wire('modules')->get('InputfieldCheckboxes'); $f->attr('name', '_create_permissions'); $f->label = 'Handy tool to create permissions for you'; $f->optionColumns = 3; $f->description = 'Check the box next to each field name you would like this tool to create a permission for you. This is the same thing as going to the Permissions page and creating them yourself, so this is here primarily as a time saver.'; $fields = array('name', 'parent', 'template', 'status'); $notes = ''; foreach(wire('fields') as $field) $fields[] = $field->name; foreach($fields as $name) { if($name == 'pass') continue; if(wire('permissions')->get("page-edit-$name")->id) { $notes .= "$name, "; continue; } $f->addOption($name); } if(!$notes) $notes = "[none yet]"; $f->notes = "Fields that already have permissions: " . rtrim($notes, ", ") . ". " . "Non-superuser roles that have page-edit access will no longer be able to see/edit these fields unless the appropriate permission is assigned to that role. "; $inputfields->add($f); return $inputfields; } Line 8 is function PageEditFieldPermissionConfig(array $data) { and line 69 is the closing bracket at the end
×
×
  • Create New...