Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.61 KB | None | 0 0
  1. <?php if ( ! defined('ABS_PATH')) exit('ABS_PATH is not loaded. Direct access is not allowed.');
  2.  
  3.     /*
  4.      *      Osclass – software for creating and publishing online classified
  5.      *                           advertising platforms
  6.      *
  7.      *                        Copyright (C) 2012 OSCLASS
  8.      *
  9.      *       This program is free software: you can redistribute it and/or
  10.      *     modify it under the terms of the GNU Affero General Public License
  11.      *     as published by the Free Software Foundation, either version 3 of
  12.      *            the License, or (at your option) any later version.
  13.      *
  14.      *     This program is distributed in the hope that it will be useful, but
  15.      *         WITHOUT ANY WARRANTY; without even the implied warranty of
  16.      *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.      *             GNU Affero General Public License for more details.
  18.      *
  19.      *      You should have received a copy of the GNU Affero General Public
  20.      * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21.      */
  22.  
  23.     class UserForm extends Form {
  24.  
  25.         static public function primary_input_hidden($user) {
  26.             parent::generic_input_hidden("id", (isset($user["pk_i_id"]) ? $user['pk_i_id'] : '') );
  27.         }
  28.  
  29.         static public function name_text($user = null) {
  30.             parent::generic_input_text("s_name", isset($user['s_name'])? $user['s_name'] : '', null, false);
  31.         }
  32.  
  33.         static public function username_text($user = null) {
  34.             parent::generic_input_text("s_username", isset($user['s_username'])? $user['s_username'] : '', null, false);
  35.         }
  36.  
  37.         static public function email_login_text($user = null) {
  38.             parent::generic_input_text("email", isset($user['s_email'])? $user['s_email'] : '', null, false);
  39.         }
  40.  
  41.         static public function password_login_text($user = null) {
  42.             parent::generic_password("password", '', null, false);
  43.         }
  44.  
  45.         static public function rememberme_login_checkbox($user = null) {
  46.             parent::generic_input_checkbox("remember", '1', false);
  47.         }
  48.  
  49.         static public function old_password_text($user = null) {
  50.             parent::generic_password("old_password", '', null, false);
  51.         }
  52.  
  53.         static public function password_text($user = null) {
  54.             parent::generic_password("s_password", '', null, false);
  55.         }
  56.  
  57.         static public function check_password_text($user = null) {
  58.             parent::generic_password("s_password2", '', null, false);
  59.         }
  60.  
  61.         static public function email_text($user = null) {
  62.             parent::generic_input_text("s_email", isset($user['s_email'])? $user['s_email'] : '', null, false);
  63.         }
  64.  
  65.         static public function website_text($user = null) {
  66.             parent::generic_input_text("s_website", isset($user['s_website'])? $user['s_website'] : '', null, false);
  67.         }
  68.  
  69.         static public function mobile_text($user = null) {
  70.             parent::generic_input_text("s_phone_mobile", isset($user['s_phone_mobile'])? $user['s_phone_mobile'] : '', null, false);
  71.         }
  72.  
  73.         static public function phone_land_text($user = null) {
  74.             parent::generic_input_text("s_phone_land", isset($user['s_phone_land'])? $user['s_phone_land'] : '', null, false);
  75.         }
  76.  
  77.         static public function info_textarea($name, $locale = 'en_US', $value = '') {
  78.             parent::generic_textarea($name . '[' . $locale . ']', $value);
  79.         }
  80.  
  81.         static public function multilanguage_info($locales, $user = null) {
  82.             $num_locales = count($locales);
  83.             if($num_locales > 1) { echo '<div class="tabber">'; }
  84.             foreach($locales as $locale) {
  85.                 if($num_locales>1) { echo '<div class="tabbertab">'; };
  86.                     if($num_locales > 1) { echo '<h2>' . $locale['s_name'] . '</h2>'; }
  87.                     $info = '';
  88.                     if( is_array($user) ) {
  89.                         if( isset($user['locale'][$locale['pk_c_code']])) {
  90.                             if(isset($user['locale'][$locale['pk_c_code']]['s_info'])) {
  91.                                 $info = $user['locale'][$locale['pk_c_code']]['s_info'];
  92.                             }
  93.                         }
  94.                     }
  95.                     self::info_textarea('s_info', $locale['pk_c_code'], $info);
  96.                 if($num_locales>1) { echo '</div>'; };
  97.             }
  98.             if($num_locales>1) { echo '</div>'; };
  99.         }
  100.  
  101.         static public function country_select($countries, $user = null) {
  102.             if( count($countries) >= 1 ) {
  103.                 parent::generic_select('countryId', $countries, 'pk_c_code', 's_name', __('Select a country...'), (isset($user['fk_c_country_code'])) ? $user['fk_c_country_code'] : null);
  104.             } else {
  105.                 parent::generic_input_text('country', (isset($user['s_country'])) ? $user['s_country'] : null);
  106.             }
  107.         }
  108.  
  109.         static public function country_text($user = null) {
  110.             parent::generic_input_text('country', (isset($user['s_country'])) ? $user['s_country'] : null);
  111.         }
  112.  
  113.         static public function region_select($regions, $user = null) {
  114.             if( count($regions) >= 1 ) {
  115.                 parent::generic_select('regionId', $regions, 'pk_i_id', 's_name', __('Select a region...'), (isset($user['fk_i_region_id'])) ? $user['fk_i_region_id'] : null);
  116.             } else {
  117.                 parent::generic_input_text('region', (isset($user['s_region'])) ? $user['s_region'] : null);
  118.             }
  119.         }
  120.  
  121.         static public function region_text($user = null) {
  122.             parent::generic_input_text('region', (isset($user['s_region'])) ? $user['s_region'] : null);
  123.         }
  124.  
  125.         static public function city_select($cities, $user = null) {
  126.             if( count($cities) >= 1 ) {
  127.                 parent::generic_select('cityId', $cities, 'pk_i_id', 's_name', __('Select a city...'), (isset($user['fk_i_city_id'])) ? $user['fk_i_city_id'] : null);
  128.             } else {
  129.                 parent::generic_input_text('city', (isset($user['s_city'])) ? $user['s_city'] : null);
  130.             }
  131.         }
  132.  
  133.         static public function city_text($user = null) {
  134.             parent::generic_input_text('city', (isset($user['s_city'])) ? $user['s_city'] : null);
  135.         }
  136.  
  137.         static public function city_area_text($user = null) {
  138.             parent::generic_input_text('cityArea', (isset($user['s_city_area'])) ? $user['s_city_area'] : null);
  139.         }
  140.  
  141.         static public function address_text($user = null) {
  142.             parent::generic_input_text('address', (isset($user['s_address'])) ? $user['s_address'] : null);
  143.         }
  144.  
  145.         static public function zip_text($user = null) {
  146.             parent::generic_input_text('zip', (isset($user['s_zip'])) ? $user['s_zip'] : null);
  147.         }
  148.  
  149.         static public function is_company_select($user = null) {
  150.             $options = array(
  151.                 array( 'i_value' => '0', 's_text' => __('User') )
  152.                 ,array( 'i_value' => '1', 's_text' => __('Company') )
  153.             );
  154.  
  155.             parent::generic_select( 'b_company', $options, 'i_value', 's_text', null, (isset($user['b_company'])) ? $user['b_company'] : null );
  156.         }
  157.  
  158.         static public function user_select($users){
  159.             Form::generic_select('userId', $users, 'pk_i_id', 's_name',  __('All') , NULL );
  160.         }
  161.  
  162.         static public function js_validation() {
  163. ?>
  164. <script type="text/javascript">
  165.     $(document).ready(function(){
  166.         // Code for form validation
  167.         $("form[name=register]").validate({
  168.             rules: {
  169.                 s_name: {
  170.                     required: true
  171.                 },
  172.                 s_email: {
  173.                     required: true,
  174.                     email: true
  175.                 },
  176.                 s_password: {
  177.                     required: true,
  178.                     minlength: 5
  179.                 },
  180.                 s_password2: {
  181.                     required: true,
  182.                     minlength: 5,
  183.                     equalTo: "#s_password"
  184.                 }
  185.             },
  186.             messages: {
  187.                 s_name: {
  188.                     required: "<?php _e("Name: this field is required"); ?>."
  189.                 },
  190.                 s_email: {
  191.                     required: "<?php _e("Email: this field is required"); ?>.",
  192.                     email: "<?php _e("Invalid email address"); ?>."
  193.                 },
  194.                 s_password: {
  195.                     required: "<?php _e("Password: this field is required"); ?>.",
  196.                     minlength: "<?php _e("Password: enter at least 5 characters"); ?>."
  197.                 },
  198.                 s_password2: {
  199.                     required: "<?php _e("Second password: this field is required"); ?>.",
  200.                     minlength: "<?php _e("Second password: enter at least 5 characters"); ?>.",
  201.                     equalTo: "<?php _e("Passwords don't match"); ?>."
  202.                 }
  203.             },
  204.             errorLabelContainer: "#error_list",
  205.             wrapper: "li",
  206.             invalidHandler: function(form, validator) {
  207.                 $('html,body').animate({ scrollTop: $('h1').offset().top }, { duration: 250, easing: 'swing'});
  208.             },
  209.             submitHandler: function(form){
  210.                 $('button[type=submit], input[type=submit]').attr('disabled', 'disabled');
  211.                 form.submit();
  212.             }
  213.         });
  214.     });
  215. </script>
  216. <?php
  217.         }
  218.  
  219.         static public function js_validation_old() {
  220. ?>
  221. <script type="text/javascript">
  222. $(document).ready(function(){
  223.     $('#s_name').focus(function(){
  224.         $('#s_name').css('border', '');
  225.     });
  226.  
  227.     $('#s_email').focus(function(){
  228.         $('#s_email').css('border', '');
  229.     });
  230.  
  231.     $('#s_password').focus(function(){
  232.         $('#s_password').css('border', '');
  233.         $('#password-error').css('display', 'none');
  234.     });
  235.  
  236.     $('#s_password2').focus(function(){
  237.         $('#s_password2').css('border', '');
  238.         $('#password-error').css('display', 'none');
  239.     });
  240. });
  241.  
  242. function checkForm() {
  243.     var num_errors = 0;
  244.     if( $('#s_name').val() == '' ) {
  245.         $('#s_name').css('border', '1px solid red');
  246.         num_errors = num_errors + 1;
  247.     }
  248.     if( $('#s_email').val() == '' ) {
  249.         $('#s_email').css('border', '1px solid red');
  250.         num_errors = num_errors + 1;
  251.     }
  252.     if( $('#s_password').val() != $('#s_password2').val() ) {
  253.         $('#password-error').css('display', 'block');
  254.         num_errors = num_errors + 1;
  255.     }
  256.     if( $('#s_password').val() == '' ) {
  257.         $('#s_password').css('border', '1px solid red');
  258.         num_errors = num_errors + 1;
  259.     }
  260.     if( $('#s_password2').val() == '' ) {
  261.         $('#s_password2').css('border', '1px solid red');
  262.         num_errors = num_errors + 1;
  263.     }
  264.     if(num_errors > 0) {
  265.         return false;
  266.     }
  267.  
  268.     return true;
  269. }
  270. </script>
  271. <?php
  272.         }
  273.  
  274.         static public function js_validation_edit() {
  275. ?>
  276. <script type="text/javascript">
  277.     $(document).ready(function(){
  278.         // Code for form validation
  279.         $("form[name=register]").validate({
  280.             rules: {
  281.                 s_name: {
  282.                     required: true
  283.                 },
  284.                 s_email: {
  285.                     required: true,
  286.                     email: true
  287.                 },
  288.                 s_password: {
  289.                     minlength: 5
  290.                 },
  291.                 s_password2: {
  292.                     minlength: 5,
  293.                     equalTo: "#s_password"
  294.                 }
  295.             },
  296.             messages: {
  297.                 s_name: {
  298.                     required: "<?php _e("Name: this field is required"); ?>."
  299.                 },
  300.                 s_email: {
  301.                     required: "<?php _e("Email: this field is required"); ?>.",
  302.                     email: "<?php _e("Invalid email address"); ?>."
  303.                 },
  304.                 s_password: {
  305.                     minlength: "<?php _e("Password: enter at least 5 characters"); ?>."
  306.                 },
  307.                 s_password2: {
  308.                     minlength: "<?php _e("Second password: enter at least 5 characters"); ?>.",
  309.                     equalTo: "<?php _e("Passwords don't match"); ?>."
  310.                 }
  311.             },
  312.             errorLabelContainer: "#error_list",
  313.             wrapper: "li",
  314.             invalidHandler: function(form, validator) {
  315.                 $('html,body').animate({ scrollTop: $('h1').offset().top }, { duration: 250, easing: 'swing'});
  316.             },
  317.             submitHandler: function(form){
  318.                 $('button[type=submit], input[type=submit]').attr('disabled', 'disabled');
  319.                 form.submit();
  320.             }
  321.         });
  322.     });
  323. </script>
  324. <?php
  325.         }
  326.  
  327.         static public function location_javascript($path = 'front') {
  328. ?>
  329. <script type="text/javascript">
  330.     $(document).ready(function(){
  331.         $("#countryId").on("change",function(){
  332.             var pk_c_code = $(this).val();
  333.             <?php if($path=="admin") { ?>
  334.                 var url = '<?php echo osc_admin_base_url(true)."?page=ajax&action=regions&countryId="; ?>' + pk_c_code;
  335.             <?php } else { ?>
  336.                 var url = '<?php echo osc_base_url(true)."?page=ajax&action=regions&countryId="; ?>' + pk_c_code;
  337.             <?php }; ?>
  338.             var result = '';
  339.  
  340.             if(pk_c_code != '') {
  341.  
  342.                 $("#regionId").attr('disabled',false);
  343.                 $("#cityId").attr('disabled',true);
  344.                 $.ajax({
  345.                     type: "POST",
  346.                     url: url,
  347.                     dataType: 'json',
  348.                     success: function(data){
  349.                         var length = data.length;
  350.                         if(length > 0) {
  351.                             result += '<option value=""><?php _e("Select a region..."); ?></option>';
  352.                             for(key in data) {
  353.                                 result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
  354.                             }
  355.                             $("#region").before('<select name="regionId" id="regionId" ></select>');
  356.                             $("#region").remove();
  357.  
  358.                             $("#city").before('<select name="cityId" id="cityId" ></select>');
  359.                             $("#city").remove();
  360.  
  361.                         } else {
  362.                             result += '<option value=""><?php _e('No results') ?></option>';
  363.                             $("#regionId").before('<input type="text" name="region" id="region" />');
  364.                             $("#regionId").remove();
  365.  
  366.                             $("#cityId").before('<input type="text" name="city" id="city" />');
  367.                             $("#cityId").remove();
  368.                         }
  369.                         $("#regionId").html(result);
  370.                         $("#cityId").html('<option selected value=""><?php _e("Select a city..."); ?></option>');
  371.                     }
  372.                  });
  373.              } else {
  374.                  // add empty select
  375.                  $("#region").before('<select name="regionId" id="regionId" ><option value=""><?php _e("Select a region..."); ?></option></select>');
  376.                  $("#region").remove();
  377.  
  378.                  $("#city").before('<select name="cityId" id="cityId" ><option value=""><?php _e("Select a city..."); ?></option></select>');
  379.                  $("#city").remove();
  380.  
  381.                  if( $("#regionId").length > 0 ){
  382.                      $("#regionId").html('<option value=""><?php _e("Select a region..."); ?></option>');
  383.                  } else {
  384.                      $("#region").before('<select name="regionId" id="regionId" ><option value=""><?php _e("Select a region..."); ?></option></select>');
  385.                      $("#region").remove();
  386.                  }
  387.                  if( $("#cityId").length > 0 ){
  388.                      $("#cityId").html('<option value=""><?php _e("Select a city..."); ?></option>');
  389.                  } else {
  390.                      $("#city").before('<select name="cityId" id="cityId" ><option value=""><?php _e("Select a city..."); ?></option></select>');
  391.                      $("#city").remove();
  392.                  }
  393.  
  394.                 $("#regionId").attr('disabled',true);
  395.                 $("#cityId").attr('disabled',true);
  396.              }
  397.         });
  398.  
  399.         $("#regionId").on("change",function(){
  400.             var pk_c_code = $(this).val();
  401.             <?php if($path=="admin") { ?>
  402.                 var url = '<?php echo osc_admin_base_url(true)."?page=ajax&action=cities&regionId="; ?>' + pk_c_code;
  403.             <?php } else { ?>
  404.                 var url = '<?php echo osc_base_url(true)."?page=ajax&action=cities&regionId="; ?>' + pk_c_code;
  405.             <?php }; ?>
  406.  
  407.             var result = '';
  408.  
  409.             if(pk_c_code != '') {
  410.  
  411.                 $("#cityId").attr('disabled',false);
  412.                 $.ajax({
  413.                     type: "POST",
  414.                     url: url,
  415.                     dataType: 'json',
  416.                     success: function(data){
  417.                         var length = data.length;
  418.                         if(length > 0) {
  419.                             result += '<option selected value=""><?php _e("Select a city..."); ?></option>';
  420.                             for(key in data) {
  421.                                 result += '<option value="' + data[key].pk_i_id + '">' + data[key].s_name + '</option>';
  422.                             }
  423.                             $("#city").before('<select name="cityId" id="cityId" ></select>');
  424.                             $("#city").remove();
  425.                         } else {
  426.                             result += '<option value=""><?php _e('No results') ?></option>';
  427.                             $("#cityId").before('<input type="text" name="city" id="city" />');
  428.                             $("#cityId").remove();
  429.                         }
  430.                         $("#cityId").html(result);
  431.                     }
  432.                  });
  433.              } else {
  434.                 $("#cityId").attr('disabled',true);
  435.              }
  436.         });
  437.  
  438.  
  439.         if( $("#regionId").attr('value') == "") {
  440.             $("#cityId").attr('disabled',true);
  441.         }
  442.  
  443.         if( $("#countryId").prop('type').match(/select-one/) ) {
  444.             if( $("#countryId").attr('value') == "") {
  445.                 $("#regionId").attr('disabled',true);
  446.             }
  447.         }
  448.     });
  449. </script>
  450.     <?php
  451.         }
  452.     }
  453.  
  454.     /* file end: ./oc-includes/osclass/frm/User.form.class.php */
  455. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement