Advertisement
Guest User

Untitled

a guest
Nov 6th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.08 KB | None | 0 0
  1. <?php
  2.  
  3. class fields_process
  4. {
  5.     public $edit;
  6.     public $error;
  7.     public $info;
  8.     public $tmp;
  9.     public $obj_id;
  10.  
  11.     public function fields_process($type = "cf")
  12.     {
  13.         $this->type = $type;
  14.         if( $type == "uf" )
  15.         {
  16.             $this->table = TABLE_USER_FIELDS;
  17.             $this->type = "uf";
  18.         }
  19.         else
  20.         {
  21.             $this->table = TABLE_FIELDS;
  22.             $this->type = "cf";
  23.         }
  24.  
  25.         $this->edit = 0;
  26.         $this->tmp = array();
  27.         $this->error = array();
  28.         $this->obj_id = 0;
  29.     }
  30.  
  31.     public function setEdit($val)
  32.     {
  33.         $this->edit = $val;
  34.     }
  35.  
  36.     public function setId($val)
  37.     {
  38.         $this->obj_id = $val;
  39.     }
  40.  
  41.     public function getError()
  42.     {
  43.         return $this->error;
  44.     }
  45.  
  46.     public function addError($err_field, $err_text)
  47.     {
  48.         array_push($this->error, array( "field" => $err_field, "error" => $err_text ));
  49.     }
  50.  
  51.     public function getTmp()
  52.     {
  53.         return $this->tmp;
  54.     }
  55.  
  56.     public function check_form_fields($set)
  57.     {
  58.         global $default_fields_types;
  59.         $this->tmp = array();
  60.         if( $this->type == "cf" )
  61.         {
  62.             $cn = "base_listing_fields";
  63.             $extra = "fieldset";
  64.         }
  65.         else
  66.         {
  67.             $cn = "base_user_fields";
  68.             $extra = "group";
  69.         }
  70.  
  71.         $fields = common::getcachedobject($cn, array( "" . $extra => $set ));
  72.         $arr_users_nocheck = array();
  73.         global $is_admin;
  74.         global $is_mod;
  75.         if( $is_admin || $this->edit )
  76.         {
  77.             array_push($arr_users_nocheck, "terms");
  78.         }
  79.  
  80.         $fields_arr = array();
  81.         $no_fields = count($fields);
  82.         for( $i = 0; $i < $no_fields; $i++ )
  83.         {
  84.             if( in_array($fields[$i]["type"], $default_fields_types) )
  85.             {
  86.                 if( $this->type == "cf" )
  87.                 {
  88.                     array_push($fields_arr, $fields[$i]["caption"]);
  89.                 }
  90.  
  91.                 if( $this->edit && !$fields[$i]["editable"] && !$is_admin && !$is_mod )
  92.                 {
  93.                     continue;
  94.                 }
  95.  
  96.                 if( $this->type == "cf" || $this->type == "uf" && !in_array($fields[$i]["type"], $arr_users_nocheck) )
  97.                 {
  98.                     $this->validate_field($fields[$i]);
  99.                 }
  100.  
  101.             }
  102.             else
  103.             {
  104.                 global $modules_array;
  105.                 if( in_array($fields[$i]["type"], $modules_array) )
  106.                 {
  107.                     $custom_obj = new $fields[$i]["type"]();
  108.                     $ok = $custom_obj->check_form_fields($fields[$i], $this->tmp);
  109.                     if( !$ok )
  110.                     {
  111.                         $this->addError("" . $fields[$i] . "['caption']", $fields[$i]["error_message"]);
  112.                     }
  113.  
  114.                 }
  115.  
  116.             }
  117.  
  118.         }
  119.         if( $this->type == "cf" )
  120.         {
  121.             global $config_abs_path;
  122.             require_once($config_abs_path . "/classes/rules.php");
  123.             $rs = new rules();
  124.             $rs->verifyRules($fields_arr);
  125.             $err_arr = $rs->getFieldError();
  126.             if( $err_arr )
  127.             {
  128.                 $this->addError($err_arr[0]["field"], $err_arr[0]["error"]);
  129.             }
  130.  
  131.         }
  132.  
  133.         return 1;
  134.     }
  135.  
  136.     public function validate_field($field)
  137.     {
  138.         global $db;
  139.         $caption = $field["caption"];
  140.         $type = $field["type"];
  141.         $error = $field["error_message"];
  142.         $error2 = $field["error_message2"];
  143.         $validation_type = $field["validation_type"];
  144.         $min = $field["min"];
  145.         $max = $field["max"];
  146.         $required = $field["required"];
  147.         $unique = $field["unique"];
  148.         $editable = $field["editable"];
  149.         $extensions = $field["extensions"];
  150.         $max_uploaded_size = $field["max_uploaded_size"] * 1000;
  151.         $image_resize = $field["image_resize"];
  152.         $date_format = $field["date_format"];
  153.         if( $field["is_numeric"] && !$validation_type )
  154.         {
  155.             $validation_type = "numeric";
  156.         }
  157.  
  158.         $set = 0;
  159.         $val = "";
  160.         switch( $type )
  161.         {
  162.             case "depending":
  163.                 $no_fields = $field["depending"]["no"];
  164.                 for( $nf = 1; $nf <= $no_fields; $nf++ )
  165.                 {
  166.                     $caption = $field["depending"]["caption" . $nf];
  167.                     $required = $field["depending"]["required" . $nf];
  168.                     if( $required == 1 && (!isset($_POST[$caption]) || !$_POST[$caption]) )
  169.                     {
  170.                         $err = 1;
  171.                         $this->addError($caption, $field["depending"]["error_message" . $nf]);
  172.                     }
  173.  
  174.                     if( isset($_POST[$caption]) )
  175.                     {
  176.                         if( $field["other_val"] && $_POST[$caption] == "-1" )
  177.                         {
  178.                             $this->tmp[$caption] = cleanStr($_POST[$caption . "_other_val"]);
  179.                         }
  180.                         else
  181.                         {
  182.                             $this->tmp[$caption] = cleanStr($_POST[$caption]);
  183.                         }
  184.  
  185.                     }
  186.  
  187.                 }
  188.                 $this->tmp["dep_id"] = $field["depending"]["id"];
  189.                 $set = 1;
  190.                 return NULL;
  191.             case "checkbox":
  192.                 $val = checkbox_value($caption);
  193.                 $set = 1;
  194.                 break;
  195.             case "checkbox_group":
  196.                 $elements = explode("|", trim($field["elements"]));
  197.                 $val = array();
  198.                 $k = 0;
  199.                 $n = 0;
  200.                 foreach( $elements as $el )
  201.                 {
  202.                     $el = trim($el);
  203.                     $check_caption = $caption . "_" . $n;
  204.                     if( isset($_POST[$check_caption]) && $_POST[$check_caption] == "on" )
  205.                     {
  206.                         $val[$k] = $el;
  207.                         $k++;
  208.                     }
  209.  
  210.                     $n++;
  211.                 }
  212.                 $set = 1;
  213.                 break;
  214.             case "multiselect":
  215.                 $val = array();
  216.                 for( $k = 0; isset($_POST[$caption][$k]) && ($f = $_POST[$caption][$k]); $k++ )
  217.                 {
  218.                     $val[$k] = $f;
  219.                 }
  220.                 $set = 1;
  221.                 break;
  222.             case "file":
  223.                 if( isset($_FILES[$caption]["name"]) )
  224.                 {
  225.                     $val = $_FILES[$caption]["name"];
  226.                 }
  227.                 else
  228.                 {
  229.                     $val = "";
  230.                 }
  231.  
  232.                 $validation_type = "file";
  233.                 $set = 1;
  234.                 break;
  235.             case "image":
  236.                 if( isset($_FILES[$caption]["name"]) )
  237.                 {
  238.                     $val = $_FILES[$caption]["name"];
  239.                 }
  240.                 else
  241.                 {
  242.                     $val = "";
  243.                 }
  244.  
  245.                 $validation_type = "image";
  246.                 $set = 1;
  247.                 break;
  248.             case "youtube":
  249.                 $validation_type = "youtube";
  250.                 if( isset($_POST[$caption]) )
  251.                 {
  252.                     $val = cleanStr($_POST[$caption]);
  253.                 }
  254.                 else
  255.                 {
  256.                     $val = "";
  257.                 }
  258.  
  259.                 $set = 1;
  260.                 break;
  261.             case "google_maps":
  262.                 $validation_type = "google_maps";
  263.                 if( isset($_POST[$caption]) )
  264.                 {
  265.                     $val = cleanStr($_POST[$caption]);
  266.                 }
  267.                 else
  268.                 {
  269.                     $val = "";
  270.                 }
  271.  
  272.                 $set = 1;
  273.                 break;
  274.             case "menu":
  275.                 if( $field["other_val"] )
  276.                 {
  277.                     if( isset($_POST[$caption]) )
  278.                     {
  279.                         if( $_POST[$caption] == "-1" )
  280.                         {
  281.                             $val = cleanStr($_POST[$caption . "_other_val"]);
  282.                         }
  283.                         else
  284.                         {
  285.                             $val = cleanStr($_POST[$caption]);
  286.                         }
  287.  
  288.                     }
  289.                     else
  290.                     {
  291.                         $val = "";
  292.                     }
  293.  
  294.                 }
  295.                 else
  296.                 {
  297.                     $val = cleanStr($_POST[$caption]);
  298.                 }
  299.  
  300.                 $set = 1;
  301.                 break;
  302.             case "date":
  303.                 if( isset($_POST[$caption . "_vis"]) )
  304.                 {
  305.                     $this->tmp["vis"][$caption] = $_POST[$caption . "_vis"];
  306.                 }
  307.                 else
  308.                 {
  309.                     $this->tmp["vis"][$caption] = "";
  310.                 }
  311.  
  312.                 $set = 1;
  313.                 break;
  314.             default:
  315.                 break;
  316.         }
  317.         if( $type == "email" )
  318.         {
  319.             $validation_type = "email";
  320.         }
  321.  
  322.         if( $type == "url" )
  323.         {
  324.             $validation_type = "url";
  325.         }
  326.  
  327.         if( $type == "price" )
  328.         {
  329.             $validation_type = "price";
  330.         }
  331.  
  332.         if( !$set )
  333.         {
  334.             if( isset($_POST[$caption]) )
  335.             {
  336.                 $val = cleanStr($_POST[$caption]);
  337.             }
  338.             else
  339.             {
  340.                 $val = "";
  341.             }
  342.  
  343.         }
  344.  
  345.         $this->tmp[$caption] = $val;
  346.         $err = 0;
  347.         if( !$val )
  348.         {
  349.             if( $required == 1 && $type != "file" && $type != "image" )
  350.             {
  351.                 $err = 1;
  352.             }
  353.  
  354.             if( $required == 1 && ($type == "file" || $type == "image") && !$this->edit )
  355.             {
  356.                 $err = 1;
  357.             }
  358.  
  359.         }
  360.         else
  361.         {
  362.             $set = 0;
  363.             if( $validation_type != "" && $val )
  364.             {
  365.                 switch( $validation_type )
  366.                 {
  367.                     case "alpha":
  368.                         if( !validator::valid_alpha($val) )
  369.                         {
  370.                             $err = 1;
  371.                         }
  372.  
  373.                         break;
  374.                     case "alphanum":
  375.                         if( !validator::valid_alphanum($val) )
  376.                         {
  377.                             $err = 1;
  378.                         }
  379.  
  380.                         break;
  381.                     case "digit":
  382.                         if( !validator::valid_digit($val) )
  383.                         {
  384.                             $err = 1;
  385.                         }
  386.  
  387.                         break;
  388.                     case "numeric":
  389.                         if( !validator::valid_numeric($val) )
  390.                         {
  391.                             $err = 1;
  392.                         }
  393.  
  394.                         break;
  395.                     case "price":
  396.                         if( !validator::valid_price($val) )
  397.                         {
  398.                             $err = 1;
  399.                         }
  400.  
  401.                         break;
  402.                     case "email":
  403.                         if( !validator::valid_email($val) )
  404.                         {
  405.                             $err = 1;
  406.                         }
  407.  
  408.                         if( $caption == "mgm_email" )
  409.                         {
  410.                             global $config_abs_path;
  411.                             require_once($config_abs_path . "/classes/blocked_emails.php");
  412.                             if( blocked_emails::isblocked(escape($val)) )
  413.                             {
  414.                                 global $lng;
  415.                                 $this->addError($caption, $lng["users"]["errors"]["email_not_permitted"]);
  416.                             }
  417.  
  418.                         }
  419.  
  420.                         break;
  421.                     case "url":
  422.                         if( !validator::valid_url($val) )
  423.                         {
  424.                             $err = 1;
  425.                         }
  426.  
  427.                         break;
  428.                     case "file":
  429.                         if( !$this->valid_file($caption, $extensions, $max_uploaded_size) )
  430.                         {
  431.                             $err = 1;
  432.                         }
  433.  
  434.                         break;
  435.                     case "image":
  436.                         global $config_abs_path;
  437.                         require_once($config_abs_path . "/classes/images.php");
  438.                         $dir = $config_abs_path . "/uploads/" . $caption;
  439.                         $img = new image($caption, $dir, "fields");
  440.                         $img->setMaxSize($max_uploaded_size);
  441.                         if( !$img->verify() )
  442.                         {
  443.                             $err = 1;
  444.                             $error .= " : " . $img->getError();
  445.                         }
  446.  
  447.                         break;
  448.                     case "youtube":
  449.                         if( !validator::valid_youtube($val) )
  450.                         {
  451.                             $err = 1;
  452.                         }
  453.  
  454.                         break;
  455.                     case "google_maps":
  456.                         if( !validator::valid_gmaps($val) )
  457.                         {
  458.                             $err = 1;
  459.                         }
  460.  
  461.                         break;
  462.                     default:
  463.                         if( $validation_type != "" && !validator::valid_pcre($val, $validation_type) )
  464.                         {
  465.                             $err = 1;
  466.                         }
  467.  
  468.                         break;
  469.                 }
  470.             }
  471.  
  472.             if( $type == "date" )
  473.             {
  474.             }
  475.  
  476.             if( 0 < $min )
  477.             {
  478.                 if( $type == "multiselect" || $type == "checkbox_group" )
  479.                 {
  480.                     if( count($val) < $min )
  481.                     {
  482.                         $err = 1;
  483.                     }
  484.  
  485.                 }
  486.                 else
  487.                 {
  488.                     if( strlen($val) < $min )
  489.                     {
  490.                         $err = 1;
  491.                     }
  492.  
  493.                 }
  494.  
  495.             }
  496.  
  497.             if( 0 < $max )
  498.             {
  499.                 if( $type == "multiselect" || $type == "checkbox_group" )
  500.                 {
  501.                     if( $max < count($val) )
  502.                     {
  503.                         $err = 1;
  504.                     }
  505.  
  506.                 }
  507.                 else
  508.                 {
  509.                     if( $max < strlen($val) )
  510.                     {
  511.                         $err = 1;
  512.                     }
  513.  
  514.                 }
  515.  
  516.             }
  517.  
  518.         }
  519.  
  520.         if( $err && $error )
  521.         {
  522.             $this->addError($caption, $error);
  523.         }
  524.  
  525.         if( $unique && !$this->validateUniqueField($caption) )
  526.         {
  527.             $this->addError($caption, $error2);
  528.         }
  529.  
  530.     }
  531.  
  532.     public function valid_file($caption, $extensions, $max_size)
  533.     {
  534.         global $config_abs_path;
  535.         global $lng;
  536.         $dir = $config_abs_path . "/uploads/" . $caption;
  537.         if( !isset($_FILES[$caption]) )
  538.         {
  539.             return 0;
  540.         }
  541.  
  542.         if( !is_dir($dir) || !is_writeable($dir) )
  543.         {
  544.             $this->addError($caption, $lng["images"]["errors"]["folder_not_writeable"]);
  545.             return 0;
  546.         }
  547.  
  548.         $extension = getExtension($_FILES[$caption]["name"]);
  549.         $blocked_extensions = array( "php", "js", "php4", "php5", "pl", "cgi", "rb" );
  550.         if( in_array($extension, $blocked_extensions) )
  551.         {
  552.             return 0;
  553.         }
  554.  
  555.         if( $extensions )
  556.         {
  557.             $extensions = trim($extensions, ",");
  558.             $extensions_array = explode(",", $extensions);
  559.             if( !in_array($extension, $extensions_array) )
  560.             {
  561.                 return 0;
  562.             }
  563.  
  564.         }
  565.  
  566.         $size = filesize($_FILES[$caption]["tmp_name"]);
  567.         if( $max_size * 1000 < $size )
  568.         {
  569.             return 0;
  570.         }
  571.  
  572.         return 1;
  573.     }
  574.  
  575.     public function add_fields($set, $array_format = 0)
  576.     {
  577.         global $db;
  578.         global $default_fields_types;
  579.         if( !$array_format )
  580.         {
  581.             $sql = "";
  582.         }
  583.         else
  584.         {
  585.             $return_array = array();
  586.         }
  587.  
  588.         if( $this->type == "cf" )
  589.         {
  590.             $cn = "base_listing_fields";
  591.             $extra = "fieldset";
  592.         }
  593.         else
  594.         {
  595.             $cn = "base_user_fields";
  596.             $extra = "group";
  597.         }
  598.  
  599.         $fields = common::getcachedobject($cn, array( "" . $extra => $set ));
  600.         $no_fields = count($fields);
  601.         global $is_admin;
  602.         global $is_mod;
  603.         for( $i = 0; $i < $no_fields; $i++ )
  604.         {
  605.             if( $this->type == "cf" )
  606.             {
  607.                 $fieldset = $fields[$i]["fieldset"];
  608.                 if( $fieldset != 0 && $fields[$i]["type"] != "price" )
  609.                 {
  610.                     $fset_array = explode(",", $fieldset);
  611.                     if( !in_array($set, $fset_array) )
  612.                     {
  613.                         continue;
  614.                     }
  615.  
  616.                 }
  617.  
  618.             }
  619.  
  620.             $field_val = "";
  621.             $field_type = $fields[$i]["type"];
  622.             if( $field_type == "terms" )
  623.             {
  624.                 continue;
  625.             }
  626.  
  627.             $validation = $fields[$i]["validation_type"];
  628.             if( $this->type == "cf" && $field_type == "price" )
  629.             {
  630.                 $validation = "price";
  631.             }
  632.  
  633.             if( $this->type == "uf" && ($field_type == "username" || $field_type == "password" || $field_type == "user_email" && $set != 0 - 1) )
  634.             {
  635.                 continue;
  636.             }
  637.  
  638.             if( !in_array($fields[$i]["type"], $default_fields_types) )
  639.             {
  640.                 global $modules_array;
  641.                 if( in_array($field_type, $modules_array) )
  642.                 {
  643.                     $custom_obj = new $field_type();
  644.                     $sql_mod = $custom_obj->add_fields();
  645.                     $sql .= $sql_mod;
  646.                     continue;
  647.                 }
  648.  
  649.             }
  650.  
  651.             if( !$is_admin && !$is_mod && $this->edit == 1 && $fields[$i]["editable"] == 0 )
  652.             {
  653.                 continue;
  654.             }
  655.  
  656.             if( $field_type == "depending" )
  657.             {
  658.                 $no_fs = $fields[$i]["depending"]["no"];
  659.                 for( $nf = 1; $nf <= $no_fs; $nf++ )
  660.                 {
  661.                     $caption = $fields[$i]["depending"]["caption" . $nf];
  662.                     if( isset($_POST[$caption]) && $_POST[$caption] )
  663.                     {
  664.                         if( $fields[$i]["other_val"] == 1 && $_POST[$caption] == "-1" )
  665.                         {
  666.                             $field_val = escape($_POST[$caption . "_other_val"]);
  667.                         }
  668.                         else
  669.                         {
  670.                             $field_val = escape($_POST[$caption]);
  671.                         }
  672.  
  673.                     }
  674.                     else
  675.                     {
  676.                         $field_val = "";
  677.                     }
  678.  
  679.                     if( !$array_format )
  680.                     {
  681.                         if( $field_val )
  682.                         {
  683.                             $sql .= "" . ", `" . $caption . "` = '" . $field_val . "'";
  684.                         }
  685.                         else
  686.                         {
  687.                             $sql .= "" . ", `" . $caption . "` = null";
  688.                         }
  689.  
  690.                     }
  691.                     else
  692.                     {
  693.                         $return_array[$caption] = $field_val;
  694.                     }
  695.  
  696.                 }
  697.             }
  698.             else
  699.             {
  700.                 $caption = $fields[$i]["caption"];
  701.                 if( $field_type == "checkbox" )
  702.                 {
  703.                     if( isset($_POST[$caption]) && $_POST[$caption] == "on" )
  704.                     {
  705.                         $field_val = 1;
  706.                     }
  707.                     else
  708.                     {
  709.                         $field_val = 0;
  710.                     }
  711.  
  712.                 }
  713.                 else
  714.                 {
  715.                     if( $field_type == "checkbox_group" )
  716.                     {
  717.                         $field_val = "";
  718.                         $j = 0;
  719.                         foreach( $fields[$i]["extra_elements_array"] as $element )
  720.                         {
  721.                             if( isset($_POST[$element["input_name"]]) && $_POST[$element["input_name"]] == "on" )
  722.                             {
  723.                                 if( $j )
  724.                                 {
  725.                                     $field_val .= "|";
  726.                                 }
  727.  
  728.                                 $field_val .= $element["name"];
  729.                                 $j++;
  730.                             }
  731.  
  732.                         }
  733.                         $field_val = escape($field_val);
  734.                     }
  735.                     else
  736.                     {
  737.                         if( $field_type == "multiselect" )
  738.                         {
  739.                             $field_val = "";
  740.                             for( $k = 0; isset($_POST[$caption][$k]) && ($fk = $_POST[$caption][$k]); $k++ )
  741.                             {
  742.                                 if( $k )
  743.                                 {
  744.                                     $field_val .= "|";
  745.                                 }
  746.  
  747.                                 $field_val .= $fk;
  748.                             }
  749.                             $field_val = escape($field_val);
  750.                         }
  751.                         else
  752.                         {
  753.                             if( $field_type == "file" )
  754.                             {
  755.                                 if( isset($_FILES[$caption]["name"]) && $_FILES[$caption]["name"] )
  756.                                 {
  757.                                     global $config_abs_path;
  758.                                     $dir = $config_abs_path . "/uploads/" . $caption . "/";
  759.                                     $extension = getExtension($_FILES[$caption]["name"]);
  760.                                     $newname = $caption . "-" . time() . "." . $extension;
  761.                                     move_uploaded_file($_FILES[$caption]["tmp_name"], $dir . $newname);
  762.                                     $field_val = $newname;
  763.                                 }
  764.                                 else
  765.                                 {
  766.                                     $field_val = "";
  767.                                 }
  768.  
  769.                             }
  770.                             else
  771.                             {
  772.                                 if( $field_type == "image" )
  773.                                 {
  774.                                     if( isset($_FILES[$caption]["name"]) && $_FILES[$caption]["name"] )
  775.                                     {
  776.                                         global $config_abs_path;
  777.                                         $dir = $config_abs_path . "/uploads/" . $caption;
  778.                                         $img = new image($caption, $dir, "fields");
  779.                                         $img->setMaxSize($fields[$i]["max_uploaded_size"]);
  780.                                         $img->setGenerate($caption);
  781.                                         $img->verify();
  782.                                         if( !$fields[$i]["image_resize"] )
  783.                                         {
  784.                                             if( $img->upload() )
  785.                                             {
  786.                                                 $field_val = $img->getUploadedFile();
  787.                                             }
  788.  
  789.                                         }
  790.                                         else
  791.                                         {
  792.                                             $fields[$i]["image_resize"] = str_replace("x", "X", $fields[$i]["image_resize"]);
  793.                                             $arr_size = explode("X", $fields[$i]["image_resize"]);
  794.                                             $img->setThmbWidth($arr_size[0]);
  795.                                             $img->setThmbHeight($arr_size[1]);
  796.                                             if( $img->makeThumb($dir) )
  797.                                             {
  798.                                                 $field_val = $img->getUploadedFile();
  799.                                             }
  800.  
  801.                                         }
  802.  
  803.                                     }
  804.                                     else
  805.                                     {
  806.                                         $field_val = "";
  807.                                     }
  808.  
  809.                                 }
  810.                                 else
  811.                                 {
  812.                                     if( isset($_POST[$caption]) )
  813.                                     {
  814.                                         $field_val = escape($_POST[$caption]);
  815.                                         if( $field_type == "menu" && $fields[$i]["other_val"] == 1 && $field_val == "-1" )
  816.                                         {
  817.                                             $field_val = escape($_POST[$caption . "_other_val"]);
  818.                                         }
  819.  
  820.                                         if( $field_type == "youtube" && !strstr($field_val, " wmode=\\\"transparent\\\"") )
  821.                                         {
  822.                                             $field_val = str_replace("></embed>", " wmode=\\\"transparent\\\"></embed>", $field_val);
  823.                                         }
  824.  
  825.                                         if( $field_type == "textarea" || $field_type == "htmlarea" )
  826.                                         {
  827.                                             $field_val = str_replace("\n", "\n<br />", escapeHtml($field_val));
  828.                                         }
  829.  
  830.                                         if( $field_type == "textbox" )
  831.                                         {
  832.                                             $field_val = escapeHtml($field_val);
  833.                                         }
  834.  
  835.                                         if( $field_type == "phone" )
  836.                                         {
  837.                                             if( $fields[$i]["ext1"] == 1 )
  838.                                             {
  839.                                                 $field_val = escape($_POST[$caption . "_hidden"]);
  840.                                             }
  841.  
  842.                                             $field_val = escapeHtml($field_val);
  843.                                         }
  844.  
  845.                                     }
  846.                                     else
  847.                                     {
  848.                                         $field_val = "";
  849.                                     }
  850.  
  851.                                 }
  852.  
  853.                             }
  854.  
  855.                         }
  856.  
  857.                     }
  858.  
  859.                 }
  860.  
  861.                 if( $validation == "url" || $field_type == "url" )
  862.                 {
  863.                     $field_val = correct_href($field_val);
  864.                 }
  865.  
  866.                 if( $validation == "numeric" )
  867.                 {
  868.                     $field_val = correct_numeric($field_val);
  869.                 }
  870.  
  871.                 if( $validation == "price" && $field_type == "price" )
  872.                 {
  873.                     $f = new fields($this->type);
  874.                     if( $f->fieldsetHasPrice($set) )
  875.                     {
  876.                         if( $field_val )
  877.                         {
  878.                             if( $field_val < 0 )
  879.                             {
  880.                                 $field_val = 0;
  881.                             }
  882.  
  883.                             $field_val = correct_price($field_val);
  884.                         }
  885.                         else
  886.                         {
  887.                             $field_val = "-1";
  888.                         }
  889.  
  890.                     }
  891.                     else
  892.                     {
  893.                         $field_val = "-1";
  894.                     }
  895.  
  896.                 }
  897.  
  898.                 if( !$this->edit || $field_val || $this->edit && $field_type != "image" && $field_type != "file" )
  899.                 {
  900.                     if( !$array_format )
  901.                     {
  902.                         if( $field_val || $field_type == "checkbox" && $field_val == 0 )
  903.                         {
  904.                             $sql .= "" . ", `" . $caption . "` = '" . $field_val . "'";
  905.                         }
  906.                         else
  907.                         {
  908.                             if( $fields[$i]["default_val"] )
  909.                             {
  910.                                 $sql .= "" . ", `" . $caption . "` = '" . $fields[$i]["default_val"] . "'";
  911.                             }
  912.                             else
  913.                             {
  914.                                 $sql .= "" . ", `" . $caption . "` = null";
  915.                             }
  916.  
  917.                         }
  918.  
  919.                     }
  920.                     else
  921.                     {
  922.                         if( $field_val || $field_type == "checkbox" && $field_val == 0 )
  923.                         {
  924.                             $return_array[$caption] = $field_val;
  925.                         }
  926.                         else
  927.                         {
  928.                             if( $fields[$i]["default_val"] )
  929.                             {
  930.                                 $return_array[$caption] = $fields[$i]["default_val"];
  931.                             }
  932.                             else
  933.                             {
  934.                                 $return_array[$caption] = null;
  935.                             }
  936.  
  937.                         }
  938.  
  939.                     }
  940.  
  941.                 }
  942.  
  943.             }
  944.  
  945.             if( $this->type == "uf" && $fields[$i]["public"] == 2 )
  946.             {
  947.                 $array_uc = array( "textbox", "textarea", "htmlarea", "menu", "url", "email", "phone", "date" );
  948.                 if( in_array($field_type, $array_uc) )
  949.                 {
  950.                     $uc_field_val = checkbox_value("pb_" . $caption);
  951.                     $sql .= ", `pb_" . $caption . "` = '" . $uc_field_val . "'";
  952.                 }
  953.  
  954.             }
  955.  
  956.         }
  957.         if( !$array_format )
  958.         {
  959.             return $sql;
  960.         }
  961.  
  962.         return $return_array;
  963.     }
  964.  
  965.     public function usernameEditable()
  966.     {
  967.         global $db;
  968.         $editable = $db->fetchRow("select `editable` from " . $this->table . " where `caption` like 'username'");
  969.         return $editable;
  970.     }
  971.  
  972.     public function emailEditable()
  973.     {
  974.         global $db;
  975.         $editable = $db->fetchRow("select `editable` from " . $this->table . " where `caption` like 'email'");
  976.         return $editable;
  977.     }
  978.  
  979.     public function validateUniqueField($caption)
  980.     {
  981.         global $db;
  982.         if( !isset($_POST[$caption]) || !$_POST[$caption] )
  983.         {
  984.             return 1;
  985.         }
  986.  
  987.         $val = escape($_POST[$caption]);
  988.         if( $this->type == "cf" )
  989.         {
  990.             $tbl = TABLE_ADS;
  991.         }
  992.         else
  993.         {
  994.             $tbl = TABLE_USERS;
  995.         }
  996.  
  997.         $edit_str = "";
  998.         if( $this->edit )
  999.         {
  1000.             $edit_str = "" . " and `id` != '" . $this->obj_id . "' ";
  1001.         }
  1002.  
  1003.         $no = $db->fetchRow("select count(*) from " . $tbl . "" . " where `" . $caption . "` like '" . $val . "'" . $edit_str);
  1004.         if( $no )
  1005.         {
  1006.             return 0;
  1007.         }
  1008.  
  1009.         return 1;
  1010.     }
  1011.  
  1012. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement