1
mjoel
Xforms Module- show user their own data report
  • 2021/5/13 13:28

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Hello

In reference to this topic, im currently trying to show user their own data report

with my limited php/mysql knowledge, here's what i tried so far. The code will show data for the currently logged in user

im stucked in how to display the data value for $udata_value , it is stored something like a:1:{i:0;s:8:"YWRtaW4=";} in the database


<?php
include("../../mainfile.php");
include(
XOOPS_ROOT_PATH."/header.php");

$meta_keywords "WFH Report";
$meta_description "WFH Report";
$pagetitle "WFH Report";

if(isset(
$xoTheme) && is_object($xoTheme)) {
    
$xoTheme->addMeta'meta''keywords'$meta_keywords);
    
$xoTheme->addMeta'meta''description'$meta_description);
} else { 
    
$xoopsTpl->assign('xoops_meta_keywords'$meta_keywords);
    
$xoopsTpl->assign('xoops_meta_description'$meta_description);
}

$xoopsTpl->assign('xoops_pagetitle'$pagetitle);

//this will only work if your theme is using this smarty variables
$xoopsTpl->assign'xoops_showlblock'0); //set to 0 to hide left blocks
$xoopsTpl->assign'xoops_showrblock'0); //set to 0 to hide right blocks
$xoopsTpl->assign'xoops_showcblock'1); //set to 0 to hide center blocks
//$xoopsUser->isAdmin() or redirect_header('index.php', 3, _NOPERM);

global $xoopsUser
//get current user id  
$loggedinuid is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0;  

?>

<div class="container-fluid">
<div class="row">

    <h2>Work From Home Report</h2>

    <?php
 $getcaption
=$GLOBALS['xoopsDB']->query("SELECT 
  form.*, element.*
FROM "
.$GLOBALS['xoopsDB']->prefix("xforms_form")." AS form 
INNER JOIN "
.$GLOBALS['xoopsDB']->prefix("xforms_element")." as element 
ON form.form_id=element.form_id WHERE element.form_id=1 ORDER BY ele_order ASC "
);
            
            if (!
$getcaption) { 
    
trigger_error($GLOBALS['xoopsDB']->error()); 
}
?>

    <table id="report" class="table table-bordered" cellspacing="0">
        <thead>
        <tr>
          <th>User</th>
          <th>Date</th>
          <th>Ip Address</th>
<?php
        
while($row $GLOBALS['xoopsDB']->fetchArray($getcaption))
{
        
$ele_id=$row['ele_id'];
        
$ele_caption=$row['ele_caption'];
        echo 
"<th>$ele_caption ($ele_id)</th>";
        }
echo 
"</tr>";
        echo 
"</thead>
        <tbody>"
;
$getdata=$GLOBALS['xoopsDB']->query("SELECT D.uid, D.form_id, D.ele_id, D.udata_time, D.udata_ip, D.udata_value
                                , U.name, U.uname
                                , E.ele_type, E.ele_caption
                                FROM "
.$GLOBALS['xoopsDB']->prefix("xforms_userdata")." D
                                LEFT JOIN "
.$GLOBALS['xoopsDB']->prefix("users")." U ON (D.uid=U.uid)
                                INNER JOIN "
.$GLOBALS['xoopsDB']->prefix("xforms_element")." E ON (D.ele_id=E.ele_id)
                                WHERE D.form_id=1 AND D.uid='
$loggedinuid'
                                ORDER BY D.uid ASC, D.udata_time ASC, D.udata_ip ASC, E.ele_order ASC"
);

            if (!
$getdata) { 
    
trigger_error($GLOBALS['xoopsDB']->error()); 
}

        while(
$row $GLOBALS['xoopsDB']->fetchArray($getdata))
{
        
$uid=$row['uid'];
        
$uname=$row['uname'];
        
$udata_time2=date("Y-m-d"strval($row["udata_time"]));
        
$udata_ip=$row['udata_ip'];
        
$udata_value=$row['udata_value'];
    
echo 
"<tr>";
          echo 
"<td>$uname</td>
          <td>
$udata_time2</td>
          <td>
$udata_ip</td>
  <td>
$udata_value</td>
    </tr>"
;
          
}
    
?>    
        </tbody>
      </table>
</div></div>


<?php
include(XOOPS_ROOT_PATH."/footer.php");
?>

2
zyspec
Re: Xforms Module- show user their own data report
  • 2021/5/13 20:36

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


The best way to get this info is to use the class object handlers (in this case UserDataHandler. Once you use the handler you can get the userData object(s) and then perform a getVar on the udata_value.

The udata_value is stored as a serialized variable. The class does some 'sanity' checking when saving/retrieving the data to prevent errors. You could do the same checking as the UserData:;getVar() method does (make sure it's a serialized value, and unserialize it and then base64_decode the values) but it would be better to use the class methods "as intended".

You might look at the ./admin/reports.php to get an idea for how to set it up. Since you're doing this on the front side you'll want to look at ./index.php to make sure you include/use the classes you need to get everything setup.

If you post (or PM me) I can try and look over what you create but my time's limited for the next couple of weeks... If you post here maybe we can get others to 'chime in' and help along the way.

I'd start with:
use XmfFilterInput;
use 
XmfRequest;
use 
XoopsModulesXforms;
use 
XoopsModulesXformsConstants;
use 
XoopsModulesXformsUtility;

require 
__DIR__ '/header.php';
$myts   MyTextSanitizer::getInstance();

3
mjoel
Re: Xforms Module- show user their own data report
  • 2021/5/14 11:07

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Thanks again
im not a programmer and i tried to replicate in the front end, it is somehow working but with error and no page style

i've send you PM zyspec.

For future it would be better this feature to be integrate in this great module

Login

Who's Online

167 user(s) are online (88 user(s) are browsing Support Forums)


Members: 0


Guests: 167


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits