88 return $this->
getVar($this->primary);
101 $this->_isNew =
false;
117 $this->_isDirty =
true;
121 $this->_isDirty =
false;
140 function initVar($key, $data_type, $value = null, $required =
false, $maxlength = null,
$options =
'')
142 if (isset($this->vars[$key]))
return;
143 $this->vars[$key] = array(
'value' => $value,
'required' => $required,
'data_type' => $data_type,
'maxlength' => $maxlength,
'changed' =>
false,
'options' =>
$options);
151 if (!isset($this->vars[$var]))
return false;
152 return $this->vars[$var][
'data_type'] =
$type;
160 if (!isset($this->vars[$var]))
return false;
161 return $this->vars[$var][
'maxlength'] = $len;
169 if (!isset($this->vars[$var]))
return false;
170 return $this->vars[$var][
'required'] = $required;
181 if (isset($value) && isset($this->vars[$key])) {
182 $this->vars[$key][
'value'] =& $value;
194 if (empty($var_arr))
return;
195 foreach ($var_arr as $key => $value) {
196 $this->
assignVar($key, stripslashes($value));
209 function setVar($key, $value, $not_gpc =
false)
211 if (!empty($key) && isset($value) && isset($this->vars[$key])) {
212 $this->vars[$key][
'value'] =& $value;
213 $this->vars[$key][
'not_gpc'] = $not_gpc;
214 $this->vars[$key][
'changed'] =
true;
228 foreach ($var_arr as $key => $value) {
229 $this->
setVar($key, $value, $not_gpc);
244 function setFormVars($var_arr=null, $pref=
'xo_', $not_gpc=
false) {
245 $len = strlen($pref);
246 foreach ($var_arr as $key => $value) {
247 if ($pref == substr($key,0,$len)) {
248 $this->
setVar(substr($key,$len), $value, $not_gpc);
261 public function getVars($formated =
false, $format =
's')
268 foreach ($this->vars as $key => $var){
283 function getValues( $keys = null, $format =
's', $maxDepth = 1 ) {
284 if ( !isset( $keys ) ) {
285 $keys = array_keys( $this->vars );
288 foreach ( $keys as $key ) {
289 if ( isset( $this->vars[$key] ) ) {
290 if ( is_object( $this->vars[$key] ) && is_a( $this->vars[$key],
'EXMObject' ) ) {
292 $vars[$key] = $this->vars[$key]->getValues( null, $format, $maxDepth - 1 );
311 $ret = $this->vars[$key][
'value'];
313 switch ($this->vars[$key][
'data_type']) {
315 case XOBJ_DTYPE_TXTBOX:
316 switch (strtolower($format)) {
322 return $ts->specialchars(
$ret);
329 return $ts->specialchars($ts->stripSlashesGPC(
$ret));
337 case XOBJ_DTYPE_TXTAREA:
338 switch (strtolower($format)) {
346 return $ts->specialchars($ts->stripslashes(
$ret));
351 $html = !empty($this->vars[
'dohtml'][
'value']) ? 1 : 0;
352 $xcode = (!isset($this->vars[
'doxcode'][
'value']) || $this->vars[
'doxcode'][
'value'] == 1) ? 1 : 0;
353 $smiley = (!isset($this->vars[
'dosmiley'][
'value']) || $this->vars[
'dosmiley'][
'value'] == 1) ? 1 : 0;
354 $image = (!isset($this->vars[
'doimage'][
'value']) || $this->vars[
'doimage'][
'value'] == 1) ? 1 : 0;
355 $br = (!isset($this->vars[
'dobr'][
'value']) || $this->vars[
'dobr'][
'value'] == 1) ? 1 : 0;
356 return $ts->previewTarea(
$ret, $html, $smiley, $xcode,
$image, $br);
361 return htmlspecialchars($ts->stripSlashesGPC(
$ret), ENT_QUOTES);
370 case XOBJ_DTYPE_ARRAY:
371 if (!is_array(
$ret) && trim(
$ret)!=
''){
377 case XOBJ_DTYPE_SOURCE:
378 switch (strtolower($format)) {
384 return htmlspecialchars(
$ret, ENT_QUOTES);
389 return $ts->stripSlashesGPC(
$ret);
394 return htmlspecialchars($ts->stripSlashesGPC(
$ret), ENT_QUOTES);
403 if ($this->vars[$key][
'options'] !=
'' &&
$ret !=
'') {
404 switch (strtolower($format)) {
407 $selected = explode(
'|',
$ret);
408 $options = explode(
'|', $this->vars[$key][
'options']);
412 if (in_array(
$i, $selected)) {
417 return implode(
', ',
$ret);
443 $this->_errors = array();
444 foreach ($this->vars as $k => $v) {
445 $cleanv = $v[
'value'];
446 if (!$v[
'changed']) {
448 $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv;
449 switch ($v[
'data_type']) {
450 case XOBJ_DTYPE_TXTBOX:
451 if ($v[
'required'] && $cleanv !=
'0' && $cleanv ==
'') {
452 $this->
setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
455 if (isset($v[
'maxlength']) && strlen($cleanv) > intval($v[
'maxlength'])) {
456 $this->
setErrors( sprintf( _XOBJ_ERR_SHORTERTHAN, $k, intval( $v[
'maxlength'] ) ) );
461 case XOBJ_DTYPE_TXTAREA:
462 if ($v[
'required'] && $cleanv !=
'0' && $cleanv ==
'') {
463 $this->
setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
469 case XOBJ_DTYPE_SOURCE:
473 $cleanv = intval($cleanv);
475 case XOBJ_DTYPE_EMAIL:
476 if ($v[
'required'] && $cleanv ==
'') {
477 $this->
setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
480 if ($cleanv !=
'' && !preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$cleanv)) {
487 if ($v[
'required'] && $cleanv ==
'') {
488 $this->
setErrors( sprintf( _XOBJ_ERR_REQUIRED, $k ) );
491 if ($cleanv !=
'' && !preg_match(
"/^http[s]*:\/\//i", $cleanv)) {
492 $cleanv =
'http://' . $cleanv;
496 case XOBJ_DTYPE_ARRAY:
497 $cleanv = !empty($cleanv) && is_array($cleanv) ? serialize($cleanv) : $cleanv;
499 case XOBJ_DTYPE_STIME:
500 case XOBJ_DTYPE_MTIME:
501 case XOBJ_DTYPE_LTIME:
502 $cleanv = !is_string($cleanv) ? intval($cleanv) : strtotime($cleanv);
512 if (count($this->_errors) > 0) {
513 $this->_errors = array_merge($existing_errors, $this->_errors);
516 $this->_errors = array_merge($existing_errors, $this->_errors);
525 foreach ($this->vars as $var){
528 $this->_isNew =
true;
529 $this->_errors = array();
530 $this->_filters = array();
541 $this->_filters[] = $filtername;
565 $class = get_class($this);
567 foreach ($this->vars as $k => $v) {
568 $clone->assignVar($k, $v[
'value']);
583 $this->_errors[] = trim($err_str);
594 return $this->
errors(
false);
605 return $this->errores(
true);
625 if (count($this->_errors)<=0){
return $html ?
'' : array(); }
629 $ret .=
"<div class='outer' style='padding: 1px;'>";
630 foreach ($this->_errors as $k){
631 $ret .=
"<div class='odd'>$k</div>";
648 if (isset($this->vars[$var])){
659 protected function logger($event,$style=
''){
661 $rtn[
'event'] = $event;
662 $rtn[
'style'] = $style;
663 $this->_log[] =
$rtn;
669 $this->_log = array();
685 foreach ($this->_log as $k){
686 $rtn .=
"<div style='padding: 2px;";
687 if ($k[
'style']!=
''){
688 if (stripos($k[
'style'],
'text-align:')==
''){
689 $rtn .=
' text-align: left;';
691 $rtn .=
' ' . $k[
'style'];
693 $rtn .=
"'>".(trim($k[
'event'])==
'' ?
' ' : $k[
'event']).
"</div>\n";
713 if (empty($this->_tblcolumns)){
714 $result = $this->db->queryF(
"SHOW COLUMNS IN ".$this->_dbtable);
715 while ($row = $this->db->fetchArray(
$result)){
716 if ($row[
'Extra'] ==
'auto_increment'){
717 $this->primary = $row[
'Field'];
720 $this->_tblcolumns[] = $row;
735 preg_match(
"/(.+)(\(([,0-9]+)\))/", $v[
'Type'], $efes);
736 if (!isset($efes[1])){
737 $efes[1] = $v[
'Type'];
749 $type = XOBJ_DTYPE_INT;
754 $type = XOBJ_DTYPE_FLOAT;
757 $type = XOBJ_DTYPE_TXTBOX;
761 $type = XOBJ_DTYPE_TXTBOX;
765 $type = XOBJ_DTYPE_TXTBOX;
769 $type = XOBJ_DTYPE_TXTBOX;
778 $type = XOBJ_DTYPE_TXTBOX;
779 $lon = isset($len[3]) ? $len[3] : null;
787 $type = XOBJ_DTYPE_TXTAREA;
791 $type = XOBJ_DTYPE_OTHER;
798 $this->
initVar($v[
'Field'],
$type, $v[
'Default'],
false, $lon);
810 if (get_magic_quotes_gpc())
813 $id = mysql_real_escape_string(
$id);
815 $sql =
"SELECT * FROM $this->_dbtable WHERE `$this->primary`='$id'";
817 if ($this->db->getRowsNum(
$result)<=0)
return false;
819 $row = $this->db->fetchArray(
$result);
820 foreach ($row as $k => $v){
832 if (get_magic_quotes_gpc())
833 $filter = stripslashes($filter);
835 $sql =
"SELECT * FROM $this->_dbtable WHERE $filter";
837 if ($this->db->getRowsNum(
$result)<=0)
return false;
839 $row = $this->db->fetchArray(
$result);
851 if (!is_array($values) || empty($values)){
858 foreach ($values as $k => $v){
859 if (get_magic_quotes_gpc())
860 $v = stripslashes($v);
861 $values[$k] = mysql_real_escape_string($v);
862 $query .= $query==
'' ?
"`$k`='$v'" :
" AND `$k`='$v'";
865 $sql =
"SELECT * FROM $this->_dbtable WHERE $query";
867 if ($this->db->getRowsNum(
$result)<=0)
return false;
869 $row = $this->db->fetchArray(
$result);
871 foreach ($row as $k => $v){
872 $this->
setVar($k, $myts->stripslashes($v));
885 $sql =
"INSERT INTO $this->_dbtable (";
888 foreach ($this->_tblcolumns as $k){
889 if ($k[
'Extra'] ==
'auto_increment')
continue;
890 $fields .= ($fields ==
'') ?
"`$k[Field]`" :
", `$k[Field]`";
891 $values .= ($values==
'') ?
"'".addslashes($this->
cleanVars[$k[
'Field']]).
"'" :
", '".addslashes($this->
cleanVars[$k[
'Field']]).
"'";
894 $sql .= $fields .
") VALUES (". $values .
")";
896 if (!$this->db->queryF(
$sql)){
897 $this->
addError($this->db->error());
900 $this->
setVar($this->primary, $this->db->getInsertId());
910 if (empty($this->_tblcolumns)) $this->
getColumns();
913 $sql =
"UPDATE $this->_dbtable SET ";
918 foreach ($this->_tblcolumns as $k){
919 if ($k[
'Extra'] ==
'auto_increment')
continue;
920 $fields .= $fields ==
'' ?
"`$k[Field]`='".addslashes($this->
cleanVars[$k[
'Field']]).
"'" :
", `$k[Field]`='".addslashes($this->
cleanVars[$k[
'Field']]).
"'";
923 $sql .= $fields .
" WHERE `$this->primary`='".$this->getVar($this->primary).
"'";
925 $this->db->queryF(
$sql);
926 if ($this->db->error()!=
''){
927 $this->
addError($this->db->error());
938 $sql =
"DELETE FROM $this->_dbtable WHERE `$this->primary`='".$this->getVar($this->primary).
"'";
939 $this->db->queryF(
$sql);
940 if ($this->db->error()!=
''){
941 $this->
addError($this->db->error());