[SOLVED] Filter for FormBrowser with FEU and FormBuilder
- Rednes
- Forum Members
- Posts: 85
- Joined: Wed Apr 08, 2009 1:09 pm
- Location: Rotterdam, The Netherlands
[SOLVED] Filter for FormBrowser with FEU and FormBuilder
Using:
PHP: 5.2.8
CMS: 1.5.3
FormBuilder: 0.5.11
FormBrowser: 0.2.3
FrontEndUsers: 1.6.4
Firstly, I want to thank all the people spending there "free" time on these modules and I'm very happy with the vary of functionality made available.
Secondly (question),
Is there a way to give a "WHERE" condition to a formbrowser so I only see forms created by a certain user?
There is a "resp_id" stored in table "cms_module_fb_resp_val", so I checked the available tags at the help section of the module and found response_id. So I entered {cms_module module='FormBrowser' browser='My browser' response_id='$userid' } on the page where I want users to see their submitted forms. but it didn't work. I also tried some other stuff with tags, but still no luck.
I just started with CMSMS so I'm not to familiar with smarty & tags. If anyone could help in the right direction? would be awesome!!
Thx in advance!
edit: just realized that resp_id isn't the user id. I submit the userid threw a hidden field on each form. So each form has a userid.
PHP: 5.2.8
CMS: 1.5.3
FormBuilder: 0.5.11
FormBrowser: 0.2.3
FrontEndUsers: 1.6.4
Firstly, I want to thank all the people spending there "free" time on these modules and I'm very happy with the vary of functionality made available.
Secondly (question),
Is there a way to give a "WHERE" condition to a formbrowser so I only see forms created by a certain user?
There is a "resp_id" stored in table "cms_module_fb_resp_val", so I checked the available tags at the help section of the module and found response_id. So I entered {cms_module module='FormBrowser' browser='My browser' response_id='$userid' } on the page where I want users to see their submitted forms. but it didn't work. I also tried some other stuff with tags, but still no luck.
I just started with CMSMS so I'm not to familiar with smarty & tags. If anyone could help in the right direction? would be awesome!!
Thx in advance!
edit: just realized that resp_id isn't the user id. I submit the userid threw a hidden field on each form. So each form has a userid.
Last edited by Rednes on Tue Apr 14, 2009 7:05 am, edited 1 time in total.
- Rednes
- Forum Members
- Posts: 85
- Joined: Wed Apr 08, 2009 1:09 pm
- Location: Rotterdam, The Netherlands
Re: Filter for FormBrowser with FEU
Does anyone know how I could achieve this?
Please point me out in the right direction, because I wanna solve this and implement the functionality as clean as possible.
Do I need to make an UDT to filter out the row's?
Please point me out in the right direction, because I wanna solve this and implement the functionality as clean as possible.
Do I need to make an UDT to filter out the row's?
- Rednes
- Forum Members
- Posts: 85
- Joined: Wed Apr 08, 2009 1:09 pm
- Location: Rotterdam, The Netherlands
Re: Filter for FormBrowser with FEU
I found that table "cms_module_fb_resp" has a field feuser_id;
And that it is (not) being filled by "modules/FormBuilder/classes/Form.Class.php"
I guess it should look more like this:
$userid is now always 1, but I need it to be a dynamic value.
I think I have two options:
The first is to get the userid value from the form that is submitted.
The second is that I get it from some other place don't know where or how...maybe threw smarty?
And that it is (not) being filled by "modules/FormBuilder/classes/Form.Class.php"
Code: Select all
// saving a new response
$secret_code = substr(md5(session_id().'_'.time()),0,7);
$response_id = $db->GenID(cms_db_prefix(). 'module_fb_resp_seq');
$sql = 'INSERT INTO ' . cms_db_prefix().
'module_fb_resp (resp_id, form_id, submitted, secret_code)' .
' VALUES (?, ?, ?, ?)';
$res = $db->Execute($sql,
array($response_id,
$this->GetId(),
$this->clean_datetime($db->DBTimeStamp(time())),
$secret_code));
Code: Select all
// saving a new response
$userid = 1;
$secret_code = substr(md5(session_id().'_'.time()),0,7);
$response_id = $db->GenID(cms_db_prefix(). 'module_fb_resp_seq');
$sql = 'INSERT INTO ' . cms_db_prefix().
'module_fb_resp (resp_id, form_id, feuser_id, submitted, secret_code)' .
' VALUES (?, ?, ?, ?, ?)';
$res = $db->Execute($sql,
array($response_id,
$this->GetId(),
$userid,
$this->clean_datetime($db->DBTimeStamp(time())),
$secret_code));
I think I have two options:
The first is to get the userid value from the form that is submitted.
The second is that I get it from some other place don't know where or how...maybe threw smarty?
Last edited by Rednes on Sat Apr 11, 2009 2:57 pm, edited 1 time in total.
- Rednes
- Forum Members
- Posts: 85
- Joined: Wed Apr 08, 2009 1:09 pm
- Location: Rotterdam, The Netherlands
Re: Filter for FormBrowser with FEU
I managed to get the userid made by FEU inserted with every form. So my next step is to insert the filter somewhere.
code to insert userid for each form submitted. (modules/FormBuilder/classes/Form.class.php)
edit: made it alot cleaner
code to insert userid for each form submitted. (modules/FormBuilder/classes/Form.class.php)
Code: Select all
function StoreResponse($response_id=-1,$approver='')
{
$db = $this->module_ptr->dbHandle;
$fields = &$this->GetFields();
$secret_code = '';
$newrec = false;
if ($response_id == -1)
{
$newrec = true;
}
if ($newrec)
{
// saving a new response
//added code start
global $gCms;
$feusers = $gCms->modules['FrontEndUsers']['object'];
if( $feusers )
{
$uid = $feusers->LoggedInId();
}
//added code end
$secret_code = substr(md5(session_id().'_'.time()),0,7);
$response_id = $db->GenID(cms_db_prefix(). 'module_fb_resp_seq');
$sql = 'INSERT INTO ' . cms_db_prefix().
'module_fb_resp (resp_id, form_id, feuser_id, submitted, secret_code)' .
' VALUES (?, ?, ?, ?, ?)';
$res = $db->Execute($sql,
array($response_id,
$this->GetId(),
$uid,
$this->clean_datetime($db->DBTimeStamp(time())),
$secret_code));
edit: made it alot cleaner
Last edited by Rednes on Tue Apr 14, 2009 7:01 am, edited 1 time in total.
- Rednes
- Forum Members
- Posts: 85
- Joined: Wed Apr 08, 2009 1:09 pm
- Location: Rotterdam, The Netherlands
Re: Filter for FormBrowser with FEU
Could anyone enlighten me with the location of the piece of code where the rows for a browser are selected?
- Rednes
- Forum Members
- Posts: 85
- Joined: Wed Apr 08, 2009 1:09 pm
- Location: Rotterdam, The Netherlands
Re: Filter for FormBrowser with FEU
So I got the filter working, sad thing is that it doesn't use feuser_id from table module_fb_resp. It uses the userid submitted in the form.
This is what I did in the List template of a certain browser.
Before:
After:
So my initial question is solved...jeeh
note: {debug} made it happen!
This is what I did in the List template of a certain browser.
Before:
Code: Select all
{foreach from=$list item=entry}
<tr>
<td>{$entry->viewlink}</td>
<td>{$entry->submitted}</td>
{section name=vals start=0 loop=$count}
<td>{$entry->fields[$smarty.section.vals.index]}</td>
{/section}
{if $allow_user_edit}<td>{$entry->editlink}</td>{/if}
{if $allow_user_delete}<td>{$entry->deletelink}</td>{/if}
</tr>
{/foreach}
Code: Select all
{foreach from=$list item=entry}
{foreach from=$entry->fields item=bla}
{if $bla == $userid}
<tr>
<td>{$entry->viewlink}</td>
<td>{$entry->submitted}</td>
{section name=vals start=0 loop=$count}
<td>{$entry->fields[$smarty.section.vals.index]}</td>
{/section}
{if $allow_user_edit}<td>{$entry->editlink}</td>{/if}
{if $allow_user_delete}<td>{$entry->deletelink}</td>{/if}
</tr>
{/if}
{/foreach}
{/foreach}
note: {debug} made it happen!
Last edited by Rednes on Tue Apr 14, 2009 7:03 am, edited 1 time in total.
Re: [SOLVED] Filter for FormBrowser with FEU and FormBuilder
My task was to allow edit record only to FEU-author of the record. I thought `feuser_id`== NULL just for me so i included hidden flield 'user_id' as author's id to my form. Just 2 days after i had finished i came over this comment and decided to determine authorship of the record by `cms_module_fb_resp`.`feuser_id. I left that part which looks for userid among rescponce values, because it might by useful to separate some records from the rest.
So i edited
I inserted new line to modules/FormBuilder/FormBuilder.module.php function GetResponse after 305 line
to get formID I created UDT "get_form_id_by_browser_title"
UDT 'user_is_author' which returns value of specified field or feuser_id
and finally that is how Formbrowser list template looks like
I am not sure about the line "$temp = $fb_ob->GetFormByParams($paramSet, true);" in UDT 'user_is_author'. I wonder if sending params and receiving values in the same array is right way.
So i edited
Rednes wrote: (modules/FormBuilder/classes/Form.class.php)Code: Select all
<?php function StoreResponse($response_id=-1,$approver='') { $db = $this->module_ptr->dbHandle; $fields = &$this->GetFields(); $secret_code = ''; $newrec = false; if ($response_id == -1) { $newrec = true; } if ($newrec) { // saving a new response //added code start global $gCms; $feusers = $gCms->modules['FrontEndUsers']['object']; if( $feusers ) { $uid = $feusers->LoggedInId(); } //added code end $secret_code = substr(md5(session_id().'_'.time()),0,7); $response_id = $db->GenID(cms_db_prefix(). 'module_fb_resp_seq'); $sql = 'INSERT INTO ' . cms_db_prefix(). 'module_fb_resp (resp_id, form_id, feuser_id, submitted, secret_code)' . ' VALUES (?, ?, ?, ?, ?)'; //----------------------------------------------modified code------------------------------- $res = $db->Execute($sql, array($response_id, $this->GetId(), $uid, $this->clean_datetime($db->DBTimeStamp(time())), $secret_code)); ?>
I inserted new line to modules/FormBuilder/FormBuilder.module.php function GetResponse after 305 line
Code: Select all
<?php
if ($dbresult && $row = $dbresult->FetchRow())
{
$oneset->id = $row['resp_id'];
$oneset->feuser_id = $row['feuser_id'];/*----------------deviance-------------------------*/
$oneset->user_approved = (empty($row['user_approved'])?'':date($dateFmt,$db->UnixTimeStamp($row['user_approved'])));
$oneset->admin_approved = (empty($row['admin_approved'])?'':date($dateFmt,$db->UnixTimeStamp($row['admin_approved'])));
$oneset->submitted = date($dateFmt,$db->UnixTimeStamp($row['submitted']));
$oneset->fields = array();
$oneset->names = array();
}
?>
Code: Select all
<?php
/*$params['browser_title']* {$browser_title}*/
$return = false;
if (!empty( $params['browser_title'] )){
global $gCms;
$fbr_ob = $gCms->modules['FormBrowser']['object'];
$browsers = $fbr_ob->GetBrowsers();
if (!empty($browsers)){
foreach($browsers as $browser){
if ($browser['name'] == $params['browser_title'] ||
$browser['alias'] == $params['browser_title'] ){
$return = $browser['form_id'];
break;
}
}
}
}
return $return;
?>
Code: Select all
<?php
/*
$params['responce_id']*
$params['form_id']*
$params['name'] something like "fbrp__123". '123' is field_id the same as in FormBuilder (don't forget two '_')
where authors id is stored.
if $params['name'] is missing it will check whether 'feuser_id' was stored during submission
*/
$return = false;
if (!empty( $params['responce_id'] ) &&
!empty( $params['form_id'] ) ){
global $gCms;
$fb_ob = $gCms->modules['FormBuilder']['object'];
if ( !empty( $fb_ob )){
if(!empty($params['name'])){
$paramSet = array('form_id'=>$params['form_id'], 'response_id'=>$params['responce_id']);
$temp = $fb_ob->GetFormByParams($paramSet, true); /*----------------not sure if this is right way to get responce values, though it works------------*/
if (!empty( $paramSet )){
if (!empty( $params['name'] ) && !empty( $paramSet[$params['name']] )){
$return = $paramSet[$params['name']];
}
}
}
else{
$responce = $fb_ob->GetResponse($params['form_id'], $params['responce_id']);
if ( !empty( $responce->feuser_id ) ){
$return = $responce->feuser_id;
}
}
}
}
return $return;
?>
{$browser_title}
{if $message!=''}{$message}{/if}
{capture assign = 'fbrForm_id'}{get_form_id_by_browser_title browser_title = $browser_title}{/capture}
{if $fbrp_arr_searchfield != ""}
{$fbrp_startfbrsearchform}
{foreach from=$fbrp_arr_searchfield item=item}
{$item}:
{/foreach}
{$submitbutton}
{**}
{$fbrp_endfbrsearchform}
{/if}
{if $hasnav == 1}
{$prev} ({$pageof}) {$pagelinks} {$next}
{/if}
{$title_sort_submit_date}
{if $userapproval}{$title_user_approved}{/if}
{section name=namelist start=0 loop=$count}
{if $sortingnames[$smarty.section.namelist.index]}
{$sortingnames[$smarty.section.namelist.index]}
{/if}
{/section}
{if $allow_user_edit}{if $customcontent_loggedin}Edit{/if}{/if}
{if $allow_user_delete} {/if}
{foreach from=$list item=entry}
{$entry->viewlink}
{$entry->submitted}
{section name=vals start=0 loop=$count}
{if $entry->fields[$smarty.section.vals.index]}
{$entry->fields[$smarty.section.vals.index]}
{/if}
{/section}
{if $allow_user_edit && $customcontent_loggedin}
{capture assign='record_author'}{user_is_author form_id=$fbrForm_id responce_id=$entry->id name='fbrp__123'}{/capture}
{if $record_author == $customcontent_loggedin}
{$entry->editlink}
{/if}
{/if}
{if $allow_user_delete}{$entry->deletelink}{/if}
{/foreach}
{if $hasnav == 1}
{$prev} {$pagelinks} {$next}
{/if}
{if $allow_user_add}{$addlink}{$addresp}{/if}
I am not sure about the line "$temp = $fb_ob->GetFormByParams($paramSet, true);" in UDT 'user_is_author'. I wonder if sending params and receiving values in the same array is right way.
Re: [SOLVED] Filter for FormBrowser with FEU and FormBuilder
Hi,
I'm trying to do this.....get an FEU just to edit their own form from the form browser list. I did everything that was mentioned in the post, but it's not working.
The edit icon disappears. And when I select the delete icon, I get this error:
string(77) "Smarty error: unable to read resource: "module_db_tpl:FormBrowser;fbr_list_4""
Can someone post the exact files, UDTs and templates that need to be changed for this to work?
Thanks a bunch!
I'm trying to do this.....get an FEU just to edit their own form from the form browser list. I did everything that was mentioned in the post, but it's not working.
The edit icon disappears. And when I select the delete icon, I get this error:
string(77) "Smarty error: unable to read resource: "module_db_tpl:FormBrowser;fbr_list_4""
Can someone post the exact files, UDTs and templates that need to be changed for this to work?
Thanks a bunch!