Ejemplo n.º 1
0
 public function add($nom)
 {
     $this->nom = $nom;
     $this->unite = 0;
     $this->id = parent::add();
     redirige("zone.php?id=" . $this->id . "&action=showZone#zone");
 }
Ejemplo n.º 2
0
 /**
  * @param SimpleXMLElement $xml
  * @return bool
  * @throws PrestaShopException
  */
 protected function _installStates($xml)
 {
     if (isset($xml->states->state)) {
         foreach ($xml->states->state as $data) {
             /** @var SimpleXMLElement $data */
             $attributes = $data->attributes();
             $id_country = $attributes['country'] ? (int) Country::getByIso(strval($attributes['country'])) : false;
             $id_state = $id_country ? State::getIdByIso($attributes['iso_code'], $id_country) : State::getIdByName($attributes['name']);
             if (!$id_state) {
                 $state = new State();
                 $state->name = strval($attributes['name']);
                 $state->iso_code = strval($attributes['iso_code']);
                 $state->id_country = $id_country;
                 $id_zone = (int) Zone::getIdByName(strval($attributes['zone']));
                 if (!$id_zone) {
                     $zone = new Zone();
                     $zone->name = (string) $attributes['zone'];
                     $zone->active = true;
                     if (!$zone->add()) {
                         $this->_errors[] = Tools::displayError('Invalid Zone name.');
                         return false;
                     }
                     $id_zone = $zone->id;
                 }
                 $state->id_zone = $id_zone;
                 if (!$state->validateFields()) {
                     $this->_errors[] = Tools::displayError('Invalid state properties.');
                     return false;
                 }
                 $country = new Country($state->id_country);
                 if (!$country->contains_states) {
                     $country->contains_states = 1;
                     if (!$country->update()) {
                         $this->_errors[] = Tools::displayError('Cannot update the associated country: ') . $country->name;
                     }
                 }
                 if (!$state->add()) {
                     $this->_errors[] = Tools::displayError('An error occurred while adding the state.');
                     return false;
                 }
             } else {
                 $state = new State($id_state);
                 if (!Validate::isLoadedObject($state)) {
                     $this->_errors[] = Tools::displayError('An error occurred while fetching the state.');
                     return false;
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 3
0
/*                                                                                   */
/*      You should have received a copy of the GNU General Public License            */
/*      along with this program.  If not, see <http://www.gnu.org/licenses/>.        */
/*                                                                                   */
/*************************************************************************************/
require_once "pre.php";
require_once "auth.php";
if (!est_autorise("acces_configuration")) {
    exit;
}
require_once "../fonctions/divers.php";
require_once "liste/zone.php";
if ($_POST['action'] == "ajouter" && $_POST['nomzone'] != "") {
    $zone = new Zone();
    $zone->nom = $_POST['nomzone'];
    $id = $zone->add();
} else {
    if ($_GET['action'] == "supprimer" && $_GET['id'] != "") {
        $zone = new Zone();
        $pays = new Pays();
        $query = "update {$pays->table} set zone=\"-1\" where zone=\"" . $_GET['id'] . "\"";
        $resul = mysql_query($query, $pays->link);
        $zone->charger($_GET['id']);
        $zone->delete();
    }
}
if ($_REQUEST['id'] != "") {
    $id = $_REQUEST['id'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 protected function importZones()
 {
     $this->truncateTables(array('zone', 'zone_shop'));
     $handle = $this->openCsvFile('zones.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('Zone', $this->zones_fields, $line);
         if (!isset($fields['id_zone'])) {
             $zone = new Zone($line[0]);
             $zone->id = $line[0];
         } else {
             $zone = new Zone($fields['id_zone']);
         }
         foreach ($fields as $key => $field) {
             $zone->{$key} = $field;
         }
         $zone->force_id = true;
         if (!$res) {
             $res = $zone->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }