Esempio n. 1
0
        /**
         * Return an array with all data necessary for do the action (ADD OR EDIT)
         * @param <type> $is_add
         * @return array
         */
        public function prepareData( $is_add )
        {
            $aItem = array();
            $data = array();

            $userId = null;
            if( $this->is_admin ) {
                // user
                $data   = User::newInstance()->findByEmail(Params::getParam('contactEmail'));
                if( isset($data['pk_i_id']) && is_numeric($data['pk_i_id']) ) {
                    $userId = $data['pk_i_id'];
                }
            } else {
                $userId = Session::newInstance()->_get('userId');
                if( $userId == '' ) {
                    $userId = NULL;
                } elseif ($userId != NULL) {
                    $data   = User::newInstance()->findByPrimaryKey( $userId );
                }
            }

            if( $userId != null ) {
                $aItem['contactName']   = $data['s_name'];
                $aItem['contactEmail']  = $data['s_email'];
                Params::setParam('contactName', $data['s_name']);
                Params::setParam('contactEmail', $data['s_email']);
            } else {
                $aItem['contactName']   = Params::getParam('contactName');
                $aItem['contactEmail']  = Params::getParam('contactEmail');
            }
            $aItem['userId']        = $userId;

            if( $is_add ) {   // ADD
                if($this->is_admin) {
                    $active = 'ACTIVE';
                } else {
                    if(osc_moderate_items()>0) { // HAS TO VALIDATE
                        if(!osc_is_web_user_logged_in()) { // NO USER IS LOGGED, VALIDATE
                            $active = 'INACTIVE';
                        } else { // USER IS LOGGED
                            if(osc_logged_user_item_validation()) { //USER IS LOGGED, BUT NO NEED TO VALIDATE
                                $active = 'ACTIVE';
                            } else { // USER IS LOGGED, NEED TO VALIDATE, CHECK NUMBER OF PREVIOUS ITEMS
                                $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id());
                                if($user['i_items']<osc_moderate_items()) {
                                    $active = 'INACTIVE';
                                } else {
                                    $active = 'ACTIVE';
                                }
                            }
                        }
                    } else if(osc_moderate_items()==0 ){
                        if(osc_is_web_user_logged_in() && osc_logged_user_item_validation() ) {
                            $active = 'ACTIVE';
                        } else {
                            $active = 'INACTIVE';
                        }
                    } else {
                        $active = 'ACTIVE';
                    }
                }
                $aItem['active']        = $active;
            } else {          // EDIT
                $aItem['secret']    = Params::getParam('secret');
                $aItem['idItem']    = Params::getParam('id');
            }

            // get params
            $aItem['catId']         = Params::getParam('catId');
            $aItem['countryId']     = Params::getParam('countryId');
            $aItem['country']       = Params::getParam('country');
            $aItem['region']        = Params::getParam('region');
            $aItem['regionId']      = Params::getParam('regionId');
            $aItem['city']          = Params::getParam('city');
            $aItem['cityId']        = Params::getParam('cityId');
            $aItem['price']         = (Params::getParam('price') != '') ? Params::getParam('price') : null;
            $aItem['cityArea']      = Params::getParam('cityArea');
            $aItem['address']       = Params::getParam('address');
            $aItem['currency']      = Params::getParam('currency');
            $aItem['showEmail']     = (Params::getParam('showEmail') != '') ? 1 : 0;
            $aItem['title']         = Params::getParam('title');
            $aItem['description']   = Params::getParam('description');
            $aItem['photos']        = Params::getFiles('photos');
            $ajax_photos            = Params::getParam('ajax_photos');
            $aItem['s_ip']          = get_ip();
            $aItem['d_coord_lat']   = (Params::getParam('d_coord_lat')  != '') ? Params::getParam('d_coord_lat') : null;
            $aItem['d_coord_long']  = (Params::getParam('d_coord_long') != '') ? Params::getParam('d_coord_long') : null;
            $aItem['s_zip']         = (Params::getParam('zip')  != '') ? Params::getParam('zip') : null;

            // $ajax_photos is an array of filenames of the photos uploaded by ajax to a temporary folder
            // fake insert them into the array of the form-uploaded photos
            if(is_array($ajax_photos)) {
                foreach($ajax_photos as $photo) {
                    if(file_exists(osc_content_path().'uploads/temp/'.$photo)) {
                        $aItem['photos']['name'][]      = $photo;
                        $aItem['photos']['type'][]      = 'image/*';
                        $aItem['photos']['tmp_name'][]  = osc_content_path().'uploads/temp/'.$photo;
                        $aItem['photos']['error'][]     = UPLOAD_ERR_OK;
                        $aItem['photos']['size'][]      = 0;
                    }
                }
            }

            if($is_add || $this->is_admin) {
                $dt_expiration = Params::getParam('dt_expiration');
                if($dt_expiration==-1) {
                    $aItem['dt_expiration'] = '';
                } else if($dt_expiration!='' && (preg_match('|^([0-9]+)$|', $dt_expiration, $match) || preg_match('|([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})|', $dt_expiration, $match))) {
                    $aItem['dt_expiration'] = $dt_expiration;
                } else {
                    $_category = Category::newInstance()->findByPrimaryKey($aItem['catId']);
                    $aItem['dt_expiration'] = $_category['i_expiration_days'];
                }
                unset($dt_expiration);
            } else {
                $aItem['dt_expiration'] = '';
            };

            // check params
            $country = Country::newInstance()->findByCode($aItem['countryId']);
            if( count($country) > 0 ) {
                $countryId = $country['pk_c_code'];
                $countryName = $country['s_name'];
            } else {
                $countryId = null;
                $countryName = $aItem['country'];
            }
            $aItem['countryId']   = $countryId;
            $aItem['countryName']   = $countryName;

            if( $aItem['regionId'] != '' ) {
                if( intval($aItem['regionId']) ) {
                    $region = Region::newInstance()->findByPrimaryKey($aItem['regionId']);
                    if( count($region) > 0 ) {
                        $regionId = $region['pk_i_id'];
                        $regionName = $region['s_name'];
                    }
                }
            } else {
                $regionId = null;
                $regionName = $aItem['region'];
                if( $aItem['countryId'] != '' ) {
                    $auxRegion  = Region::newInstance()->findByName($aItem['region'], $aItem['countryId'] );
                    if($auxRegion){
                        $regionId   = $auxRegion['pk_i_id'];
                        $regionName = $auxRegion['s_name'];
                    }
                }
            }

            $aItem['regionId']      = $regionId;
            $aItem['regionName']    = $regionName;

            if( $aItem['cityId'] != '' ) {
                if( intval($aItem['cityId']) ) {
                    $city = City::newInstance()->findByPrimaryKey($aItem['cityId']);
                    if( count($city) > 0 ) {
                        $cityId = $city['pk_i_id'];
                        $cityName = $city['s_name'];
                    }
                }
            } else {
                $cityId = null;
                $cityName = $aItem['city'];
                if( $aItem['countryId'] != '' ) {
                    $auxCity = City::newInstance()->findByName($aItem['city'], $aItem['regionId'] );
                    if($auxCity){
                        $cityId   = $auxCity['pk_i_id'];
                        $cityName = $auxCity['s_name'];
                    }
                }
            }

            $aItem['cityId']      = $cityId;
            $aItem['cityName']    = $cityName;

            if( $aItem['cityArea'] == '' ) {
                $aItem['cityArea'] = null;
            }

            if( $aItem['address'] == '' ) {
                $aItem['address'] = null;
            }

            if( !is_null($aItem['price']) ) {
                $price = str_replace(osc_locale_thousands_sep(), '', trim($aItem['price']));
                $price = str_replace(osc_locale_dec_point(), '.', $price);
                $aItem['price'] = $price*1000000;
                //$aItem['price'] = (float) $aItem['price'];
            }

            if( $aItem['catId'] == ''){
                $aItem['catId'] = 0;
            }

            if( $aItem['currency'] == '' ) {
                $aItem['currency'] = null;
            }

            $this->data = $aItem;
        }
Esempio n. 2
0
                                </div>
                                <div class="separate-top-medium">
                                    <label>
                                        <input type="checkbox" <?php 
echo osc_moderate_items() == -1 ? '' : 'checked="checked"';
?>
 name="moderate_items" value="1" />
                                        <?php 
_e('Users have to validate their listings');
?>
                                    </label>
                                </div>
                                <div class="num-moderated-items" >
                                    <div>
                                        <?php 
printf(__("After %s validated listings the user doesn't need to validate the listings any more"), '<input type="text" class="input-small" name="num_moderate_items" value="' . (osc_moderate_items() == -1 ? '' : osc_moderate_items()) . '" />');
?>
                                        <div class="help-box">
                                            <?php 
_e('If the value is zero, it means that each listing must be validated');
?>
                                        </div>
                                    </div>
                                    <div class="separate-top-medium">
                                        <label>
                                            <input type="checkbox" <?php 
echo osc_logged_user_item_validation() ? 'checked="checked"' : '';
?>
 name="logged_user_item_validation" value="1" />
                                            <?php 
_e("Logged in users don't need to validate their listings");
Esempio n. 3
0
 /**
  * Return an array with all data necessary for do the action (ADD OR EDIT)
  * @param <type> $is_add
  * @return array
  */
 public function prepareData($is_add)
 {
     $aItem = array();
     // prepare user
     $userId = null;
     if ($this->is_admin) {
         if (Params::getParam('userId') != '') {
             $userId = Params::getParam('userId');
         }
     } else {
         $userId = Session::newInstance()->_get('userId');
         if ($userId == '') {
             $userId = NULL;
         }
     }
     if ($is_add) {
         // ADD
         if ($this->is_admin) {
             $active = 'ACTIVE';
         } else {
             if (osc_moderate_items() > 0) {
                 // HAS TO VALIDATE
                 if (!osc_is_web_user_logged_in()) {
                     // NO USER IS LOGGED, VALIDATE
                     $active = 'INACTIVE';
                 } else {
                     // USER IS LOGGED
                     if (osc_logged_user_item_validation()) {
                         //USER IS LOGGED, BUT NO NEED TO VALIDATE
                         $active = 'ACTIVE';
                     } else {
                         // USER IS LOGGED, NEED TO VALIDATE, CHECK NUMBER OF PREVIOUS ITEMS
                         $user = User::newInstance()->findByPrimaryKey(osc_logged_user_id());
                         if ($user['i_items'] < osc_moderate_items()) {
                             $active = 'INACTIVE';
                         } else {
                             $active = 'ACTIVE';
                         }
                     }
                 }
             } else {
                 if (osc_moderate_items() == 0) {
                     if (osc_is_web_user_logged_in() && osc_logged_user_item_validation()) {
                         $active = 'ACTIVE';
                     } else {
                         $active = 'INACTIVE';
                     }
                 } else {
                     $active = 'ACTIVE';
                 }
             }
         }
         if ($userId != null) {
             $data = User::newInstance()->findByPrimaryKey($userId);
             $aItem['contactName'] = $data['s_name'];
             $aItem['contactEmail'] = $data['s_email'];
             Params::setParam('contactName', $data['s_name']);
             Params::setParam('contactEmail', $data['s_email']);
         } else {
             $aItem['contactName'] = Params::getParam('contactName');
             $aItem['contactEmail'] = Params::getParam('contactEmail');
         }
         $aItem['active'] = $active;
         $aItem['userId'] = $userId;
     } else {
         // EDIT
         $aItem['secret'] = Params::getParam('secret');
         $aItem['idItem'] = Params::getParam('id');
         if ($userId != null) {
             $data = User::newInstance()->findByPrimaryKey($userId);
             $aItem['contactName'] = $data['s_name'];
             $aItem['contactEmail'] = $data['s_email'];
             Params::setParam('contactName', $data['s_name']);
             Params::setParam('contactEmail', $data['s_email']);
         } else {
             $aItem['contactName'] = Params::getParam('contactName');
             $aItem['contactEmail'] = Params::getParam('contactEmail');
         }
         $aItem['userId'] = $userId;
     }
     // get params
     $aItem['catId'] = Params::getParam('catId');
     $aItem['countryId'] = Params::getParam('countryId');
     $aItem['country'] = Params::getParam('country');
     $aItem['region'] = Params::getParam('region');
     $aItem['regionId'] = Params::getParam('regionId');
     $aItem['city'] = Params::getParam('city');
     $aItem['cityId'] = Params::getParam('cityId');
     $aItem['price'] = Params::getParam('price') != '' ? Params::getParam('price') : null;
     $aItem['cityArea'] = Params::getParam('cityArea');
     $aItem['address'] = Params::getParam('address');
     $aItem['currency'] = Params::getParam('currency');
     $aItem['showEmail'] = Params::getParam('showEmail') != '' ? 1 : 0;
     $aItem['title'] = Params::getParam('title');
     $aItem['description'] = Params::getParam('description');
     $aItem['photos'] = Params::getFiles('photos');
     // check params
     $country = Country::newInstance()->findByCode($aItem['countryId']);
     if (count($country) > 0) {
         $countryId = $country['pk_c_code'];
         $countryName = $country['s_name'];
     } else {
         $countryId = null;
         $countryName = $aItem['country'];
     }
     $aItem['countryId'] = $countryId;
     $aItem['countryName'] = $countryName;
     if ($aItem['regionId'] != '') {
         if (intval($aItem['regionId'])) {
             $region = Region::newInstance()->findByPrimaryKey($aItem['regionId']);
             if (count($region) > 0) {
                 $regionId = $region['pk_i_id'];
                 $regionName = $region['s_name'];
             }
         }
     } else {
         $regionId = null;
         $regionName = $aItem['region'];
         if ($aItem['countryId'] != '') {
             $auxRegion = Region::newInstance()->findByName($aItem['region'], $aItem['countryId']);
             if ($auxRegion) {
                 $regionId = $auxRegion['pk_i_id'];
                 $regionName = $auxRegion['s_name'];
             }
         }
     }
     $aItem['regionId'] = $regionId;
     $aItem['regionName'] = $regionName;
     if ($aItem['cityId'] != '') {
         if (intval($aItem['cityId'])) {
             $city = City::newInstance()->findByPrimaryKey($aItem['cityId']);
             if (count($city) > 0) {
                 $cityId = $city['pk_i_id'];
                 $cityName = $city['s_name'];
             }
         }
     } else {
         $cityId = null;
         $cityName = $aItem['city'];
         if ($aItem['countryId'] != '') {
             $auxCity = City::newInstance()->findByName($aItem['city'], $aItem['regionId']);
             if ($auxCity) {
                 $cityId = $auxCity['pk_i_id'];
                 $cityName = $auxCity['s_name'];
             }
         }
     }
     $aItem['cityId'] = $cityId;
     $aItem['cityName'] = $cityName;
     if ($aItem['cityArea'] == '') {
         $aItem['cityArea'] = null;
     }
     if ($aItem['address'] == '') {
         $aItem['address'] = null;
     }
     if (!is_null($aItem['price'])) {
         $price = str_replace(osc_locale_thousands_sep(), '', trim($aItem['price']));
         $price = str_replace(osc_locale_dec_point(), '.', $price);
         $aItem['price'] = $price * 1000000;
         //$aItem['price'] = (float) $aItem['price'];
     }
     if ($aItem['catId'] == '') {
         $aItem['catId'] = 0;
     }
     if ($aItem['currency'] == '') {
         $aItem['currency'] = null;
     }
     $this->data = $aItem;
 }
Esempio n. 4
0
?>
                                        <span class="help-box">
                                            <?php 
_e('If the value is zero, it means that each item must be validated');
?>
                                        </span>
                                    </td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td>
                                        <input type="checkbox" <?php 
echo osc_logged_user_item_validation() ? 'checked="true"' : '';
?>
 name="logged_user_item_validation" value="1" <?php 
echo osc_moderate_items() != -1 ? '' : 'disabled';
?>
 />
                                        <?php 
_e("Logged in users don't need to validate their items");
?>
                                    </td>
                                </tr>
                                <tr>
                                    <td></td>
                                    <td>
                                        <input type="checkbox" <?php 
echo osc_recaptcha_items_enabled() == '0' ? '' : 'checked="true"';
?>
 name="enabled_recaptcha_items" value="1" />
                                        <?php