1
tdldp
Xoops Kernel / user.php functions.... Devs i need you ;)
  • 2004/2/2 9:05

  • tdldp

  • Just popping in

  • Posts: 9

  • Since: 2002/3/13


hi all,

Trying to understand how kernel / user.php works (i am having problems storing new fields on database in xoops_user tables)

I was wondering how the :

$this->initVar('Var_name', XOBJ_DTYPE_XXXXX, null, false);

worked...

I'd like to know what are the different XXXXX type accepted by XOOPS (Else the INT,TXTBOX,TXTAREA,OTHER)

My problem is the following. When storing departement data, i can have to store : 01, 02, 03, 04, 05, 06, 07, 08, 09, 2A, 2B in database. Yet these always appear like this in database :
1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 2

Everything goes on well until storage in database (hidden vars are correct) So i guess it comes from the :
$this->initVar('dept', XOBJ_DTYPE_INT, 0, false);
Thing. But if i modify it, (putting TXTBOX, or OTHER) i get suddenly blank page out of xoops...

What must i do ???
Thanls for you help
Tdldp

2
Mithrandir
Re: Xoops Kernel / user.php functions.... Devs i need you ;)

Turn on PHP debug and go to the page again and see if there comes an error.

The available types are:
XOBJ_DTYPE_TXTBOX
XOBJ_DTYPE_TXTAREA
XOBJ_DTYPE_INT
XOBJ_DTYPE_URL
XOBJ_DTYPE_EMAIL
XOBJ_DTYPE_ARRAY
XOBJ_DTYPE_OTHER
XOBJ_DTYPE_SOURCE
XOBJ_DTYPE_STIME
XOBJ_DTYPE_MTIME
XOBJ_DTYPE_LTIME

I'd say that TXTBOX was the correct one to choose for you. See if the PHP debug won't get you closer to the answer

3
tdldp
Re: Xoops Kernel / user.php functions.... Devs i need you ;)
  • 2004/2/4 8:16

  • tdldp

  • Just popping in

  • Posts: 9

  • Since: 2002/3/13


Thks for your answer mithrandir, i appreciated it and it help me a round... But here it goes :

turning on debug gave me this :

page register.php

Notice: Undefined variable: dept in /www/include/registerform.php on line 83

Notice: Undefined variable: type in /www/include/registerform.php on line 84

These lines correspond in registerform.php at :

$reg_form->addElement(new XoopsFormSelectDept(_US_DEPT, "dept", $dept));
$reg_form->addElement(new XoopsFormSelectType(_US_TYPECHASSE, "type", $type));

XoopsFormSelectDept and Type are 2 scripts of my composition which were inspired from FormSelectCountry :
here is coding :

[/quote]
/**
* lists of values
*/
include_once XOOPS_ROOT_PATH."/class/xoopslists.php";

/**
* Parent
*/
include_once XOOPS_ROOT_PATH."/class/xoopsform/formselect.php";

/**
* A select field with types
*
* @package kernel
* @subpackage form
*
* @author Tdldp
* @copyright
*/
class XoopsFormSelectDept extends XoopsFormSelect
{
/**
* Constructor
*
* @param string $caption Caption
* @param string $name "name" attribute
* @param mixed $value Pre-selected value (or array of them).
* Legal are all 2-letter country codes (in capitals).
* @param int $size Number or rows. "1" makes a drop-down-list
*/
function XoopsFormSelectDept($caption, $name, $value=null, $size=1)
{
$this->XoopsFormSelect($caption, $name, $value, $size);
$this->addOptionArray(XoopsLists::getDeptList());
}
}
[/quote]

here is extract from xoopslist corresponding at select list :
Quote:

function &getTypeList()
{
$type_list = array (
"1" => "Chasse Petit Gibier Sedentaire",
"2" => "Chasse du Grand Gibier",
"3" => "Chasse du Gibier d'eau",
"4" => "Chasse Petit Gibier Migrateur",
"5" => "Chasse à Courre",
"6" => "Chasse à L'arc",
);
asort($type_list);
reset($type_list);
return $type_list;
}

function &getDeptList()
{
$db =& Database::getInstance();
$myts =& MyTextSanitizer::getInstance();
$sql = "SELECT dept, intitule FROM ".$db->prefix("departements")." ORDER BY dept";
$result = $db->query($sql);
$dept_list = array();
while ( $myrow = $db->fetchArray($result) ) {
$dept_list[$myrow['dept']] = $myts->makeTboxData4Show($myrow['intitule']);
}
return $dept_list;
}


I have correcly defined these 2 files in Xoopsformloader :
include_once XOOPS_ROOT_PATH."/class/xoopsform/formselectType.php";
include_once XOOPS_ROOT_PATH."/class/xoopsform/formselectDept.php";

Finally in Kernel / User.php i added this :

$this->initVar('dept', XOBJ_DTYPE_INT, 0, false);

and lower :
function dept()
{
return $this->getVar("dept");
}

Not forgetting :

$sql = sprintf("INSERT INTO %s (uid, uname, name, email, url, user_avatar, user_regdate, user_icq, user_from, user_sig, user_viewemail, actkey, user_aim, user_yim, user_msnm, pass, posts, attachsig, rank, level, theme, timezone_offset, last_login, umode, uorder, notify_method, notify_mode, user_occ, bio, user_intrest, user_mailok, date, ip, prenom, dept, type, mailing, valide) VALUES (%u, %s, %s, %s, %s, %s, %u, %s, %s, %s, %u, %s, %s, %s, %s, %s, %u, %u, %u, %u, %s, %.2f, %u, %s, %u, %u, %u, %s, %s, %s, %u, %u, %u, %s, %u, %u, %u, %u)", $this->db->prefix('users'), $uid, $this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), time(), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail, $this->db->quoteString($actkey), $this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $this->db->quoteString($pass), $posts, $attachsig, $rank, $level, $this->db->quoteString($theme), $timezone_offset, 0, $this->db->quoteString($umode), $uorder, $notify_method, $notify_mode, $this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $user_mailok, $this->db->quoteString($date), $this->db->quoteString($ip), $this->db->quoteString($prenom), $dept, $type, $mailing, $valide);
} else {
$sql = sprintf("UPDATE %s SET uname = %s, name = %s, email = %s, url = %s, user_avatar = %s, user_icq = %s, user_from = %s, user_sig = %s, user_viewemail = %u, user_aim = %s, user_yim = %s, user_msnm = %s, posts = %d, pass = %s, attachsig = %u, rank = %u, level= %u, theme = %s, timezone_offset = %.2f, umode = %s, last_login = %u, uorder = %u, notify_method = %u, notify_mode = %u, user_occ = %s, bio = %s, user_intrest = %s, user_mailok = %u, date = %s, ip = %s, prenom = %s, dept = %s, type = %u, mailing = %u, valide = %u WHERE uid = %u", $this->db->prefix('users'), $this->db->quoteString($uname), $this->db->quoteString($name), $this->db->quoteString($email), $this->db->quoteString($url), $this->db->quoteString($user_avatar), $this->db->quoteString($user_icq), $this->db->quoteString($user_from), $this->db->quoteString($user_sig), $user_viewemail, $this->db->quoteString($user_aim), $this->db->quoteString($user_yim), $this->db->quoteString($user_msnm), $posts, $this->db->quoteString($pass), $attachsig, $rank, $level, $this->db->quoteString($theme), $timezone_offset, $this->db->quoteString($umode), $last_login, $uorder, $notify_method, $notify_mode, $this->db->quoteString($user_occ), $this->db->quoteString($bio), $this->db->quoteString($user_intrest), $user_mailok, $this->db->quoteString($date), $this->db->quoteString($ip), $this->db->quoteString($prenom), $dept, $type, $mailing, $valide, $uid);

As precised storage of $dept in database has attribute "Char(2)"

When switching to Dept to XobJ_Dtype_TXTBOX, i get no changes, that is to say departements are still stored under 1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 2 instead of 01, 02, 03, 04, 05, 06, 07, 08, 09, 2A, 2B...

When switching function dept to :
function dept($format="S")
{
return $this->getVar("dept", $format);
}

And sql insert and update to :
Insert ...dept...VALUES...%s....$this->db->quoteString($dept)...

Update ...SET...dept = %s...WHERE...$this->db->quoteString($dept)...

I get errors
Any idea on how solving this problem ???

Thks for any help
Tdldp

4
tdldp
Re: Strange did you say strange....
  • 2004/2/4 9:37

  • tdldp

  • Just popping in

  • Posts: 9

  • Since: 2002/3/13


I don't know what i did, but that f..... darn script finally works...

I do Get storage in the format desired...

But here i have a more general question...

Once stored 2A or anything else in database field dept, i can't retrieve information as soon as i have 2A or 2B (only 2 that i have btw) in my sql query:

SELECT * FROM `cef_users` WHERE dept = 2A;

although i can retrieve all information for any other departement : 02 , 44, etc... this one gives me following error :

#1054 - Unknown column '2A' in 'where clause'


An idea ???

Tdldp

5
Dave_L
Re: Strange did you say strange....
  • 2004/2/4 10:33

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


Strings need to be quoted:

SELECT FROM cef_users WHERE dept '2A';


The backticks (``) around the table name are unnecessary here. Backticks around identifiers are only needed when those names contain special characters (characters other than "_", "$" and those outside the set of alphanumeric characters from the current character set). Reference

6
tdldp
Re: Strange did you say strange....
  • 2004/2/4 21:29

  • tdldp

  • Just popping in

  • Posts: 9

  • Since: 2002/3/13


Tks a lot dave, indeed it was the problem with my scripting...

what a poor developper i make ;)

Tdldp

7
Mithrandir
Re: Strange did you say strange....

Practice makes perfect

Login

Who's Online

356 user(s) are online (294 user(s) are browsing Support Forums)


Members: 0


Guests: 356


more...

Donat-O-Meter

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

Latest GitHub Commits